diff --git a/add.sql b/add.sql index 68fe42b..c28e966 100644 --- a/add.sql +++ b/add.sql @@ -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`; -- 已执行 2025-05-18 +ALTER TABLE `zy_circle` ADD COLUMN `top` int NOT NULL DEFAULT 0 COMMENT '置顶' AFTER `status`; +-- 已执行 2025-05-31 diff --git a/addons/shopro/controller/zy/Circle.php b/addons/shopro/controller/zy/Circle.php index a10fa5a..f919085 100644 --- a/addons/shopro/controller/zy/Circle.php +++ b/addons/shopro/controller/zy/Circle.php @@ -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); } }