feat(OrderLogic, CapitalFlowLogic): 重构余额支付逻辑,优化库存计算与用户余额处理

This commit is contained in:
mkm 2024-06-09 20:14:21 +08:00
parent 2d1cb8f485
commit 1ea3a0ab14
2 changed files with 5 additions and 35 deletions

View File

@ -254,36 +254,6 @@ class OrderLogic extends BaseLogic
}
/**
* 余额订单支付
* @param User $user
* @param $order
* @return bool
* @throws Exception
* @throws ValidateException
*/
static public function payBalance(User $user, $order)
{
if ($user['now_money'] < $order['pay_price']) {
self::setError('余额不足,请更换支付方式');
return false;
}
Db::startTrans();
try {
$user->now_money = bcsub($user->now_money, $order['pay_price'], 2);
$user->save();
$capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order['pay_price']);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error('余额支付失败' . $e->getMessage() . '。line:' . $e->getLine() . '。file:' . $e->getFile());
self::setError('余额支付失败' . $e->getMessage());
return false;
}
}
/**
* @notes 订单支付成功
* @param $order 订单

View File

@ -63,13 +63,13 @@ class CapitalFlowLogic extends BaseLogic
$model->link_type = $linkType;
$model->link_id = $linkId;
$model->amount = $amount;
if($payType == 1){
// if($payType == 1){
$model->before_balance = $this->user['now_money'];
$model->balance = $this->user['now_money'];
}else{
$model->before_balance = $this->user['now_money'];
$model->balance = bcsub($this->user['now_money'], $amount, 2);
}
// }else{
// $model->before_balance = $this->user['now_money'];
// $model->balance = bcsub($this->user['now_money'], $amount, 2);
// }
$model->create_time = date('Y-m-d H:i:s');
$model->type = 'out';
$model->title = $this->getTitle($category, $amount);