|
@@ -106,6 +106,13 @@ public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCou
|
|
|
throw new BusinessException(400, "优惠券已领完");
|
|
throw new BusinessException(400, "优惠券已领完");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (template.getValidType() == ValidTypeEnum.FIXED_TIME.getCode()
|
|
|
|
|
+ && template.getValidEndTime() != null
|
|
|
|
|
+ && LocalDateTime.now().isAfter(template.getValidEndTime())) {
|
|
|
|
|
+ log.warn("[优惠券服务] 领取优惠券失败 - 优惠券已过期, templateId: {}, validEndTime: {}", templateId, template.getValidEndTime());
|
|
|
|
|
+ throw new BusinessException(400, "优惠券已过期");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
int receivedCount = userCouponMapper.countByTemplateAndUser(templateId, userId);
|
|
int receivedCount = userCouponMapper.countByTemplateAndUser(templateId, userId);
|
|
|
if (receivedCount >= template.getReceiveLimit()) {
|
|
if (receivedCount >= template.getReceiveLimit()) {
|
|
|
log.warn("[优惠券服务] 领取优惠券失败 - 超过领取上限, userId: {}, templateId: {}, receivedCount: {}, limit: {}",
|
|
log.warn("[优惠券服务] 领取优惠券失败 - 超过领取上限, userId: {}, templateId: {}, receivedCount: {}, limit: {}",
|
|
@@ -157,11 +164,17 @@ public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCou
|
|
|
dto.getTemplateId(), template != null ? "存在" : "不存在");
|
|
dto.getTemplateId(), template != null ? "存在" : "不存在");
|
|
|
|
|
|
|
|
if (template == null || template.getDeleted() == CommonConstants.DELETED) {
|
|
if (template == null || template.getDeleted() == CommonConstants.DELETED) {
|
|
|
- log.error("[优惠券发放] 模板不存在或已删除 - templateId={}, deleted={}",
|
|
|
|
|
|
|
+ log.error("[优惠券发放] 模板不存在或已删除 - templateId={}, deleted={}",
|
|
|
dto.getTemplateId(), template != null ? template.getDeleted() : "N/A");
|
|
dto.getTemplateId(), template != null ? template.getDeleted() : "N/A");
|
|
|
throw new BusinessException(404, "优惠券模板不存在");
|
|
throw new BusinessException(404, "优惠券模板不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (template.getValidType() == ValidTypeEnum.FIXED_TIME.getCode()
|
|
|
|
|
+ && template.getValidEndTime() != null
|
|
|
|
|
+ && LocalDateTime.now().isAfter(template.getValidEndTime())) {
|
|
|
|
|
+ throw new BusinessException(400, "优惠券已过期,无法发放");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
List<Long> targetUserIds = getTargetUserIds(dto.getTargetType(), dto.getUserIds());
|
|
List<Long> targetUserIds = getTargetUserIds(dto.getTargetType(), dto.getUserIds());
|
|
|
if (targetUserIds.isEmpty()) {
|
|
if (targetUserIds.isEmpty()) {
|
|
|
throw new BusinessException(400, "没有目标用户");
|
|
throw new BusinessException(400, "没有目标用户");
|
|
@@ -269,7 +282,10 @@ public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCou
|
|
|
throw new BusinessException(400, "优惠券不可用");
|
|
throw new BusinessException(400, "优惠券不可用");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 4. 检查优惠券是否过期
|
|
|
|
|
|
|
+ // 4. 检查优惠券是否在有效期内
|
|
|
|
|
+ if (LocalDateTime.now().isBefore(userCoupon.getValidStartTime())) {
|
|
|
|
|
+ throw new BusinessException(400, "优惠券尚未生效");
|
|
|
|
|
+ }
|
|
|
if (LocalDateTime.now().isAfter(userCoupon.getValidEndTime())) {
|
|
if (LocalDateTime.now().isAfter(userCoupon.getValidEndTime())) {
|
|
|
throw new BusinessException(400, "优惠券已过期");
|
|
throw new BusinessException(400, "优惠券已过期");
|
|
|
}
|
|
}
|