|
|
@@ -970,6 +970,33 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
|
|
|
lifeDiscountCouponUser.setIssueSource(3); // 3-好评送券
|
|
|
lifeDiscountCouponUserMapper.insert(lifeDiscountCouponUser);
|
|
|
coupon.setSingleQty(coupon.getSingleQty() - 1);
|
|
|
+// 1. 获取开始日期
|
|
|
+ LocalDate beginDate = coupon.getBeginGetDate();
|
|
|
+// 2. 获取字符串类型的天数
|
|
|
+ String specifiedDayStr = coupon.getSpecifiedDay();
|
|
|
+
|
|
|
+// 3. 基础校验
|
|
|
+ if (beginDate == null) {
|
|
|
+ throw new IllegalArgumentException("优惠券开始日期不能为空");
|
|
|
+ }
|
|
|
+ if (specifiedDayStr == null || specifiedDayStr.isEmpty()) {
|
|
|
+ throw new IllegalArgumentException("有效天数不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+// 4. 字符串转整数 + 合法性校验
|
|
|
+ int days;
|
|
|
+ try {
|
|
|
+ days = Integer.parseInt(specifiedDayStr);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new IllegalArgumentException("有效天数必须是纯数字:" + specifiedDayStr);
|
|
|
+ }
|
|
|
+ if (days <= 0) {
|
|
|
+ throw new IllegalArgumentException("有效天数必须大于0");
|
|
|
+ }
|
|
|
+
|
|
|
+// 5. 计算结束日期并赋值
|
|
|
+ LocalDate endDate = beginDate.plusDays(days);
|
|
|
+ coupon.setEndGetDate(endDate);
|
|
|
lifeDiscountCouponMapper.updateById(coupon);
|
|
|
grantedCoupon = 1;
|
|
|
couponName = coupon.getName(); // 保存优惠券名称
|