Преглед изворни кода

优惠券查询状态添加

lutong пре 1 месец
родитељ
комит
7db401fa7b

+ 1 - 1
alien-store/src/main/java/shop/alien/store/controller/LifeDiscountCouponController.java

@@ -240,7 +240,7 @@ public class LifeDiscountCouponController {
             @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = false),
             @ApiImplicitParam(name = "storeId", value = "商户id", dataType = "String", paramType = "query", required = true),
             @ApiImplicitParam(name = "couponName", value = "优惠券名称", dataType = "String", paramType = "query", required = false),
-            @ApiImplicitParam(name = "tab", value = "分页类型(0:全部(传其他也查全部),1:进行中,2:已结束)", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "tab", value = "分页类型(0:全部,1:进行中,2:已结束,3:草稿,4:未开始,5:已下架,6:已清库)", dataType = "String", paramType = "query", required = true),
             @ApiImplicitParam(name = "couponsFromType", required = false, value = "查询类型(1:我的优惠券,2:好友的优惠券)", dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "couponStatus", required = false, value = "优惠券状态(0:草稿,1:正式)", dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "couponType", value = "优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选)", dataType = "Integer", paramType = "query", required = false),

+ 118 - 13
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponServiceImpl.java

@@ -997,7 +997,16 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
             IPage<LifeDiscountCoupon> iPage = new Page<>(page, size);
             List<LifeDiscountCouponVo> lifeDiscountCouponVos = new ArrayList<>();
             LambdaQueryWrapper<LifeDiscountCoupon> lifeDiscountCouponLambdaQueryWrapper = new LambdaQueryWrapper<LifeDiscountCoupon>();
-            lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getCouponStatus, couponStatus);
+            
+            // 如果tab=3(草稿),强制设置couponStatus=0;否则使用传入的couponStatus参数
+            if ("3".equals(tab)) {
+                // 草稿:强制设置为couponStatus = 0
+                lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getCouponStatus, 0);
+            } else {
+                // 非草稿状态:使用传入的couponStatus参数
+                lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getCouponStatus, couponStatus);
+            }
+            
             //如果couponName不为空,则模糊查询
             if (!StringUtils.isEmpty(couponName)) {
                 lifeDiscountCouponLambdaQueryWrapper.like(LifeDiscountCoupon::getName, couponName);
@@ -1020,8 +1029,18 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                 // 已结束:结束时间 < 当前时间 且 开启领取
                 lifeDiscountCouponLambdaQueryWrapper.lt(LifeDiscountCoupon::getEndGetDate, pureDate)
                         .eq(LifeDiscountCoupon::getGetStatus, 1);
+            } else if ("4".equals(tab)) {
+                // 未开始:开始时间 > 当前时间
+                lifeDiscountCouponLambdaQueryWrapper.gt(LifeDiscountCoupon::getBeginGetDate, pureDate);
+            } else if ("5".equals(tab)) {
+                // 已下架:getStatus = 0(暂停领取)
+                lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getGetStatus, 0);
+            } else if ("6".equals(tab)) {
+                // 已清库:库存为0
+                lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getSingleQty, 0);
             }
             // tab=0或其他值:查询全部,不添加额外条件
+            // tab=3(草稿)已在上面处理,这里不再重复设置
             lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getStoreId, storeId);
             lifeDiscountCouponLambdaQueryWrapper.orderByDesc(LifeDiscountCoupon::getCreatedTime);
             //根据店铺id查询该店铺的优惠券,状态是开启领取的券
@@ -1034,30 +1053,63 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                 Instant instant = now.toInstant();
                 ZoneId zoneId = ZoneId.systemDefault();
                 LocalDate localNow = instant.atZone(zoneId).toLocalDate();
+                
+                // 计算优惠券状态
+                Integer calculatedStatus = null;
                 if (!StringUtils.isEmpty(lifeDiscountCoupon.getBeginGetDate()) && !StringUtils.isEmpty(lifeDiscountCoupon.getEndGetDate())) {
                     int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
                     int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
                     //如果当前时间小于开始时间
                     if (lifeDiscountCoupon.getSingleQty() == null || lifeDiscountCoupon.getSingleQty() == 0) {//无库存则已售罄
-                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue());
                     } else if (startResult < 0) {
-                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue());
                     } else if (lifeDiscountCoupon.getGetStatus() == null || lifeDiscountCoupon.getGetStatus().toString().equals(DiscountCouponEnum.NO_GET.getValue())) {
-                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue());
                     } else if (endResult > 0) {
-                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.FINISHED.getValue());
                     } else if (startResult >= 0 && endResult <= 0) {
-                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue());
                     }
                 } else {
                     if (lifeDiscountCoupon.getCouponStatus() == 0) {
                         //如果为草稿则状态为未开始
-                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue());
                     } else {
                         // 开始结束时间为空,数据异常跳过
                         continue;
                     }
                 }
+                
+                // 如果状态计算失败,跳过该记录
+                if (calculatedStatus == null) {
+                    continue;
+                }
+                
+                // 根据tab类型过滤状态
+                if (!"0".equals(tab)) {
+                    if ("3".equals(tab) && lifeDiscountCoupon.getCouponStatus() != 0) {
+                        // 草稿:必须是couponStatus=0
+                        continue;
+                    } else if ("4".equals(tab) && !calculatedStatus.equals(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()))) {
+                        // 未开始:必须是未开始状态
+                        continue;
+                    } else if ("5".equals(tab) && !calculatedStatus.equals(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()))) {
+                        // 已下架:必须是暂停领取状态
+                        continue;
+                    } else if ("6".equals(tab) && !calculatedStatus.equals(Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue()))) {
+                        // 已清库:必须是已售罄状态
+                        continue;
+                    } else if ("1".equals(tab) && !calculatedStatus.equals(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()))) {
+                        // 进行中:必须是进行中状态
+                        continue;
+                    } else if ("2".equals(tab) && !calculatedStatus.equals(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()))) {
+                        // 已结束:必须是已结束状态
+                        continue;
+                    }
+                }
+                
+                lifeDiscountCouponVo.setStatus(calculatedStatus);
                 // 查询优惠券不可用规则(工作日、节假日、领取规则)
                 List<LifeDiscountCouponUnavailableRules> unavailableRules = lifeDiscountCouponUnavailableRulesMapper.selectList(
                         new LambdaQueryWrapper<LifeDiscountCouponUnavailableRules>()
@@ -1100,6 +1152,16 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
             IPage<LifeDiscountCouponStoreFriendVo> iPage = new Page<>(page, size);
             List<LifeDiscountCouponVo> friendLifeDiscountCouponVos = new ArrayList<>();
             QueryWrapper<LifeDiscountCouponStoreFriendVo> friendLifeDiscountCouponQueryWrapper = new QueryWrapper<>();
+            
+            // 如果tab=3(草稿),强制设置couponStatus=0;否则使用传入的couponStatus参数
+            if ("3".equals(tab)) {
+                // 草稿:强制设置为couponStatus = 0
+                friendLifeDiscountCouponQueryWrapper.eq("ldc.coupon_status", 0);
+            } else {
+                // 非草稿状态:使用传入的couponStatus参数(好友优惠券也需要根据couponStatus过滤)
+                friendLifeDiscountCouponQueryWrapper.eq("ldc.coupon_status", couponStatus);
+            }
+            
             //如果couponName不为空,则模糊查询
             if (!StringUtils.isEmpty(couponName)) {
                 friendLifeDiscountCouponQueryWrapper.like("ldc.name", couponName);
@@ -1121,8 +1183,18 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                 // 已结束:结束时间 < 当前时间 且 开启领取
                 friendLifeDiscountCouponQueryWrapper.lt("ldc.end_date", pureDate)
                         .eq("ldc.get_status", 1);
+            } else if ("4".equals(tab)) {
+                // 未开始:开始时间 > 当前时间
+                friendLifeDiscountCouponQueryWrapper.gt("ldc.start_date", pureDate);
+            } else if ("5".equals(tab)) {
+                // 已下架:getStatus = 0(暂停领取)
+                friendLifeDiscountCouponQueryWrapper.eq("ldc.get_status", 0);
+            } else if ("6".equals(tab)) {
+                // 已清库:库存为0
+                friendLifeDiscountCouponQueryWrapper.eq("ldc.single_qty", 0);
             }
             // tab=0或其他值:查询全部,不添加额外条件
+            // tab=3(草稿)已在上面处理,这里不再重复设置
             friendLifeDiscountCouponQueryWrapper.orderByDesc("ldc.created_time");
             friendLifeDiscountCouponQueryWrapper.eq("ldcsf.store_user_id", storeId);
             friendLifeDiscountCouponQueryWrapper.eq("ldcsf.delete_flag", 0);
@@ -1134,30 +1206,63 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                 Instant instant = now.toInstant();
                 ZoneId zoneId = ZoneId.systemDefault();
                 LocalDate localNow = instant.atZone(zoneId).toLocalDate();
+                
+                // 计算优惠券状态
+                Integer calculatedStatus = null;
                 if (!StringUtils.isEmpty(record.getBeginGetDate()) && !StringUtils.isEmpty(record.getEndGetDate())) {
                     int startResult = localNow.compareTo(record.getBeginGetDate());
                     int endResult = localNow.compareTo(record.getEndGetDate());
                     //如果当前时间小于开始时间
                     if (record.getSingleQty() == null || record.getSingleQty() == 0) {//无库存则已售罄
-                        record.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue());
                     } else if (record.getGetStatus() == null || record.getGetStatus().toString().equals(DiscountCouponEnum.NO_GET.getValue())) {
-                        record.setStatus(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue());
                     } else if (startResult < 0) {
-                        record.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue());
                     } else if (endResult > 0) {
-                        record.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.FINISHED.getValue());
                     } else {
-                        record.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue());
                     }
                 } else {
                     if (record.getCouponStatus() == 0) {
                         //如果为草稿则状态为未开始
-                        record.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
+                        calculatedStatus = Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue());
                     } else {
                         // 开始结束时间为空,数据异常跳过
                         continue;
                     }
                 }
+                
+                // 如果状态计算失败,跳过该记录
+                if (calculatedStatus == null) {
+                    continue;
+                }
+                
+                // 根据tab类型过滤状态
+                if (!"0".equals(tab)) {
+                    if ("3".equals(tab) && record.getCouponStatus() != 0) {
+                        // 草稿:必须是couponStatus=0
+                        continue;
+                    } else if ("4".equals(tab) && !calculatedStatus.equals(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()))) {
+                        // 未开始:必须是未开始状态
+                        continue;
+                    } else if ("5".equals(tab) && !calculatedStatus.equals(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()))) {
+                        // 已下架:必须是暂停领取状态
+                        continue;
+                    } else if ("6".equals(tab) && !calculatedStatus.equals(Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue()))) {
+                        // 已清库:必须是已售罄状态
+                        continue;
+                    } else if ("1".equals(tab) && !calculatedStatus.equals(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()))) {
+                        // 进行中:必须是进行中状态
+                        continue;
+                    } else if ("2".equals(tab) && !calculatedStatus.equals(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()))) {
+                        // 已结束:必须是已结束状态
+                        continue;
+                    }
+                }
+                
+                record.setStatus(calculatedStatus);
                 // 查询优惠券不可用规则(好友优惠券)
                 List<LifeDiscountCouponUnavailableRules> unavailableRules = lifeDiscountCouponUnavailableRulesMapper.selectList(
                         new LambdaQueryWrapper<LifeDiscountCouponUnavailableRules>()