From 39e5cc13d451c9ce02e3118725b6e1e06f83c270 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Fri, 15 Dec 2023 16:15:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=90=8C=E4=B8=80=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=AD=98=E5=9C=A8=E6=BB=A1=E5=87=8F=E5=92=8C=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E7=9A=84=E9=80=89=E6=8B=A9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/UserCouponService.php | 64 ++++++++++-------------------- 1 file changed, 20 insertions(+), 44 deletions(-) diff --git a/app/Services/UserCouponService.php b/app/Services/UserCouponService.php index 2901752..5dd9bad 100644 --- a/app/Services/UserCouponService.php +++ b/app/Services/UserCouponService.php @@ -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) { - // 处理优惠卷数量限制问题 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,55 +211,27 @@ 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']; - } + $coupon_high_price = $coupon['coupon_price']; 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; - } - - if ($coupon['coupon_price'] > $coupon_high_price) { - $coupon_high_price = $coupon['coupon_price']; - - // 选中的优惠卷数据置空 - $selected_coupons = array(); - $selected_coupons[] = $coupon; - - continue; - } + // 选择金额最高的为选中 + if ($coupon['coupon_price'] < $coupon_high_price){ + continue; } - // 数量 - if ($coupon['coupon_type'] == 3){ - // 选择金额最高的为选中 - if ($coupon['min_usable_number'] < $coupon_high_num){ - continue; - } + if ($coupon['coupon_price'] > $coupon_high_price) { + $coupon_high_price = $coupon['coupon_price']; - if ($coupon['min_usable_number'] > $coupon_high_num) { - $coupon_high_num = $coupon['min_usable_number']; + // 选中的优惠卷数据置空 + $selected_coupons = array(); + $selected_coupons[] = $coupon; - // 选中的优惠卷数据置空 - $selected_coupons = array(); - $selected_coupons[] = $coupon; - - continue; - } + continue; } }