生日
This commit is contained in:
@@ -239,55 +239,61 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ShopUser shopUser = shopUserService.getOne(new QueryWrapper()
|
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) {
|
if (shopUser == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (StrUtil.isBlank(birthdayGift.getConfigList())) {
|
if (StrUtil.isBlank(birthdayGift.getConfigList())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//获取当天日期
|
try {
|
||||||
LocalDate current = DateUtil.date().toLocalDateTime().toLocalDate();
|
//获取当天日期
|
||||||
// 解析用户生日(仅取月日)
|
LocalDate current = DateUtil.date().toLocalDateTime().toLocalDate();
|
||||||
LocalDate userBirthday = DateUtil.parseDate(shopUser.getBirthDay()).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)) {
|
LocalDate thisYearBirthday = LocalDate.of(current.getYear(), userBirthday.getMonth(), userBirthday.getDayOfMonth());
|
||||||
if ("day".equals(config.getDeliverDate())) {
|
for (MkBirthdayGiftConfig config : JSONArray.parseArray(birthdayGift.getConfigList()).toJavaList(MkBirthdayGiftConfig.class)) {
|
||||||
// 获取偏移天数,默认为0(偏移天数应为非负数,代表未来的天数)
|
if ("day".equals(config.getDeliverDate())) {
|
||||||
int offsetDays = config.getDeliverTime() != null ? Math.max(config.getDeliverTime(), 0) : 0;
|
// 获取偏移天数,默认为0(偏移天数应为非负数,代表未来的天数)
|
||||||
// 计算偏移后的结束日期(当前日期 + 偏移天数)
|
int offsetDays = config.getDeliverTime() != null ? Math.max(config.getDeliverTime(), 0) : 0;
|
||||||
LocalDate endDate = current.plusDays(offsetDays);
|
// 计算偏移后的结束日期(当前日期 + 偏移天数)
|
||||||
// 开始日期固定为当前日期
|
LocalDate endDate = current.plusDays(offsetDays);
|
||||||
LocalDate startDate = current;
|
// 开始日期固定为当前日期
|
||||||
|
LocalDate startDate = current;
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(shopUser.getBirthDay())) {
|
if (StrUtil.isNotBlank(shopUser.getBirthDay())) {
|
||||||
try {
|
try {
|
||||||
boolean isInRange = false;
|
boolean isInRange = false;
|
||||||
if ((thisYearBirthday.isEqual(startDate) || thisYearBirthday.isAfter(startDate))
|
if ((thisYearBirthday.isEqual(startDate) || thisYearBirthday.isAfter(startDate))
|
||||||
&& (thisYearBirthday.isEqual(endDate) || thisYearBirthday.isBefore(endDate))) {
|
&& (thisYearBirthday.isEqual(endDate) || thisYearBirthday.isBefore(endDate))) {
|
||||||
isInRange = true;
|
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));
|
shopUserService.updateById(new ShopUser().setId(shopUser.getId()).setBirthDayRemind(1));
|
||||||
return buildCouponList(config);
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user