Browse Source

会员升级

Kirin 7 months ago
parent
commit
97591ebff8

+ 1 - 0
app/controller/admin/v1/user/User.php

@@ -503,6 +503,7 @@ class User extends AuthController
             ['street', 0],
             ['spread_uid', -1],
             ['area_admin', -1],
+            ['is_shop', 0],
             ['area_admin_province', ''],
             ['area_admin_city', ''],
             ['area_admin_district', ''],

+ 21 - 11
app/services/user/UserBillServices.php

@@ -686,21 +686,22 @@ class UserBillServices extends BaseServices
 
     public function shop_integral_trade(int $uid, int $to_uid, $num)
     {
-        $switch = sys_config('shop_integral_trade_switch', 1);
-        $commission = sys_config('shop_integral_trade_commission', 8);
-        if (!$switch) throw new ValidateException('暂不支持');
-        if ($commission >= 100 || $commission < 0) throw new ValidateException('暂不支持');
         /** @var UserServices $userService */
         $userService = app()->make(UserServices::class);
         $user = $userService->getUserInfo($uid);
         $to_user = $userService->getUserInfo($to_uid);
+        if ($user['is_shop'] && $to_user['is_shop']) throw new ValidateException('商家只可转给用户');
+        if (!$user['is_shop'] && !$to_user['is_shop']) throw new ValidateException('用户只可转给商家');
+        $switch = sys_config('shop_integral_trade_switch', 1);
+        $commission = sys_config('shop_integral_trade_commission', 8);
+        if ($user['is_shop']) $commission = sys_config('shop_integral_trade_commission_shop', 3);
+        if (!$switch) throw new ValidateException('暂不支持');
+        if ($commission >= 100 || $commission < 0) throw new ValidateException('暂不支持');
         if (!$user || !$to_user) {
             throw new ValidateException('数据不存在');
         }
         if ($to_uid == $uid) throw new ValidateException('不能自己转给自己');
         if ($user['is_auth'] != 2) throw new ValidateException('请先完成实名认证');
-
-
         $extractPrice = $user['integral'];
         if ($num > $extractPrice) {
             throw new ValidateException('转账消费分不足' . $num);
@@ -712,16 +713,25 @@ class UserBillServices extends BaseServices
             //修改用户佣金
             $balance = bcsub((string)$user['integral'], (string)$num, 2) ?? 0;
             $real_get = bcdiv(bcmul(bcsub('100', $commission, 2), (string)$num, 2), '100', 2);
-            $balance2 = bcadd((string)$to_user['integral'], (string)$real_get, 2) ?? 0;
+            $balance2 = bcadd((string)$to_user['integral'], (string)$real_get, 2);
+            if ($user['is_shop']) $balance = bcadd((string)$to_user['now_money'], (string)$real_get, 2);
             if (!$userService->update($user['uid'], ['integral' => $balance], 'uid')) {
                 throw new ValidateException('修改用户信息失败');
             }
-            if (!$userService->update($to_user['uid'], ['integral' => $balance2], 'uid')) {
-                throw new ValidateException('修改用户信息失败');
+            $this->income('trade_out_shop_integral', $user['uid'], ['mark' => '转账给' . $to_user['nickname'] . '(' . $to_user['uid'] . ')', 'number' => $num], $balance, $to_user['uid']);
+            if (!$user['is_shop']) {
+                if (!$userService->update($to_user['uid'], ['integral' => $balance2], 'uid')) {
+                    throw new ValidateException('修改用户信息失败');
+                }
+                $this->income('trade_in_shop_integral', $to_user['uid'], ['mark' => '转账自' . $user['nickname'] . '(' . $user['uid'] . ')', 'number' => $num, 'real_get' => $real_get], $balance2, $user['uid']);
+            } else {
+                $server = app()->make(UserMoneyServices::class);
+                if (!$userService->update($to_user['uid'], ['now_money' => $balance2], 'uid')) {
+                    throw new ValidateException('修改用户信息失败');
+                }
+                $server->income('trade_in_shop_integral', $to_user['uid'], ['mark' => '转账自' . $user['nickname'] . '(' . $user['uid'] . ')', 'number' => $num, 'real_get' => $real_get], $balance2, $user['uid']);
             }
             //保存佣金记录
-            $this->income('trade_out_shop_integral', $user['uid'], ['mark' => '转账给' . $to_user['nickname'] . '(' . $to_user['uid'] . ')', 'number' => $num], $balance, 0);
-            $this->income('trade_in_shop_integral', $to_user['uid'], ['mark' => '转账自' . $user['nickname'] . '(' . $user['uid'] . ')', 'number' => $num, 'real_get' => $real_get], $balance2, 0);
             return true;
         });
     }

+ 8 - 0
app/services/user/UserMoneyServices.php

@@ -130,6 +130,14 @@ class UserMoneyServices extends BaseServices
             'status' => 1,
             'pm' => 1
         ],
+        'trade_in_shop_integral' => [
+            'title' => '消费分转入',
+            'category' => 'integral',
+            'type' => 'trade_in',
+            'mark' => '{%mark%}{%number%},扣除手续费后实际到账{%real_get%}',
+            'status' => 1,
+            'pm' => 1
+        ],
     ];
 
     /**

+ 1 - 0
app/services/user/UserServices.php

@@ -909,6 +909,7 @@ class UserServices extends BaseServices
             $edit['city'] = $data['city'];
             $edit['area'] = $data['area'];
             $edit['street'] = $data['street'];
+            $edit['is_shop'] = $data['is_shop'] ?? 0;
             if (isset($data['extend_info']) && $data['extend_info']) $edit['extend_info'] = $data['extend_info'];
             if ($user['level'] != $data['level']) {
                 /** @var UserLevelServices $userLevelService */