feat(zy): 优化影圈审核功能并添加新功能

- 在 zy_circle 表中添加 top 字段,用于置顶影圈帖子
- 重构 Circle 控制器中的 approve 方法,支持批量审核影圈帖子
- 新增 delete 方法,支持批量删除影圈帖子
- 新增 top 方法,用于置顶影圈帖子
- 优化影圈帖子列表的排序逻辑,按置顶和创建时间排序
This commit is contained in:
2025-05-31 17:16:51 +08:00
parent be7ee40690
commit a44f364914
2 changed files with 71 additions and 22 deletions

View File

@@ -3,3 +3,5 @@ ALTER TABLE `zy_club` ADD COLUMN `contect` varchar(255) CHARACTER SET utf8mb4 CO
ALTER TABLE `zy_club` ADD COLUMN `attention` int(11) NOT NULL DEFAULT 0 COMMENT '关注人数' AFTER `contect`; ALTER TABLE `zy_club` ADD COLUMN `attention` int(11) NOT NULL DEFAULT 0 COMMENT '关注人数' AFTER `contect`;
-- 已执行 2025-05-18 -- 已执行 2025-05-18
ALTER TABLE `zy_circle` ADD COLUMN `top` int NOT NULL DEFAULT 0 COMMENT '置顶' AFTER `status`;
-- 已执行 2025-05-31

View File

@@ -60,6 +60,7 @@ class Circle extends Base
$friend = Relation::where('user_id', $this->auth->id)->where('status', 'IN', explode(',', $params['friend']))->column('target_id'); $friend = Relation::where('user_id', $this->auth->id)->where('status', 'IN', explode(',', $params['friend']))->column('target_id');
$query->where('c.user_id', 'IN', $friend); $query->where('c.user_id', 'IN', $friend);
} }
$query->order(['c.top' => 'desc', 'c.create_time' => 'desc']);
$res = $query->paginate($params['pageSize'] ?? 10); $res = $query->paginate($params['pageSize'] ?? 10);
$list = $res->items(); $list = $res->items();
foreach ($list as &$r) { foreach ($list as &$r) {
@@ -208,35 +209,81 @@ class Circle extends Base
public function approve() public function approve()
{ {
$params = $this->request->param(); $params = $this->request->param();
$model = CircleModel::get($params['id'] ?? NULL); $ids = explode(',', $params['ids'] ?? '');
if (empty($model)) { if (empty($ids) || empty($params['club_id'])) {
$this->error(__('No rows were found')); $this->error('参数错误');
} }
$member = Menber::get(['club_id' => $model->club_id, 'user_id' => $this->auth->id]); if (empty($params['status']) || ($params['status'] != -1 && $params['status'] != 1)) {
$this->error('status:参数错误');
}
$member = Menber::get(['club_id' => $params['club_id'], 'user_id' => $this->auth->id]);
if (empty($member) || $member->role < 2) { if (empty($member) || $member->role < 2) {
$this->error('无权审核'); $this->error('无权审核');
} }
if ($model->status != 0) { $models = CircleModel::where('id', 'IN', $ids)->where('club_id', $params['club_id'])->select();
$this->error('已审核'); if (empty($models)) {
$this->error('数据不存在');
} }
if ($params['status'] != -1 && $params['status'] != 1) { Db::startTrans();
$this->error('status:参数错误'); try {
foreach ($models as $model) {
if ($model->status != 0) {
throw new Exception($model->id . ' 此记录不在待审核状态');
}
$model->save(['status' => $params['status']]);
(new Message())->allowField(true)->save([ // 消息通知
'type' => 3,
'name' => '系统通知',
'avatar' => '',
'from_id' => 0,
'target_id' => $model->user_id,
'content' => json_encode([
'topic' => '影圈审核',
'result' => ($params['status'] == 1) ? '通过' : '不通过',
'circle_id' => $model->id
])
]);
}
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage());
} }
$model->save(['status' => $params['status']]);
(new Message())->allowField(true)->save([ // 消息通知 $this->success('Success', count($models));
'type' => 3, }
'name' => '系统通知',
'avatar' => '',
'from_id' => 0,
'target_id' => $model->user_id,
'content' => json_encode([
'topic' => '影圈审核',
'result' => ($params['status'] == 1) ? '通过' : '不通过',
'circle_id' => $model->id
])
]);
$this->success('Success'); public function delete()
{
$params = $this->request->param();
$ids = explode(',', $params['ids'] ?? '');
if (empty($ids) || empty($params['club_id'])) {
$this->error('参数错误');
}
$member = Menber::get(['club_id' => $params['club_id'], 'user_id' => $this->auth->id]);
if (empty($member) || $member->role < 2) {
$this->error('无权删除');
}
$result = CircleModel::where('id', 'IN', $ids)->where('club_id', $params['club_id'])->delete();
$this->success('Success', $result);
}
public function top()
{
$params = $this->request->param();
$model = CircleModel::get($params['id'] ?? null);
if (empty($model)) {
$this->error('数据不存在');
}
$member = Menber::get(['club_id' => $model['club_id'], 'user_id' => $this->auth->id]);
if (empty($member) || $member->role < 2) {
$this->error('无权操作');
}
$result = CircleModel::where('club_id', $model['club_id'])->column('max(top) as top');
$model->save(['top' => $result[0] + 1]);
$this->success('Success', $model);
} }
} }