feat(zy): 优化影圈审核功能并添加新功能
- 在 zy_circle 表中添加 top 字段,用于置顶影圈帖子 - 重构 Circle 控制器中的 approve 方法,支持批量审核影圈帖子 - 新增 delete 方法,支持批量删除影圈帖子 - 新增 top 方法,用于置顶影圈帖子 - 优化影圈帖子列表的排序逻辑,按置顶和创建时间排序
This commit is contained in:
@@ -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');
|
||||
$query->where('c.user_id', 'IN', $friend);
|
||||
}
|
||||
$query->order(['c.top' => 'desc', 'c.create_time' => 'desc']);
|
||||
$res = $query->paginate($params['pageSize'] ?? 10);
|
||||
$list = $res->items();
|
||||
foreach ($list as &$r) {
|
||||
@@ -208,35 +209,81 @@ class Circle extends Base
|
||||
public function approve()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$model = CircleModel::get($params['id'] ?? NULL);
|
||||
if (empty($model)) {
|
||||
$this->error(__('No rows were found'));
|
||||
$ids = explode(',', $params['ids'] ?? '');
|
||||
if (empty($ids) || empty($params['club_id'])) {
|
||||
$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) {
|
||||
$this->error('无权审核');
|
||||
}
|
||||
if ($model->status != 0) {
|
||||
$this->error('已审核');
|
||||
$models = CircleModel::where('id', 'IN', $ids)->where('club_id', $params['club_id'])->select();
|
||||
if (empty($models)) {
|
||||
$this->error('数据不存在');
|
||||
}
|
||||
if ($params['status'] != -1 && $params['status'] != 1) {
|
||||
$this->error('status:参数错误');
|
||||
Db::startTrans();
|
||||
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([ // 消息通知
|
||||
'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', count($models));
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user