|
@@ -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;
|
|
|
});
|
|
|
}
|