Merge pull request 'feat(StoreOrderController, PayNotifyLogic, StoreFinanceFlowLogic): 更新订单处理流程,优化退款逻辑,调整资金流动记录处理方式' (#89) from dev into main

Reviewed-on: #89
This commit is contained in:
mkm 2024-08-02 23:56:58 +08:00
commit 78e0fc2a49
3 changed files with 67 additions and 47 deletions

View File

@ -116,8 +116,11 @@ class StoreOrderController extends BaseAdminController
if(empty($detail)){ if(empty($detail)){
return $this->fail('无该订单请检查'); return $this->fail('无该订单请检查');
} }
StoreOrderLogic::refund($detail,$params); $res=StoreOrderLogic::refund($detail,$params);
return $this->fail('退款失败'); if($res==false){
return $this->fail('退款失败');
}
return $this->success('退款成功');
} }
} }

View File

@ -315,43 +315,47 @@ class PayNotifyLogic extends BaseLogic
$order->refund_reason_time = time(); $order->refund_reason_time = time();
$order->refund_num += 1; $order->refund_num += 1;
$order->save(); $order->save();
//日志记录 // $deal_money = bcdiv($extra['amount']['refund'], 100, 2);
//加用户余额,采购款, 日志记录 加数量
$user = User::where('id', $order['uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user);
$deal_money = bcdiv($extra['amount']['refund'], 100, 2);
//对应比例得退礼品券逻辑 //对应比例得退礼品券逻辑
// $discount = self::getDiscount($user->user_ship); // $discount = self::getDiscount($user->user_ship);
// $total_price = bcmul($order->refund_price, $discount, 2); // $total_price = bcmul($order->refund_price, $discount, 2);
//订单购物详情
StoreOrderCartInfo::where('oid',$order['id'])->update(['status'=>OrderEnum::REFUND_STATUS_FINISH]);
//处理财务流水退还
(new StoreFinanceFlowLogic())->store_finance_back($orderSn);
if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付
$user->now_money = bcadd($user->now_money, $deal_money, 2); $user= User::where('id', $order['uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user);
$user->now_money = bcadd($user['now_money'], $order['pay_price'], 2);
$user->save(); $user->save();
//增加数量 //增加数量
self::addStock($order['id']); self::addStock($order['id']);
//退款 //退款
$capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money); $capitalFlowDao->userIncome('system_balance_add', 'system_back', $order['id'], $order['pay_price']);
} }
if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付 if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付
$user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2); $user= User::where('id', $order['uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user);
$user->purchase_funds = bcadd($user['purchase_funds'],$order['pay_price'], 2);
$user->save(); $user->save();
//增加数量 //增加数量
self::addStock($order['id']); self::addStock($order['id']);
//退款 //退款
$capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money); $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $order['pay_price']);
} }
UserSignLogic::RefundOrder($order); UserSignLogic::RefundOrder($order);
return true; return true;
} }
//订单购物详情
StoreOrderCartInfo::where('oid',$order['id'])->update(['status'=>OrderEnum::REFUND_STATUS_FINISH]);
//积分 //积分
UserSignLogic::RefundOrder($order); UserSignLogic::RefundOrder($order);
//微信日志 user_order_refund //微信日志 user_order_refund
$capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1); $user= User::where('id', $order['uid'])->findOrEmpty();
//处理财务流水退还 $capitalFlowDao = new CapitalFlowLogic($user);
(new StoreFinanceFlowLogic())->store_finance_back($orderSn); $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $order['pay_price'], '', 1);
self::addStock($order['id']); //微信 self::addStock($order['id']); //微信
return true; return true;
// self::afterPay($order,$extra['transaction_id']); // self::afterPay($order,$extra['transaction_id']);

View File

@ -134,8 +134,8 @@ class StoreFinanceFlowLogic extends BaseLogic
*/ */
public function updateStatusUser($id, $uid, $money, $order_id) public function updateStatusUser($id, $uid, $money, $order_id)
{ {
$flow=StoreFinanceFlow::where('id', $id)->find(); $flow = StoreFinanceFlow::where('id', $id)->find();
StoreFinanceFlow::where('order_id',$order_id)->where('financial_type',$flow['financial_type'])->update(['status'=>1]); StoreFinanceFlow::where('order_id', $order_id)->where('financial_type', $flow['financial_type'])->update(['status' => 1]);
$find = User::where('id', $uid)->find(); $find = User::where('id', $uid)->find();
$capitalFlowDao = new CapitalFlowLogic($find); $capitalFlowDao = new CapitalFlowLogic($find);
$capitalFlowDao->userIncome('system_balance_add', 'order', $order_id, $money); $capitalFlowDao->userIncome('system_balance_add', 'order', $order_id, $money);
@ -148,8 +148,8 @@ class StoreFinanceFlowLogic extends BaseLogic
{ {
StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 11])->update(['status' => 1]); StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 11])->update(['status' => 1]);
StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 2])->update(['status' => 1]); StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 2])->update(['status' => 1]);
$store=SystemStore::where('id',$store_id)->find(); $store = SystemStore::where('id', $store_id)->find();
$capitalFlowDao = new CapitalFlowLogic($store); $capitalFlowDao = new CapitalFlowLogic($store, 'store');
if ($money > 0) { if ($money > 0) {
$capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money); $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money);
SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); SystemStore::where('id', $store_id)->inc('store_money', $money)->update();
@ -178,36 +178,49 @@ class StoreFinanceFlowLogic extends BaseLogic
*/ */
public function store_finance_back($orderSn) public function store_finance_back($orderSn)
{ {
$data = StoreFinanceFlow::where('order_sn', $orderSn) $list=StoreFinanceFlow::where('order_sn', $orderSn)
->where(['financial_pm' => 1]) ->where(['financial_pm' => 1, 'status' => 1])
->select()->toArray(); ->select();
foreach ($data as &$value) { foreach ($list as $k => $value) {
unset($value['id']); //用户
$value['financial_record_sn'] = (new StoreFinanceFlowLogic)->getSn(); switch ($value['type']) {
$value['financial_pm'] = 0; case 0:
$value['financial_type'] = OrderEnum::PAY_BACK; if ($value['financial_type'] == 12&& $value['other_uid']>0) {
$value['create_time'] = time();
if ($value['status'] == 1) {
switch ($value['type']) {
case 0:
$user = User::where('id', $value['other_uid'])->findOrEmpty(); $user = User::where('id', $value['other_uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userExpense('system_now_money_back', 'system_back', $value['order_id'], $value['number']); $user->now_money = bcsub($user['now_money'],$value['number'], 2);
break; $user->save();
case 1: // Log::error('aa'.$a);
if ($value['number'] > 0 &&$value['financial_type']==2) { // Log::error('aa'.$user['now_money']);
SystemStore::where('id', $value['store_id'])->dec('store_money',$value['number'])->update(); // Log::error('aa'.$value['number']);
} $capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'],'',$value['pay_type']);
if ($value['number'] > 0 &&$value['financial_type']==11) { }
SystemStore::where('id', $value['store_id'])->dec('paid_deposit',$value['number'])->update(); break;
} //商户
if ($value['number'] > 0 &&$value['financial_type']==16) { case 1:
SystemStore::where('id', $value['store_id'])->dec('attrition',$value['number'])->update(); if ($value['number'] > 0 && $value['financial_type'] == 2) {
} SystemStore::where('id', $value['store_id'])->dec('store_money', $value['number'])->update();
break; }
} if ($value['number'] > 0 && $value['financial_type'] == 16) {
SystemStore::where('id', $value['store_id'])->dec('attrition', $value['number'])->update();
}
break;
} }
} }
(new StoreFinanceFlow)->saveAll($data); $find = StoreFinanceFlow::where('order_sn', $orderSn)->where('financial_type', 11)->where('status',1)->find();
if ($find && $find['number'] > 0) {
SystemStore::where('id', $find['store_id'])->dec('paid_deposit', $find['number'])->update();
}
// $data = StoreFinanceFlow::where('order_sn', $orderSn)->select();
// foreach ($data as $k => &$value) {
// $value['status'] = -1;
// $value['financial_record_sn'] = (new StoreFinanceFlowLogic)->getSn();
// $value['financial_pm'] = 0;
// $value['financial_type'] = OrderEnum::PAY_BACK;
// $value['create_time'] = time();
// }
StoreFinanceFlow::where('order_sn', $orderSn)->update(['status'=>-1]);
// (new StoreFinanceFlow)->saveAll($data);
} }
} }