Browse Source

feat(admin): 添加分红积分基准价格设置并进行有效性验证

- 在系统配置中添加"award_integral_price"字段,用于设置分红积分基准价格
- 添加对分红积分基准价格的验证,确保其值大于 0
- 优化了代码格式,调整了数组元素的缩进
kirin 5 months ago
parent
commit
3c42a52bc3

+ 57 - 48
app/common/repositories/user/UserExtractRepository.php

@@ -147,46 +147,53 @@ class UserExtractRepository extends BaseRepository
      * 该函数用于处理用户的提现申请,包括验证提现条件、更新用户佣金余额、
      * 创建提现记录等操作。在执行过程中,会触发相应的事件,以便于其他系统组件监听和处理相关逻辑。
      */
-    public function create($user,$data)
+    public function create($user, $data)
     {
         // 触发提现前的提取事件,允许其他系统组件在这个阶段进行干预
-        event('user.extract.before',compact('user','data'));
-        $config = systemConfig(['extract_switch','sys_extension_type','withdraw_type','extract_type']);
+        event('user.extract.before', compact('user', 'data'));
+        $config = systemConfig(['extract_switch', 'sys_extension_type', 'withdraw_type', 'extract_type']);
         if (empty($config['withdraw_type'])) $config['withdraw_type'] = [self::EXTRACT_TYPE_YUE];
         $config['withdraw_type'][] = 3;
-        if (!in_array($data['extract_type'],$config['withdraw_type']))
+        if (!in_array($data['extract_type'], $config['withdraw_type']))
             throw new ValidateException('未开启该提现功能');
         //if ($data['extract_type'] == self::EXTRACT_TYPE_WEXIN && !$config['sys_extension_type'])
         //    throw new ValidateException('未开启微信自动转账');
         if ($data['extract_type'] == self::EXTRACT_TYPE_WECHAT && $config['sys_extension_type'])
             $data['extract_type'] = self::EXTRACT_TYPE_WEXIN;
-            //throw new ValidateException('仅支持微信自动转账');
+        //throw new ValidateException('仅支持微信自动转账');
         // 校验用户可提现金额是否满足最小值要求
-        if($user['brokerage_price'] < (systemConfig('user_extract_min')))
+        if ($user['brokerage_price'] < (systemConfig('user_extract_min')))
             throw new ValidateException('可提现金额不足');
         // 校验提现金额是否满足最小值要求
-        if($data['extract_price'] < (systemConfig('user_extract_min')))
+        if ($data['extract_price'] < (systemConfig('user_extract_min')))
             throw new ValidateException('提现金额不得小于最低额度');
         // 校验提现金额是否超过用户可提现余额
-        if($user['brokerage_price'] < $data['extract_price'])
+        if ($user['brokerage_price'] < $data['extract_price'])
             throw new ValidateException('提现金额不足');
-        if($data['extract_price'] >= 2000 && empty($data['real_name']) && $data['extract_type'] == self::EXTRACT_TYPE_WEXIN) {
+        if ($data['extract_price'] >= 2000 && empty($data['real_name']) && $data['extract_type'] == self::EXTRACT_TYPE_WEXIN) {
             throw new ValidateException('提现金额大于等于2000时,收款人姓名必须填写');
         }
 
+        $commission = systemConfig('extract_commission', 0);
+
+        $data['commission'] = bcdiv(bcmul((string)$data['extract_price'], (string)$commission), '100', 2);
+        $data['real_get'] = bcsub($data['extract_price'], $data['commission'], 2);
+
+        if ($data['real_get'] <= 0) throw new ValidateException('未开启该提现功能');
+
         // 如果提现类型为微信,验证用户的微信OpenID是否存在
-        if($data['extract_type'] == self::EXTRACT_TYPE_WEXIN) {
+        if ($data['extract_type'] == self::EXTRACT_TYPE_WEXIN) {
             $make = app()->make(WechatUserRepository::class);
             $openid = $make->idByOpenId((int)$user['wechat_user_id']);
-            if (!$openid){
+            if (!$openid) {
                 $openid = $make->idByRoutineId((int)$user['wechat_user_id']);
-                if(!$openid) throw new ValidateException('openID获取失败,请确认是微信用户');
+                if (!$openid) throw new ValidateException('openID获取失败,请确认是微信用户');
             }
         }
         // 使用数据库事务来确保操作的原子性
-        $userExtract = Db::transaction(function()use($user,$data){
+        $userExtract = Db::transaction(function () use ($user, $data) {
             // 计算用户更新后的佣金余额
-            $brokerage_price = bcsub($user['brokerage_price'],$data['extract_price'],2);
+            $brokerage_price = bcsub($user['brokerage_price'], $data['extract_price'], 2);
             // 更新用户佣金余额
             $user->brokerage_price = $brokerage_price;
             $user->save();
@@ -212,8 +219,8 @@ class UserExtractRepository extends BaseRepository
             ]);
         }
         // 触发提现完成事件,允许其他系统组件进行后续处理
-        event('user.extract',compact('userExtract'));
-        return  $userExtract;
+        event('user.extract', compact('userExtract'));
+        return $userExtract;
     }
 
     /**
@@ -250,14 +257,14 @@ class UserExtractRepository extends BaseRepository
      * @param array $data 提交的数据,包含状态等信息
      * @throws ValidateException 如果用户不存在
      */
-    public function switchStatus($id,$data)
+    public function switchStatus($id, $data)
     {
         // 根据提取ID获取提取记录
         $extract = $this->dao->getWhere(['extract_id' => $id]);
         // 根据提取记录中的用户ID获取用户信息
         $user = app()->make(UserRepository::class)->get($extract['uid']);
         // 如果用户不存在,抛出异常
-        if(!$user) throw new ValidateException('用户不存在');
+        if (!$user) throw new ValidateException('用户不存在');
         // 获取系统配置的扩展类型
         $type = systemConfig('sys_extension_type');
         // 初始化返回数组和支付服务变量
@@ -277,21 +284,21 @@ class UserExtractRepository extends BaseRepository
                     'status' => 1,
                     'title' => '佣金提现',
                     'number' => $extract['extract_price'],
-                    'mark' => '成功佣金提现' . floatval($extract['extract_price']) . '元',
+                    'mark' => '成功佣金提现' . floatval($extract['extract_price']) . '元' . $extract['commission'] > 0 ? (',扣除手续费后实际到账' . $extract['real_get'] . '元') : '',
                     'balance' => $brokerage
                 ]
             ];
             switch ($extract['extract_type']) {
                 case self::EXTRACT_TYPE_WEXIN:
-                    if (in_array($type,[1,2])) {
+                    if (in_array($type, [1, 2])) {
                         // 根据扩展类型确定使用的支付方法
                         $func = $type == 1 ? 'merchantPay' : 'companyPay';
                         // 构建企业付款所需的信息
                         $ret = [
                             'sn' => $extract['extract_sn'],
-                            'price' => $extract['extract_price'],
-                            'mark' => '企业付款给用户:'.$user->nickname,
-                            'batch_name' => '企业付款给用户:'.$user->nickname,
+                            'price' => $extract['real_get'],
+                            'mark' => '企业付款给用户:' . $user->nickname,
+                            'batch_name' => '企业付款给用户:' . $user->nickname,
                             'realName' => $extract['real_name'] ?? ''
                         ];
                         // 尝试通过微信用户ID获取OpenID
@@ -307,12 +314,12 @@ class UserExtractRepository extends BaseRepository
                             if (!$routineOpenid) throw new ValidateException('非微信用户不支持付款到零钱');
                             $ret['openid'] = $routineOpenid;
                             // 使用小程序服务进行付款
-                            $service =  MiniProgramService::create();
+                            $service = MiniProgramService::create();
                         }
                     }
                     break;
                 case self::EXTRACT_TYPE_YUE:
-                    $ret = ['extract' => $extract['extract_price'], 'extract_id' => $id];
+                    $ret = ['extract' => $extract['real_get'], 'extract_id' => $id];
                     $service = app()->make(UserExtractRepository::class);
                     $func = 'toBalance';
                     $out = [
@@ -322,7 +329,7 @@ class UserExtractRepository extends BaseRepository
                             'status' => 1,
                             'title' => '佣金转入余额',
                             'number' => $extract['extract_price'],
-                            'mark' => '成功转入余额' . floatval($extract['extract_price']) . '元',
+                            'mark' => '成功转入余额' . floatval($extract['extract_price']) . '元' . $extract['commission'] > 0 ? (',扣除手续费后实际到账' . $extract['real_get'] . '元') : '',
                             'balance' => $brokerage
                         ]
                     ];
@@ -332,17 +339,17 @@ class UserExtractRepository extends BaseRepository
             }
         } else {
             // 如果数据中的状态为-1,计算新的佣金价格
-            $brokerage_price = bcadd($user['brokerage_price'] ,$extract['extract_price'],2);
+            $brokerage_price = bcadd($user['brokerage_price'], $extract['extract_price'], 2);
         }
         $userBillRepository = app()->make(UserBillRepository::class);
         // 使用事务处理以下操作,确保数据的一致性
-        Db::transaction(function()use($id,$data,$user,$brokerage_price,$ret,$service,$func,$userBillRepository,$out){
+        Db::transaction(function () use ($id, $data, $user, $brokerage_price, $ret, $service, $func, $userBillRepository, $out) {
             // 触发状态切换前的事件
-            event('user.extractStatus.before',compact('id','data'));
+            event('user.extractStatus.before', compact('id', 'data'));
             // 如果有返回数组,调用相应的支付方法
 
-            if($data['status'] == 1 && $func) {
-                $res = $service->{$func}($ret,$user);
+            if ($data['status'] == 1 && $func) {
+                $res = $service->{$func}($ret, $user);
                 if ($res && $func == 'companyPay') {
                     $this->dao->update(
                         $id,
@@ -357,19 +364,20 @@ class UserExtractRepository extends BaseRepository
                 };
             }
             // 如果有计算出的佣金价格,更新用户佣金信息
-            if($brokerage_price){
+            if ($brokerage_price) {
                 $user->brokerage_price = $brokerage_price;
                 $user->save();
             }
+            $data['check_time'] = time();
             // 更新提取记录状态
-            $userExtract = $this->dao->update($id,$data);
-            if($out) $userBillRepository->decBill($user->uid, 'brokerage', $out['type'], $out['data']);
+            $userExtract = $this->dao->update($id, $data);
+            if ($out) $userBillRepository->decBill($user->uid, 'brokerage', $out['type'], $out['data']);
             // 触发状态切换后的事件
-            event('user.extractStatus',compact('id','userExtract'));
+            event('user.extractStatus', compact('id', 'userExtract'));
         });
 
         // 推送发送短信的任务到队列
-        Queue::push(SendSmsJob::class,['tempId' => 'PAYMENT_RECEIVED', 'id' =>$id]);
+        Queue::push(SendSmsJob::class, ['tempId' => 'PAYMENT_RECEIVED', 'id' => $id]);
     }
 
     /**
@@ -433,7 +441,7 @@ class UserExtractRepository extends BaseRepository
     public function getHistoryBank($uid)
     {
         // 使用DAO对象进行查询,指定查询条件为UID和提取类型为0,按创建时间降序排序,并指定返回的字段。
-        return $this->dao->getSearch(['uid' => $uid,'extract_type' => 0])->order('create_time DESC')->field('real_name,bank_code,bank_address,bank_name')->find();
+        return $this->dao->getSearch(['uid' => $uid, 'extract_type' => 0])->order('create_time DESC')->field('real_name,bank_code,bank_address,bank_name')->find();
     }
 
     /**
@@ -454,28 +462,29 @@ class UserExtractRepository extends BaseRepository
         }]);
 
         // 检查查询结果,如果为空,则抛出异常提示数据异常
-        if(empty($info)){
+        if (empty($info)) {
             throw new ValidateException('数据异常');
         }
 
         // 将查询结果转换为数组格式并返回
         return $info->toArray();
     }
+
     /**
      * 回调事件更新提现记录状态
      *
      * @param array $params
      * @return boolean
      */
-    public function updateStatus(array $params) : bool
+    public function updateStatus(array $params): bool
     {
         $where = [];
         $where['transfer_bill_no'] = $params['data']['transfer_bill_no'];
         $where['extract_sn'] = $params['data']['out_bill_no'];
 
         $info = $this->dao->getWhere($where);
-        if(!$info) {
-            Log::info('商家提现记录变更:提现记录不存在。params:'.json_encode($params));
+        if (!$info) {
+            Log::info('商家提现记录变更:提现记录不存在。params:' . json_encode($params));
             return false;
         };
         $user = app()->make(UserRepository::class)->get($info['uid']);
@@ -484,28 +493,28 @@ class UserExtractRepository extends BaseRepository
         $extractData = [];
         $extractData['wechat_status'] = $params['data']['state'];
         $extractData['status'] = 2; // 提现成功
-        if($extractData['wechat_status'] !== 'SUCCESS') {
+        if ($extractData['wechat_status'] !== 'SUCCESS') {
             $extractData['status'] = -2; // 提现失败
             // 失败则回退佣金
-            $brokerage_price = bcadd($user['brokerage_price'] ,$info['extract_price'],2);
+            $brokerage_price = bcadd($user['brokerage_price'], $info['extract_price'], 2);
         }
 
         // 使用事务处理以下操作,确保数据的一致性
-        Db::transaction(function()use($info, $extractData, $user, $brokerage_price, $params){
+        Db::transaction(function () use ($info, $extractData, $user, $brokerage_price, $params) {
             // 如果有佣金,更新用户佣金信息
-            if($brokerage_price){
+            if ($brokerage_price) {
                 $user->brokerage_price = $brokerage_price;
                 $user->save();
             }
             $res = $this->dao->update($info['extract_id'], $extractData);
-            if(!$res) {
-                Log::info('商家提现记录变更:提现记录状态变更失败。params:'.json_encode($params),',res:'.json_encode($res));
+            if (!$res) {
+                Log::info('商家提现记录变更:提现记录状态变更失败。params:' . json_encode($params), ',res:' . json_encode($res));
                 return false;
             };
         });
 
 
-        Log::info('商家提现记录变更:提现记录状态变更成功,id:'.$info['extract_id'].',status:'.$params['data']['state']);
+        Log::info('商家提现记录变更:提现记录状态变更成功,id:' . $info['extract_id'] . ',status:' . $params['data']['state']);
         return true;
     }
 }

+ 66 - 46
app/common/repositories/user/UserRepository.php

@@ -78,18 +78,18 @@ class UserRepository extends BaseRepository
     {
         // 定义用户筛选条件的列表,每个条件包括标签和对应的值
         $data = [
-            ['label' => 'UID',       'value' => 'uid'],
-            ['label' => '用户昵称',   'value' => 'nickname'],
-            ['label' => '手机号',     'value' => 'phone'],
-            ['label' => '性别',       'value' => 'sex'],
-            ['label' => '身份',       'value' => 'is_promoter'],
-            ['label' => '用户分组',    'value' => 'group_id'],
-            ['label' => '用户标签',    'value' => 'label_id'],
-            ['label' => '用户类别',    'value' => 'is_svip'],
-            ['label' => '生日',        'value' => 'birthday'],
-            ['label' => '消费次数',     'value' => 'pay_count'],
-            ['label' => '会员等级',     'value' => 'member_level'],
-            ['label' => '余额',        'value' => 'now_money'],
+            ['label' => 'UID', 'value' => 'uid'],
+            ['label' => '用户昵称', 'value' => 'nickname'],
+            ['label' => '手机号', 'value' => 'phone'],
+            ['label' => '性别', 'value' => 'sex'],
+            ['label' => '身份', 'value' => 'is_promoter'],
+            ['label' => '用户分组', 'value' => 'group_id'],
+            ['label' => '用户标签', 'value' => 'label_id'],
+            ['label' => '用户类别', 'value' => 'is_svip'],
+            ['label' => '生日', 'value' => 'birthday'],
+            ['label' => '消费次数', 'value' => 'pay_count'],
+            ['label' => '会员等级', 'value' => 'member_level'],
+            ['label' => '余额', 'value' => 'now_money'],
             ['label' => '首次访问时间', 'value' => 'create_time'],
             ['label' => '最近访问时间', 'value' => 'last_time'],
         ];
@@ -127,14 +127,14 @@ class UserRepository extends BaseRepository
     public function meetWithPromoter($uid)
     {
         $user = $this->dao->get($uid);
-        if (!$user->is_promoter && $user->promoter_switch && systemConfig('promoter_type') == 3){
+        if (!$user->is_promoter && $user->promoter_switch && systemConfig('promoter_type') == 3) {
             $storeOrderRepository = app()->make(StoreOrderRepository::class);
             $pay_price = $storeOrderRepository->getSearch([])
-                ->where(['uid' => $uid,'paid' => 1])
+                ->where(['uid' => $uid, 'paid' => 1])
                 ->whereNotNull('pay_time')
                 ->sum('pay_price');
             $promoter_low_money = systemConfig('promoter_low_money');
-            if (bccomp($pay_price,$promoter_low_money,2) !== -1) $this->promoter($uid);
+            if (bccomp($pay_price, $promoter_low_money, 2) !== -1) $this->promoter($uid);
         }
     }
 
@@ -187,10 +187,10 @@ class UserRepository extends BaseRepository
                 ['value' => 1, 'label' => '开启'],
             ])->requiredNum()
         ])
-        // 设置表单标题
-        ->setTitle('添加用户')
-        // 设置表单初始数据
-        ->formData([]);
+            // 设置表单标题
+            ->setTitle('添加用户')
+            // 设置表单初始数据
+            ->formData([]);
     }
 
     /**
@@ -305,8 +305,8 @@ class UserRepository extends BaseRepository
                 ['value' => 1, 'label' => '开启'],
             ])->requiredNum()
         ])
-        // 设置表单标题和预填充数据
-        ->setTitle('编辑')->formData($user->toArray());
+            // 设置表单标题和预填充数据
+            ->setTitle('编辑')->formData($user->toArray());
     }
 
     /**
@@ -323,7 +323,7 @@ class UserRepository extends BaseRepository
      */
     public function getList(array $where, int $page, int $limit, array $viewSearch = [])
     {
-        $query = $this->dao->search($where,$viewSearch);
+        $query = $this->dao->search($where, $viewSearch);
         $query->with([
             'spread' => function ($query) {
                 $query->field('uid,nickname,spread_uid');
@@ -389,7 +389,7 @@ class UserRepository extends BaseRepository
             $where['is_promoter'] = 1;
             $where['promoter_switch'] = 1;
         } else {
-            $where['is_promoter'] = [0,1];
+            $where['is_promoter'] = [0, 1];
         }
         // 查询并计算各种统计数据
         $total = $this->dao->search($where)
@@ -454,7 +454,7 @@ class UserRepository extends BaseRepository
             $where['is_promoter'] = 1;
             $where['promoter_switch'] = 1;
         } else {
-            $where['is_promoter'] = [0,1];
+            $where['is_promoter'] = [0, 1];
         }
 
         // 构建查询,包括推广员的传播信息和佣金信息
@@ -498,7 +498,7 @@ class UserRepository extends BaseRepository
         }
 
         // 返回推广员列表和总数
-        return compact('count','list');
+        return compact('count', 'list');
     }
 
     /**
@@ -925,7 +925,7 @@ class UserRepository extends BaseRepository
         // 初始化扩展信息数组
         $extend_info = [];
         // 检查并提取userInfo中的扩展信息,然后从userInfo中移除
-        if(isset($userInfo['extend_info'])){
+        if (isset($userInfo['extend_info'])) {
             $extend_info = $userInfo['extend_info'];
             unset($userInfo['extend_info']);
         }
@@ -988,7 +988,10 @@ class UserRepository extends BaseRepository
 
             }
             $user->save();
-            try {Queue::push(SendNewPeopleCouponJob::class, $user->uid);} catch (\Exception $e) {}
+            try {
+                Queue::push(SendNewPeopleCouponJob::class, $user->uid);
+            } catch (\Exception $e) {
+            }
         }
         return true;
     }
@@ -1033,7 +1036,7 @@ class UserRepository extends BaseRepository
         $isPromoter = $user->is_promoter;
         //如果人人分销不想改变用户本来的分销状态,就将if 中的代码注释代码注释,并修改 get_extension_info 方法中的注释部分
         if (!$isPromoter && systemConfig('extension_status')) {
-            $isPromoter = systemConfig('promoter_type') == 2  ? 1 : 0;
+            $isPromoter = systemConfig('promoter_type') == 2 ? 1 : 0;
             $user->is_promoter = $isPromoter;
         }
         $user->save();
@@ -1073,7 +1076,7 @@ class UserRepository extends BaseRepository
         // 检查缓存中是否存在以'user_'前缀加上令牌值为键的记录
         $has = Cache::has('user_' . $token);
         // 如果令牌不存在于缓存中,则抛出授权异常
-        if (!$has)throw new AuthException('无效的token');
+        if (!$has) throw new AuthException('无效的token');
         // 从缓存中获取令牌的最后更新时间
         $lastTime = Cache::get('user_' . $token);
         // 检查令牌是否过期,如果过期,则抛出授权异常
@@ -1184,7 +1187,7 @@ class UserRepository extends BaseRepository
             'phone' => $phone,
             'last_ip' => app('request')->ip()
         ];
-        env('registr.before',compact('data'));
+        env('registr.before', compact('data'));
         // 调用create方法,根据用户类型创建新用户
         return $this->create($user_type, $data);
     }
@@ -1560,7 +1563,7 @@ class UserRepository extends BaseRepository
     public function bindSpread(User $user, $spreadUid)
     {
         if ($spreadUid && !$user->spread_uid && $user->uid != $spreadUid && ($spread = $this->dao->get($spreadUid)) && $spread->spread_uid != $user->uid && !$spread->cancel_time) {
-            $config = systemConfig(['extension_limit', 'extension_limit_day', 'integral_user_give','integral_status']);
+            $config = systemConfig(['extension_limit', 'extension_limit_day', 'integral_user_give', 'integral_status']);
             event('user.spread.before', compact('user', 'spreadUid'));
             Db::transaction(function () use ($spread, $spreadUid, $user, $config) {
                 $user->spread_uid = $spreadUid;
@@ -1908,8 +1911,8 @@ class UserRepository extends BaseRepository
      *
      * @param object $user 用户对象,包含用户详细信息。
      * @param array $tokenInfo 令牌信息数组,包含令牌字符串和过期时间。
-     * @throws ValidateException 如果用户状态为禁用,则抛出异常。
      * @return array 返回包含令牌、过期时间及用户信息的数组。
+     * @throws ValidateException 如果用户状态为禁用,则抛出异常。
      */
     public function returnToken($user, $tokenInfo)
     {
@@ -2192,7 +2195,7 @@ class UserRepository extends BaseRepository
             Elm::select($field, '级别:', $data->$field)
                 ->options(function () use ($type) {
                     $options = app()->make(UserBrokerageRepository::class)->options(['type' => $type])->toArray();
-                    $options = array_merge([['value' => 0 , 'label' => '请选择']],$options);
+                    $options = array_merge([['value' => 0, 'label' => '请选择']], $options);
                     return $options;
                 })
                 ->placeholder('请选择级别'),
@@ -2213,8 +2216,8 @@ class UserRepository extends BaseRepository
      * @param int $id 用户ID
      * @param array $data 包含新级别数据的数组
      * @param int $type 类型标志,1表示更新会员级别,0表示更新代理级别
-     * @throws ValidateException 如果新级别不存在,则抛出此异常
      * @return bool 如果级别未更新则返回true,否则返回false
+     * @throws ValidateException 如果新级别不存在,则抛出此异常
      */
     public function updateLevel(int $id, array $data, int $type)
     {
@@ -2612,21 +2615,21 @@ class UserRepository extends BaseRepository
     {
         $isPromoter = false;//是否分销员
         $isSelfBuy = false;//是否内购
-        if(systemConfig('extension_status') && !$user){
+        if (systemConfig('extension_status') && !$user) {
             $isPromoter = systemConfig('extension_all') || $user->is_promoter ? true : false;
             $isSelfBuy = $isPromoter && systemConfig('extension_self') ? 1 : 0;//是否内购
         }
-        return ['isPromoter'=>$isPromoter,'isSelfBuy'=>$isSelfBuy];
+        return ['isPromoter' => $isPromoter, 'isSelfBuy' => $isSelfBuy];
     }
 
-    public function queryCustomer(array $where, int $page, int $size) : array
+    public function queryCustomer(array $where, int $page, int $size): array
     {
         $search = $where['search'] ?? null;
         unset($where['search']);
 
         // 根据条件初始化查询
         $query = $this->dao->search($where);
-        if(isset($search)) {
+        if (isset($search)) {
             $query->where('User.uid|User.nickname|User.phone', 'LIKE', '%' . $search . '%');
         }
 
@@ -2638,13 +2641,14 @@ class UserRepository extends BaseRepository
 
         return compact('count', 'list');
     }
-     /**
-      * 商户添加新用户
-      * 代客下单时,商户可以为用户添加新用户。商户需要提供用户的电话号码,系统会自动生成一个默认密码
-      *
-      * @param array $params
-      * @return mixed 具体类型取决于create方法的返回值
-      */
+
+    /**
+     * 商户添加新用户
+     * 代客下单时,商户可以为用户添加新用户。商户需要提供用户的电话号码,系统会自动生成一个默认密码
+     *
+     * @param array $params
+     * @return mixed 具体类型取决于create方法的返回值
+     */
     public function merchantRegistrs(array $params)
     {
         $phone = $params['phone'];
@@ -2657,7 +2661,7 @@ class UserRepository extends BaseRepository
             'is_svip' => -1,
             'last_ip' => app('request')->ip()
         ];
-        env('registr.before',compact('data'));
+        env('registr.before', compact('data'));
 
         return $this->create('h5', $data);
     }
@@ -2666,4 +2670,20 @@ class UserRepository extends BaseRepository
     {
         return $this->dao->get($uid);
     }
+
+    public function awardIntegralPrice()
+    {
+        $basePrice = systemConfig('award_integral_price', 0.1);
+        //业绩
+        $achievement = 0;
+        /** @var UserExtractRepository $extractRepositories */
+        $extractRepositories = app()->make(UserExtractRepository::class);
+        $extractCommission = $extractRepositories->search(['status' => 1])->whereTime('check_time', 'today')->sum('commission');
+        $sumAwardIntegral = $this->dao->search(['status' => 1])->sum('award_integral');
+        $achievement = $extractCommission + $achievement;
+
+        $rise = bcdiv($achievement, $sumAwardIntegral, 3);
+        $price = bcadd($rise, $basePrice, 3);
+        return compact('basePrice', 'price', 'rise');
+    }
 }

+ 2 - 1
app/controller/admin/system/config/ConfigOthers.php

@@ -64,7 +64,8 @@ class ConfigOthers extends BaseController
             'extract_switch',
             'extension_pop',
             'transfer_scene_id',
-            'award_integral_price'
+            'award_integral_price',
+            'extract_commission'
         ]);
 
         if ($data['extension_two_rate'] < 0 || $data['extension_one_rate'] < 0)