|
@@ -997,7 +997,16 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
IPage<LifeDiscountCoupon> iPage = new Page<>(page, size);
|
|
IPage<LifeDiscountCoupon> iPage = new Page<>(page, size);
|
|
|
List<LifeDiscountCouponVo> lifeDiscountCouponVos = new ArrayList<>();
|
|
List<LifeDiscountCouponVo> lifeDiscountCouponVos = new ArrayList<>();
|
|
|
LambdaQueryWrapper<LifeDiscountCoupon> lifeDiscountCouponLambdaQueryWrapper = new LambdaQueryWrapper<LifeDiscountCoupon>();
|
|
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不为空,则模糊查询
|
|
//如果couponName不为空,则模糊查询
|
|
|
if (!StringUtils.isEmpty(couponName)) {
|
|
if (!StringUtils.isEmpty(couponName)) {
|
|
|
lifeDiscountCouponLambdaQueryWrapper.like(LifeDiscountCoupon::getName, couponName);
|
|
lifeDiscountCouponLambdaQueryWrapper.like(LifeDiscountCoupon::getName, couponName);
|
|
@@ -1020,8 +1029,18 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
// 已结束:结束时间 < 当前时间 且 开启领取
|
|
// 已结束:结束时间 < 当前时间 且 开启领取
|
|
|
lifeDiscountCouponLambdaQueryWrapper.lt(LifeDiscountCoupon::getEndGetDate, pureDate)
|
|
lifeDiscountCouponLambdaQueryWrapper.lt(LifeDiscountCoupon::getEndGetDate, pureDate)
|
|
|
.eq(LifeDiscountCoupon::getGetStatus, 1);
|
|
.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=0或其他值:查询全部,不添加额外条件
|
|
|
|
|
+ // tab=3(草稿)已在上面处理,这里不再重复设置
|
|
|
lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getStoreId, storeId);
|
|
lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getStoreId, storeId);
|
|
|
lifeDiscountCouponLambdaQueryWrapper.orderByDesc(LifeDiscountCoupon::getCreatedTime);
|
|
lifeDiscountCouponLambdaQueryWrapper.orderByDesc(LifeDiscountCoupon::getCreatedTime);
|
|
|
//根据店铺id查询该店铺的优惠券,状态是开启领取的券
|
|
//根据店铺id查询该店铺的优惠券,状态是开启领取的券
|
|
@@ -1034,30 +1053,63 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
Instant instant = now.toInstant();
|
|
Instant instant = now.toInstant();
|
|
|
ZoneId zoneId = ZoneId.systemDefault();
|
|
ZoneId zoneId = ZoneId.systemDefault();
|
|
|
LocalDate localNow = instant.atZone(zoneId).toLocalDate();
|
|
LocalDate localNow = instant.atZone(zoneId).toLocalDate();
|
|
|
|
|
+
|
|
|
|
|
+ // 计算优惠券状态
|
|
|
|
|
+ Integer calculatedStatus = null;
|
|
|
if (!StringUtils.isEmpty(lifeDiscountCoupon.getBeginGetDate()) && !StringUtils.isEmpty(lifeDiscountCoupon.getEndGetDate())) {
|
|
if (!StringUtils.isEmpty(lifeDiscountCoupon.getBeginGetDate()) && !StringUtils.isEmpty(lifeDiscountCoupon.getEndGetDate())) {
|
|
|
int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
|
|
int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
|
|
|
int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
|
|
int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
|
|
|
//如果当前时间小于开始时间
|
|
//如果当前时间小于开始时间
|
|
|
if (lifeDiscountCoupon.getSingleQty() == null || lifeDiscountCoupon.getSingleQty() == 0) {//无库存则已售罄
|
|
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) {
|
|
} 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())) {
|
|
} 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) {
|
|
} else if (endResult > 0) {
|
|
|
- lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
|
|
|
|
|
|
|
+ calculatedStatus = Integer.parseInt(DiscountCouponEnum.FINISHED.getValue());
|
|
|
} else if (startResult >= 0 && endResult <= 0) {
|
|
} else if (startResult >= 0 && endResult <= 0) {
|
|
|
- lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
|
|
|
|
|
|
|
+ calculatedStatus = Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue());
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
if (lifeDiscountCoupon.getCouponStatus() == 0) {
|
|
if (lifeDiscountCoupon.getCouponStatus() == 0) {
|
|
|
//如果为草稿则状态为未开始
|
|
//如果为草稿则状态为未开始
|
|
|
- lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
|
|
|
|
|
|
|
+ calculatedStatus = Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue());
|
|
|
} else {
|
|
} else {
|
|
|
// 开始结束时间为空,数据异常跳过
|
|
// 开始结束时间为空,数据异常跳过
|
|
|
continue;
|
|
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(
|
|
List<LifeDiscountCouponUnavailableRules> unavailableRules = lifeDiscountCouponUnavailableRulesMapper.selectList(
|
|
|
new LambdaQueryWrapper<LifeDiscountCouponUnavailableRules>()
|
|
new LambdaQueryWrapper<LifeDiscountCouponUnavailableRules>()
|
|
@@ -1100,6 +1152,16 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
IPage<LifeDiscountCouponStoreFriendVo> iPage = new Page<>(page, size);
|
|
IPage<LifeDiscountCouponStoreFriendVo> iPage = new Page<>(page, size);
|
|
|
List<LifeDiscountCouponVo> friendLifeDiscountCouponVos = new ArrayList<>();
|
|
List<LifeDiscountCouponVo> friendLifeDiscountCouponVos = new ArrayList<>();
|
|
|
QueryWrapper<LifeDiscountCouponStoreFriendVo> friendLifeDiscountCouponQueryWrapper = new QueryWrapper<>();
|
|
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不为空,则模糊查询
|
|
//如果couponName不为空,则模糊查询
|
|
|
if (!StringUtils.isEmpty(couponName)) {
|
|
if (!StringUtils.isEmpty(couponName)) {
|
|
|
friendLifeDiscountCouponQueryWrapper.like("ldc.name", couponName);
|
|
friendLifeDiscountCouponQueryWrapper.like("ldc.name", couponName);
|
|
@@ -1121,8 +1183,18 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
// 已结束:结束时间 < 当前时间 且 开启领取
|
|
// 已结束:结束时间 < 当前时间 且 开启领取
|
|
|
friendLifeDiscountCouponQueryWrapper.lt("ldc.end_date", pureDate)
|
|
friendLifeDiscountCouponQueryWrapper.lt("ldc.end_date", pureDate)
|
|
|
.eq("ldc.get_status", 1);
|
|
.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=0或其他值:查询全部,不添加额外条件
|
|
|
|
|
+ // tab=3(草稿)已在上面处理,这里不再重复设置
|
|
|
friendLifeDiscountCouponQueryWrapper.orderByDesc("ldc.created_time");
|
|
friendLifeDiscountCouponQueryWrapper.orderByDesc("ldc.created_time");
|
|
|
friendLifeDiscountCouponQueryWrapper.eq("ldcsf.store_user_id", storeId);
|
|
friendLifeDiscountCouponQueryWrapper.eq("ldcsf.store_user_id", storeId);
|
|
|
friendLifeDiscountCouponQueryWrapper.eq("ldcsf.delete_flag", 0);
|
|
friendLifeDiscountCouponQueryWrapper.eq("ldcsf.delete_flag", 0);
|
|
@@ -1134,30 +1206,63 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
Instant instant = now.toInstant();
|
|
Instant instant = now.toInstant();
|
|
|
ZoneId zoneId = ZoneId.systemDefault();
|
|
ZoneId zoneId = ZoneId.systemDefault();
|
|
|
LocalDate localNow = instant.atZone(zoneId).toLocalDate();
|
|
LocalDate localNow = instant.atZone(zoneId).toLocalDate();
|
|
|
|
|
+
|
|
|
|
|
+ // 计算优惠券状态
|
|
|
|
|
+ Integer calculatedStatus = null;
|
|
|
if (!StringUtils.isEmpty(record.getBeginGetDate()) && !StringUtils.isEmpty(record.getEndGetDate())) {
|
|
if (!StringUtils.isEmpty(record.getBeginGetDate()) && !StringUtils.isEmpty(record.getEndGetDate())) {
|
|
|
int startResult = localNow.compareTo(record.getBeginGetDate());
|
|
int startResult = localNow.compareTo(record.getBeginGetDate());
|
|
|
int endResult = localNow.compareTo(record.getEndGetDate());
|
|
int endResult = localNow.compareTo(record.getEndGetDate());
|
|
|
//如果当前时间小于开始时间
|
|
//如果当前时间小于开始时间
|
|
|
if (record.getSingleQty() == null || record.getSingleQty() == 0) {//无库存则已售罄
|
|
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())) {
|
|
} 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) {
|
|
} 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) {
|
|
} else if (endResult > 0) {
|
|
|
- record.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
|
|
|
|
|
|
|
+ calculatedStatus = Integer.parseInt(DiscountCouponEnum.FINISHED.getValue());
|
|
|
} else {
|
|
} else {
|
|
|
- record.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
|
|
|
|
|
|
|
+ calculatedStatus = Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue());
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
if (record.getCouponStatus() == 0) {
|
|
if (record.getCouponStatus() == 0) {
|
|
|
//如果为草稿则状态为未开始
|
|
//如果为草稿则状态为未开始
|
|
|
- record.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
|
|
|
|
|
|
|
+ calculatedStatus = Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue());
|
|
|
} else {
|
|
} else {
|
|
|
// 开始结束时间为空,数据异常跳过
|
|
// 开始结束时间为空,数据异常跳过
|
|
|
continue;
|
|
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(
|
|
List<LifeDiscountCouponUnavailableRules> unavailableRules = lifeDiscountCouponUnavailableRulesMapper.selectList(
|
|
|
new LambdaQueryWrapper<LifeDiscountCouponUnavailableRules>()
|
|
new LambdaQueryWrapper<LifeDiscountCouponUnavailableRules>()
|