From 439dd21d81165b09daaa2f605a2be7460fbb62ac Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sun, 4 Feb 2024 16:51:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=80=80=E6=AC=BE=E9=87=91?= =?UTF-8?q?=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumption/StoreConsumptionUserDao.php | 1 + .../order/StoreRefundOrderRepository.php | 56 +++++-------------- 2 files changed, 15 insertions(+), 42 deletions(-) diff --git a/app/common/dao/store/consumption/StoreConsumptionUserDao.php b/app/common/dao/store/consumption/StoreConsumptionUserDao.php index 6a09e7d6..1b79fbb6 100755 --- a/app/common/dao/store/consumption/StoreConsumptionUserDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionUserDao.php @@ -330,6 +330,7 @@ class StoreConsumptionUserDao extends BaseDao } /** + * @deprecated 已废弃,用下面的 typeTwoByProduct 和 typeOneByProduct * 根据订单商品计算实际金额和红包金额 * @return array */ diff --git a/app/common/repositories/store/order/StoreRefundOrderRepository.php b/app/common/repositories/store/order/StoreRefundOrderRepository.php index bbdd3bdc..11a23fc8 100755 --- a/app/common/repositories/store/order/StoreRefundOrderRepository.php +++ b/app/common/repositories/store/order/StoreRefundOrderRepository.php @@ -244,23 +244,14 @@ class StoreRefundOrderRepository extends BaseRepository $productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id')); $totalPostage = 0; $totalRefundPrice = 0; - $realPriceTotal = 0; $consumptionTotal = 0; foreach ($products as $k => $product) { - $isLast = count($products->toArray()) == ($k + 1); - $storeConsumptionUserDao = new StoreConsumptionUserDao(); - $storeConsumptionUserDao->orderTotalPrice = $order['total_price']; - $storeConsumptionUserDao->orderPayPrice = $order['pay_price']; - $storeConsumptionUserDao->orderProductPrice = $product['product_price']; - $storeConsumptionUserDao->realPriceTotal = $realPriceTotal; - $storeConsumptionUserDao->isLast = $isLast; - [$realPrice, $realPriceTotal, $consumptionPrice] = $storeConsumptionUserDao->calculate(); - $consumptionTotal = bcadd($consumptionTotal, $consumptionPrice, 2); + $consumptionTotal = bcadd($consumptionTotal, $product['consumption_price'], 2); $productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? []; $postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0; $refundPrice = 0; - if ($realPrice > 0) { - $refundPrice = bcsub($realPrice, bcsub($productRefundPrice['refund_price'] ?? 0,$productRefundPrice['refund_postage']??0 ,2), 2); + if ($product['pay_price'] > 0) { + $refundPrice = bcsub($product['pay_price'], bcsub($productRefundPrice['refund_price'] ?? 0,$productRefundPrice['refund_postage']??0 ,2), 2); } $totalPostage = bcadd($totalPostage, $postagePrice, 2); $totalRefundPrice = bcadd($totalRefundPrice, $refundPrice, 2); @@ -291,12 +282,8 @@ class StoreRefundOrderRepository extends BaseRepository $productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id')); $product = $products[0]; $productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? []; - $storeConsumptionUserDao = new StoreConsumptionUserDao(); - $storeConsumptionUserDao->orderTotalPrice = $order['total_price']; - $storeConsumptionUserDao->orderPayPrice = $order['pay_price']; - $storeConsumptionUserDao->orderProductPrice = $product['product_price']; - [$realPrice, $realPriceTotal, $consumptionPrice] = $storeConsumptionUserDao->calculate(); - $total_refund_price = bcsub($realPrice, bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2); + $consumptionPrice = $product['consumption_price']; + $total_refund_price = bcsub($product['pay_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2); $postage_price = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0; return compact('total_refund_price', 'postage_price', 'consumptionPrice'); @@ -342,18 +329,10 @@ class StoreRefundOrderRepository extends BaseRepository $total_extension_two = bcadd($total_extension_two, bcmul($product['refund_num'], $product['extension_two'], 2), 2); $postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0; $totalRefundNum += $product['refund_num']; + $refundPrice = 0; - //计算可退金额 - if ($order['total_price'] > 0) { - $isLast = count($products->toArray()) == ($k + 1); - $storeConsumptionUserDao = new StoreConsumptionUserDao(); - $storeConsumptionUserDao->orderTotalPrice = $order['total_price']; - $storeConsumptionUserDao->orderPayPrice = $order['pay_price']; - $storeConsumptionUserDao->orderProductPrice = $product['product_price']; - $storeConsumptionUserDao->realPriceTotal = $totalRefundPrice; - $storeConsumptionUserDao->isLast = $isLast; - [$refundPrice, $totalRefundPrice, $consumptionPrice] = $storeConsumptionUserDao->calculate(); - $consumptionTotal = bcadd($consumptionTotal, $consumptionPrice, 2); + if ($product['pay_price'] > 0) { + $refundPrice = bcsub($product['pay_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2); } $platform_refund_price = 0; @@ -366,6 +345,8 @@ class StoreRefundOrderRepository extends BaseRepository $integral = bcsub($product['integral_total'], $productRefundPrice['refund_integral'] ?? 0, 0); } + $consumptionTotal = bcadd($consumptionTotal, $product['consumption_price'], 2); + $totalRefundPrice = bcadd($totalRefundPrice, $refundPrice, 2); $totalPostage = bcadd($totalPostage, $postagePrice, 2); $totalPlatformRefundPrice = bcadd($totalPlatformRefundPrice, $platform_refund_price, 2); $totalIntegral = bcadd($totalIntegral, $integral, 2); @@ -377,7 +358,7 @@ class StoreRefundOrderRepository extends BaseRepository 'platform_refund_price' => $platform_refund_price, 'refund_integral' => $integral, 'refund_price' => $refundPrice, - 'refund_consumption' => $consumptionPrice, + 'refund_consumption' => $product['consumption_price'], 'refund_postage' => $postagePrice, ]; } @@ -478,22 +459,13 @@ class StoreRefundOrderRepository extends BaseRepository $refundPrice = 0; //计算可退金额 if ($product['product_price'] > 0) { - $storeConsumptionUserDao = new StoreConsumptionUserDao(); - $storeConsumptionUserDao->orderTotalPrice = $order['total_price']; - $storeConsumptionUserDao->orderPayPrice = $order['pay_price']; - $storeConsumptionUserDao->orderProductPrice = $product['product_price']; - $storeConsumptionUserDao->realPriceTotal = 0; - [$realPrice, $realPriceTotal, $consumptionPrice] = $storeConsumptionUserDao->calculate(); - // 商品原始单价 - $originPrice = bcdiv($product['product_price'], $product['product_num'], 2); // 商品实付单价 - $payPrice = bcdiv($realPrice, $product['product_num'], 2); + $payPrice = bcdiv($product['pay_price'], $product['product_num'], 2); + $consumptionPrice = $product['consumption_price']; if ($product['refund_num'] == $num) { - $refundPrice = bcsub($realPrice, bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2); - $consumptionPrice = bcmul(bcsub($originPrice, $payPrice, 2), $num, 2); + $refundPrice = bcsub($product['pay_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2); } else { $refundPrice = bcmul($payPrice, $num, 2); - $consumptionPrice = bcmul(bcsub($originPrice, $payPrice, 2), $num, 2); } } $totalRefundPrice = bcadd($refundPrice, $postagePrice, 2);