回调加入资金流水

This commit is contained in:
liu 2024-06-06 10:59:27 +08:00
parent ec71741e53
commit bae7a58f0e
2 changed files with 38 additions and 26 deletions

View File

@ -31,7 +31,7 @@ class CapitalFlowLogic extends BaseLogic
public function userIncome($category, $linkType, $linkId, $amount, $mark = '')
{
$model = new CapitalFlow();
$model->uid = $this->user['uid'];
$model->uid = $this->user['id'];
$model->category = $category;
$model->link_type = $linkType;
$model->link_id = $linkId;
@ -55,7 +55,7 @@ class CapitalFlowLogic extends BaseLogic
* @param $mark
* @return mixed
*/
public function userExpense($category, $linkType, $linkId, $amount, $mark = '')
public function userExpense($category, $linkType, $linkId, $amount, $mark = '',$payType=0)
{
$model = new CapitalFlow();
$model->uid = $this->user['id'];
@ -63,8 +63,13 @@ class CapitalFlowLogic extends BaseLogic
$model->link_type = $linkType;
$model->link_id = $linkId;
$model->amount = $amount;
$model->before_balance = $this->user['now_money'];
$model->balance = bcsub($this->user['now_money'], $amount, 2);
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);
}
$model->create_time = date('Y-m-d H:i:s');
$model->type = 'out';
$model->title = $this->getTitle($category, $amount);

View File

@ -49,7 +49,7 @@ class PayNotifyLogic extends BaseLogic
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
static function balancePay($orderSn, $extra = [])
public static function balancePay($orderSn, $extra = [])
{
$order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
$user = User::where('id', $order['uid'])->find();
@ -92,6 +92,10 @@ class PayNotifyLogic extends BaseLogic
if ($order->pay_type == 9) {
$order->status = 2;
}
$user = User::where('id', $order['uid'])->find();
$capitalFlowDao = new CapitalFlowLogic($user);
//微信支付和用户余额无关
$capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price,'',1);
self::afterPay($order,$extra['transaction_id']);
if ($order->pay_type == 9) {
@ -111,27 +115,30 @@ class PayNotifyLogic extends BaseLogic
public static function recharge($orderSn, $extra = [])
{
$order = UserRecharge::where('order_id', $orderSn)->findOrEmpty();
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
$order = UserRecharge::where('order_id', $orderSn)->findOrEmpty();
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
return true;
}
$price = bcdiv($extra['amount']['payer_total'], 100, 2);
$order->price = $price;
$order->paid = 1;
$order->pay_time = time();
$order->save();
$uid = $order->uid;
$user = User::where('id',$uid)->findOrEmpty();
if ($user->isEmpty()) {
return true;
}
bcscale(2);
$user->user_money = bcadd($user->user_money, $price, 2);
$user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2);
$user->save();
//用户的财务add
$capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price);
//更新等级
self::dealLevel($uid,$user->total_recharge_amount);
return true;
}
$price = bcdiv($extra['amount']['payer_total'], 100, 2);
$order->price = $price;
$order->paid = 1;
$order->pay_time = time();
$order->save();
$uid = $order->uid;
$user = User::where('id',$uid)->findOrEmpty();
if ($user->isEmpty()) {
return true;
}
bcscale(2);
$user->user_money = bcadd($user->user_money, $price, 2);
$user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2);
$user->save();
//更新等级
self::dealLevel($uid,$user->total_recharge_amount);
return true;
}
@ -196,7 +203,7 @@ class PayNotifyLogic extends BaseLogic
* @param $order
* @return void
*/
public static function afterPay($order,$transaction_id)
public static function afterPay($order,$transaction_id=0)
{
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order = $order;