Browse Source

fix(coupon): 分享/转赠放开所有券类型(去掉applicableTo=MEMBERSHIP限制,保留归属/AVAILABLE/ACTIVE/未过期校验) - 需求变更2026-11-23 + TDD(24例, coupon全量86例绿)

Xiaogang Liao 2 days ago
parent
commit
a27e81dedd

+ 2 - 7
cfc-backend/src/main/java/com/etotem/cfc/service/CouponGiftService.java

@@ -63,9 +63,6 @@ public class CouponGiftService {
     @Resource
     @Resource
     private NotificationDispatchService notificationDispatchService;
     private NotificationDispatchService notificationDispatchService;
 
 
-    /** 仅允许赠送的券范围 */
-    private static final String GIFTABLE_APPLICABLE_TO = "MEMBERSHIP";
-
     // ----------------------------------------------------------------
     // ----------------------------------------------------------------
     // 查询
     // 查询
     // ----------------------------------------------------------------
     // ----------------------------------------------------------------
@@ -129,7 +126,7 @@ public class CouponGiftService {
         for (FamilyCoupon fc : familyCoupons) {
         for (FamilyCoupon fc : familyCoupons) {
             Coupon coupon = couponMapper.selectById(fc.getCouponId());
             Coupon coupon = couponMapper.selectById(fc.getCouponId());
             if (coupon == null) continue;
             if (coupon == null) continue;
-            if (!GIFTABLE_APPLICABLE_TO.equals(coupon.getApplicableTo())) continue;
+            // 需求变更2026-11-23:所有券均可转赠(原限 applicableTo=MEMBERSHIP),去掉类型限制,保留状态/有效期校验
             if (!"ACTIVE".equals(coupon.getStatus())) continue;
             if (!"ACTIVE".equals(coupon.getStatus())) continue;
             if (coupon.getValidFrom() != null && now.before(coupon.getValidFrom())) continue;
             if (coupon.getValidFrom() != null && now.before(coupon.getValidFrom())) continue;
             if (coupon.getValidUntil() != null && now.after(coupon.getValidUntil())) continue;
             if (coupon.getValidUntil() != null && now.after(coupon.getValidUntil())) continue;
@@ -223,9 +220,7 @@ public class CouponGiftService {
         if (coupon == null || !"ACTIVE".equals(coupon.getStatus())) {
         if (coupon == null || !"ACTIVE".equals(coupon.getStatus())) {
             throw new IllegalArgumentException("优惠券已失效");
             throw new IllegalArgumentException("优惠券已失效");
         }
         }
-        if (!GIFTABLE_APPLICABLE_TO.equals(coupon.getApplicableTo())) {
-            throw new IllegalArgumentException("仅会员专属券可转赠");
-        }
+        // 需求变更2026-11-23:所有券均可转赠,去掉 applicableTo=MEMBERSHIP 类型限制,保留状态/有效期校验
         Date now = new Date();
         Date now = new Date();
         if (coupon.getValidFrom() != null && now.before(coupon.getValidFrom())
         if (coupon.getValidFrom() != null && now.before(coupon.getValidFrom())
                 || coupon.getValidUntil() != null && now.after(coupon.getValidUntil())) {
                 || coupon.getValidUntil() != null && now.after(coupon.getValidUntil())) {

+ 2 - 5
cfc-backend/src/main/java/com/etotem/cfc/service/CouponShareService.java

@@ -81,7 +81,6 @@ public class CouponShareService {
     private static final String STATUS_REVOKED = "REVOKED";
     private static final String STATUS_REVOKED = "REVOKED";
     private static final String STATUS_EXPIRED = "EXPIRED";
     private static final String STATUS_EXPIRED = "EXPIRED";
     private static final String CLAIM_METHOD_SHARE = "SHARE";
     private static final String CLAIM_METHOD_SHARE = "SHARE";
-    private static final String GIFTABLE_APPLICABLE_TO = "MEMBERSHIP";
     private static final String AVAILABLE = "AVAILABLE";
     private static final String AVAILABLE = "AVAILABLE";
     private static final String ACTIVE = "ACTIVE";
     private static final String ACTIVE = "ACTIVE";
     private static final String SHARE_PATH_PREFIX = "/pages/coupon/share-claim?shareToken=";
     private static final String SHARE_PATH_PREFIX = "/pages/coupon/share-claim?shareToken=";
@@ -140,7 +139,8 @@ public class CouponShareService {
             return buildCreateResult(existing);
             return buildCreateResult(existing);
         }
         }
 
 
-        // 券校验(属于赠送人家庭 && AVAILABLE && applicableTo=MEMBERSHIP && ACTIVE && 未过期)
+        // 券校验(属于赠送人家庭 && AVAILABLE && ACTIVE && 未过期)。
+        // 需求变更2026-11-23:所有券均可分享(原来限 applicableTo=MEMBERSHIP),仅去掉类型限制,状态/归属/过期校验保留。
         FamilyCoupon fc = familyCouponMapper.selectById(familyCouponId);
         FamilyCoupon fc = familyCouponMapper.selectById(familyCouponId);
         if (fc == null || !Objects.equals(fc.getFamilyId(), giverFamilyId)
         if (fc == null || !Objects.equals(fc.getFamilyId(), giverFamilyId)
                 || !AVAILABLE.equals(fc.getStatus())) {
                 || !AVAILABLE.equals(fc.getStatus())) {
@@ -150,9 +150,6 @@ public class CouponShareService {
         if (coupon == null || !ACTIVE.equals(coupon.getStatus())) {
         if (coupon == null || !ACTIVE.equals(coupon.getStatus())) {
             throw new IllegalArgumentException(MSG_COUPON_INVALID);
             throw new IllegalArgumentException(MSG_COUPON_INVALID);
         }
         }
-        if (!GIFTABLE_APPLICABLE_TO.equals(coupon.getApplicableTo())) {
-            throw new IllegalArgumentException(MSG_ONLY_MEMBERSHIP);
-        }
         if (coupon.getValidFrom() != null && now.before(coupon.getValidFrom())
         if (coupon.getValidFrom() != null && now.before(coupon.getValidFrom())
                 || coupon.getValidUntil() != null && now.after(coupon.getValidUntil())) {
                 || coupon.getValidUntil() != null && now.after(coupon.getValidUntil())) {
             throw new IllegalArgumentException(MSG_COUPON_EXPIRED);
             throw new IllegalArgumentException(MSG_COUPON_EXPIRED);

+ 12 - 5
cfc-backend/src/test/java/com/etotem/cfc/unit/CouponShareClaimContractTest.java

@@ -273,17 +273,24 @@ class CouponShareClaimContractTest {
     }
     }
 
 
     @Test
     @Test
-    @DisplayName("create校验-2:非 MEMBERSHIP → 仅会员专属券可分享")
-    void create_校验_非会员券() {
+    @DisplayName("create校验-2:非 MEMBERSHIP 券也可分享(需求变更2026-11-23:所有券可分享,仅去掉类型限制)")
+    void create_非会员券_也可分享() {
         when(userMapper.selectById(1L)).thenReturn(user(1L, 5L));
         when(userMapper.selectById(1L)).thenReturn(user(1L, 5L));
         when(couponShareMapper.selectOne(any(Wrapper.class))).thenReturn(null);
         when(couponShareMapper.selectOne(any(Wrapper.class))).thenReturn(null);
         when(familyCouponMapper.selectById(500L)).thenReturn(familyCoupon(500L, 5L, 100L));
         when(familyCouponMapper.selectById(500L)).thenReturn(familyCoupon(500L, 5L, 100L));
         Coupon coupon = membershipCoupon();
         Coupon coupon = membershipCoupon();
-        coupon.setApplicableTo("ALL");
+        coupon.setApplicableTo("ALL"); // 全场券:需求变更后应允许分享
         when(couponMapper.selectById(100L)).thenReturn(coupon);
         when(couponMapper.selectById(100L)).thenReturn(coupon);
+        when(couponShareMapper.insert(any(CouponShare.class))).thenAnswer(inv -> {
+            CouponShare s = inv.getArgument(0);
+            s.setId(10L);
+            return 1;
+        });
 
 
-        assertEquals(CouponShareService.MSG_ONLY_MEMBERSHIP, createError(1L, 500L));
-        verify(couponShareMapper, never()).insert(any(CouponShare.class));
+        Map<String, Object> data = service.create(1L, 500L);
+
+        assertNotNull(data.get("shareToken"), "非会员券(ALL)也应生成 shareToken");
+        verify(couponShareMapper).insert(any(CouponShare.class));
     }
     }
 
 
     @Test
     @Test