调整退款金额

This commit is contained in:
luofei 2024-02-04 16:51:59 +08:00
parent 9d19ea5a1a
commit 439dd21d81
2 changed files with 15 additions and 42 deletions

View File

@ -330,6 +330,7 @@ class StoreConsumptionUserDao extends BaseDao
} }
/** /**
* @deprecated 已废弃,用下面的 typeTwoByProduct typeOneByProduct
* 根据订单商品计算实际金额和红包金额 * 根据订单商品计算实际金额和红包金额
* @return array * @return array
*/ */

View File

@ -244,23 +244,14 @@ class StoreRefundOrderRepository extends BaseRepository
$productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id')); $productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id'));
$totalPostage = 0; $totalPostage = 0;
$totalRefundPrice = 0; $totalRefundPrice = 0;
$realPriceTotal = 0;
$consumptionTotal = 0; $consumptionTotal = 0;
foreach ($products as $k => $product) { foreach ($products as $k => $product) {
$isLast = count($products->toArray()) == ($k + 1); $consumptionTotal = bcadd($consumptionTotal, $product['consumption_price'], 2);
$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);
$productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? []; $productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? [];
$postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0; $postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$refundPrice = 0; $refundPrice = 0;
if ($realPrice > 0) { if ($product['pay_price'] > 0) {
$refundPrice = bcsub($realPrice, bcsub($productRefundPrice['refund_price'] ?? 0,$productRefundPrice['refund_postage']??0 ,2), 2); $refundPrice = bcsub($product['pay_price'], bcsub($productRefundPrice['refund_price'] ?? 0,$productRefundPrice['refund_postage']??0 ,2), 2);
} }
$totalPostage = bcadd($totalPostage, $postagePrice, 2); $totalPostage = bcadd($totalPostage, $postagePrice, 2);
$totalRefundPrice = bcadd($totalRefundPrice, $refundPrice, 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')); $productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id'));
$product = $products[0]; $product = $products[0];
$productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? []; $productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? [];
$storeConsumptionUserDao = new StoreConsumptionUserDao(); $consumptionPrice = $product['consumption_price'];
$storeConsumptionUserDao->orderTotalPrice = $order['total_price']; $total_refund_price = bcsub($product['pay_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
$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);
$postage_price = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0; $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'); 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); $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; $postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$totalRefundNum += $product['refund_num']; $totalRefundNum += $product['refund_num'];
$refundPrice = 0; $refundPrice = 0;
//计算可退金额 if ($product['pay_price'] > 0) {
if ($order['total_price'] > 0) { $refundPrice = bcsub($product['pay_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
$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);
} }
$platform_refund_price = 0; $platform_refund_price = 0;
@ -366,6 +345,8 @@ class StoreRefundOrderRepository extends BaseRepository
$integral = bcsub($product['integral_total'], $productRefundPrice['refund_integral'] ?? 0, 0); $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); $totalPostage = bcadd($totalPostage, $postagePrice, 2);
$totalPlatformRefundPrice = bcadd($totalPlatformRefundPrice, $platform_refund_price, 2); $totalPlatformRefundPrice = bcadd($totalPlatformRefundPrice, $platform_refund_price, 2);
$totalIntegral = bcadd($totalIntegral, $integral, 2); $totalIntegral = bcadd($totalIntegral, $integral, 2);
@ -377,7 +358,7 @@ class StoreRefundOrderRepository extends BaseRepository
'platform_refund_price' => $platform_refund_price, 'platform_refund_price' => $platform_refund_price,
'refund_integral' => $integral, 'refund_integral' => $integral,
'refund_price' => $refundPrice, 'refund_price' => $refundPrice,
'refund_consumption' => $consumptionPrice, 'refund_consumption' => $product['consumption_price'],
'refund_postage' => $postagePrice, 'refund_postage' => $postagePrice,
]; ];
} }
@ -478,22 +459,13 @@ class StoreRefundOrderRepository extends BaseRepository
$refundPrice = 0; $refundPrice = 0;
//计算可退金额 //计算可退金额
if ($product['product_price'] > 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) { if ($product['refund_num'] == $num) {
$refundPrice = bcsub($realPrice, bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2); $refundPrice = bcsub($product['pay_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
$consumptionPrice = bcmul(bcsub($originPrice, $payPrice, 2), $num, 2);
} else { } else {
$refundPrice = bcmul($payPrice, $num, 2); $refundPrice = bcmul($payPrice, $num, 2);
$consumptionPrice = bcmul(bcsub($originPrice, $payPrice, 2), $num, 2);
} }
} }
$totalRefundPrice = bcadd($refundPrice, $postagePrice, 2); $totalRefundPrice = bcadd($refundPrice, $postagePrice, 2);