|
|
@@ -184,17 +184,39 @@ public class CouponService {
|
|
|
if (coupon.getValidUntil() != null && now.after(coupon.getValidUntil())) {
|
|
|
return "优惠券已过期";
|
|
|
}
|
|
|
- // 去重:同一个家庭同一张券只发一次(同 grantType 的幂等也通过 grant 方法保证)
|
|
|
- Long count = familyCouponMapper.selectCount(
|
|
|
+ // 去重:同一个家庭同一张券只发一次(COUPON-C3 口径:family_coupon 记录 ∪ 发券流水)。
|
|
|
+ // 以发券流水(任意 grant_type)为补充判定口径:JOIN/POPULATION/PERIODIC/CF_EXCHANGE 等
|
|
|
+ // 自动发放链路发过券的家庭,手动 /claim 同券不再二次发放(S-cfc-293 AC-3)。
|
|
|
+ Long fcCount = familyCouponMapper.selectCount(
|
|
|
new LambdaQueryWrapper<FamilyCoupon>()
|
|
|
.eq(FamilyCoupon::getFamilyId, familyId)
|
|
|
.eq(FamilyCoupon::getCouponId, couponId));
|
|
|
- if (count != null && count > 0) {
|
|
|
+ Long grantCount = 0L;
|
|
|
+ if (familyCouponGrantLogMapper != null) {
|
|
|
+ grantCount = familyCouponGrantLogMapper.selectCount(
|
|
|
+ new LambdaQueryWrapper<FamilyCouponGrantLog>()
|
|
|
+ .eq(FamilyCouponGrantLog::getFamilyId, familyId)
|
|
|
+ .eq(FamilyCouponGrantLog::getCouponId, couponId));
|
|
|
+ }
|
|
|
+ if ((fcCount != null && fcCount > 0) || (grantCount != null && grantCount > 0)) {
|
|
|
return "已领取过该优惠券";
|
|
|
}
|
|
|
issueToFamily(couponId, familyId);
|
|
|
coupon.setUsedCount(coupon.getUsedCount() == null ? 1 : coupon.getUsedCount() + 1);
|
|
|
couponMapper.updateById(coupon);
|
|
|
+ // AC-1:落发券流水(grantType=CLAIM),作为「已领拦截」的流水口径防重记录。
|
|
|
+ // 判空仅兼容未注入 grantLogMapper 的旧式单测(S-cfc-12 CouponUseScP57ScP75ContractTest
|
|
|
+ // 用 new CouponService() 未注入该字段),Spring 注入场景恒非 null。
|
|
|
+ if (familyCouponGrantLogMapper != null) {
|
|
|
+ FamilyCouponGrantLog grantLog = new FamilyCouponGrantLog();
|
|
|
+ grantLog.setFamilyId(familyId);
|
|
|
+ grantLog.setCouponId(couponId);
|
|
|
+ grantLog.setGrantType("CLAIM");
|
|
|
+ grantLog.setQuantity(1);
|
|
|
+ grantLog.setSource("claim:userId:" + userId);
|
|
|
+ grantLog.setCreatedAt(new Date());
|
|
|
+ familyCouponGrantLogMapper.insert(grantLog);
|
|
|
+ }
|
|
|
return "领取成功";
|
|
|
}
|
|
|
|