From c76019416aa5a792dbb3b3995c1d463aadedf9d1 Mon Sep 17 00:00:00 2001 From: xiadc <251308692@qq.com> Date: Sun, 4 May 2025 17:23:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(user):=20=E6=B7=BB=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=94=B3=E8=AF=B7=E8=81=94=E7=B3=BB=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BF=B1=E4=B9=90=E9=83=A8=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增用户申请联系信息功能,包括申请、审核和处理流程 - 优化俱乐部申请、邀请和处理申请的逻辑 - 修复活动不存在时的错误提示 - 优化活动查询条件,支持一次性活动的特殊处理 --- addons/shopro/controller/user/User.php | 125 +++++++++++- addons/shopro/controller/zy/Activity.php | 13 +- addons/shopro/controller/zy/Club.php | 240 +++++++++++++---------- addons/shopro/job/Test.php | 10 +- 4 files changed, 272 insertions(+), 116 deletions(-) diff --git a/addons/shopro/controller/user/User.php b/addons/shopro/controller/user/User.php index 197fe97..9b96b00 100644 --- a/addons/shopro/controller/user/User.php +++ b/addons/shopro/controller/user/User.php @@ -2,15 +2,21 @@ namespace addons\shopro\controller\user; +use think\Db; +use think\Exception; use app\common\library\Sms; +use think\exception\PDOException; +use app\admin\model\zy\link\Apply; use addons\shopro\controller\Common; +use app\admin\model\zy\link\Message; +use app\admin\model\zy\link\Relation; +use app\admin\model\shopro\ThirdOauth; +use think\exception\ValidateException; use addons\shopro\service\user\UserAuth; use app\admin\model\shopro\user\User as UserModel; -use app\admin\model\shopro\user\Coupon as UserCouponModel; use app\admin\model\shopro\order\Order as OrderModel; +use app\admin\model\shopro\user\Coupon as UserCouponModel; use app\admin\model\shopro\order\Aftersale as AftersaleModel; -use app\admin\model\zy\link\Message; -use app\admin\model\shopro\ThirdOauth; class User extends Common { @@ -331,4 +337,117 @@ class User extends Common $this->success('Success', $model); } + + // 申请联系信息 + public function apply() + { + $params = $this->request->param(); + if (empty($params['content'])) { + return $this->error('申请内容不能为空'); + } + Db::startTrans(); + try { + $fromUser = auth_user(); + $user = UserModel::get($params['user_id'] ?? NULL); + if (empty($user)) { + return $this->error('用户不存在'); + } + $apply = (new Apply); + if ($apply::get(['type' => 2, 'user_id' => $fromUser->id, 'target_id' => $user->id, 'status' => 1])) { + return $this->error('申请处理中'); + } + $apply->allowField(true)->save([ // 记录申请 + 'type' => 2, + 'user_id' => $fromUser->id, + 'target_id' => $user->id, + 'content' => $params['content'], + 'reason' => $params['reason'] ?? '', + 'status' => 1 + ]); + (new Message())->allowField(true)->save([ // 消息通知 + 'type' => 2, + 'name' => $fromUser->nickname, + 'avatar' => $fromUser->avatar, + 'from_id' => $fromUser->id, + 'user_id' => $user->id, + 'content' => json_encode([ + 'topic' => '申请联系信息', + '申请人' => $fromUser->nickname, + '申请时间' => date('Y-m-d H:i:s'), + 'reason' => $params['reason'] ?? '', + 'apply_id' => $apply->id + ]) + ]); + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + $this->success('已邀请,请等候审核'); + } + + // 获取申请列表 + public function applyList() + { + $params = $this->request->param(); + $query = Apply::where('type', 2)->where('target_id', $this->auth->id); + if (isset($params['status'])) { + $query->where('status', $params['status']); + } + $applyList = $query->select(); + $this->success('Success', $applyList); + } + + // 处理申请 + public function handle() + { + $params = $this->request->param(); + Db::startTrans(); + try { + $apply = Apply::get(['id' => $params['apply_id'], 'user_id' => $this->auth->id, 'status' => 1]); + if (empty($apply)) { + return $this->error('申请记录不存在'); + } + if ($params['status'] == 2) { //同意 + $relation = Relation::get(['user_id' => $apply['user_id'], 'target_id' => $apply['user_id']]); + if (empty($relation)) { + $relation = new Relation; + } + $relation->allowField(true)->save([ + 'target_id' => $apply['user_id'], + 'user_id' => $apply['target_id'], + 'status' => 1, + 'content' => $params['content'], + ]); + } + $apply->save([ + 'status' => $params['status'], + 'reply' => $params['reply'] ?? '' + ]); + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + $this->success('Success'); + } + + // 好友关系 + public function relation() + { + $params = $this->request->param(); + if (!isset($params['status'])) { + $this->error('缺少参数:status'); + } + $relation = Relation::get(['user_id' => $this->auth->id, 'target_id' => $params['user_id']]); + if (empty($relation)) { + $relation = new Relation; + } + $relation->allowField(true)->save([ + 'target_id' => $params['user_id'], + 'user_id' => $this->auth->id, + 'status' => $params['status'], + ]); + $this->success('Success'); + } } diff --git a/addons/shopro/controller/zy/Activity.php b/addons/shopro/controller/zy/Activity.php index d0e791b..c6f5dcb 100644 --- a/addons/shopro/controller/zy/Activity.php +++ b/addons/shopro/controller/zy/Activity.php @@ -5,8 +5,9 @@ namespace addons\shopro\controller\zy; use think\Db; use think\Cache; use think\Exception; +use app\admin\model\zy\game\Game; use think\exception\PDOException; -use addons\shopro\library\RedisCache; +use app\admin\model\zy\game\GameJoin; use think\exception\ValidateException; use addons\shopro\service\order\OrderCreate; @@ -87,10 +88,13 @@ class Activity extends Base Db::startTrans(); try { $params = $this->request->param(); - $game = \app\admin\model\zy\game\Game::where('id', $params['act_id'] ?? NULL) + $game = Game::where('id', $params['act_id'] ?? NULL) ->where('date', $params['date'] ?? NULL)->find(); if (empty($game)) { - $this->error(__('No rows were found')); + $this->error('活动不存在'); + } + if ($game['join_start_time'] > date('Y-m-d H:i:s')) { + $this->error('活动报名时间未开始'); } $this->svalidate($params, ".create"); @@ -98,7 +102,7 @@ class Activity extends Base $result = $orderCreate->calc('create'); $order = $orderCreate->create($result); - $join = new \app\admin\model\zy\game\GameJoin; + $join = new GameJoin; $join->allowField(true)->save([ 'act_id' => $game['act_id'], 'game_id' => $game['id'], @@ -113,6 +117,7 @@ class Activity extends Base Db::rollback(); $this->error($e->getMessage(), $e); } + $this->success('Success', $join); } } diff --git a/addons/shopro/controller/zy/Club.php b/addons/shopro/controller/zy/Club.php index 46c750c..62bccd9 100644 --- a/addons/shopro/controller/zy/Club.php +++ b/addons/shopro/controller/zy/Club.php @@ -38,12 +38,12 @@ class Club extends Base $params = $this->request->param(); Db::startTrans(); try { - $params['president'] = $this->user->id; + $params['president'] = $this->auth->id; $result = $this->model->allowField(true)->save($params); $menber = new Menber; $menber->allowField(true)->save([ 'club_id' => $this->model->id, - 'user_id' => $this->user->id, + 'user_id' => $this->auth->id, 'role' => 3 ]); Db::commit(); @@ -100,46 +100,58 @@ class Club extends Base public function apply() { $params = $this->request->param(); - $club = $this->model->get($params['club_id']); - if (empty($club)) { - return $this->error('俱乐部不存在'); - } - if ($club['join_type'] > 1) { - $this->error('该俱乐部不允许申请'); - } - if (!empty(Menber::get(['club_id' => $params['club_id'], 'user_id' => $this->user->id]))) { - $this->error('您已经是俱乐部成员,无需重复申请'); - } - if ($club['join_type'] == 0) { - (new Menber)->allowField(true)->save([ - 'club_id' => $params['club_id'], - 'user_id' => $this->user->id, - 'role' => 1 + Db::startTrans(); + try { + $club = $this->model->get($params['club_id']); + if (empty($club)) { + return $this->error('俱乐部不存在'); + } + if ($club['join_type'] > 1) { + $this->error('该俱乐部不允许申请'); + } + if (!empty(Menber::get(['club_id' => $club->id, 'user_id' => $this->auth->id]))) { + $this->error('您已经是俱乐部成员,无需重复申请'); + } + if ($club['join_type'] == 0) { + (new Menber)->allowField(true)->save([ + 'club_id' => $club->id, + 'user_id' => $this->auth->id, + 'role' => 1 + ]); + $this->success('加入成功'); + } + $apply = new Apply; + if ($apply::get(['type' => 1, 'user_id' => $this->auth->id, 'target_id' => $club->id, 'status' => 1])) { + return $this->error('申请审核中'); + } + $apply->allowField(true)->save([ // 记录申请 + 'type' => 1, + 'user_id' => $this->auth->id, + 'target_id' => $club->id, + 'content' => json_encode(['reason' => $params['reason'] ?? '']), + 'reason' => $params['reason'], + 'status' => 1 ]); - $this->success('加入成功'); + (new Message())->allowField(true)->save([ // 消息通知 + 'type' => 3, + 'name' => $club->name, + 'avatar' => $club->logo, + 'from_id' => $this->auth->id, + 'target_id' => $club->id, + 'content' => json_encode([ + 'topic' => '俱乐部加入申请', + '俱乐部名称' => $club->name, + '申请人' => $this->user->nickname, + '申请时间' => date('Y-m-d H:i:s'), + 'reason' => $params['reason'] ?? '', + 'apply_id' => $apply->id + ]) + ]); + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); } - (new Apply)->allowField(true)->save([ // 记录申请 - 'type' => 1, - 'user_id' => $this->user->id, - 'target_id' => $params['club_id'], - 'content' => json_encode(['reason' => $params['reason'] ?? '']), - 'reason' => $params['reason'], - 'status' => 1 - ]); - (new Message())->allowField(true)->save([ // 消息通知 - 'type' => 3, - 'name' => $club->name, - 'avatar' => $club->logo, - 'from_id' => $this->user->id, - 'target_id' => $params['club_id'], - 'content' => json_encode([ - 'topic' => '俱乐部加入申请', - '俱乐部名称' => $club->name, - '申请人' => $this->user->nickname, - '申请时间' => date('Y-m-d H:i:s'), - 'reason' => $params['reason'] ?? '' - ]) - ]); $this->success('已申请,请等候审核'); } //join_type 0:'开放加入,无需审核',1:'开放申请,审核加入',2:'会员邀请,无需审核',3:'会员邀请,审核加入',4:'仅管理员邀请,无需审核' @@ -148,50 +160,62 @@ class Club extends Base public function invite() { $params = $this->request->param(); - $club = $this->model->get($params['club_id']); - if (empty($club)) { - return $this->error('俱乐部不存在'); - } - $menber = Menber::where('club_id', $params['club_id']) - ->where('user_id', $this->user->id) - ->where('role', '>', 0)->find(); - if (empty($menber)) { - $this->error('您无权邀请加入俱乐部'); - } - $user = User::get($params['user_id']); - if (empty($user)) { - return $this->error('用户不存在'); - } - if ($menber['role'] > 1 || $club['join_type'] == 0 || $club['join_type'] == 2) { // 管理员或者开放加入 - (new Menber)->allowField(true)->save([ - 'club_id' => $club->id, + Db::startTrans(); + try { + $club = $this->model->get($params['club_id']); + if (empty($club)) { + return $this->error('俱乐部不存在'); + } + $menber = Menber::where('club_id', $params['club_id']) + ->where('user_id', $this->auth->id) + ->where('role', '>', 0)->find(); + if (empty($menber)) { + $this->error('您无权邀请加入俱乐部'); + } + $user = User::get($params['user_id']); + if (empty($user)) { + return $this->error('用户不存在'); + } + $apply = new Apply; + if ($apply::get(['type' => 1, 'user_id' => $this->auth->id, 'target_id' => $user->id, 'status' => 1])) { + return $this->error('申请审核中'); + } + if ($menber['role'] > 1 || $club['join_type'] == 0 || $club['join_type'] == 2) { // 管理员或者开放加入 + (new Menber)->allowField(true)->save([ + 'club_id' => $club->id, + 'user_id' => $user->id, + 'role' => 1 + ]); + $this->success('邀请加入成功'); + } + $apply->allowField(true)->save([ // 记录申请 + 'type' => 1, 'user_id' => $user->id, - 'role' => 1 + 'target_id' => $club->id, + 'content' => json_encode(['reason' => $params['reason'] ?? '']), + 'reason' => $params['reason'], + 'status' => 1 ]); - $this->success('邀请加入成功'); + (new Message())->allowField(true)->save([ // 消息通知 + 'type' => 3, + 'name' => $club->name, + 'avatar' => $club->logo, + 'from_id' => $this->auth->id, + 'target_id' => $params['club_id'], + 'content' => json_encode([ + 'topic' => '俱乐部加入申请', + '俱乐部名称' => $club->name, + '申请人' => $user->nickname, + '申请时间' => date('Y-m-d H:i:s'), + 'reason' => $params['reason'] ?? '', + 'apply_id' => $apply->id, + ]) + ]); + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); } - (new Apply)->allowField(true)->save([ // 记录申请 - 'type' => 1, - 'user_id' => $user->id, - 'target_id' => $club->id, - 'content' => json_encode(['reason' => $params['reason'] ?? '']), - 'reason' => $params['reason'], - 'status' => 1 - ]); - (new Message())->allowField(true)->save([ // 消息通知 - 'type' => 3, - 'name' => $club->name, - 'avatar' => $club->logo, - 'from_id' => $this->user->id, - 'target_id' => $params['club_id'], - 'content' => json_encode([ - 'topic' => '俱乐部加入申请', - '俱乐部名称' => $club->name, - '申请人' => $this->user->nickname, - '申请时间' => date('Y-m-d H:i:s'), - 'reason' => $params['reason'] ?? '' - ]) - ]); $this->success('已邀请,请等候审核'); } @@ -204,7 +228,7 @@ class Club extends Base return $this->error('俱乐部不存在'); } $menber = Menber::where('club_id', $params['club_id']) - ->where('user_id', $this->user->id) + ->where('user_id', $this->auth->id) ->where('role', '>', 1)->find(); if (empty($menber)) { $this->error('您无权处理申请'); @@ -221,31 +245,37 @@ class Club extends Base public function handle() { $params = $this->request->param(); - $apply = Apply::get($params['apply_id']); - $menber = Menber::where('club_id', $apply['target_id']) - ->where('user_id', $this->user->id) - ->where('role', '>', 1)->find(); - if (empty($menber)) { - $this->error('您无权处理申请'); - } - if (empty($apply)) { - return $this->error('申请记录不存在'); - } - if ($apply['status'] != 1) { - return $this->error('该申请已处理'); - } - if ($params['status'] == 2) { - (new Menber)->allowField(true)->save([ - 'club_id' => $apply['target_id'], - 'user_id' => $apply['user_id'], - 'role' => 1 + Db::startTrans(); + try { + $apply = Apply::get(['id' => $params['apply_id'], 'status' => 1]); + if (empty($apply)) { + return $this->error('申请记录不存在'); + } + $menber = Menber::where('club_id', $apply['target_id']) + ->where('user_id', $this->auth->id) + ->where('role', '>', 1)->find(); + if (empty($menber)) { + $this->error('您无权处理申请'); + } + if ($apply['status'] != 1) { + return $this->error('该申请已处理'); + } + if ($params['status'] == 2) { + (new Menber)->allowField(true)->save([ + 'club_id' => $apply['target_id'], + 'user_id' => $apply['user_id'], + 'role' => 1 + ]); + } + $apply->save([ + 'status' => $params['status'], + 'reply' => $params['reply'] ?? '' ]); + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); } - $apply->save([ - 'status' => $params['status'], - 'reply' => $params['reply'] ?? '' - ]); - $this->success('处理成功'); } } diff --git a/addons/shopro/job/Test.php b/addons/shopro/job/Test.php index 551c043..b57a100 100644 --- a/addons/shopro/job/Test.php +++ b/addons/shopro/job/Test.php @@ -64,7 +64,7 @@ class Test extends BaseJob $_gameModel = new \app\admin\model\zy\game\Game(); $week = date('w'); //当前星期 $current = time(); //当前时间 - $activity = (clone $_actModel)::where('type', 1)->where('pid', 0)->select(); //周期性主活动 + $activity = (clone $_actModel)::where('pid', 0)->select(); //周期性主活动 foreach ($activity as $act) { $act = $act->toArray(); $publicTime = json_decode($act['public_time'] ?? '[]', true); @@ -81,9 +81,11 @@ class Test extends BaseJob } $act['public_time'] = date('Y-m-d H:i:s', $public_time - $publicBefore * 86400); //设定的时间 $act['date'] = date('Y-m-d', $public_time - $publicBefore * 86400); //设定的日期 - $games = (clone $_gameModel)::where('act_id', $act['id']) - ->where('public_time', $act['public_time']) - ->where('date', $act['date'])->select(); + $query = (clone $_gameModel)::where('act_id', $act['id']); + if ($act['type'] == 0) { //一次性活动 + $query->where('public_time', $act['public_time'])->where('date', $act['date']); + } + $games = $query->select(); if (!empty($games)) { print_r('已存在'); continue; // 已存在