ソースを参照

Merge branch 'master' of http://git.qiniu1314.com/Kirin/shenying

Kirin 11 ヶ月 前
コミット
3db47e666e

+ 14 - 0
app/controller/api/v1/user/UserBrokerageController.php

@@ -94,4 +94,18 @@ class UserBrokerageController
         $uid = (int)$request->uid();
         return app('json')->success($this->services->brokerage_rank($uid, $data['type']));
     }
+
+
+    public function trade(Request $request)
+    {
+        [$to_uid, $num] = $request->postMore([
+            ['to_uid', 0],
+            ['num', 0],
+        ], true);
+        $uid = (int)$request->uid();
+        if ($this->services->trade($uid, $to_uid, $num))
+            return app('json')->successful('转账成功!');
+        else
+            return app('json')->fail('转账失败');
+    }
 }

+ 66 - 0
app/services/user/UserBrokerageServices.php

@@ -117,6 +117,20 @@ class UserBrokerageServices extends BaseServices
             'status' => 1,
             'pm' => 1
         ],
+        'trade_in' => [
+            'title' => '佣金转入',
+            'type' => 'trade_in',
+            'mark' => '{%mark%}{$number}元',
+            'status' => 1,
+            'pm' => 1
+        ],
+        'trade_out' => [
+            'title' => '佣金转出',
+            'type' => 'trade_out',
+            'mark' => '{%mark%}{$number}元',
+            'status' => 1,
+            'pm' => 0
+        ],
     ];
 
     /**
@@ -658,4 +672,56 @@ class UserBrokerageServices extends BaseServices
         }
         return ['list' => $list, 'time' => $times];
     }
+
+
+    public function trade(int $uid, int $to_uid, $num)
+    {
+        $switch = sys_config('brokerage_trade_switch', 1);
+        if (!$switch) throw new ValidateException('暂不支持');
+        /** @var UserServices $userService */
+        $userService = app()->make(UserServices::class);
+        $user = $userService->getUserInfo($uid);
+        $to_user = $userService->getUserInfo($to_uid);
+        if (!$user || !$to_user) {
+            throw new ValidateException('数据不存在');
+        }
+        if ($to_uid == $uid) throw new ValidateException('不能自己转给自己');
+        if ($user['is_auth'] != 2) throw new ValidateException('请先完成实名认证');
+
+        $broken_commission = $this->getUserFrozenPrice($uid);
+        if ($broken_commission < 0)
+            $broken_commission = 0;
+        $brokerage_price = $user['brokerage_price'];
+        //可提现佣金
+        $commissionCount = (float)bcsub((string)$brokerage_price, (string)$broken_commission, 2);
+        if ($num > $commissionCount) {
+            throw new ValidateException('可用佣金不足');
+        }
+
+        $extractPrice = $user['brokerage_price'];
+        if ($extractPrice < 0) {
+            throw new ValidateException('转账佣金不足' . $num);
+        }
+        if ($num > $extractPrice) {
+            throw new ValidateException('转账佣金不足' . $num);
+        }
+        if ($num <= 0) {
+            throw new ValidateException('转账佣金大于0');
+        }
+        return $this->transaction(function () use ($num, $user, $to_user, $userService) {
+            //修改用户佣金
+            $balance = bcsub((string)$user['brokerage_price'], (string)$num, 2) ?? 0;
+            $balance2 = bcadd((string)$to_user['brokerage_price'], (string)$num, 2) ?? 0;
+            if (!$userService->update($user['uid'], ['brokerage_price' => $balance], 'uid')) {
+                throw new ValidateException('修改用户信息失败');
+            }
+            if (!$userService->update($to_user['uid'], ['brokerage_price' => $balance2], 'uid')) {
+                throw new ValidateException('修改用户信息失败');
+            }
+            //保存佣金记录
+            $this->income('trade_out', $user['uid'], ['mark' => '转账给' . $to_user['nickname'] . '(' . $to_user['uid'] . ')', 'number' => $num], $balance, 0);
+            $this->income('trade_in', $to_user['uid'], ['mark' => '转账自' . $user['nickname'] . '(' . $user['uid'] . ')', 'number' => $num], $balance2, 0);
+            return true;
+        });
+    }
 }

+ 3 - 0
app/services/user/UserExtractServices.php

@@ -482,6 +482,9 @@ class UserExtractServices extends BaseServices
         $data['minPrice'] = sys_config('user_extract_min_price');//提现最低金额
         $data['withdraw_fee'] = sys_config('withdraw_fee');//提现手续费
         $data['extract_wechat_type'] = sys_config('brokerage_type');//微信提现到账方式
+        $data['brokerage_to_money_switch'] = sys_config('brokerage_to_money_switch');//微信提现到账方式
+        $data['brokerage_to_energy_switch'] = sys_config('brokerage_to_energy_switch');//微信提现到账方式
+        $data['brokerage_trade_switch'] = sys_config('brokerage_trade_switch');//微信提现到账方式
         return $data;
     }