From edc3da4d48929aa8f0f1b6e60f2d35b75cbfe4a5 Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Fri, 12 Apr 2024 22:03:11 +0800 Subject: [PATCH] 1 --- addons/shopro/controller/user/User.php | 2 +- addons/shopro/service/CommissionScoreLog.php | 13 +++-- .../admin/controller/shopro/user/User.php | 48 +++++++++++++++++-- .../admin/view/shopro/user/user/detail.html | 22 +++++++++ 4 files changed, 76 insertions(+), 9 deletions(-) diff --git a/addons/shopro/controller/user/User.php b/addons/shopro/controller/user/User.php index 30626da..a3a3524 100755 --- a/addons/shopro/controller/user/User.php +++ b/addons/shopro/controller/user/User.php @@ -161,7 +161,7 @@ class User extends Common //如果已经有账号则直接登录 $ret = $this->auth->direct($user->id); }else { - $ret = $this->auth->register($params['mobile'], Random::alnum(), '', $params['mobile'], ['parent_user_id'=>$parent_user_id]); + $ret = $this->auth->register($params['mobile'], Random::alnum(), '', $params['mobile'], ['parent_user_id'=>$parent_user_id, 'user_code' => Random::alnum(8)]); $user = $this->auth->getUserinfo(); //写入分销表 AgentModel::create([ diff --git a/addons/shopro/service/CommissionScoreLog.php b/addons/shopro/service/CommissionScoreLog.php index ebeee32..256c2eb 100644 --- a/addons/shopro/service/CommissionScoreLog.php +++ b/addons/shopro/service/CommissionScoreLog.php @@ -106,11 +106,13 @@ class CommissionScoreLog //1.非用户角色下单立即反积分 if ($initLevel > self::LEVEL_1 && $currentCommissionLevel == 1) { $amount = bcsub($order['goods_price'], $current_level_price, 2); + + $amount = bcmul($amount, $order['goods_num'], 2); //算积分 Wallet::change($currentAgent->user->id, 'score', $amount, 'back_score', [], '下单返现'); //如果没有上级 给公司账户返积分 if(empty($parentUserId)) { - $this->calcCompany($current_level_price, $company_level_price); + $this->calcCompany($current_level_price, $company_level_price, $order); } } @@ -153,6 +155,7 @@ class CommissionScoreLog \think\Log::info('当前商品价格'.$current_level_price); if (!empty($amount) && $amount> 0) { //算积分 + $amount = bcmul($amount, $order['goods_num'], 2); Wallet::change($parentAgent->user->id, 'score', $amount, 'team_order', [], '团队下单'); } } @@ -164,8 +167,9 @@ class CommissionScoreLog if ($level5 == 0) { $amount = bcmul($order['goods_price'], '0.02', 2); - $this->calcCompany($parent_level_price, $company_level_price, $amount); + $this->calcCompany($parent_level_price, $company_level_price, $order, $amount); //算积分 + $amount = bcmul($amount, $order['goods_num'], 2); Wallet::change($parentAgent->user->id, 'score', $amount, 'team_order', [], '团队下单'); } $level5++; @@ -184,7 +188,7 @@ class CommissionScoreLog } else { //7.只有最后一级是高级时反公司积分 if ($currentLevel == self::LEVEL_5 && $sonLevel != self::LEVEL_5 && $currentCommissionLevel > 1) { - $this->calcCompany($current_level_price, $company_level_price); + $this->calcCompany($current_level_price, $company_level_price, $order); } return true; } @@ -195,12 +199,13 @@ class CommissionScoreLog * @param $order * 公司账户算佣金 */ - public function calcCompany($currentPrice, $companyPrice, $amountRate = 0) { + public function calcCompany($currentPrice, $companyPrice, $order, $amountRate = 0) { $amount = bcsub($currentPrice, $companyPrice, 2); //同级奖励佣金 算差额 if ($amountRate > 0) { $amount = bcsub($amount, $amountRate, 2); } + $amount = bcmul($amount, $order['goods_num'], 2); Wallet::change(2, 'score', $amount, 'team_order', [], '用户下单'); } diff --git a/application/admin/controller/shopro/user/User.php b/application/admin/controller/shopro/user/User.php index 753cc1e..f529a43 100755 --- a/application/admin/controller/shopro/user/User.php +++ b/application/admin/controller/shopro/user/User.php @@ -3,6 +3,7 @@ namespace app\admin\controller\shopro\user; use app\admin\model\shopro\commission\Agent; +use app\admin\model\shopro\commission\Agent as AgentModel; use app\admin\model\shopro\commission\Level; use think\Db; use app\admin\controller\shopro\Common; @@ -38,7 +39,7 @@ class User extends Common // dd($user_info); $agent = Agent::with('level_info')->where('user_id', $row['id'])->find(); if (!empty($agent)) { - $row['user_level'] = $agent['level_info']['name']; + $row['user_level'] = $agent['level_info']['name']??""; } if ($row['parent_user_id'] > 0) { @@ -120,6 +121,24 @@ class User extends Common $this->error(__('No Results were found')); } + $level_list = (new Level())->select(); + $new_level_list = []; + $userLevel = Agent::where('user_id', $user->id)->value('level') ?? 0; + foreach ($level_list as $level) { + $disabled = false; + + if ($userLevel >= $level['level']) { + $disabled = true; + } + $new_level_list[] = [ + 'value' => $level['level'], + 'label' => $level['name'], + 'disabled' => $disabled + ]; + } + $user['levelList'] = $new_level_list; + $user['userLevel'] = $userLevel; + $this->success('获取成功', null, $user); } @@ -136,16 +155,37 @@ class User extends Common if (empty($params['password'])) unset($params['password']); if (empty($params['username'])) unset($params['username']); + $userLevel = $this->request->param('userLevel'); $params['id'] = $id; - $this->svalidate($params, '.edit'); +// $this->svalidate($params, '.edit'); unset($params['id']); $user = $this->model->where('id', $id)->find(); - $user->save($params); + $userTotalConsume = Level::get($userLevel)->total_consume ?? 0; + $agent = Agent::get(['user_id' => $id]); + + if (!empty($agent)) { + if ($userLevel > $agent->level) { + $agent->level = $userLevel; + $agent->save(); + $params['total_consume'] = $userTotalConsume; + } + } else { + //写入分销表 + AgentModel::create([ + 'user_id' => $user['id'], + 'level' => $userLevel, // 默认分销商等级 + 'status' => 'normal', + 'apply_info' => [], + 'apply_num' => 1, + 'become_time' => time() + ]); + $params['total_consume'] = $userTotalConsume; + } + $user->save($params); $this->success('更新成功', null, $user); } - /** * 删除用户(支持批量) * diff --git a/application/admin/view/shopro/user/user/detail.html b/application/admin/view/shopro/user/user/detail.html index 7621b4e..2f2c7b9 100755 --- a/application/admin/view/shopro/user/user/detail.html +++ b/application/admin/view/shopro/user/user/detail.html @@ -153,6 +153,22 @@ + +
设置等级
+
+ + + + + + +
+
@@ -226,6 +242,12 @@
注册时间
{{ state.detail.createtime }}
+ +
邀请码
+
+ {{ state.detail.user_code }} +
+