Browse Source

fixed 卡券可否使用判断逻辑

fushengqian 1 year ago
parent
commit
af9f276972

+ 23 - 6
fuint-application/src/main/java/com/fuint/common/service/impl/CouponServiceImpl.java

@@ -71,6 +71,11 @@ public class CouponServiceImpl extends ServiceImpl<MtCouponMapper, MtCoupon> imp
      * */
     private MemberService memberService;
 
+    /**
+     * 会员等级服务接口
+     * */
+    private UserGradeService userGradeService;
+
     /**
      * 短信发送服务接口
      * */
@@ -818,8 +823,6 @@ public class CouponServiceImpl extends ServiceImpl<MtCouponMapper, MtCoupon> imp
             }
         }
 
-
-
         // 使用优惠券,判断满多少可用
         if (couponInfo.getType().equals(CouponTypeEnum.COUPON.getKey()) && StringUtil.isNotEmpty(couponInfo.getOutRule())) {
             if (orderInfo != null) {
@@ -830,10 +833,7 @@ public class CouponServiceImpl extends ServiceImpl<MtCouponMapper, MtCoupon> imp
         }
 
         // 判断可用店铺
-        if (couponInfo.getStoreId() != null || StringUtil.isNotEmpty(couponInfo.getStoreIds())) {
-            if (couponInfo.getStoreId() != null && !couponInfo.getStoreId().equals(orderInfo.getStoreId())) {
-                throw new BusinessCheckException("该卡券不能在当前门店使用");
-            }
+        if (StringUtil.isNotEmpty(couponInfo.getStoreIds())) {
             if (StringUtil.isNotEmpty(couponInfo.getStoreIds())) {
                 String[] storeIds = couponInfo.getStoreIds().split(",");
                 if (storeIds.length > 0 && !Arrays.asList(storeIds).contains(orderInfo.getStoreId().toString())) {
@@ -842,6 +842,23 @@ public class CouponServiceImpl extends ServiceImpl<MtCouponMapper, MtCoupon> imp
             }
         }
 
+        // 判断适用会员等级
+        if (userId != null && userId > 0 && StringUtil.isNotEmpty(couponInfo.getGradeIds())) {
+            MtUser mtUser = memberService.queryMemberById(userId);
+            if (StringUtil.isEmpty(mtUser.getGradeId())) {
+                MtUserGrade defaultGrade = userGradeService.getInitUserGrade(mtUser.getMerchantId());
+                if (defaultGrade != null) {
+                    mtUser.setGradeId(defaultGrade.getId().toString());
+                } else {
+                    mtUser.setGradeId("0");
+                }
+            }
+            String[] gradeIds = couponInfo.getGradeIds().split(",");
+            if (gradeIds.length > 0 && !Arrays.asList(gradeIds).contains(mtUser.getGradeId())) {
+                throw new BusinessCheckException("该卡券不适用该会员等级");
+            }
+        }
+
         if (couponInfo.getType().equals(CouponTypeEnum.COUPON.getKey())) {
             // 优惠券核销直接修改状态
             userCoupon.setStatus(UserCouponStatusEnum.USED.getKey());

+ 1 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/OrderServiceImpl.java

@@ -426,6 +426,7 @@ public class OrderServiceImpl extends ServiceImpl<MtOrderMapper, MtOrder> implem
 
             // 购物使用了卡券
             if (mtOrder.getCouponId() > 0) {
+                updateOrder(mtOrder);
                 String useCode = couponService.useCoupon(mtOrder.getCouponId(), mtOrder.getUserId(), mtOrder.getStoreId(), mtOrder.getId(), mtOrder.getDiscount(), "购物使用卡券");
                 // 卡券使用失败
                 if (StringUtil.isEmpty(useCode)) {