From 38137ef6419fd3c4cf5fa89d5d843b685b39470c Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Mon, 25 Mar 2024 23:15:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=AF=E5=88=86=E8=BD=AC=E8=AE=A9=E5=92=8C?= =?UTF-8?q?=E6=88=91=E7=9A=84=E5=9B=A2=E9=98=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/shopro/controller/commission/Agent.php | 122 ++++++++++++++++++ addons/shopro/controller/user/WalletLog.php | 22 ++-- addons/shopro/job/trade/OrderPaid.php | 16 +-- 3 files changed, 143 insertions(+), 17 deletions(-) diff --git a/addons/shopro/controller/commission/Agent.php b/addons/shopro/controller/commission/Agent.php index fe0862f..81465a3 100755 --- a/addons/shopro/controller/commission/Agent.php +++ b/addons/shopro/controller/commission/Agent.php @@ -2,6 +2,7 @@ namespace addons\shopro\controller\commission; +use addons\shopro\controller\Pay; use think\Db; use app\admin\model\shopro\user\User as UserModel; use app\admin\model\shopro\commission\Agent as AgentModel; @@ -148,4 +149,125 @@ class Agent extends Commission }); $this->success(''); } + + /** + * 我的团队 + */ + public function myTeam() { + $user = auth_user(); + $list = []; + //团队总数 + $team_total = 0; + //好友总数 + $son_total = 0; + $user_id = $user->id; + + $son_total = UserModel::where('parent_user_id', $user_id)->count('id'); + + $team_total = UserModel::with(['parentUser' => function($query) use ($user_id) { +// $query->where(''); + }])->where('parent_user_id', $user_id)->count('id'); + + + $list = UserModel::with('agent.levelInfo')->where('id', $user_id)->select(); + + + + $result = [ + 'team_total' => $team_total, + 'son_total' => $son_total ?? 0, + 'list' => $list + ]; + + foreach ($list as &$item) { + $item['nextUserCount'] = 0; + } + + $this->success('success', $result); + + } + + public function test() { + $result = $this->runNextUser( $this->getTestData(1)); + $this->success('success', $result); + } + + + + /** + * 测试数据 + */ + public function getTestData($id) { + $data = [ + ['id' => 1, 'pid' => 0], + ['id' => 2, 'pid' => 1], + ['id' => 3, 'pid' => 1], + ['id' => 4, 'pid' => 2], + ['id' => 5, 'pid' => 4], + ['id' => 6, 'pid' => 5], + ['id' => 7, 'pid' => 6], + ['id' => 8, 'pid' => 2], + ['id' => 9, 'pid' => 2], + ['id' => 10, 'pid' => 7], + ['id' => 11, 'pid' => 3], + ]; + $data = array_column($data, null, 'id'); + $new_data = []; + foreach ($data as $key => $val) { + if ($id == $val['pid']) { + $new_data[] = $val; + } + } + return $new_data; + } + + /** + * 递归处理用户的下级人数 + * @param $list + * @param $pid + * @return mixed + */ + public function runNextUser($user) { + static $data = []; + $nextUser = $user; +// return $nextUser; +// $nextUserCount = count($this->getTestData($user_id)); + + foreach ($nextUser as $k => $v) { +// if($v['pid'] == $user_id) { +// $data[] = $v; + $v['son'] = $this->runNextUser($v['id']); + !empty($son)&& $v['son'] = $this->runNextUser($v['id']); + $data[] = $v; + unset($nextUser[$k]); +// } + + + } + return $data; + } + + public function getParent($pid) { + return UserModel::where('parent_user_id', $pid)->select(); + } + + + /** + * 返回树形结构 + * @param $list + * @param $pid + * @return array + */ + public function getTreeData($list, $pid = 0) { + static $data = []; + foreach ($list as $key => $item) { + if ($item['user_id'] == $pid) { + $children = $this->getTreeData($item, $item['user_id']); + !empty($children) && $item['children'] = $children; + $data[] = $item; + unset($list[$key]); + } + } + return $data; + } } diff --git a/addons/shopro/controller/user/WalletLog.php b/addons/shopro/controller/user/WalletLog.php index fb09b37..3f88168 100755 --- a/addons/shopro/controller/user/WalletLog.php +++ b/addons/shopro/controller/user/WalletLog.php @@ -71,25 +71,29 @@ class WalletLog extends Common $user = auth_user(); $user_id = $user->id; - - if (!Sms::check($params['exchange_phone'], $params['code'], 'score')) { - $this->error('验证码不正确'); + + if ($user->mobile == $params['exchange_phone']) { + $this->error('转让人不能是自己'); } + $exchange_user = UserModel::getByMobile($params['exchange_phone']); - if ($user) { - if ($user->status != 'normal') { - $this->error(__('账户已经被锁定')); + if ($exchange_user) { + if ($exchange_user->status != 'normal') { + $this->error(__('转让账户已经被锁定')); } }else { - $this->error('该手机号暂未注册'); + $this->error('未查到转让用户'); } + if (!Sms::check($params['exchange_phone'], $params['code'], 'score')) { + $this->error('验证码不正确'); + } $exchange_user_id = $exchange_user->id; $result = Db::transaction(function () use ($params, $exchange_user_id, $user_id) { - WalletService::change($user_id, $params['type'], -$params['amount'], 'user_exchange', [], '积分转让'); - return WalletService::change($exchange_user_id, $params['type'], $params['amount'], 'user_exchange', [], '积分转让'); + WalletService::change($user_id, $params['type'], -$params['exchange_amount'], 'user_exchange', [], '积分转让'); + return WalletService::change($exchange_user_id, $params['type'], $params['exchange_amount'], 'user_exchange', [], '积分转让'); }); if ($result) { $this->success('转让成功'); diff --git a/addons/shopro/job/trade/OrderPaid.php b/addons/shopro/job/trade/OrderPaid.php index a374129..ed9cef5 100755 --- a/addons/shopro/job/trade/OrderPaid.php +++ b/addons/shopro/job/trade/OrderPaid.php @@ -42,18 +42,18 @@ class OrderPaid extends BaseJob $gift = (isset($rule['gift']) && $rule['gift'] > 0) ? $rule['gift'] : 0; if ($money > 0) { // 增加余额 -// WalletService::change($user, 'money', $money, 'order_recharge', [ -// 'order_id' => $order->id, -// 'order_sn' => $order->order_sn, -// 'order_type' => 'trade_order', -// ]); - - // 增加积分 - WalletService::change($user, 'score', $money, 'order_recharge', [ + WalletService::change($user, 'money', $money, 'order_recharge', [ 'order_id' => $order->id, 'order_sn' => $order->order_sn, 'order_type' => 'trade_order', ]); + + // 增加积分 +// WalletService::change($user, 'score', $money, 'order_recharge', [ +// 'order_id' => $order->id, +// 'order_sn' => $order->order_sn, +// 'order_type' => 'trade_order', +// ]); } if ($gift > 0) {