调整优惠券余额扣除
This commit is contained in:
parent
71fa117ae8
commit
b9211cbb48
@ -390,6 +390,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
unset($coupon);
|
unset($coupon);
|
||||||
$pay_price = max(bcsub($valid_total_price, $coupon_price, 2), 0);
|
$pay_price = max(bcsub($valid_total_price, $coupon_price, 2), 0);
|
||||||
$_pay_price = $pay_price;
|
$_pay_price = $pay_price;
|
||||||
|
$cartCoupon = []; //购物车各商品的优惠券信息
|
||||||
//计算店铺券
|
//计算店铺券
|
||||||
foreach ($merchantCart['coupon'] as &$coupon) {
|
foreach ($merchantCart['coupon'] as &$coupon) {
|
||||||
if (!in_array($coupon['coupon']['type'], [0, 2])) continue;
|
if (!in_array($coupon['coupon']['type'], [0, 2])) continue;
|
||||||
@ -419,6 +420,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
[$payPrice, $useAmount, $couponUsed] = $storeCouponUserDao->couponByProduct($coupon['coupon_type']);
|
[$payPrice, $useAmount, $couponUsed] = $storeCouponUserDao->couponByProduct($coupon['coupon_type']);
|
||||||
$coupon_price = bcadd($coupon_price, $useAmount, 2);
|
$coupon_price = bcadd($coupon_price, $useAmount, 2);
|
||||||
$_pay_price = bcsub($_pay_price, $useAmount, 2);
|
$_pay_price = bcsub($_pay_price, $useAmount, 2);
|
||||||
|
$cartCoupon[$cart['cart_id']][] = ['coupon_user_id' => $coupon['coupon_user_id'], 'coupon_price' => $useAmount, 'true_price' => $payPrice];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$coupon_price = bcadd($coupon_price, $coupon['coupon_price'], 2);
|
$coupon_price = bcadd($coupon_price, $coupon['coupon_price'], 2);
|
||||||
@ -439,7 +441,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
$productCouponRate[$productId] = [
|
$productCouponRate[$productId] = [
|
||||||
'rate' => $product_price[$productId] > 0 ? bcdiv($coupon['coupon_price'], $product_price[$productId], 4) : 1,
|
'rate' => $product_price[$productId] > 0 ? bcdiv($coupon['coupon_price'], $product_price[$productId], 4) : 1,
|
||||||
'coupon_price' => $coupon['coupon_price'],
|
'coupon_price' => $coupon['coupon_price'],
|
||||||
'price' => $product_price[$productId]
|
'price' => $product_price[$productId],
|
||||||
|
'coupon_user_id' => $coupon['coupon_user_id']
|
||||||
];
|
];
|
||||||
$useCouponIds[] = $coupon['coupon_user_id'];
|
$useCouponIds[] = $coupon['coupon_user_id'];
|
||||||
}
|
}
|
||||||
@ -448,7 +451,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
$storeCouponRate = [
|
$storeCouponRate = [
|
||||||
'rate' => $pay_price > 0 ? bcdiv($use_store_coupon['coupon_price'], $pay_price, 4) : 1,
|
'rate' => $pay_price > 0 ? bcdiv($use_store_coupon['coupon_price'], $pay_price, 4) : 1,
|
||||||
'coupon_price' => $use_store_coupon['coupon_price'],
|
'coupon_price' => $use_store_coupon['coupon_price'],
|
||||||
'price' => $coupon_price
|
'price' => $coupon_price,
|
||||||
|
'coupon_user_id' => $use_store_coupon['coupon_user_id']
|
||||||
];
|
];
|
||||||
$useCouponIds[] = $use_store_coupon['coupon_user_id'];
|
$useCouponIds[] = $use_store_coupon['coupon_user_id'];
|
||||||
}
|
}
|
||||||
@ -465,27 +469,35 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
} else {
|
} else {
|
||||||
array_pop($product_cart);
|
array_pop($product_cart);
|
||||||
if (!count($product_cart)) {
|
if (!count($product_cart)) {
|
||||||
|
$cartCoupon[$cart['cart_id']][] = ['coupon_user_id' => $productCouponRate[$cart['product_id']]['coupon_user_id'], 'coupon_price' => $productCouponRate[$cart['product_id']]['coupon_price']];
|
||||||
$cartTotalPrice = bcsub($cartTotalPrice, $productCouponRate[$cart['product_id']]['coupon_price'], 2);
|
$cartTotalPrice = bcsub($cartTotalPrice, $productCouponRate[$cart['product_id']]['coupon_price'], 2);
|
||||||
$productCouponRate[$cart['product_id']]['coupon_price'] = 0;
|
$productCouponRate[$cart['product_id']]['coupon_price'] = 0;
|
||||||
} else {
|
} else {
|
||||||
$couponPrice = bcmul($cartTotalPrice, $productCouponRate[$cart['product_id']]['rate'], 2);
|
$couponPrice = $productCouponRate[$cart['product_id']]['coupon_price'];
|
||||||
$cartTotalPrice = bcsub($cartTotalPrice, $couponPrice, 2);
|
$cartTotalPrice = bcsub($cartTotalPrice, $couponPrice, 2);
|
||||||
$productCouponRate[$cart['product_id']]['coupon_price'] = bcsub($productCouponRate[$cart['product_id']]['coupon_price'], $couponPrice, 2);
|
$productCouponRate[$cart['product_id']]['coupon_price'] = bcsub($productCouponRate[$cart['product_id']]['coupon_price'], $couponPrice, 2);
|
||||||
|
$cartCoupon[$cart['cart_id']][] = ['coupon_user_id' => $productCouponRate[$cart['product_id']]['coupon_user_id'], 'coupon_price' => $couponPrice];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//(店铺券)
|
//(店铺券)
|
||||||
if ($storeCouponRate && $cartTotalPrice > 0) {
|
if ($storeCouponRate && $cartTotalPrice > 0) {
|
||||||
if ($storeCouponRate['rate'] >= 1) {
|
if (isset($cartCoupon[$cart['cart_id']])) {
|
||||||
$cartTotalPrice = 0;
|
$couponPrice = $cartCoupon[$cart['cart_id']][0]['coupon_price'];
|
||||||
|
$cartTotalPrice = bcsub($cartTotalPrice, $couponPrice, 2);
|
||||||
|
$storeCouponRate['coupon_price'] = bcsub($storeCouponRate['coupon_price'], $couponPrice, 2);
|
||||||
} else {
|
} else {
|
||||||
if (count($merchantCart['list']) == $_k + 1) {
|
if ($storeCouponRate['rate'] >= 1) {
|
||||||
$cartTotalPrice = bcsub($cartTotalPrice, $storeCouponRate['coupon_price'], 2);
|
$cartTotalPrice = 0;
|
||||||
} else {
|
} else {
|
||||||
$couponPrice = bcmul($cartTotalPrice, $storeCouponRate['rate'], 2);
|
if (count($merchantCart['list']) == $_k + 1) {
|
||||||
$cartTotalPrice = bcsub($cartTotalPrice, $couponPrice, 2);
|
$cartTotalPrice = bcsub($cartTotalPrice, $storeCouponRate['coupon_price'], 2);
|
||||||
$storeCouponRate['coupon_price'] = bcsub($storeCouponRate['coupon_price'], $couponPrice, 2);
|
} else {
|
||||||
|
$couponPrice = bcmul($cartTotalPrice, $storeCouponRate['rate'], 2);
|
||||||
|
$cartTotalPrice = bcsub($cartTotalPrice, $couponPrice, 2);
|
||||||
|
$storeCouponRate['coupon_price'] = bcsub($storeCouponRate['coupon_price'], $couponPrice, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -520,6 +532,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
'svip_discount' => $total_svip_discount,
|
'svip_discount' => $total_svip_discount,
|
||||||
'use_svip' => $use_svip,
|
'use_svip' => $use_svip,
|
||||||
'order_refund_switch' => $order_refund_switch,
|
'order_refund_switch' => $order_refund_switch,
|
||||||
|
'store_coupon' => $cartCoupon,
|
||||||
];
|
];
|
||||||
$order_total_postage = bcadd($order_total_postage, $postage_price, 2);
|
$order_total_postage = bcadd($order_total_postage, $postage_price, 2);
|
||||||
$order_svip_discount = bcadd($total_svip_discount, $order_svip_discount, 2);
|
$order_svip_discount = bcadd($total_svip_discount, $order_svip_discount, 2);
|
||||||
@ -1173,7 +1186,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($useCoupon[$order['mer_id']])) {
|
if (!empty($useCoupon[$order['mer_id']])) {
|
||||||
$storeCouponUserDao->reduce($useCoupon[$order['mer_id']][0], $order['total_price']);
|
$storeCouponUserDao->reduceAll($order['cartInfo']['order']['store_coupon']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1188,7 +1201,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
|
|
||||||
//使用了平台优惠券
|
//使用了平台优惠券
|
||||||
if (!empty($useCoupon[0])) {
|
if (!empty($useCoupon[0])) {
|
||||||
$storeCouponUserDao->reduce($useCoupon[0][0], $groupOrder['total_price']);
|
$storeCouponUserDao->reduce($useCoupon[0][0], $orderInfo['total_platform_coupon_price']);
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建订单
|
//创建订单
|
||||||
|
Loading…
x
Reference in New Issue
Block a user