处理同一商品存在满减和数量的选择问题

This commit is contained in:
wucongxing 2023-12-15 16:15:36 +08:00
parent 269856d09c
commit 39e5cc13d4

View File

@ -124,9 +124,6 @@ class UserCouponService extends BaseService
// 优惠卷最高金额
$coupon_high_price = 0;
// 优惠卷最大数量
$coupon_high_num = 0;
// 是否存在互斥卷
$is_mutex = 0;
@ -136,8 +133,8 @@ class UserCouponService extends BaseService
$coupons[$key]['cannot_use_coupon_reason'] = ""; // 不可使用原因
}
foreach ($coupons as $key => $coupon) {
// 处理优惠卷数量限制问题
foreach ($coupons as $key => $coupon) {
if ($coupon['coupon_type'] == 3 && !empty($coupon['product_id'])){
// 数量是否足够标识字段
$quantity_quantity = 0;
@ -175,7 +172,14 @@ class UserCouponService extends BaseService
continue;
}
$product_price = bcadd($product_price,$coupon_product_data['product_price'],2);
$product_price = bcadd($product_price,
bcmul( // 商品价格*数量
$coupon_product_data['product_price'],
$coupon_product_data['product_num'],
2
),
2
);
}
if ($coupon['with_amount'] > $product_price){
@ -207,23 +211,14 @@ class UserCouponService extends BaseService
if (empty($selected_coupons)) {
$selected_coupons[] = $coupon; // 选中的优惠卷数据
// 满减/无门槛-最高价格
if ($coupon['coupon_type'] == 1 || $coupon['coupon_type'] == 2){
$coupon_high_price = $coupon['coupon_price'];
}
// 数量
if ($coupon['coupon_type'] == 3){
$coupon_high_num = $coupon['min_usable_number'];
}
continue;
}
dump($coupon_high_price);
// 处理存在互斥卷情况
if ($is_mutex == 1) {
// 满减/无门槛-最高价格
if ($coupon['coupon_type'] == 1 || $coupon['coupon_type'] == 2){
// 选择金额最高的为选中
if ($coupon['coupon_price'] < $coupon_high_price){
continue;
@ -240,25 +235,6 @@ class UserCouponService extends BaseService
}
}
// 数量
if ($coupon['coupon_type'] == 3){
// 选择金额最高的为选中
if ($coupon['min_usable_number'] < $coupon_high_num){
continue;
}
if ($coupon['min_usable_number'] > $coupon_high_num) {
$coupon_high_num = $coupon['min_usable_number'];
// 选中的优惠卷数据置空
$selected_coupons = array();
$selected_coupons[] = $coupon;
continue;
}
}
}
$selected_coupons[] = $coupon; // 选中的优惠卷数据
}