修改订单金额的错误
This commit is contained in:
parent
67131a8e5a
commit
19c9cf3c3b
app/common
dao/store/consumption
repositories/store/order
@ -18,17 +18,28 @@ class StoreConsumptionUserDao extends BaseDao
|
|||||||
|
|
||||||
/** @var float $maxAmount 单笔订单计算红包的最大有效金额 */
|
/** @var float $maxAmount 单笔订单计算红包的最大有效金额 */
|
||||||
public $maxAmount = 20000;
|
public $maxAmount = 20000;
|
||||||
|
|
||||||
/** @var float $orderTotalPrice 订单总金额 */
|
/** @var float $orderTotalPrice 订单总金额 */
|
||||||
public $orderTotalPrice;
|
public $orderTotalPrice;
|
||||||
|
|
||||||
/** @var float $orderPayPrice 订单实付金额 */
|
/** @var float $orderPayPrice 订单实付金额 */
|
||||||
public $orderPayPrice;
|
public $orderPayPrice;
|
||||||
|
|
||||||
/** @var float $orderProductPrice 当前商品金额 */
|
/** @var float $orderProductPrice 当前商品金额 */
|
||||||
public $orderProductPrice;
|
public $orderProductPrice;
|
||||||
|
|
||||||
/** @var float $realPriceTotal 扣除红包后实际支付金额 */
|
/** @var float $realPriceTotal 扣除红包后实际支付金额 */
|
||||||
public $realPriceTotal = 0;
|
public $realPriceTotal = 0;
|
||||||
|
|
||||||
/** @var float $isLast 是否最后一条数据 */
|
/** @var float $isLast 是否最后一条数据 */
|
||||||
public $isLast = false;
|
public $isLast = false;
|
||||||
|
|
||||||
|
/** @var float $groupOrderTotalPrice 订单组总金额 */
|
||||||
|
public $groupOrderTotalPrice;
|
||||||
|
|
||||||
|
/** @var float $consumptionTotalAmount 红包总金额 */
|
||||||
|
public $consumptionTotalAmount;
|
||||||
|
|
||||||
protected function getModel(): string
|
protected function getModel(): string
|
||||||
{
|
{
|
||||||
return StoreConsumptionUser::class;
|
return StoreConsumptionUser::class;
|
||||||
@ -293,7 +304,7 @@ class StoreConsumptionUserDao extends BaseDao
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据计算商品实际金额和红包金额
|
* 根据订单商品计算实际金额和红包金额
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function calculate()
|
public function calculate()
|
||||||
@ -319,4 +330,32 @@ class StoreConsumptionUserDao extends BaseDao
|
|||||||
return [$realPrice, $realPriceTotal, $consumptionAmount];
|
return [$realPrice, $realPriceTotal, $consumptionAmount];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单计算实际金额和红包金额
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function calculateByOrder()
|
||||||
|
{
|
||||||
|
// 把所有金额转换成分,避免红包金额产生误差
|
||||||
|
$orderTotalPrice = $this->orderTotalPrice * 100;
|
||||||
|
$groupOrderTotalPrice = $this->groupOrderTotalPrice * 100;
|
||||||
|
$consumptionBalance = $this->consumptionTotalAmount * 100;
|
||||||
|
$rate = bcdiv($orderTotalPrice, $groupOrderTotalPrice, 5);
|
||||||
|
if ($consumptionBalance >= $orderTotalPrice) {
|
||||||
|
$useAmount = $orderTotalPrice;
|
||||||
|
} else {
|
||||||
|
$useAmount = $this->isLast ? $consumptionBalance : bcmul($consumptionBalance, $rate, 5);
|
||||||
|
}
|
||||||
|
$consumptionBalance -= $useAmount;
|
||||||
|
$payPrice = $orderTotalPrice - $useAmount;
|
||||||
|
$groupOrderTotalPrice -= $useAmount;
|
||||||
|
|
||||||
|
$payPrice = bcdiv($payPrice, 100, 2);
|
||||||
|
$useAmount = bcdiv($useAmount, 100, 2);
|
||||||
|
$consumptionBalance = bcdiv($consumptionBalance, 100, 2);
|
||||||
|
$groupOrderTotalPrice = bcdiv($groupOrderTotalPrice, 100, 2);
|
||||||
|
/** $payPrice:实际支付的金额,$groupOrderTotalPrice:实际支付金额总计,$useAmount:红包金额总计,$consumptionAmount:红包余额总计 */
|
||||||
|
return [$payPrice, $groupOrderTotalPrice, $useAmount, $consumptionBalance];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace app\common\repositories\store\order;
|
namespace app\common\repositories\store\order;
|
||||||
|
|
||||||
|
use app\common\dao\store\consumption\StoreConsumptionUserDao;
|
||||||
use app\common\dao\store\order\StoreCartDao;
|
use app\common\dao\store\order\StoreCartDao;
|
||||||
use app\common\dao\store\StoreActivityDao;
|
use app\common\dao\store\StoreActivityDao;
|
||||||
use app\common\model\store\order\StoreGroupOrder;
|
use app\common\model\store\order\StoreGroupOrder;
|
||||||
@ -638,30 +639,28 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
}
|
}
|
||||||
$consumptionTotal = min($consumptionTotal, $this->balance);
|
$consumptionTotal = min($consumptionTotal, $this->balance);
|
||||||
}
|
}
|
||||||
|
$groupOrderPayPrice = $order_total_price;
|
||||||
foreach ($merchantCartList as $k => &$merchantCart) {
|
foreach ($merchantCartList as $k => &$merchantCart) {
|
||||||
$isLast = count($merchantCartList) == $k + 1;
|
$isLast = count($merchantCartList) == $k + 1;
|
||||||
$merchantPrice = 0;
|
$orderPayPrice = 0;
|
||||||
foreach ($merchantCart['list'] as &$cart) {
|
foreach ($merchantCart['list'] as &$cart) {
|
||||||
$cart['total_price'] = bcadd($cart['total_price'], $cart['svip_discount'], 2);
|
$cart['total_price'] = bcadd($cart['total_price'], $cart['svip_discount'], 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($consumptionTotal) {
|
if ($consumptionTotal) {
|
||||||
// 按当前店铺的商品金额计算使用的红包金额
|
$storeConsumptionUserDao = new StoreConsumptionUserDao();
|
||||||
$rate = bcdiv($merchantCart['order']['total_price'], $order_total_price, 6);
|
$storeConsumptionUserDao->groupOrderTotalPrice = $groupOrderPayPrice;
|
||||||
if ($consumptionTotal >= $order_total_price) {
|
$storeConsumptionUserDao->orderTotalPrice = $merchantCart['order']['total_price'];
|
||||||
$useAmount = $merchantCart['order']['total_price'];
|
$storeConsumptionUserDao->consumptionTotalAmount = $consumptionTotal;
|
||||||
} else {
|
$storeConsumptionUserDao->isLast = $isLast;
|
||||||
$useAmount = $isLast ? bcsub($consumptionTotal, $this->consumption_money, 2) : bcmul($consumptionTotal, $rate, 2);
|
[$orderPayPrice, $groupOrderPayPrice, $useAmount, $consumptionTotal] = $storeConsumptionUserDao->calculateByOrder();
|
||||||
}
|
|
||||||
$merchantProductPrice = bcsub($merchantCart['order']['total_price'], $useAmount, 2);
|
|
||||||
$merchantPrice = bcadd($merchantPrice, $merchantProductPrice, 2);
|
|
||||||
$this->consumption_money = bcadd($this->consumption_money, $useAmount, 2);
|
$this->consumption_money = bcadd($this->consumption_money, $useAmount, 2);
|
||||||
$this->balance = bcsub($this->balance, $useAmount, 2);
|
$this->balance = bcsub($this->balance, $useAmount, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($cart);
|
unset($cart);
|
||||||
$merchantCart['order']['consumption_money'] = $useAmount ?? '0.00';
|
$merchantCart['order']['consumption_money'] = $useAmount ?? '0.00';
|
||||||
$merchantCart['order']['real_price'] = $merchantPrice;
|
$merchantCart['order']['pay_price'] = $orderPayPrice;
|
||||||
$merchantCart['order']['total_price'] = bcadd($merchantCart['order']['total_price'], $merchantCart['order']['svip_discount'], 2);
|
$merchantCart['order']['total_price'] = bcadd($merchantCart['order']['total_price'], $merchantCart['order']['svip_discount'], 2);
|
||||||
$order_total_price = bcadd($order_total_price, $merchantCart['order']['svip_discount'], 2);
|
$order_total_price = bcadd($order_total_price, $merchantCart['order']['svip_discount'], 2);
|
||||||
}
|
}
|
||||||
@ -669,8 +668,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
$status = ($address || $order_model || $allow_no_address) ? ($noDeliver ? 'noDeliver' : 'finish') : 'noAddress';
|
$status = ($address || $order_model || $allow_no_address) ? ($noDeliver ? 'noDeliver' : 'finish') : 'noAddress';
|
||||||
$order = $merchantCartList;
|
$order = $merchantCartList;
|
||||||
$consumption_money = $this->consumption_money;
|
$consumption_money = $this->consumption_money;
|
||||||
$order_total_price = bcsub($order_total_price, $this->consumption_money, 2);
|
$order_price = $groupOrderPayPrice;
|
||||||
$order_price = $order_total_price;
|
|
||||||
$total_price = $order_total_price;
|
$total_price = $order_total_price;
|
||||||
$openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0;
|
$openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0;
|
||||||
$total_coupon = bcadd($order_svip_discount, bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2), 2);
|
$total_coupon = bcadd($order_svip_discount, bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2), 2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user