From 35725ffd2d6ab398cbb4ceaf487ebd130e9e4438 Mon Sep 17 00:00:00 2001 From: xiadc <251308692@qq.com> Date: Sat, 31 May 2025 21:22:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(zy):=20=E4=BF=AE=E5=A4=8D=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E6=8A=A5=E5=90=8D=E6=97=B6=E9=97=B4=E5=92=8C=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复了活动报名时间判断逻辑,增加了对报名结束时间的判断 - 修改了活动报名状态的判断条件,提高了代码的可读性和准确性 - 优化了订单自动操作和支付后的处理流程,确保活动报名状态正确更新 - 新增了用户权限验证功能,确保只有管理员或裁判可以修改用户状态 --- addons/shopro/controller/zy/Activity.php | 14 +++++---- addons/shopro/controller/zy/Game.php | 27 +++++++++++++++++ addons/shopro/job/OrderAutoOper.php | 38 +++++++++++++++--------- addons/shopro/job/OrderPaid.php | 21 +++++++++---- addons/shopro/library/Tree.php | 4 +-- 5 files changed, 76 insertions(+), 28 deletions(-) diff --git a/addons/shopro/controller/zy/Activity.php b/addons/shopro/controller/zy/Activity.php index 53b8c07..c9e0e32 100644 --- a/addons/shopro/controller/zy/Activity.php +++ b/addons/shopro/controller/zy/Activity.php @@ -198,13 +198,15 @@ class Activity extends Base if (empty($game)) { $this->error('活动不存在'); } - if ($game['join_start_time'] > date('Y-m-d H:i:s')) { - $this->error('活动报名时间未开始'); + $currentTime = date('Y-m-d H:i:s'); + if ($game['join_start_time'] > $currentTime || $game['join_end_time'] < $currentTime) { + $this->error('不在报名时间'); } if (empty($params['users']) || !is_array($params['users']) || empty($params['goods_list']) || !is_array($params['goods_list'])) { $this->error('请核对报名人员'); } - if (GameJoin::get(['game_id' => $game['id'], 'act_id' => $game['act_id'], 'user_id' => $this->auth->id])) { + $join = GameJoin::where(['game_id' => $game['id'], 'user_id' => $this->auth->id])->where('status', '>', -1)->find(); + if (!empty($join)) { $this->error('您已报名此活动'); } $order = GameJoin::where('game_id', $game['id'])->count(); @@ -241,8 +243,8 @@ class Activity extends Base 'act_id' => $game['act_id'], 'game_id' => $game['id'], 'user_id' => $this->auth->id, - 'orer_id' => $order['id'], - 'status' => 0,//待支付 + 'order_id' => $order['id'], + 'status' => 0, //待支付 'users' => json_encode($params['users'] ?? []) ]); foreach ($participant as &$p) { @@ -256,6 +258,6 @@ class Activity extends Base $this->error($e->getMessage(), $e); } - $this->success('Success'); + $this->success('Success', $order); } } diff --git a/addons/shopro/controller/zy/Game.php b/addons/shopro/controller/zy/Game.php index f3f4e14..a531a5a 100644 --- a/addons/shopro/controller/zy/Game.php +++ b/addons/shopro/controller/zy/Game.php @@ -237,6 +237,8 @@ class Game extends Base } if (isset($params['status'])) { $query->where('status', $params['status']); + } else { + $query->where('status', 1); } if (isset($params['gender'])) { $query->where('gender', $params['gender']); @@ -248,6 +250,31 @@ class Game extends Base $this->success('Success', $query->select()); } + // 用户 + public function setUser() + { + $params = $this->request->param(); + $user = Participant::get($params['id'] ?? NULL); + if (empty($user)) { + $this->error('用户不存在'); + } + $game = $this->model->get($user['game_id']); + $referee = explode(',', $game['referee']); //裁判 + $menber = Menber::where(['club_id' => $game['club_id'], 'user_id' => $this->auth->id])->where('role', '>', 1)->find(); + if (empty($menber) && !in_array($this->auth->id, $referee)) { + $this->error('您没有权限'); + } + $update['status'] = intval($params['status']); + if ($update['status'] > 1 || $update['status'] < -1) { + $this->error('status错误'); + } + if (!empty($params['mark'])) { + $update['mark'] = $params['mark']; + } + $user->save($update); + $this->success('修改成功'); + } + // 获取比赛匹配列表 public function macthList() { diff --git a/addons/shopro/job/OrderAutoOper.php b/addons/shopro/job/OrderAutoOper.php index f719806..0e9d657 100644 --- a/addons/shopro/job/OrderAutoOper.php +++ b/addons/shopro/job/OrderAutoOper.php @@ -2,16 +2,18 @@ namespace addons\shopro\job; -use think\queue\Job; -use think\Log; use think\Db; +use think\Log; +use think\queue\Job; use think\Collection; -use think\exception\HttpResponseException; -use addons\shopro\exception\ShoproException; +use app\admin\model\zy\game\GameJoin; use app\admin\model\shopro\order\Order; -use app\admin\model\shopro\order\OrderItem; -use addons\shopro\service\order\OrderOper; use app\admin\model\shopro\order\Action; +use app\admin\model\zy\game\Participant; +use addons\shopro\service\order\OrderOper; +use think\exception\HttpResponseException; +use app\admin\model\shopro\order\OrderItem; +use addons\shopro\exception\ShoproException; /** * 订单自动操作 @@ -22,12 +24,13 @@ class OrderAutoOper extends BaseJob /** * 订单自动关闭 */ - public function autoClose(Job $job, $data){ + public function autoClose(Job $job, $data) + { if (check_env('yansongda', false)) { set_addon_config('epay', ['version' => 'v3'], false); \think\Hook::listen('epay_config_init'); } - + try { $order = $data['order']; @@ -38,7 +41,12 @@ class OrderAutoOper extends BaseJob Db::transaction(function () use ($order, $data) { $orderOper = new OrderOper(); $order = $orderOper->close($order, null, 'system'); - + // zy体育报名处理(未支付,自动退坑) + $join = GameJoin::where('order_id', $data['order']['id'])->find(); + if (!empty($join)) { + $join->save([' status' => -1]); + Participant::where('game_join_id', $join['id'])->update(['status' => -1]); + } return $order; }); } @@ -67,7 +75,8 @@ class OrderAutoOper extends BaseJob /** * 订单自动确认收货 */ - public function autoConfirm(Job $job, $data) { + public function autoConfirm(Job $job, $data) + { try { $order = $data['order']; $items = $data['items']; @@ -80,7 +89,7 @@ class OrderAutoOper extends BaseJob $order = Db::transaction(function () use ($order, $itemIds) { $orderOper = new OrderOper(); $order = $orderOper->confirm($order, $itemIds, null, 'system'); - + return $order; }); } @@ -107,7 +116,8 @@ class OrderAutoOper extends BaseJob - public function autoComment(Job $job, $data) { + public function autoComment(Job $job, $data) + { try { $order = $data['order']; $item = $data['item']; @@ -123,7 +133,7 @@ class OrderAutoOper extends BaseJob 'item_id' => $item['id'], 'level' => 5, ]; - + // 评价一个订单商品 $order = $orderOper->comment($order, $comments, null, 'system'); @@ -152,4 +162,4 @@ class OrderAutoOper extends BaseJob $job->delete(); } } -} \ No newline at end of file +} diff --git a/addons/shopro/job/OrderPaid.php b/addons/shopro/job/OrderPaid.php index 5e21faa..bf0f2a1 100644 --- a/addons/shopro/job/OrderPaid.php +++ b/addons/shopro/job/OrderPaid.php @@ -2,15 +2,18 @@ namespace addons\shopro\job; -use think\queue\Job; use think\Db; -use think\exception\HttpResponseException; -use app\admin\model\shopro\order\Order; +use think\queue\Job; use addons\shopro\service\StockSale; +use addons\shopro\controller\zy\Game; use app\admin\model\shopro\user\User; -use app\admin\model\shopro\order\Invoice as OrderInvoice; +use app\admin\model\zy\game\GameJoin; +use app\admin\model\shopro\order\Order; +use app\admin\model\zy\game\Participant; use addons\shopro\service\order\OrderOper; +use think\exception\HttpResponseException; use addons\shopro\facade\Activity as ActivityFacade; +use app\admin\model\shopro\order\Invoice as OrderInvoice; /** * 订单自动操作 @@ -52,10 +55,13 @@ class OrderPaid extends BaseJob // 将订单参与活动信息改为已支付 $orderOper = new OrderOper(); $orderOper->activityOrderPaid($order); - + // 触发订单支付完成事件 $data = ['order' => $order, 'user' => $user]; \think\Hook::listen('order_paid_after', $data); + + // zy体育报名处理 + GameJoin::where('order_id', $order->id)->update(['status' => 1]); }); } @@ -96,6 +102,9 @@ class OrderPaid extends BaseJob // 触发订单选择线下支付(货到付款)完成事件 $data = ['order' => $order, 'user' => $user]; \think\Hook::listen('order_offline_after', $data); + + // zy体育报名处理 + GameJoin::where('order_id', $order->id)->update(['status' => 1]); }); } @@ -110,4 +119,4 @@ class OrderPaid extends BaseJob format_log_error($e, 'OrderPaid.offline'); } } -} \ No newline at end of file +} diff --git a/addons/shopro/library/Tree.php b/addons/shopro/library/Tree.php index a081e52..efb795a 100644 --- a/addons/shopro/library/Tree.php +++ b/addons/shopro/library/Tree.php @@ -24,7 +24,7 @@ class Tree * @param \Closure $resultCb 用来处理每一次查询的结果 比如要取出树中的所有 name * @return Collection */ - public function getTree($items = 0, \Closure $resultCb = null) + public function getTree($items = 0, ?\Closure $resultCb = null) { if (!is_array($items) && !$items instanceof Collection) { $items = $this->getQuery()->where('parent_id', $items)->select(); @@ -48,7 +48,7 @@ class Tree * @param \Closure $resultCb 用来处理每一次查询的结果 比如要取出树中的所有 name * @return Collection */ - public function getChildren($id, \Closure $resultCb = null) + public function getChildren($id, ?\Closure $resultCb = null) { $self = $this->getQuery()->where('id', $id)->select(); if(!$self) {