From 269856d09c3886b8b1a8f20fda551c1b32460512 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Fri, 15 Dec 2023 15:47:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=8D=B7=E6=97=B6=E5=90=8C=E4=B8=80=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E6=95=B0=E9=87=8F=E4=BC=98=E6=83=A0=E5=8D=B7?= =?UTF-8?q?=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 | 55 ++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/app/Services/UserCouponService.php b/app/Services/UserCouponService.php index 43b9a7c..2901752 100644 --- a/app/Services/UserCouponService.php +++ b/app/Services/UserCouponService.php @@ -124,6 +124,9 @@ class UserCouponService extends BaseService // 优惠卷最高金额 $coupon_high_price = 0; + // 优惠卷最大数量 + $coupon_high_num = 0; + // 是否存在互斥卷 $is_mutex = 0; @@ -201,28 +204,58 @@ class UserCouponService extends BaseService continue; } - if (empty($selected_coupon)) { + if (empty($selected_coupons)) { $selected_coupons[] = $coupon; // 选中的优惠卷数据 - $coupon_high_price = $coupon['coupon_price']; + // 满减/无门槛-最高价格 + 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; } // 处理存在互斥卷情况 if ($is_mutex == 1) { - // 选择金额最高的为选中 - if ($coupon['coupon_price'] < $coupon_high_price){ - continue; + // 满减/无门槛-最高价格 + 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) { - $coupon_high_price = $coupon['coupon_price']; + // 数量 + if ($coupon['coupon_type'] == 3){ + // 选择金额最高的为选中 + if ($coupon['min_usable_number'] < $coupon_high_num){ + continue; + } - // 选中的优惠卷数据置空 - $selected_coupons = array(); - $selected_coupons[] = $coupon; + if ($coupon['min_usable_number'] > $coupon_high_num) { + $coupon_high_num = $coupon['min_usable_number']; - continue; + // 选中的优惠卷数据置空 + $selected_coupons = array(); + $selected_coupons[] = $coupon; + + continue; + } } }