修改退款的错误
This commit is contained in:
parent
33e4dd43f2
commit
28cdc83da0
@ -36,14 +36,11 @@ class RefundOrderService
|
|||||||
throw new BusinessException('订单不能退款');
|
throw new BusinessException('订单不能退款');
|
||||||
}
|
}
|
||||||
$orderCartInfoWhere = ['oid' => $order['id']];
|
$orderCartInfoWhere = ['oid' => $order['id']];
|
||||||
$refundNum = 0;
|
|
||||||
if (!empty($params['product_arr'])) {
|
if (!empty($params['product_arr'])) {
|
||||||
$orderCartInfoWhere['product_id'] = array_column($params['product_arr'], 'product_id');
|
$orderCartInfoWhere['product_id'] = array_column($params['product_arr'], 'product_id');
|
||||||
$refundNum = count($params['product_arr']);
|
|
||||||
}
|
}
|
||||||
if (!empty($params['old_cart_id'])) {
|
if (!empty($params['old_cart_id'])) {
|
||||||
$orderCartInfoWhere['id'] = $params['old_cart_id'];
|
$orderCartInfoWhere['id'] = $params['old_cart_id'];
|
||||||
$refundNum = count($params['old_cart_id']);
|
|
||||||
$params['product_arr'] = StoreOrderCartInfo::field('product_id,cart_num')->where($orderCartInfoWhere)->select()->toArray();
|
$params['product_arr'] = StoreOrderCartInfo::field('product_id,cart_num')->where($orderCartInfoWhere)->select()->toArray();
|
||||||
}
|
}
|
||||||
$orderCartProducts = StoreOrderCartInfo::where($orderCartInfoWhere)->select();
|
$orderCartProducts = StoreOrderCartInfo::where($orderCartInfoWhere)->select();
|
||||||
@ -63,7 +60,7 @@ class RefundOrderService
|
|||||||
$this->refundMoney($order, $refundAmount);
|
$this->refundMoney($order, $refundAmount);
|
||||||
$this->updateProductStock($orderCartProducts, $productInfo);
|
$this->updateProductStock($orderCartProducts, $productInfo);
|
||||||
$this->updateOrderCartInfo($order, $orderCartProducts, $refundAmount, $productInfo);
|
$this->updateOrderCartInfo($order, $orderCartProducts, $refundAmount, $productInfo);
|
||||||
$this->updateOrderStatus($order, $refundAmount, $refundNum);
|
$this->updateOrderStatus($order, $refundAmount);
|
||||||
$this->resetStoreFinanceFlow($order, $orderCartProducts, $productInfo);
|
$this->resetStoreFinanceFlow($order, $orderCartProducts, $productInfo);
|
||||||
// if ($order->status == 2 && $order->is_writeoff == 1) {
|
// if ($order->status == 2 && $order->is_writeoff == 1) {
|
||||||
// $this->financeSettle($order);
|
// $this->financeSettle($order);
|
||||||
@ -116,6 +113,8 @@ class RefundOrderService
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$number = $productInfo[$product['product_id']]['cart_num'];
|
$number = $productInfo[$product['product_id']]['cart_num'];
|
||||||
|
$maxNumber = bcsub($product['cart_num'], $product['refund_num'], 2);
|
||||||
|
$number = min($number, $maxNumber);
|
||||||
$storeBranchProductId = StoreBranchProduct::where('store_id', $product['store_id'])
|
$storeBranchProductId = StoreBranchProduct::where('store_id', $product['store_id'])
|
||||||
->where('product_id', $product['product_id'])
|
->where('product_id', $product['product_id'])
|
||||||
->withTrashed()->value('id');
|
->withTrashed()->value('id');
|
||||||
@ -133,7 +132,8 @@ class RefundOrderService
|
|||||||
/**
|
/**
|
||||||
* 更新订单商品状态
|
* 更新订单商品状态
|
||||||
* @param $order
|
* @param $order
|
||||||
* @param $orderCartIds
|
* @param $orderCartProducts
|
||||||
|
* @param $refundAmount
|
||||||
* @param $productInfo
|
* @param $productInfo
|
||||||
* @return void
|
* @return void
|
||||||
* @throws DbException
|
* @throws DbException
|
||||||
@ -178,14 +178,13 @@ class RefundOrderService
|
|||||||
* 更新订单状态
|
* 更新订单状态
|
||||||
* @param $order
|
* @param $order
|
||||||
* @param $refundAmount
|
* @param $refundAmount
|
||||||
* @param $refundNum
|
|
||||||
* @return void
|
* @return void
|
||||||
* @throws DbException
|
* @throws DbException
|
||||||
*/
|
*/
|
||||||
public function updateOrderStatus($order, $refundAmount, $refundNum): void
|
public function updateOrderStatus($order, $refundAmount): void
|
||||||
{
|
{
|
||||||
$order->refund_price = bcadd($order['refund_price'], $refundAmount, 2);
|
$order->refund_price = bcadd($order['refund_price'], $refundAmount, 2);
|
||||||
$order->refund_num += $refundNum;
|
$order->refund_num = StoreOrderCartInfo::where('oid', $order['id'])->where('refund_num', '>', 0)->count();
|
||||||
if ($order->pay_price == $order->refund_price) {
|
if ($order->pay_price == $order->refund_price) {
|
||||||
// 全部退款完成,订单状态改为已退款
|
// 全部退款完成,订单状态改为已退款
|
||||||
$order->refund_status = OrderEnum::REFUND_STATUS_FINISH;
|
$order->refund_status = OrderEnum::REFUND_STATUS_FINISH;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user