This commit is contained in:
2025-10-17 13:59:14 +08:00
parent 237b1f3b88
commit a095f7dc73

View File

@@ -239,55 +239,61 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
return null;
}
ShopUser shopUser = shopUserService.getOne(new QueryWrapper()
.eq(ShopUser::getUserId, userId).eq(ShopUser::getMainShopId, shopId).eq(ShopUser::getBirthDayRemind, 0));
.eq(ShopUser::getUserId, userId).isNotNull(ShopUser::getBirthDay)
.eq(ShopUser::getMainShopId, shopId).eq(ShopUser::getBirthDayRemind, 0));
if (shopUser == null) {
return null;
}
if (StrUtil.isBlank(birthdayGift.getConfigList())) {
return null;
}
//获取当天日期
LocalDate current = DateUtil.date().toLocalDateTime().toLocalDate();
// 解析用户生日(仅取月日)
LocalDate userBirthday = DateUtil.parseDate(shopUser.getBirthDay()).toLocalDateTime().toLocalDate();
// 构造当前年份的生日日期(用于区间判断)
LocalDate thisYearBirthday = LocalDate.of(current.getYear(), userBirthday.getMonth(), userBirthday.getDayOfMonth());
for (MkBirthdayGiftConfig config : JSONArray.parseArray(birthdayGift.getConfigList()).toJavaList(MkBirthdayGiftConfig.class)) {
if ("day".equals(config.getDeliverDate())) {
// 获取偏移天数默认为0偏移天数应为非负数代表未来的天数
int offsetDays = config.getDeliverTime() != null ? Math.max(config.getDeliverTime(), 0) : 0;
// 计算偏移后的结束日期(当前日期 + 偏移天数)
LocalDate endDate = current.plusDays(offsetDays);
// 开始日期固定为当前日期
LocalDate startDate = current;
try {
//获取当天日期
LocalDate current = DateUtil.date().toLocalDateTime().toLocalDate();
// 解析用户生日(仅取月日)
LocalDate userBirthday = DateUtil.parseDate(shopUser.getBirthDay()).toLocalDateTime().toLocalDate();
// 构造当前年份的生日日期(用于区间判断)
LocalDate thisYearBirthday = LocalDate.of(current.getYear(), userBirthday.getMonth(), userBirthday.getDayOfMonth());
for (MkBirthdayGiftConfig config : JSONArray.parseArray(birthdayGift.getConfigList()).toJavaList(MkBirthdayGiftConfig.class)) {
if ("day".equals(config.getDeliverDate())) {
// 获取偏移天数默认为0偏移天数应为非负数代表未来的天数
int offsetDays = config.getDeliverTime() != null ? Math.max(config.getDeliverTime(), 0) : 0;
// 计算偏移后的结束日期(当前日期 + 偏移天数)
LocalDate endDate = current.plusDays(offsetDays);
// 开始日期固定为当前日期
LocalDate startDate = current;
if (StrUtil.isNotBlank(shopUser.getBirthDay())) {
try {
boolean isInRange = false;
if ((thisYearBirthday.isEqual(startDate) || thisYearBirthday.isAfter(startDate))
&& (thisYearBirthday.isEqual(endDate) || thisYearBirthday.isBefore(endDate))) {
isInRange = true;
if (StrUtil.isNotBlank(shopUser.getBirthDay())) {
try {
boolean isInRange = false;
if ((thisYearBirthday.isEqual(startDate) || thisYearBirthday.isAfter(startDate))
&& (thisYearBirthday.isEqual(endDate) || thisYearBirthday.isBefore(endDate))) {
isInRange = true;
}
// 如果生日在范围内,返回优惠券列表
if (isInRange) {
shopUserService.updateById(new ShopUser().setId(shopUser.getId()).setBirthDayRemind(1));
return buildCouponList(config);
}
} catch (Exception e) {
log.error("解析用户生日失败", e);
}
// 如果生日在范围内,返回优惠券列表
if (isInRange) {
}
} else {
// 解析用户生日
if (StrUtil.isNotBlank(shopUser.getBirthDay())) {
// 判断当前月份是否等于用户生日月份
if (current.getMonthValue() == thisYearBirthday.getMonthValue()
&& (current.isEqual(thisYearBirthday) || current.isBefore(thisYearBirthday))) {
shopUserService.updateById(new ShopUser().setId(shopUser.getId()).setBirthDayRemind(1));
return buildCouponList(config);
}
} catch (Exception e) {
log.error("解析用户生日失败", e);
}
}
} else {
// 解析用户生日
if (StrUtil.isNotBlank(shopUser.getBirthDay())) {
// 判断当前月份是否等于用户生日月份
if (current.getMonthValue() == thisYearBirthday.getMonthValue()
&& (current.isEqual(thisYearBirthday) || current.isBefore(thisYearBirthday))) {
shopUserService.updateById(new ShopUser().setId(shopUser.getId()).setBirthDayRemind(1));
return buildCouponList(config);
}
}
}
} catch (Exception e) {
log.error("获取生日礼包配置失败, shopUser: {}", shopUser, e);
return null;
}
return null;
}