调整红包使用逻辑

This commit is contained in:
luofei 2024-01-24 18:36:07 +08:00
parent 46d2e3f382
commit 0ba2a41731

View File

@ -643,16 +643,18 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$merchantPrice = 0;
foreach ($merchantCart['list'] as &$cart) {
$cart['total_price'] = bcadd($cart['total_price'], $cart['svip_discount'], 2);
if ($consumptionTotal) {
// 按当前店铺的商品金额计算使用的红包金额
$rate = bcdiv($cart['total_price'], $order_total_price, 6);
$useAmount = $isLast ? bcsub($consumptionTotal, $this->consumption_money, 2) : bcmul($consumptionTotal, $rate, 2);
$merchantProductPrice = bcsub($cart['total_price'], $useAmount, 2);
$merchantPrice = bcadd($merchantPrice, $merchantProductPrice, 2);
$this->consumption_money = bcadd($this->consumption_money, $useAmount, 2);
$this->balance = bcsub($this->balance, $useAmount, 2);
}
}
if ($consumptionTotal) {
// 按当前店铺的商品金额计算使用的红包金额
$rate = bcdiv($merchantCart['order']['total_price'], $order_total_price, 6);
$useAmount = $isLast ? bcsub($consumptionTotal, $this->consumption_money, 2) : bcmul($consumptionTotal, $rate, 2);
$merchantProductPrice = bcsub($merchantCart['order']['total_price'], $useAmount, 2);
$merchantPrice = bcadd($merchantPrice, $merchantProductPrice, 2);
$this->consumption_money = bcadd($this->consumption_money, $useAmount, 2);
$this->balance = bcsub($this->balance, $useAmount, 2);
}
unset($cart);
$merchantCart['order']['consumption_money'] = $useAmount ?? '0.00';
$merchantCart['order']['real_price'] = $merchantPrice;