|
|
@@ -401,4 +401,45 @@ class UserExchangeServices extends BaseServices
|
|
|
return $this->dao->getGroupField($where, $SumField, $group);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入佣金到余额
|
|
|
+ * @param int $uid
|
|
|
+ * @param $price
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function importEnergy(int $uid, $price)
|
|
|
+ {
|
|
|
+ $switch = sys_config('brokerage_to_energy_switch', 1);
|
|
|
+ if (!$switch) throw new ValidateException('暂不支持');
|
|
|
+ /** @var UserServices $userServices */
|
|
|
+ $userServices = app()->make(UserServices::class);
|
|
|
+ $user = $userServices->getUserInfo($uid);
|
|
|
+ if (!$user) {
|
|
|
+ throw new ValidateException('数据不存在');
|
|
|
+ }
|
|
|
+ /** @var UserBrokerageServices $userBrokerageServices */
|
|
|
+ $userBrokerageServices = app()->make(UserBrokerageServices::class);
|
|
|
+ $broken_commission = $userBrokerageServices->getUserFrozenPrice($uid);
|
|
|
+ $commissionCount = bcsub((string)$user['brokerage_price'], (string)$broken_commission, 2);
|
|
|
+ if ($price > $commissionCount) {
|
|
|
+ throw new ValidateException('转入金额不能大于可提现佣金!');
|
|
|
+ }
|
|
|
+ return $this->transaction(function () use ($uid, $user, $price, $userServices) {
|
|
|
+ $edit_data = [];
|
|
|
+ $edit_data['energy'] = bcadd((string)$user['energy'], (string)$price, 2);
|
|
|
+ $edit_data['brokerage_price'] = $user['brokerage_price'] > $price ? bcsub((string)$user['brokerage_price'], (string)$price, 2) : 0;
|
|
|
+ //修改用户佣金、余额信息
|
|
|
+ $userServices->update($uid, $edit_data, 'uid');
|
|
|
+ /** @var UserBillServices $userMoneyServices */
|
|
|
+ $userMoneyServices = app()->make(UserBillServices::class);
|
|
|
+ //余额记录
|
|
|
+ $userMoneyServices->income('brokerage_to_energy', $uid, $price, $edit_data['energy'], 0);
|
|
|
+ //佣金提现记录
|
|
|
+ /** @var UserBrokerageServices $userBrokerageServices */
|
|
|
+ $userBrokerageServices = app()->make(UserBrokerageServices::class);
|
|
|
+ $userBrokerageServices->income('brokerage_to_energy', $uid, $price, $edit_data['brokerage_price'], 0);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|