feat(StoreOrderController, PayNotifyLogic, StoreFinanceFlowLogic): 更新订单处理流程,优化退款逻辑,调整资金流动记录处理方式

This commit is contained in:
mkm 2024-08-02 23:56:37 +08:00
parent e0b7f75fdc
commit 87f40a0b04
3 changed files with 67 additions and 47 deletions

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

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

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