Browse Source

会员升级

Kirin 7 months ago
parent
commit
a4feedb203
1 changed files with 11 additions and 11 deletions
  1. 11 11
      app/services/user/UserBillServices.php

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

@@ -239,7 +239,7 @@ class UserBillServices extends BaseServices
             'title' => '消费分转入',
             'category' => 'integral',
             'type' => 'trade_in',
-            'mark' => '{%mark%}{%origin%},扣除手续费后实际到账{%number%}',
+            'mark' => '{%mark%}{%origin%}',
             'status' => 1,
             'pm' => 1
         ],
@@ -247,7 +247,7 @@ class UserBillServices extends BaseServices
             'title' => '消费分转出',
             'category' => 'integral',
             'type' => 'trade_out',
-            'mark' => '{%mark%}{%number%}',
+            'mark' => '{%mark%}{%number%},转账手续费{%fee%}',
             'status' => 1,
             'pm' => 0
         ],
@@ -700,36 +700,36 @@ class UserBillServices extends BaseServices
         if (!$user || !$to_user) {
             throw new ValidateException('数据不存在');
         }
+        $fee = bcdiv(bcmul($commission, (string)$num, 2), '100', 2);
         if ($to_uid == $uid) throw new ValidateException('不能自己转给自己');
         if ($user['is_auth'] != 2) throw new ValidateException('请先完成实名认证');
         $extractPrice = $user['integral'];
-        if ($num > $extractPrice) {
+        if ($num + $fee > $extractPrice) {
             throw new ValidateException('转账消费分不足' . $num);
         }
         if ($num <= 0) {
             throw new ValidateException('转账消费分大于0');
         }
-        return $this->transaction(function () use ($num, $user, $to_user, $userService, $commission) {
+        return $this->transaction(function () use ($num, $user, $to_user, $userService, $commission, $fee) {
             //修改用户佣金
-            $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);
-            if ($user['is_shop']) $balance2 = bcadd((string)$to_user['now_money'], (string)$real_get, 2);
+            $balance = bcsub((string)$user['integral'], (string)($num + $fee), 2) ?? 0;
+            $balance2 = bcadd((string)$to_user['integral'], (string)$num, 2);
+            if ($user['is_shop']) $balance2 = bcadd((string)$to_user['now_money'], (string)$num, 2);
             if (!$userService->update($user['uid'], ['integral' => $balance], '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']);
+            $this->income('trade_out_shop_integral', $user['uid'], ['mark' => '转账给' . $to_user['nickname'] . '(' . $to_user['uid'] . ')', 'number' => $num, 'fee' => $fee], $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'] . ')', 'origin' => $num, 'number' => $real_get], $balance2, $user['uid']);
+                $this->income('trade_in_shop_integral', $to_user['uid'], ['mark' => '转账自' . $user['nickname'] . '(' . $user['uid'] . ')', 'number' => $num], $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'] . ')', 'origin' => $num, 'number' => $real_get], $balance2, $user['uid']);
+                $server->income('trade_in_shop_integral', $to_user['uid'], ['mark' => '转账自' . $user['nickname'] . '(' . $user['uid'] . ')', 'number' => $num], $balance2, $user['uid']);
             }
             //保存佣金记录
             return true;