From 98d65a1cad2cbaf7583aa8643729553342405be3 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Mon, 5 Feb 2024 17:59:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BA=A2=E5=8C=85=E9=80=80?= =?UTF-8?q?=E8=BF=98=E9=87=91=E9=A2=9D=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/order/StoreRefundProductDao.php | 2 +- .../store/order/StoreRefundOrderRepository.php | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/common/dao/store/order/StoreRefundProductDao.php b/app/common/dao/store/order/StoreRefundProductDao.php index c3287853..8857dec9 100755 --- a/app/common/dao/store/order/StoreRefundProductDao.php +++ b/app/common/dao/store/order/StoreRefundProductDao.php @@ -40,7 +40,7 @@ class StoreRefundProductDao extends BaseDao $lst = $this->getModel()::getDB()->alias('A')->leftJoin('StoreRefundOrder B', 'A.refund_order_id = B.refund_order_id') ->where('B.status', '>', -1) ->whereIn('A.order_product_id', $ids)->group('A.order_product_id') - ->field('A.order_product_id, SUM(A.refund_price) as refund_price, SUM(A.platform_refund_price) as platform_refund_price, SUM(A.refund_postage) as refund_postage, SUM(A.refund_integral) as refund_integral') + ->field('A.order_product_id, SUM(A.refund_price) as refund_price, SUM(A.platform_refund_price) as platform_refund_price, SUM(A.refund_postage) as refund_postage, SUM(A.refund_integral) as refund_integral, SUM(A.refund_consumption) as refund_consumption') ->select()->toArray(); $data = []; foreach ($lst as $item) { diff --git a/app/common/repositories/store/order/StoreRefundOrderRepository.php b/app/common/repositories/store/order/StoreRefundOrderRepository.php index 11a23fc8..d348e254 100755 --- a/app/common/repositories/store/order/StoreRefundOrderRepository.php +++ b/app/common/repositories/store/order/StoreRefundOrderRepository.php @@ -457,15 +457,18 @@ class StoreRefundOrderRepository extends BaseRepository $postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0; $refundPrice = 0; + $consumptionRefund = 0; //计算可退金额 if ($product['product_price'] > 0) { // 商品实付单价 $payPrice = bcdiv($product['pay_price'], $product['product_num'], 2); - $consumptionPrice = $product['consumption_price']; + $consumptionPrice = bcdiv($product['consumption_price'], $product['product_num'], 2); if ($product['refund_num'] == $num) { $refundPrice = bcsub($product['pay_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2); + $consumptionRefund = bcsub($product['consumption_price'], $productRefundPrice['refund_consumption'] ?? 0, 2); } else { $refundPrice = bcmul($payPrice, $num, 2); + $consumptionRefund = bcmul($consumptionPrice, $num, 2); } } $totalRefundPrice = bcadd($refundPrice, $postagePrice, 2); @@ -516,12 +519,12 @@ class StoreRefundOrderRepository extends BaseRepository $data['refund_num'] = $num; $data['extension_one'] = $total_extension_one; $data['extension_two'] = $total_extension_two; - $data['refund_consumption'] = $consumptionPrice ?? 0; + $data['refund_consumption'] = $consumptionRefund; if ($order['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) { $data['refund_price'] = 0; } - return Db::transaction(function () use ($order, $data, $product, $productId, $num) { + return Db::transaction(function () use ($order, $data, $product, $productId, $num, $consumptionRefund) { event('refund.create.before', compact('data')); $refund = $this->dao->create($data); app()->make(StoreRefundProductRepository::class)->create([ @@ -532,6 +535,7 @@ class StoreRefundOrderRepository extends BaseRepository 'refund_price' => $data['refund_price'], 'refund_integral' => $data['integral'], 'refund_postage' => $data['refund_postage'], + 'refund_consumption' => $consumptionRefund, ]); $product->refund_num -= $num; $product->is_refund = 1;