feat: 重构了退款逻辑,优化了代码结构
This commit is contained in:
parent
6ffd57704b
commit
b65ce4717a
@ -132,49 +132,21 @@ class StoreOrderLogic extends BaseLogic
|
||||
$refund = (new \app\common\logic\store_order\StoreOrderLogic())
|
||||
->refund($params['order_id'], $money, $pay_price);
|
||||
if ($refund) {
|
||||
$refund_price = $params['refund_price'];
|
||||
$refund_num = 0;
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find();
|
||||
if ($find) {
|
||||
$refund_num += $v['cart_num'];
|
||||
$cart_num = bcsub($find['cart_num'], $v['cart_num']);
|
||||
$total_price = bcmul($find['price'], $cart_num);
|
||||
$data = ['cart_num' => $cart_num, 'total_price' => $total_price];
|
||||
StoreOrderCartInfo::where('id', $find['id'])->update($data);
|
||||
$arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray();
|
||||
foreach ($arr as $key => $value) {
|
||||
$value['cart_num'] = $cart_num;
|
||||
$value['total_price'] = bcmul($cart_num, $value['price'], 2);
|
||||
$value['number'] = bcmul($value['total_price'], $value['rate'], 2);
|
||||
StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]);
|
||||
unset($value['id']);
|
||||
$value['create_time'] = strtotime($value['create_time']);
|
||||
$value['update_time'] = strtotime($value['update_time']);
|
||||
StoreFinanceFlowProduct::create($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
$village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid');
|
||||
$brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid');
|
||||
$transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id');
|
||||
StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]);
|
||||
$detail['refund_price']=$refund_price;
|
||||
CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
|
||||
|
||||
StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]);
|
||||
self::refundProduct($detail, $params);
|
||||
return '退款成功';
|
||||
}
|
||||
}
|
||||
//余额支付 采购款支付
|
||||
if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
|
||||
PayNotifyLogic::balance_purchase_refund($detail,0,$params['refund_price']);
|
||||
self::refundProduct($detail, $params);
|
||||
return '退款成功';
|
||||
|
||||
}
|
||||
//现金支付
|
||||
if ($detail['pay_type'] = PayEnum::CASH_PAY) {
|
||||
PayNotifyLogic::cash_refund($params['order_id']);
|
||||
self::refundProduct($detail, $params);
|
||||
return '退款成功';
|
||||
|
||||
}
|
||||
@ -208,7 +180,7 @@ class StoreOrderLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
public function refundProduct($detail, $params)
|
||||
public static function refundProduct($detail, $params)
|
||||
{
|
||||
$refund_price = $params['refund_price'];
|
||||
$refund_num = 0;
|
||||
@ -237,9 +209,9 @@ class StoreOrderLogic extends BaseLogic
|
||||
$brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid');
|
||||
$transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id');
|
||||
StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]);
|
||||
$detail['refund_price']=$refund_price;
|
||||
CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
|
||||
|
||||
StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]);
|
||||
StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]);
|
||||
}
|
||||
}
|
||||
|
@ -855,7 +855,7 @@ class PayNotifyLogic extends BaseLogic
|
||||
$updateData[] = [
|
||||
'id' => $StoreBranchProduct['id'],
|
||||
'stock' => $StoreBranchProduct['stock'] + $v['cart_num'],
|
||||
// 'sales' => ['inc', $v['cart_num']]
|
||||
'sales' => ['dec', $v['cart_num']]
|
||||
// 'sales' => ['inc', $v['cart_num']]
|
||||
];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user