|
|
@@ -796,23 +796,43 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
* @param type 券类型:保留兼容,仅 null 或 1(仅用户优惠券);4 已废弃
|
|
|
* @param couponType 优惠券类型:1-满减券,2-折扣券,null-全部
|
|
|
* @param storeId 商铺ID,可为空,传则仅返回该商铺的优惠券
|
|
|
+ * @param storeKeyword 店铺名称关键字,非空时仅门店名称匹配的券参与分页(与筛选后再分页一致)
|
|
|
* @return 优惠券列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type, Integer couponType, String storeId) {
|
|
|
+ public List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type, Integer couponType, String storeId, String storeKeyword) {
|
|
|
validateGetUserCouponListParams(userLoginInfo, tabType, type);
|
|
|
|
|
|
ZoneId zone = ZoneId.systemDefault();
|
|
|
LocalDate today = LocalDate.now(zone);
|
|
|
|
|
|
- LambdaQueryWrapper<LifeDiscountCouponUser> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(LifeDiscountCouponUser::getUserId, userLoginInfo.getUserId());
|
|
|
- applyUserCouponTabTypeFilter(queryWrapper, tabType, today, today.plusDays(7), today.minusDays(7));
|
|
|
- // 仅 life_discount_coupon 用户券(有 coupon_id);模板可能已被商家逻辑删除,下层用 includeDeleted 再查属性
|
|
|
- queryWrapper.isNotNull(LifeDiscountCouponUser::getCouponId);
|
|
|
- queryWrapper.orderByDesc(LifeDiscountCouponUser::getCreatedTime);
|
|
|
+ String filterStoreId = null;
|
|
|
+ if (storeId != null) {
|
|
|
+ String trimmed = storeId.trim();
|
|
|
+ if (!trimmed.isEmpty()) {
|
|
|
+ filterStoreId = trimmed;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String keyword = null;
|
|
|
+ if (storeKeyword != null) {
|
|
|
+ String t = storeKeyword.trim();
|
|
|
+ if (!t.isEmpty()) {
|
|
|
+ keyword = t;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 联表先按模板 + tab + couponType + storeId + 店铺名称关键字筛选再分页(含商家逻辑删除的模板)
|
|
|
+ IPage<LifeDiscountCouponUser> pageResult = lifeDiscountCouponUserMapper.selectPageAfterTemplateFilter(
|
|
|
+ new Page<>(page, size),
|
|
|
+ userLoginInfo.getUserId(),
|
|
|
+ tabType,
|
|
|
+ today,
|
|
|
+ today.plusDays(7),
|
|
|
+ today.minusDays(7),
|
|
|
+ couponType,
|
|
|
+ filterStoreId,
|
|
|
+ keyword);
|
|
|
|
|
|
- IPage<LifeDiscountCouponUser> pageResult = lifeDiscountCouponUserMapper.selectPage(new Page<>(page, size), queryWrapper);
|
|
|
List<LifeDiscountCouponUser> userRows = pageResult.getRecords();
|
|
|
if (userRows.isEmpty()) {
|
|
|
return new ArrayList<>();
|
|
|
@@ -825,11 +845,8 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
|
|
|
List<LifeDiscountCouponVo> result = new ArrayList<>();
|
|
|
for (LifeDiscountCouponUser row : userRows) {
|
|
|
- if (row.getCouponId() == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- LifeDiscountCoupon template = templateById.get(row.getCouponId());
|
|
|
- if (template == null || !matchesUserCouponListFilters(template, couponType, storeId)) {
|
|
|
+ LifeDiscountCoupon template = row.getCouponId() == null ? null : templateById.get(row.getCouponId());
|
|
|
+ if (template == null) {
|
|
|
continue;
|
|
|
}
|
|
|
result.add(buildCouponVo(template, row, zone, today, storeByIdStr));
|
|
|
@@ -855,33 +872,6 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /** tabType:与用户券分页 tab 对齐的 SQL 条件(expiration/status) */
|
|
|
- private void applyUserCouponTabTypeFilter(LambdaQueryWrapper<LifeDiscountCouponUser> queryWrapper, String tabType,
|
|
|
- LocalDate today, LocalDate sevenDaysLater, LocalDate sevenDaysAgo) {
|
|
|
- if (DiscountCouponEnum.ALL.getValue().equals(tabType)) {
|
|
|
- // 未使用:过期日 >= 今天 或过期时间为 null;含「今天过期」仍可展示
|
|
|
- queryWrapper.and(w -> w.ge(LifeDiscountCouponUser::getExpirationTime, today)
|
|
|
- .or().isNull(LifeDiscountCouponUser::getExpirationTime))
|
|
|
- .eq(LifeDiscountCouponUser::getStatus, DiscountCouponEnum.WAITING_USED.getValue());
|
|
|
- return;
|
|
|
- }
|
|
|
- if (DiscountCouponEnum.BE_ABOUT_TO_EXPORE.getValue().equals(tabType)) {
|
|
|
- queryWrapper.ge(LifeDiscountCouponUser::getExpirationTime, today)
|
|
|
- .le(LifeDiscountCouponUser::getExpirationTime, sevenDaysLater)
|
|
|
- .eq(LifeDiscountCouponUser::getStatus, DiscountCouponEnum.WAITING_USED.getValue());
|
|
|
- return;
|
|
|
- }
|
|
|
- if (DiscountCouponEnum.HAVE_ALREADY_APPLIED.getValue().equals(tabType)) {
|
|
|
- queryWrapper.eq(LifeDiscountCouponUser::getStatus, DiscountCouponEnum.HAVE_BEEN_USED.getValue());
|
|
|
- return;
|
|
|
- }
|
|
|
- if (DiscountCouponEnum.HAVE_EXPIRED.getValue().equals(tabType)) {
|
|
|
- queryWrapper.gt(LifeDiscountCouponUser::getExpirationTime, sevenDaysAgo)
|
|
|
- .lt(LifeDiscountCouponUser::getExpirationTime, today)
|
|
|
- .eq(LifeDiscountCouponUser::getStatus, DiscountCouponEnum.WAITING_USED.getValue());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private List<LifeDiscountCoupon> loadCouponTemplatesIncludeDeleted(List<LifeDiscountCouponUser> userRows) {
|
|
|
List<Integer> couponIds = userRows.stream()
|
|
|
.map(LifeDiscountCouponUser::getCouponId)
|
|
|
@@ -907,13 +897,6 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
return infos.stream().collect(Collectors.toMap(s -> s.getId().toString(), s -> s, (a, b) -> a));
|
|
|
}
|
|
|
|
|
|
- private boolean matchesUserCouponListFilters(LifeDiscountCoupon template, Integer couponType, String filterStoreId) {
|
|
|
- if (couponType != null && !couponType.equals(template.getCouponType())) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- return StringUtils.isEmpty(filterStoreId) || filterStoreId.equals(template.getStoreId());
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 构建优惠券VO
|
|
|
*/
|