From b7023e7ab30089295d9c781e9fbcad04f211d06d Mon Sep 17 00:00:00 2001 From: xiadc <251308692@qq.com> Date: Mon, 26 May 2025 11:03:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(zy):=20=E6=B7=BB=E5=8A=A0=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E9=80=9A=E7=9F=A5=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=B4=BB=E5=8A=A8=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Circle 控制器中添加点赞、评论和审核通知 - 在 Game 控制器中添加退坑、取消活动和发送消息功能 - 优化 Activity 控制器中的订单关联逻辑 - 更新语言包,添加新的活动状态翻译 --- addons/shopro/controller/zy/Activity.php | 2 +- addons/shopro/controller/zy/Circle.php | 50 +++++- addons/shopro/controller/zy/Game.php | 149 ++++++++++++++++++ addons/shopro/controller/zy/Sys.php | 42 ++++- addons/shopro/job/Test.php | 10 ++ application/admin/lang/zh-cn/zy/game/game.php | 1 + .../admin/lang/zh-cn/zy/game/game_join.php | 2 +- 7 files changed, 247 insertions(+), 9 deletions(-) diff --git a/addons/shopro/controller/zy/Activity.php b/addons/shopro/controller/zy/Activity.php index 57e16dc..da9d83f 100644 --- a/addons/shopro/controller/zy/Activity.php +++ b/addons/shopro/controller/zy/Activity.php @@ -169,7 +169,7 @@ class Activity extends Base 'act_id' => $game['act_id'], 'game_id' => $game['id'], 'user_id' => $this->auth->id, - 'orer_id' => $order['order_sn'], + 'orer_id' => $order['id'], 'status' => 1, 'users' => json_encode($params['users'] ?? []) ]); diff --git a/addons/shopro/controller/zy/Circle.php b/addons/shopro/controller/zy/Circle.php index ef5a9f6..a10fa5a 100644 --- a/addons/shopro/controller/zy/Circle.php +++ b/addons/shopro/controller/zy/Circle.php @@ -8,10 +8,11 @@ use app\admin\model\zy\Club; use app\admin\model\zy\Menber; use think\exception\PDOException; use app\admin\model\zy\circle\Likes; +use app\admin\model\zy\link\Message; +use app\admin\model\zy\link\Relation; +use app\admin\model\zy\circle\Comment; use think\exception\ValidateException; use app\admin\model\zy\circle\Circle as CircleModel; -use app\admin\model\zy\circle\Comment; -use app\admin\model\zy\link\Relation; class Circle extends Base { @@ -116,8 +117,8 @@ class Circle extends Base public function like() { $params = $this->request->param(); - $club = CircleModel::get($params['circle_id']); - if (empty($club)) { + $circle = CircleModel::get($params['circle_id']); + if (empty($circle)) { $this->error('数据不存在'); } $user = auth_user(); @@ -132,6 +133,18 @@ class Circle extends Base 'avatar' => $user['avatar'], 'gender' => $user['gender'], ]); + (new Message())->allowField(true)->save([ // 消息通知 + 'type' => 1, + 'name' => '互动消息', + 'avatar' => '', + 'from_id' => 0, + 'target_id' => $circle->user_id, + 'content' => json_encode([ + 'topic' => '点赞', + 'content' => $user['nickname'] . '点赞了你的帖子', + 'circle_id' => $circle->id + ]) + ]); } else { // 取消点赞 $like->delete(); } @@ -147,8 +160,8 @@ class Circle extends Base public function comment() { $params = $this->request->param(); - $club = CircleModel::get($params['circle_id']); - if (empty($club)) { + $circle = CircleModel::get($params['circle_id']); + if (empty($circle)) { $this->error('数据不存在'); } if (empty($params['content'])) { @@ -172,6 +185,18 @@ class Circle extends Base 'gender' => $user['gender'], 'content' => $params['content'], ]); + (new Message())->allowField(true)->save([ // 消息通知 + 'type' => 1, + 'name' => '互动消息', + 'avatar' => '', + 'from_id' => 0, + 'target_id' => $circle->user_id, + 'content' => json_encode([ + 'topic' => '评论', + 'content' => $user['nickname'] . '评论了你的帖子', + 'circle_id' => $circle->id + ]) + ]); Db::commit(); } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); @@ -199,6 +224,19 @@ class Circle extends Base } $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'); } } diff --git a/addons/shopro/controller/zy/Game.php b/addons/shopro/controller/zy/Game.php index bcf4d71..39c2433 100644 --- a/addons/shopro/controller/zy/Game.php +++ b/addons/shopro/controller/zy/Game.php @@ -5,12 +5,15 @@ namespace addons\shopro\controller\zy; use think\Db; use think\Exception; use app\admin\model\zy\Club; +use app\admin\model\zy\Menber; use app\admin\model\zy\Stadium; use think\exception\PDOException; +use app\admin\model\zy\link\Message; use app\admin\model\zy\game\GameJoin; use app\admin\model\zy\game\GameMatch; use think\exception\ValidateException; use app\admin\model\zy\game\Participant; +use addons\shopro\service\order\OrderRefund; class Game extends Base @@ -76,6 +79,125 @@ class Game extends Base $this->success('Success', $model); } + // 退坑 + public function quit() + { + $model = $this->model->get($this->request->param('id')); + if (empty($model)) { + $this->error(__('No rows were found')); + } + if ($model['status'] > 1) { + $this->error('活动已开始或结束,不能退出'); + } + if ($model['status'] == -1) { + $this->error('活动已取消'); + } + $join = GameJoin::where('user_id', $this->auth->id)->find(); + if (empty($join) || $join['status'] == -1) { + $this->error('未报名或已取消'); + } + if (date('Y-m-d H:i:s') >= $model['quit_time']) { + $this->error('已超过免费退出时间'); + } + Db::startTrans(); + try { + $join->save(['status' => -1]); + if ($join['status'] == 1) { + $order = $this->model->paid()->where('id', $join->order_id)->lock(true)->find(); + if (!$order) { + $this->error('订单不存在或不可退款'); + } + $orderRefund = new OrderRefund($order); + $orderRefund->fullRefund(NULL, [ + 'refund_type' => 'back', + 'remark' => '用户自行退出活动' + ]); + } + (new Message())->save([ + 'type' => 1, + 'name' => '系统消息', + 'avatar' => '', + 'from_id' => 0, + 'target_id' => $join->user_id, + 'content' => json_encode([ + 'topic' => '退出', + 'content' => '已退出 ' . $model['name'] . ' 活动', + 'game_id' => $model->id + ]) + ]); + + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + + $this->success('Success'); + } + + // 取消活动 + public function cancle() + { + $model = $this->model->get($this->request->param('id')); + if (empty($model)) { + $this->error(__('No rows were found')); + } + $member = Menber::get(['club_id' => $model->club_id, 'user_id' => $this->auth->id]); + if (empty($member) || $member->role < 2) { + $this->error('无权取消活动'); + } + if ($model['pid'] != 0) { + $this->error('不能取消子活动'); + } + if ($model['status'] > 1) { + $this->error('活动已开始或结束,不能取消'); + } + if ($model['status'] == -1) { + $this->error('活动已取消'); + } + Db::startTrans(); + try { + $model->save(['status' => -1]); + (new \app\admin\model\zy\game\Game)->where('pid', $model->id)->update(['status' => -1]); + //取消成功,进入退款流程并通知用户 + $join = GameJoin::where('game_id', $model['id'])->select(); + $msgs = []; + foreach ($join as $j) { + $j->save(['status' => -1]); + if ($j['status'] == 1) { + $order = $this->model->paid()->where('id', $j->order_id)->lock(true)->find(); + if (!$order) { + $this->error('订单不存在或不可退款'); + } + $orderRefund = new OrderRefund($order); + $orderRefund->fullRefund(NULL, [ + 'refund_type' => 'back', + 'remark' => '活动取消,全额退款' + ]); + } + $msgs[] = [ + 'type' => 1, + 'name' => '系统消息', + 'avatar' => '', + 'from_id' => 0, + 'target_id' => $j->user_id, + 'content' => json_encode([ + 'topic' => '评论', + 'content' => $model['name'] . ' 活动已取消', + 'game_id' => $model->id + ]) + ]; + } + + (new Message())->insertAll($msgs);; + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + + $this->success('Success'); + } public function getMacth() { @@ -138,4 +260,31 @@ class Game extends Base // print_r($res); $this->success('Success', $res); } + + public function describe() + { + $params = $this->request->param(); + Db::startTrans(); + try { + $game = $this->model->get($params['id'] ?? NULL); + if (empty($game)) { + $this->error('比赛不存在'); + } + $gameClass = 'format\\Game' . $game['team_type'] . $game['rule_type']; + if (!class_exists($gameClass)) { + throw new Exception("赛制文件不存在,请联系管理人员: {$gameClass}"); + } + $format = new $gameClass; + if (!$format instanceof \format\GameInterface) { + throw new Exception("赛制配置错误,请联系管理人员: {$gameClass}"); + } + $describe = $format->describe(); + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage(), $e); + } + + $this->success('Success', $describe); + } } diff --git a/addons/shopro/controller/zy/Sys.php b/addons/shopro/controller/zy/Sys.php index 44da8b4..1cfac86 100644 --- a/addons/shopro/controller/zy/Sys.php +++ b/addons/shopro/controller/zy/Sys.php @@ -6,6 +6,7 @@ use think\Db; use think\Exception; use app\admin\model\zy\Tags; use think\exception\PDOException; +use app\admin\model\zy\link\Message; use app\admin\model\shopro\user\User; use app\admin\model\zy\circle\Circle; use app\admin\model\zy\link\Complaint; @@ -50,7 +51,7 @@ class Sys extends Base $this->error('举报内容不能为空'); } $user = auth_user(); - $res = Complaint::get(['user_id' => $user['id'], 'target_id' => $params['target_id'], 'type' => $params['type'],'status' => 0]); + $res = Complaint::get(['user_id' => $user['id'], 'target_id' => $params['target_id'], 'type' => $params['type'], 'status' => 0]); if ($res) { $this->error('您已举报过该对象'); } @@ -70,4 +71,43 @@ class Sys extends Base } $this->success('Success'); } + + // 发送用户消息 + public function sendMsg() + { + $params = $this->request->param(); + if ($params['user_id'] == $this->auth->id) { + $this->error('不能发送给自己'); + } + $user = auth_user(); + $target = User::get($params['user_id']); + if (empty($target)) { + $this->error('用户不存在'); + } + + Db::startTrans(); + try { + $result = (new Message())->allowField(true)->save([ + 'type' => 2, + 'name' => $user['nickname'], + 'avatar' => $user['avatar'], + 'from_id' => $user['id'], + 'target_id' => $params['user_id'], + 'content' => json_encode([ + 'topic' => '好友消息', + 'time' => date('Y-m-d H:i:s'), + 'content' => $params['content'] + ]), + 'status' => 0 + ]); + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result === false) { + $this->error('操作失败'); + } + $this->success('Success'); + } } diff --git a/addons/shopro/job/Test.php b/addons/shopro/job/Test.php index b57a100..3d92b49 100644 --- a/addons/shopro/job/Test.php +++ b/addons/shopro/job/Test.php @@ -62,6 +62,7 @@ class Test extends BaseJob try { $_actModel = new \app\admin\model\zy\game\Activity(); $_gameModel = new \app\admin\model\zy\game\Game(); + $dateTime = date('Y-m-d H:i:s'); //当前星期 $week = date('w'); //当前星期 $current = time(); //当前时间 $activity = (clone $_actModel)::where('pid', 0)->select(); //周期性主活动 @@ -112,6 +113,15 @@ class Test extends BaseJob $res = (clone $_gameModel)->allowField(true)->save($sub); } } + //处理已生成的比赛 + $games = (clone $_gameModel)::where('join_start_time', '>=', $dateTime)->where('status', '<', 2)->select(); + foreach ($games as $g) { + if ($g['join_start_time'] <= $dateTime && $g['join_end_time'] > $dateTime) { + $g->save(['status' => 1]); //开始报名 + } elseif ($g['join_end_time'] <= $dateTime) { + $g->save(['status' => 2]); //报名截止,活动进行中 + } + } Db::commit(); } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); diff --git a/application/admin/lang/zh-cn/zy/game/game.php b/application/admin/lang/zh-cn/zy/game/game.php index 9a024bf..66b9478 100644 --- a/application/admin/lang/zh-cn/zy/game/game.php +++ b/application/admin/lang/zh-cn/zy/game/game.php @@ -72,6 +72,7 @@ return [ "Type0" => "一次性", "Type1" => "周期性", + "Status-1" => "取消", "Status0" => "未开始", "Status1" => "报名中", "Status2" => "进行中", diff --git a/application/admin/lang/zh-cn/zy/game/game_join.php b/application/admin/lang/zh-cn/zy/game/game_join.php index a1bc8ad..30ab611 100644 --- a/application/admin/lang/zh-cn/zy/game/game_join.php +++ b/application/admin/lang/zh-cn/zy/game/game_join.php @@ -14,7 +14,7 @@ return [ 'User.username' => '用户名', 'Order.order_sn' => '订单号', + "Status-1" => "取消", "Status0" => "待支付", "Status1" => "已支付", - "Status2" => "报名成功", ];