Просмотр исходного кода

test(cfc-backend): TR-8 商城/会员域 18 SC 契约测试三类流证据

为商城-会员域 18 个 SC(SC-A-12/A-17/G-05/P-52/P-53/P-55/P-56/P-57/P-59/P-60/P-75/P-80/S-02/S-03/S-04/S-06/X-07/X-12)补三
类流(正常/异常/权限)契约测试执行证据,纯 Mockito(无 Spring 上下文 / 无 DB),沿用 O-3 TaskCreateScP10ContractTest 范式。

- 10 个契约测试类 / 94 用例全绿:mvn test -DskipTests=false 通过
- 覆盖:商品浏览/详情/游客过滤、订单创建-支付-发货-收货闭环、退款申请与平台处理、
  优惠券领取/使用/配置管理、会员权益查看/开通续费/退款、服务商商品管理/发货核销、售后全流程
- 新增证据登记 docs/tdd/orchestration/tr8-shop-member-contract-evidence-20261107.md
- 不新增 DB 迁移、不改业务实现代码
Sisyphus 1 неделя назад
Родитель
Сommit
64b3ac0cb4

+ 222 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/AfterSalesScS06ContractTest.java

@@ -0,0 +1,222 @@
+package com.etotem.cfc.unit;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.entity.AfterSalesRequest;
+import com.etotem.cfc.entity.ProductOrder;
+import com.etotem.cfc.mapper.AfterSalesRequestMapper;
+import com.etotem.cfc.mapper.ProductOrderMapper;
+import com.etotem.cfc.service.AfterSalesService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * SC-S-06 售后退款处理(申请/列表/详情/审核/完成) 契约测试(S-cfc-12,vendor.order)
+ *
+ * <p>覆盖三类流(纯 Mockito,无 Spring 上下文 / 无 DB):</p>
+ * <ul>
+ *   <li><b>正常流</b>:已支付订单申请售后(订单转 refunding);我的售后列表;售后详情;审核通过(approved);退款完成(completed);</li>
+ *   <li><b>异常流</b>:订单不存在;未支付订单申请售后 → 「仅已支付、未完成的订单可申请售后」;非待审核状态 → 「仅待审核的申请可处理」;非已批准 → 「仅已批准的申请可完成」;</li>
+ *   <li><b>权限流</b>:他人订单申请售后 → 「无权操作此订单」;他人售后查看 → 「无权查看」。</li>
+ * </ul>
+ */
+class AfterSalesScS06ContractTest {
+
+    private AfterSalesService service;
+    private AfterSalesRequestMapper requestMapper;
+    private ProductOrderMapper orderMapper;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        service = new AfterSalesService();
+        requestMapper = mock(AfterSalesRequestMapper.class);
+        orderMapper = mock(ProductOrderMapper.class);
+
+        inject(service, "afterSalesRequestMapper", requestMapper);
+        inject(service, "productOrderMapper", orderMapper);
+    }
+
+    private static void inject(Object target, String field, Object value) throws Exception {
+        Field f = target.getClass().getDeclaredField(field);
+        f.setAccessible(true);
+        f.set(target, value);
+    }
+
+    private ProductOrder paidOrder(Long id, String orderNo) {
+        ProductOrder o = new ProductOrder();
+        o.setId(id);
+        o.setOrderNo(orderNo);
+        o.setStatus("paid");
+        o.setBuyerId(1L);
+        o.setMoneyAmount(9900);
+        return o;
+    }
+
+    private AfterSalesRequest request(Long id, String status, Long userId) {
+        AfterSalesRequest r = new AfterSalesRequest();
+        r.setId(id);
+        r.setOrderId(100L);
+        r.setOrderNo("PO_AS");
+        r.setUserId(userId);
+        r.setStatus(status);
+        r.setRefundAmount(9900);
+        return r;
+    }
+
+    // ==================== 正常流(SC-S-06) ====================
+
+    @Test
+    void 正常流_已支付订单_申请售后() {
+        ProductOrder order = paidOrder(100L, "PO_AS");
+        when(orderMapper.selectById(100L)).thenReturn(order);
+        when(requestMapper.insert(any(AfterSalesRequest.class))).thenAnswer(inv -> {
+            AfterSalesRequest r = inv.getArgument(0);
+            r.setId(500L);
+            return 1;
+        });
+
+        AfterSalesRequest req = new AfterSalesRequest();
+        req.setOrderId(100L);
+        req.setReason("商品破损");
+        Result<AfterSalesRequest> result = service.create(req, 1L);
+
+        assertEquals(200, result.getCode(), "申请售后应成功");
+        assertEquals("pending", result.getData().getStatus());
+        assertEquals(9900, result.getData().getRefundAmount());
+        assertEquals("refunding", order.getStatus(), "订单应转 refunding");
+        verify(requestMapper).insert(any(AfterSalesRequest.class));
+        verify(orderMapper).updateById(order);
+    }
+
+    @Test
+    void 正常流_我的售后列表() {
+        when(requestMapper.selectList(any(Wrapper.class)))
+                .thenReturn(Collections.singletonList(request(500L, "pending", 1L)));
+
+        Result<List<AfterSalesRequest>> result = service.list(1L, "pending");
+
+        assertEquals(200, result.getCode());
+        assertEquals(1, result.getData().size());
+        assertEquals(500L, result.getData().get(0).getId());
+    }
+
+    @Test
+    void 正常流_售后详情() {
+        when(requestMapper.selectById(500L)).thenReturn(request(500L, "pending", 1L));
+
+        Result<AfterSalesRequest> result = service.detail(500L, 1L);
+
+        assertEquals(200, result.getCode());
+        assertEquals("pending", result.getData().getStatus());
+    }
+
+    @Test
+    void 正常流_审核通过() {
+        AfterSalesRequest req = request(500L, "pending", 1L);
+        when(requestMapper.selectById(500L)).thenReturn(req);
+
+        Result<String> result = service.review(500L, "approve", null, 9L);
+
+        assertEquals(200, result.getCode(), "审核通过应成功");
+        assertEquals("approved", req.getStatus(), "审核通过后状态应为 approved");
+        assertEquals(9L, req.getHandledBy());
+        verify(requestMapper).updateById(req);
+    }
+
+    @Test
+    void 正常流_审核拒绝() {
+        AfterSalesRequest req = request(500L, "pending", 1L);
+        when(requestMapper.selectById(500L)).thenReturn(req);
+
+        Result<String> result = service.review(500L, "reject", "证据不足", 9L);
+
+        assertEquals(200, result.getCode());
+        assertEquals("rejected", req.getStatus());
+        assertEquals("证据不足", req.getRejectReason());
+        verify(requestMapper).updateById(req);
+    }
+
+    @Test
+    void 正常流_退款完成() {
+        when(requestMapper.selectById(500L)).thenReturn(request(500L, "approved", 1L));
+
+        Result<String> result = service.complete(500L);
+
+        assertEquals(200, result.getCode(), "已批准申请可完成");
+        verify(requestMapper).updateById(any(AfterSalesRequest.class));
+    }
+
+    // ==================== 异常流(SC-S-06) ====================
+
+    @Test
+    void 异常流_订单不存在_不可申请() {
+        when(orderMapper.selectById(999L)).thenReturn(null);
+        AfterSalesRequest req = new AfterSalesRequest();
+        req.setOrderId(999L);
+        Result<AfterSalesRequest> result = service.create(req, 1L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("订单不存在"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_未支付订单_不可申请售后() {
+        ProductOrder order = paidOrder(100L, "PO_X");
+        order.setStatus("pending");
+        when(orderMapper.selectById(100L)).thenReturn(order);
+        AfterSalesRequest req = new AfterSalesRequest();
+        req.setOrderId(100L);
+        Result<AfterSalesRequest> result = service.create(req, 1L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("仅已支付"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_非待审核_不可审核() {
+        when(requestMapper.selectById(500L)).thenReturn(request(500L, "approved", 1L));
+        Result<String> result = service.review(500L, "approve", null, 9L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("仅待审核的申请可处理"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_非已批准_不可完成() {
+        when(requestMapper.selectById(500L)).thenReturn(request(500L, "pending", 1L));
+        Result<String> result = service.complete(500L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("仅已批准的申请可完成"), "实际: " + result.getMessage());
+    }
+
+    // ==================== 权限流(SC-S-06) ====================
+
+    @Test
+    void 权限流_他人订单_不可申请售后() {
+        ProductOrder order = paidOrder(100L, "PO_Y");
+        order.setBuyerId(1L);
+        when(orderMapper.selectById(100L)).thenReturn(order);
+        AfterSalesRequest req = new AfterSalesRequest();
+        req.setOrderId(100L);
+        Result<AfterSalesRequest> result = service.create(req, 99L); // 非买家
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("无权操作此订单"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 权限流_他人售后_不可查看() {
+        when(requestMapper.selectById(500L)).thenReturn(request(500L, "pending", 1L));
+        Result<AfterSalesRequest> result = service.detail(500L, 99L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("无权查看"), "实际: " + result.getMessage());
+    }
+}

+ 280 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/CouponUseScP57ScP75ContractTest.java

@@ -0,0 +1,280 @@
+package com.etotem.cfc.unit;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.etotem.cfc.entity.Coupon;
+import com.etotem.cfc.entity.FamilyCoupon;
+import com.etotem.cfc.entity.User;
+import com.etotem.cfc.mapper.CouponMapper;
+import com.etotem.cfc.mapper.FamilyCouponMapper;
+import com.etotem.cfc.mapper.UserMapper;
+import com.etotem.cfc.service.CouponService;
+import com.etotem.cfc.service.MembershipService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * SC-P-75 优惠券领取 + SC-P-57 优惠券使用 + SC-A-17 券配置管理(领券中心/加入规则) 契约测试(S-cfc-12,coupon)
+ *
+ * <p>覆盖三类流(纯 Mockito,无 Spring 上下文 / 无 DB):</p>
+ * <ul>
+ *   <li><b>正常流</b>:领取 →「领取成功」且 used_count+1;满减券抵扣 / 折扣券抵扣;领券中心模板列表 / 加入规则列表;</li>
+ *   <li><b>异常流</b>:已领完 →「优惠券已领完」;重复领取 →「已领取过该优惠券」;满减门槛不足 / 已过期 → 不可用(null,不抵扣);</li>
+ *   <li><b>权限流</b>:他人家庭的券实例不可用(family_id 不匹配 → 不抵扣)。</li>
+ * </ul>
+ */
+class CouponUseScP57ScP75ContractTest {
+
+    private CouponService service;
+    private UserMapper userMapper;
+    private CouponMapper couponMapper;
+    private FamilyCouponMapper familyCouponMapper;
+    private MembershipService membershipService;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        service = new CouponService();
+        userMapper = mock(UserMapper.class);
+        couponMapper = mock(CouponMapper.class);
+        familyCouponMapper = mock(FamilyCouponMapper.class);
+        membershipService = mock(MembershipService.class);
+
+        inject(service, "userMapper", userMapper);
+        inject(service, "couponMapper", couponMapper);
+        inject(service, "familyCouponMapper", familyCouponMapper);
+        inject(service, "membershipService", membershipService);
+    }
+
+    private static void inject(Object target, String field, Object value) throws Exception {
+        Field f = target.getClass().getDeclaredField(field);
+        f.setAccessible(true);
+        f.set(target, value);
+    }
+
+    private void stubUserFamily(Long familyId) {
+        User user = new User();
+        user.setId(1L);
+        user.setFamilyId(familyId);
+        when(userMapper.selectById(1L)).thenReturn(user);
+    }
+
+    private Coupon activeCoupon(String type) {
+        Coupon c = new Coupon();
+        c.setId(100L);
+        c.setName("满100减10");
+        c.setType(type);
+        c.setStatus("ACTIVE");
+        c.setApplicableTo("ALL");
+        c.setValue(1000);
+        c.setMinSpend(0);
+        c.setTotalCount(100);
+        c.setUsedCount(50);
+        return c;
+    }
+
+    // ==================== 正常流(SC-P-75 领取) ====================
+
+    @Test
+    void 正常流_领取优惠券_usedCount递增() {
+        stubUserFamily(5L);
+        Coupon coupon = activeCoupon("CASH");
+        when(couponMapper.selectById(100L)).thenReturn(coupon);
+        when(familyCouponMapper.selectCount(any(Wrapper.class))).thenReturn(0L);
+        when(familyCouponMapper.insert(any(FamilyCoupon.class))).thenAnswer(inv -> {
+            FamilyCoupon fc = inv.getArgument(0);
+            fc.setId(500L);
+            return 1;
+        });
+
+        String result = service.claim(1L, 100L);
+
+        assertEquals("领取成功", result);
+        assertEquals(51, coupon.getUsedCount().intValue(), "used_count 应 +1");
+        verify(couponMapper).updateById(coupon);
+        verify(familyCouponMapper).insert(any(FamilyCoupon.class));
+    }
+
+    // ==================== 异常流(SC-P-75 领取) ====================
+
+    @Test
+    void 异常流_优惠券已领完() {
+        stubUserFamily(5L);
+        Coupon coupon = activeCoupon("CASH");
+        coupon.setTotalCount(100);
+        coupon.setUsedCount(100);
+        when(couponMapper.selectById(100L)).thenReturn(coupon);
+
+        String result = service.claim(1L, 100L);
+
+        assertEquals("优惠券已领完", result);
+    }
+
+    @Test
+    void 异常流_未加入家庭_不可领取() {
+        User user = new User();
+        user.setId(1L);
+        user.setFamilyId(null);
+        when(userMapper.selectById(1L)).thenReturn(user);
+
+        String result = service.claim(1L, 100L);
+
+        assertEquals("未加入家庭", result);
+    }
+
+    @Test
+    void 异常流_重复领取_同一家庭仅一次() {
+        stubUserFamily(5L);
+        Coupon coupon = activeCoupon("CASH");
+        when(couponMapper.selectById(100L)).thenReturn(coupon);
+        when(familyCouponMapper.selectCount(any(Wrapper.class))).thenReturn(1L);
+
+        String result = service.claim(1L, 100L);
+
+        assertEquals("已领取过该优惠券", result);
+    }
+
+    // ==================== 正常流(SC-P-57 使用) ====================
+
+    @Test
+    void 正常流_满减券_按面额抵扣() {
+        stubUserFamily(5L);
+        FamilyCoupon fc = new FamilyCoupon();
+        fc.setId(500L);
+        fc.setFamilyId(5L);
+        fc.setCouponId(100L);
+        fc.setStatus("AVAILABLE");
+        when(familyCouponMapper.selectById(500L)).thenReturn(fc);
+        Coupon coupon = activeCoupon("CASH");
+        when(couponMapper.selectById(100L)).thenReturn(coupon);
+
+        Integer discount = service.apply(1L, 500L, "PRODUCT", 9900,
+                Collections.singleton(10L));
+
+        assertNotNull(discount);
+        assertEquals(1000, discount.intValue(), "满减券按面额抵扣 10 元");
+    }
+
+    @Test
+    void 正常流_折扣券_按折扣率抵扣() {
+        stubUserFamily(5L);
+        FamilyCoupon fc = new FamilyCoupon();
+        fc.setId(501L);
+        fc.setFamilyId(5L);
+        fc.setCouponId(101L);
+        fc.setStatus("AVAILABLE");
+        when(familyCouponMapper.selectById(501L)).thenReturn(fc);
+        Coupon coupon = activeCoupon("DISCOUNT");
+        coupon.setId(101L);
+        coupon.setDiscountRate(8000); // 8 折 → 20% 抵扣
+        when(couponMapper.selectById(101L)).thenReturn(coupon);
+
+        Integer discount = service.apply(1L, 501L, "PRODUCT", 9900,
+                Collections.singleton(10L));
+
+        assertNotNull(discount);
+        assertEquals(1980, discount.intValue(), "9900 的 8 折券应抵扣 1980");
+    }
+
+    // ==================== 异常流(SC-P-57 使用) ====================
+
+    @Test
+    void 异常流_满减门槛不足_不抵扣() {
+        stubUserFamily(5L);
+        FamilyCoupon fc = new FamilyCoupon();
+        fc.setId(502L);
+        fc.setFamilyId(5L);
+        fc.setCouponId(102L);
+        fc.setStatus("AVAILABLE");
+        when(familyCouponMapper.selectById(502L)).thenReturn(fc);
+        Coupon coupon = activeCoupon("DISCOUNT");
+        coupon.setId(102L);
+        coupon.setDiscountRate(8000);
+        coupon.setMinSpend(10000); // 门槛 100 元
+        when(couponMapper.selectById(102L)).thenReturn(coupon);
+
+        Integer discount = service.apply(1L, 502L, "PRODUCT", 9900,
+                Collections.singleton(10L));
+
+        assertNull(discount, "未达门槛券不可用");
+    }
+
+    @Test
+    void 异常流_优惠券已过期_不抵扣() {
+        stubUserFamily(5L);
+        FamilyCoupon fc = new FamilyCoupon();
+        fc.setId(503L);
+        fc.setFamilyId(5L);
+        fc.setCouponId(103L);
+        fc.setStatus("AVAILABLE");
+        when(familyCouponMapper.selectById(503L)).thenReturn(fc);
+        Coupon coupon = activeCoupon("CASH");
+        coupon.setId(103L);
+        coupon.setValidUntil(new Date(System.currentTimeMillis() - 86400000L)); // 昨天过期
+        when(couponMapper.selectById(103L)).thenReturn(coupon);
+
+        Integer discount = service.apply(1L, 503L, "PRODUCT", 9900,
+                Collections.singleton(10L));
+
+        assertNull(discount, "过期券不可用");
+    }
+
+    // ==================== 权限流(SC-P-57 使用) ====================
+
+    @Test
+    void 权限流_他人家庭券_不可用() {
+        stubUserFamily(5L); // 用户家庭 = 5
+        FamilyCoupon fc = new FamilyCoupon();
+        fc.setId(504L);
+        fc.setFamilyId(99L); // 券属于家庭 99
+        fc.setCouponId(100L);
+        fc.setStatus("AVAILABLE");
+        when(familyCouponMapper.selectById(504L)).thenReturn(fc);
+
+        Integer discount = service.apply(1L, 504L, "PRODUCT", 9900,
+                Collections.singleton(10L));
+
+        assertNull(discount, "他人家庭的券不可用");
+    }
+
+    // ==================== 正常流(SC-A-17 券管理列表) ====================
+
+    @Test
+    void 正常流_领券中心可用模板() {
+        stubUserFamily(5L);
+        when(familyCouponMapper.selectList(any(Wrapper.class))).thenReturn(Collections.emptyList());
+        Coupon coupon = activeCoupon("CASH");
+        when(couponMapper.selectList(any(Wrapper.class)))
+                .thenReturn(Collections.singletonList(coupon));
+
+        List<Coupon> result = service.listAvailableTemplates(1L);
+
+        assertEquals(1, result.size());
+        assertEquals(100L, result.get(0).getId());
+    }
+
+    @Test
+    void 正常流_加入规则列表() {
+        Coupon joinCoupon = activeCoupon("CASH");
+        joinCoupon.setId(200L);
+        when(couponMapper.selectList(any(Wrapper.class)))
+                .thenReturn(Collections.singletonList(joinCoupon));
+
+        List<Coupon> result = service.listJoinRules();
+
+        assertEquals(1, result.size());
+        assertTrue(result.get(0).getId() == 200L);
+    }
+}

+ 255 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/MembershipRenewScP60ScP80ContractTest.java

@@ -0,0 +1,255 @@
+package com.etotem.cfc.unit;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.etotem.cfc.dto.PaymentOrderDTO;
+import com.etotem.cfc.entity.Family;
+import com.etotem.cfc.entity.FamilyMembership;
+import com.etotem.cfc.entity.MembershipLevel;
+import com.etotem.cfc.entity.PaymentOrder;
+import com.etotem.cfc.entity.User;
+import com.etotem.cfc.mapper.FamilyMapper;
+import com.etotem.cfc.mapper.FamilyMembershipMapper;
+import com.etotem.cfc.mapper.MembershipLevelMapper;
+import com.etotem.cfc.mapper.PaymentOrderMapper;
+import com.etotem.cfc.mapper.UserMapper;
+import com.etotem.cfc.service.CfCommissionService;
+import com.etotem.cfc.service.CouponService;
+import com.etotem.cfc.service.MembershipService;
+import com.etotem.cfc.service.VirtualGoodsConfigService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.Date;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * SC-P-60 会员开通/续费 + SC-P-80 会员退款与发票 + SC-X-12 会员权益闭环·支付侧 契约测试(S-cfc-12,membership)
+ *
+ * <p>覆盖三类流(纯 Mockito,无 Spring 上下文 / 无 DB):</p>
+ * <ul>
+ *   <li><b>正常流</b>:创建会员订单(待支付);支付回调 → 开通(插入 FamilyMembership + 置 paid);退款 → 订单 refunded + 会员记录 refunded;</li>
+ *   <li><b>异常流</b>:等级不存在 →「会员等级不存在」;无家庭 →「请先创建或加入家庭后再购买会员」;回调订单不存在 → false;重复退款(幂等)→ 不重复处理;</li>
+ *   <li><b>权限流</b>:退款重复推送(已 refunded)→ 幂等跳过,不二次变更。</li>
+ * </ul>
+ */
+class MembershipRenewScP60ScP80ContractTest {
+
+    private MembershipService service;
+    private MembershipLevelMapper levelMapper;
+    private PaymentOrderMapper paymentOrderMapper;
+    private FamilyMembershipMapper membershipMapper;
+    private FamilyMapper familyMapper;
+    private UserMapper userMapper;
+    private CouponService couponService;
+    private CfCommissionService cfCommissionService;
+    private VirtualGoodsConfigService virtualGoodsConfigService;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        service = new MembershipService();
+        levelMapper = mock(MembershipLevelMapper.class);
+        paymentOrderMapper = mock(PaymentOrderMapper.class);
+        membershipMapper = mock(FamilyMembershipMapper.class);
+        familyMapper = mock(FamilyMapper.class);
+        userMapper = mock(UserMapper.class);
+        couponService = mock(CouponService.class);
+        cfCommissionService = mock(CfCommissionService.class);
+        virtualGoodsConfigService = mock(VirtualGoodsConfigService.class);
+
+        inject(service, "levelMapper", levelMapper);
+        inject(service, "paymentOrderMapper", paymentOrderMapper);
+        inject(service, "membershipMapper", membershipMapper);
+        inject(service, "familyMapper", familyMapper);
+        inject(service, "userMapper", userMapper);
+        inject(service, "couponService", couponService);
+        inject(service, "cfCommissionService", cfCommissionService);
+        inject(service, "virtualGoodsConfigService", virtualGoodsConfigService);
+    }
+
+    private static void inject(Object target, String field, Object value) throws Exception {
+        Field f = target.getClass().getDeclaredField(field);
+        f.setAccessible(true);
+        f.set(target, value);
+    }
+
+    private MembershipLevel familyLevel() {
+        MembershipLevel l = new MembershipLevel();
+        l.setId(3L);
+        l.setLevelCode("FAMILY");
+        l.setLevelName("家庭版");
+        l.setLevelOrder(3);
+        l.setPriceYearly(39800);
+        l.setPriceMonthly(9900);
+        l.setPriceQuarterly(19800);
+        return l;
+    }
+
+    private PaymentOrder pendingOrder(String orderNo) {
+        PaymentOrder o = new PaymentOrder();
+        o.setId(1L);
+        o.setOrderNo(orderNo);
+        o.setFamilyId(5L);
+        o.setLevelCode("FAMILY");
+        o.setPaymentType("yearly");
+        o.setPeriod("yearly");
+        o.setAmount(39800);
+        o.setStatus("pending");
+        o.setPeriodNo(1);
+        o.setCreatedAt(new Date());
+        return o;
+    }
+
+    // ==================== 正常流(SC-P-60 创建订单) ====================
+
+    @Test
+    void 正常流_创建会员订单_待支付() {
+        when(levelMapper.selectOne(any(Wrapper.class))).thenReturn(familyLevel());
+        when(virtualGoodsConfigService.getEnabled("MEMBERSHIP", "FAMILY")).thenReturn(null);
+        when(paymentOrderMapper.insert(any(PaymentOrder.class))).thenAnswer(inv -> {
+            PaymentOrder o = inv.getArgument(0);
+            o.setId(10L);
+            return 1;
+        });
+
+        PaymentOrderDTO dto = service.createOrder(1L, 5L, "FAMILY", "wechat", "yearly", null);
+
+        assertNotNull(dto);
+        assertNotNull(dto.getOrderNo());
+        assertEquals("pending", dto.getStatus(), "会员订单应待支付");
+        assertEquals(39800, dto.getAmount());
+        assertEquals("FAMILY", dto.getLevelCode());
+        assertEquals(1, dto.getTotalPeriods());
+        verify(paymentOrderMapper).insert(any(PaymentOrder.class));
+    }
+
+    // ==================== 异常流(SC-P-60) ====================
+
+    @Test
+    void 异常流_等级不存在() {
+        when(levelMapper.selectOne(any(Wrapper.class))).thenReturn(null);
+        RuntimeException ex = assertThrows(RuntimeException.class,
+                () -> service.createOrder(1L, 5L, "GOLD", "wechat", "yearly", null));
+        assertTrue(ex.getMessage().contains("会员等级不存在"), "实际: " + ex.getMessage());
+    }
+
+    @Test
+    void 异常流_无家庭() {
+        RuntimeException ex = assertThrows(RuntimeException.class,
+                () -> service.createOrder(1L, null, "FAMILY", "wechat", "yearly", null));
+        assertTrue(ex.getMessage().contains("请先创建或加入家庭"), "实际: " + ex.getMessage());
+    }
+
+    // ==================== 正常流(SC-X-12 支付回调开通) ====================
+
+    @Test
+    void 正常流_支付回调_开通会员() {
+        PaymentOrder order = pendingOrder("MO20261107001");
+        when(paymentOrderMapper.selectOne(any(Wrapper.class))).thenReturn(order);
+        Family family = new Family();
+        family.setId(5L);
+        family.setCreatorId(7L);
+        when(familyMapper.selectById(5L)).thenReturn(family);
+        User admin = new User();
+        admin.setId(7L);
+        admin.setFamilyId(5L);
+        admin.setMemberLevel("FREE");
+        when(userMapper.selectById(7L)).thenReturn(admin);
+        when(userMapper.selectList(any(Wrapper.class))).thenReturn(Collections.emptyList());
+        when(membershipMapper.insert(any(FamilyMembership.class))).thenReturn(1);
+
+        boolean ok = service.processPaymentCallback("MO20261107001", "wx_tx_999", "wechat");
+
+        assertTrue(ok, "支付回调应成功开通");
+        assertEquals("paid", order.getStatus(), "回调后订单应已支付");
+        verify(membershipMapper).insert(any(FamilyMembership.class));
+    }
+
+    // ==================== 异常流(SC-X-12 回调) ====================
+
+    @Test
+    void 异常流_回调订单不存在_返回false() {
+        when(paymentOrderMapper.selectOne(any(Wrapper.class))).thenReturn(null);
+        assertFalse(service.processPaymentCallback("MO_NOT_EXIST", "tx", "wechat"));
+    }
+
+    @Test
+    void 异常流_已支付且有开通记录_幂等返回true() {
+        PaymentOrder order = pendingOrder("MO20261107002");
+        order.setStatus("paid");
+        when(paymentOrderMapper.selectOne(any(Wrapper.class))).thenReturn(order);
+        when(membershipMapper.selectCount(any(Wrapper.class))).thenReturn(1L);
+
+        boolean ok = service.processPaymentCallback("MO20261107002", "tx2", "wechat");
+
+        assertTrue(ok, "重复回调应幂等返回 true");
+        verify(paymentOrderMapper, never()).updateById(order);
+    }
+
+    // ==================== 正常流(SC-P-80 退款) ====================
+
+    @Test
+    void 正常流_退款_订单与会员记录置refunded() {
+        PaymentOrder order = pendingOrder("MO20261107003");
+        order.setStatus("paid");
+        when(paymentOrderMapper.selectOne(any(Wrapper.class))).thenReturn(order);
+        FamilyMembership membership = new FamilyMembership();
+        membership.setId(1L);
+        membership.setOrderNo("MO20261107003");
+        membership.setFamilyId(5L);
+        membership.setLevelCode("FAMILY");
+        membership.setPaymentStatus("paid");
+        when(membershipMapper.selectOne(any(Wrapper.class))).thenReturn(membership);
+        Family family = new Family();
+        family.setId(5L);
+        family.setCreatorId(7L);
+        when(familyMapper.selectById(5L)).thenReturn(family);
+        User admin = new User();
+        admin.setId(7L);
+        admin.setMemberLevel("FAMILY");
+        when(userMapper.selectById(7L)).thenReturn(admin);
+        when(membershipMapper.selectCount(any(Wrapper.class))).thenReturn(0L);
+        when(userMapper.selectList(any(Wrapper.class))).thenReturn(Collections.emptyList());
+
+        service.refundByOrderNo("MO20261107003");
+
+        assertEquals("refunded", order.getStatus(), "订单应置 refunded");
+        assertEquals("refunded", membership.getPaymentStatus(), "会员记录应置 refunded");
+        verify(paymentOrderMapper).updateById(order);
+        verify(membershipMapper).updateById(membership);
+    }
+
+    // ==================== 异常流/权限流(SC-P-80 退款幂等) ====================
+
+    @Test
+    void 权限流_退款重复推送_幂等跳过() {
+        PaymentOrder order = pendingOrder("MO20261107004");
+        order.setStatus("refunded"); // 已退款
+        when(paymentOrderMapper.selectOne(any(Wrapper.class))).thenReturn(order);
+
+        service.refundByOrderNo("MO20261107004");
+
+        verify(paymentOrderMapper, never()).updateById(order);
+        verify(membershipMapper, never()).updateById(any(FamilyMembership.class));
+    }
+
+    @Test
+    void 异常流_退款订单不存在_无操作() {
+        when(paymentOrderMapper.selectOne(any(Wrapper.class))).thenReturn(null);
+        service.refundByOrderNo("MO_NOT_EXIST");
+        verify(paymentOrderMapper, never()).updateById(any(PaymentOrder.class));
+    }
+}

+ 172 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/MembershipViewScP59ContractTest.java

@@ -0,0 +1,172 @@
+package com.etotem.cfc.unit;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.etotem.cfc.dto.MembershipLevelDTO;
+import com.etotem.cfc.entity.Family;
+import com.etotem.cfc.entity.FamilyMembership;
+import com.etotem.cfc.entity.MembershipLevel;
+import com.etotem.cfc.entity.User;
+import com.etotem.cfc.mapper.FamilyMapper;
+import com.etotem.cfc.mapper.MembershipLevelMapper;
+import com.etotem.cfc.mapper.FamilyMembershipMapper;
+import com.etotem.cfc.mapper.UserMapper;
+import com.etotem.cfc.service.MembershipService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * SC-P-59 会员权益查看(等级列表/当前等级/权益判定)+ SC-X-12 会员闭环·权益侧(canUseFeature) 契约测试(S-cfc-12,membership)
+ *
+ * <p>覆盖三类流(纯 Mockito,无 Spring 上下文 / 无 DB):</p>
+ * <ul>
+ *   <li><b>正常流</b>:等级列表(FREE/FAMILY/PREMIUM/PROVIDER);有效会员家庭 → 当前等级 FAMILY;有效会员可开「会员活动」功能;</li>
+ *   <li><b>异常流</b>:无有效会员记录 → 回退 FREE;未知家庭 → 功能权限 false;</li>
+ *   <li><b>权限流</b>:FREE 用户不可用会员专属功能(member_activities=false、mascot_ai=false),仅免费功能可用。</li>
+ * </ul>
+ */
+class MembershipViewScP59ContractTest {
+
+    private MembershipService service;
+    private MembershipLevelMapper levelMapper;
+    private FamilyMembershipMapper membershipMapper;
+    private FamilyMapper familyMapper;
+    private UserMapper userMapper;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        service = new MembershipService();
+        levelMapper = mock(MembershipLevelMapper.class);
+        membershipMapper = mock(FamilyMembershipMapper.class);
+        familyMapper = mock(FamilyMapper.class);
+        userMapper = mock(UserMapper.class);
+
+        inject(service, "levelMapper", levelMapper);
+        inject(service, "membershipMapper", membershipMapper);
+        inject(service, "familyMapper", familyMapper);
+        inject(service, "userMapper", userMapper);
+    }
+
+    private static void inject(Object target, String field, Object value) throws Exception {
+        Field f = target.getClass().getDeclaredField(field);
+        f.setAccessible(true);
+        f.set(target, value);
+    }
+
+    private MembershipLevel level(String code, String name, int order) {
+        MembershipLevel l = new MembershipLevel();
+        l.setId((long) order);
+        l.setLevelCode(code);
+        l.setLevelName(name);
+        l.setLevelOrder(order);
+        l.setPriceYearly(0);
+        return l;
+    }
+
+    private FamilyMembership activeMembership(String levelCode) {
+        FamilyMembership m = new FamilyMembership();
+        m.setId(1L);
+        m.setFamilyId(5L);
+        m.setLevelCode(levelCode);
+        m.setPaymentStatus("paid");
+        m.setStartDate(new Date(System.currentTimeMillis() - 86400000L));      // 昨日生效
+        m.setEndDate(new Date(System.currentTimeMillis() + 30L * 86400000L));   // 30 天后到期
+        return m;
+    }
+
+    // ==================== 正常流(SC-P-59) ====================
+
+    @Test
+    void 正常流_等级列表() {
+        when(levelMapper.selectList(null)).thenReturn(Arrays.asList(
+                level("FREE", "免费版", 1),
+                level("FAMILY", "家庭版", 3),
+                level("PREMIUM", "旗舰版", 4),
+                level("PROVIDER", "服务商", 1)));
+
+        List<MembershipLevelDTO> result = service.getAllLevels();
+
+        assertNotNull(result);
+        assertEquals(4, result.size());
+        assertEquals("FAMILY", result.get(1).getLevelCode());
+    }
+
+    @Test
+    void 正常流_有效会员_当前等级FAMILY() {
+        FamilyMembership membership = activeMembership("FAMILY");
+        when(membershipMapper.selectOne(any(Wrapper.class))).thenReturn(membership);
+        when(levelMapper.selectOne(any(Wrapper.class))).thenReturn(level("FAMILY", "家庭版", 3));
+
+        MembershipLevelDTO result = service.getCurrentLevel(5L);
+
+        assertNotNull(result);
+        assertEquals("FAMILY", result.getLevelCode(), "有效会员应返回 FAMILY");
+    }
+
+    @Test
+    void 正常流_会员可用会员活动权益() {
+        when(familyMapper.selectById(5L)).thenReturn(familyWithCreator(7L));
+        User admin = new User();
+        admin.setId(7L);
+        admin.setMemberLevel("FAMILY");
+        when(userMapper.selectById(7L)).thenReturn(admin);
+
+        assertTrue(service.canUseFeature(5L, "member_activities"), "FAMILY 会员应可用会员活动");
+        assertTrue(service.canUseFeature(5L, "mascot_ai"), "FAMILY 会员应可用 AI 助手");
+    }
+
+    // ==================== 异常流(SC-P-59) ====================
+
+    @Test
+    void 异常流_无有效会员_回退免费版() {
+        when(membershipMapper.selectOne(any(Wrapper.class))).thenReturn(null);
+        when(levelMapper.selectOne(any(Wrapper.class))).thenReturn(level("FREE", "免费版", 1));
+
+        MembershipLevelDTO result = service.getCurrentLevel(5L);
+
+        assertNotNull(result);
+        assertEquals("FREE", result.getLevelCode(), "无有效会员应回退 FREE");
+    }
+
+    @Test
+    void 异常流_未知家庭_功能权限false() {
+        when(familyMapper.selectById(999L)).thenReturn(null);
+
+        assertFalse(service.canUseFeature(999L, "member_activities"), "未知家庭无任何权益");
+    }
+
+    // ==================== 权限流(SC-P-59 权益边界) ====================
+
+    @Test
+    void 权限流_FREE用户_会员专属功能不可用() {
+        when(familyMapper.selectById(5L)).thenReturn(familyWithCreator(7L));
+        User admin = new User();
+        admin.setId(7L);
+        admin.setMemberLevel("FREE");
+        when(userMapper.selectById(7L)).thenReturn(admin);
+
+        assertFalse(service.canUseFeature(5L, "member_activities"), "FREE 不可用会员活动");
+        assertFalse(service.canUseFeature(5L, "mascot_ai"), "FREE 不可用 AI 助手");
+        assertTrue(service.canUseFeature(5L, "free_activities"), "FREE 可用免费活动");
+    }
+
+    private Family familyWithCreator(Long creatorId) {
+        Family f = new Family();
+        f.setId(5L);
+        f.setCreatorId(creatorId);
+        return f;
+    }
+}

+ 327 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/OrderCreatePayShipConfirmScX07ContractTest.java

@@ -0,0 +1,327 @@
+package com.etotem.cfc.unit;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.dto.CreateProductOrderDTO;
+import com.etotem.cfc.dto.ProductOrderDTO;
+import com.etotem.cfc.entity.Product;
+import com.etotem.cfc.entity.ProductOrder;
+import com.etotem.cfc.entity.User;
+import com.etotem.cfc.mapper.ProductMapper;
+import com.etotem.cfc.mapper.ProductOrderMapper;
+import com.etotem.cfc.mapper.UserMapper;
+import com.etotem.cfc.service.InventoryService;
+import com.etotem.cfc.service.MemberPriceResolver;
+import com.etotem.cfc.service.PaymentService;
+import com.etotem.cfc.service.ProductGiftRuleService;
+import com.etotem.cfc.service.ProductOrderService;
+import com.etotem.cfc.service.ProductService;
+import com.etotem.cfc.util.RedisLockUtil;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * SC-X-07 商城履约闭环(下单→支付→发货→确认收货)+ SC-P-55 订单支付 契约测试(S-cfc-12,product.order)
+ *
+ * <p>覆盖三类流(纯 Mockito,无 Spring 上下文 / 无 DB):</p>
+ * <ul>
+ *   <li><b>正常流</b>:创建订单(待支付)→ 支付回调(标记已付+扣库存)→ 快递发货(待收货)→ 确认收货(完成);</li>
+ *   <li><b>异常流</b>:商品不存在/已下架/库存不足;订单不存在/状态异常;发货未支付;确认收货非待收货;</li>
+ *   <li><b>权限流</b>:非本人支付 → 「无权操作此订单」;非买家确认收货 → 「无权操作此订单」;未登录下单 → 「请先登录」。</li>
+ * </ul>
+ */
+class OrderCreatePayShipConfirmScX07ContractTest {
+
+    private ProductOrderService service;
+    private ProductOrderMapper orderMapper;
+    private ProductMapper productMapper;
+    private UserMapper userMapper;
+    private MemberPriceResolver memberPriceResolver;
+    private ProductGiftRuleService productGiftRuleService;
+    private PaymentService paymentService;
+    private ProductService productService;
+    private InventoryService inventoryService;
+    private RedisLockUtil redisLockUtil;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        service = new ProductOrderService();
+        orderMapper = mock(ProductOrderMapper.class);
+        productMapper = mock(ProductMapper.class);
+        userMapper = mock(UserMapper.class);
+        memberPriceResolver = mock(MemberPriceResolver.class);
+        productGiftRuleService = mock(ProductGiftRuleService.class);
+        paymentService = mock(PaymentService.class);
+        productService = mock(ProductService.class);
+        inventoryService = mock(InventoryService.class);
+        redisLockUtil = mock(RedisLockUtil.class);
+
+        inject(service, "orderMapper", orderMapper);
+        inject(service, "productMapper", productMapper);
+        inject(service, "userMapper", userMapper);
+        inject(service, "memberPriceResolver", memberPriceResolver);
+        inject(service, "productGiftRuleService", productGiftRuleService);
+        inject(service, "paymentService", paymentService);
+        inject(service, "productService", productService);
+        inject(service, "inventoryService", inventoryService);
+        inject(service, "redisLockUtil", redisLockUtil);
+    }
+
+    private static void inject(Object target, String field, Object value) throws Exception {
+        Field f = target.getClass().getDeclaredField(field);
+        f.setAccessible(true);
+        f.set(target, value);
+    }
+
+    private Product physicalProduct(Long id, String name, Integer price, Integer stock) {
+        Product p = new Product();
+        p.setId(id);
+        p.setName(name);
+        p.setPrice(price);
+        p.setStatus("on_shelf");
+        p.setProductType("physical");
+        p.setStock(stock);
+        p.setCoverImage("img.png");
+        return p;
+    }
+
+    private ProductOrder baseOrder(String orderNo, String status, Long buyerId) {
+        ProductOrder o = new ProductOrder();
+        o.setId(1L);
+        o.setOrderNo(orderNo);
+        o.setStatus(status);
+        o.setBuyerId(buyerId);
+        o.setProductId(10L);
+        o.setProductName("成长测评");
+        o.setProductType("physical");
+        o.setQuantity(1);
+        o.setUnitPrice(9900);
+        o.setTotalAmount(9900);
+        o.setMoneyAmount(9900);
+        o.setPointsUsed(0);
+        o.setDeliveryMethod(1);
+        return o;
+    }
+
+    // ==================== 正常流(SC-X-07 闭环) ====================
+
+    @Test
+    void 正常流_创建订单_待支付() {
+        Product product = physicalProduct(10L, "成长测评", 9900, 100);
+        when(productMapper.selectById(10L)).thenReturn(product);
+        User buyer = new User();
+        buyer.setId(1L);
+        buyer.setFamilyId(5L);
+        when(userMapper.selectById(1L)).thenReturn(buyer);
+        when(memberPriceResolver.resolveEligibleMemberPrice(product, 1L)).thenReturn(9900);
+        when(productGiftRuleService.getActiveByProductId(10L)).thenReturn(null);
+        when(orderMapper.insert(any(ProductOrder.class))).thenAnswer(inv -> {
+            ProductOrder o = inv.getArgument(0);
+            o.setId(100L);
+            return 1;
+        });
+
+        CreateProductOrderDTO dto = new CreateProductOrderDTO();
+        dto.setProductId(10L);
+        dto.setQuantity(1);
+        dto.setAddressSnapshot("北京市朝阳区xx路1号");
+        dto.setPaymentMethod("wechat");
+
+        Result<ProductOrderDTO> result = service.create(dto, 1L);
+
+        assertEquals(200, result.getCode(), "下单应成功");
+        ProductOrderDTO dto2 = result.getData();
+        assertNotNull(dto2);
+        assertEquals("pending", dto2.getStatus(), "新订单应为待支付");
+        assertEquals(9900, dto2.getMoneyAmount());
+        assertEquals(1, dto2.getQuantity());
+        // 订单已入库
+        verify(orderMapper).insert(any(ProductOrder.class));
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void 正常流_支付回调_标记已付并扣库存() {
+        ProductOrder order = baseOrder("PO20261107A", "pending", 1L);
+        order.setOrderNo("PO20261107A");
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+        when(redisLockUtil.tryLock(anyString(), anyLong())).thenReturn(true);
+        Product product = physicalProduct(10L, "成长测评", 9900, 100);
+        when(productMapper.selectById(10L)).thenReturn(product);
+        when(productService.decreaseStock(10L, 1)).thenReturn(true);
+
+        Result<String> result = service.handlePaymentSuccess("PO20261107A", "wx_tx_001");
+
+        assertEquals(200, result.getCode());
+        assertEquals("paid", order.getStatus(), "回调后订单应为已支付");
+        verify(productService).decreaseStock(10L, 1);
+        verify(orderMapper).updateById(order);
+    }
+
+    @Test
+    void 正常流_快递发货_待收货() {
+        ProductOrder order = baseOrder("PO20261107B", "paid", 1L);
+        order.setOrderNo("PO20261107B");
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+        when(userMapper.selectById(1L)).thenReturn(null); // 无openid → 微信同步跳过
+
+        Result<String> result = service.ship("PO20261107B", "SF123456", "顺丰速运");
+
+        assertEquals(200, result.getCode(), "发货应成功");
+        assertEquals("pending_receipt", order.getStatus(), "发货后应待收货");
+        assertEquals("SF123456", order.getLogisticsNo());
+        verify(orderMapper).updateById(order);
+    }
+
+    @Test
+    void 正常流_确认收货_完成() {
+        ProductOrder order = baseOrder("PO20261107C", "pending_receipt", 1L);
+        order.setOrderNo("PO20261107C");
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+
+        Result<String> result = service.confirmReceive("PO20261107C", 1L);
+
+        assertEquals(200, result.getCode(), "确认收货应成功");
+        assertEquals("completed", order.getStatus(), "确认后应完成");
+        verify(orderMapper).updateById(order);
+    }
+
+    // ==================== 正常流(SC-P-55 支付) ====================
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void 正常流_P55_微信支付参数() {
+        ProductOrder order = baseOrder("PO20261107D", "pending", 1L);
+        order.setOrderNo("PO20261107D");
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+        User buyer = new User();
+        buyer.setId(1L);
+        buyer.setOpenid("oABCDEF");
+        when(userMapper.selectById(1L)).thenReturn(buyer);
+        when(paymentService.createWechatPrepay(anyString(), anyString(), any(Integer.class),
+                anyString(), any(List.class))).thenReturn(Collections.singletonMap("prepay_id", "wx_prepay_1"));
+
+        Result<Map<String, Object>> result = service.pay("PO20261107D", 1L);
+
+        assertEquals(200, result.getCode());
+        Map<String, Object> data = result.getData();
+        assertNotNull(data.get("wechatPayParams"), "应返回微信支付参数");
+        assertEquals(0, data.get("pointsUsed"));
+    }
+
+    // ==================== 异常流 ====================
+
+    @Test
+    void 异常流_创建订单_商品不存在() {
+        when(productMapper.selectById(999L)).thenReturn(null);
+        CreateProductOrderDTO dto = new CreateProductOrderDTO();
+        dto.setProductId(999L);
+        dto.setQuantity(1);
+        Result<ProductOrderDTO> result = service.create(dto, 1L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("不存在"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_创建订单_已下架() {
+        Product product = physicalProduct(11L, "已下架商品", 5000, 10);
+        product.setStatus("off_shelf");
+        when(productMapper.selectById(11L)).thenReturn(product);
+        CreateProductOrderDTO dto = new CreateProductOrderDTO();
+        dto.setProductId(11L);
+        dto.setQuantity(1);
+        Result<ProductOrderDTO> result = service.create(dto, 1L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("下架"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_创建订单_库存不足() {
+        Product product = physicalProduct(12L, "库存告急", 5000, 1);
+        when(productMapper.selectById(12L)).thenReturn(product);
+        CreateProductOrderDTO dto = new CreateProductOrderDTO();
+        dto.setProductId(12L);
+        dto.setQuantity(5);
+        Result<ProductOrderDTO> result = service.create(dto, 1L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("库存不足"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_支付_订单不存在() {
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(null);
+        Result<Map<String, Object>> result = service.pay("PO_NOT_EXIST", 1L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("订单不存在"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_发货_未支付() {
+        ProductOrder order = baseOrder("PO20261107E", "pending", 1L);
+        order.setOrderNo("PO20261107E");
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+        Result<String> result = service.ship("PO20261107E", "SF1", "顺丰");
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("仅已支付订单可发货"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_确认收货_非待收货() {
+        ProductOrder order = baseOrder("PO20261107F", "paid", 1L);
+        order.setOrderNo("PO20261107F");
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+        Result<String> result = service.confirmReceive("PO20261107F", 1L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("仅待收货订单可确认收货"), "实际: " + result.getMessage());
+    }
+
+    // ==================== 权限流 ====================
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void 权限流_非本人支付_无权操作() {
+        ProductOrder order = baseOrder("PO20261107G", "pending", 1L); // 买家=1
+        order.setOrderNo("PO20261107G");
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+        Result<Map<String, Object>> result = service.pay("PO20261107G", 2L); // 操作者=2
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("无权操作此订单"), "实际: " + result.getMessage());
+        verify(paymentService, never()).createWechatPrepay(anyString(), anyString(), any(), anyString(), any());
+    }
+
+    @Test
+    void 权限流_非买家确认收货_无权操作() {
+        ProductOrder order = baseOrder("PO20261107H", "pending_receipt", 1L);
+        order.setOrderNo("PO20261107H");
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+        Result<String> result = service.confirmReceive("PO20261107H", 99L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("无权操作此订单"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 权限流_未登录下单_请先登录() {
+        CreateProductOrderDTO dto = new CreateProductOrderDTO();
+        dto.setProductId(10L);
+        dto.setQuantity(1);
+        Result<ProductOrderDTO> result = service.create(dto, null);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("请先登录"), "实际: " + result.getMessage());
+    }
+}

+ 247 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/OrderRefundScP56ScA12ContractTest.java

@@ -0,0 +1,247 @@
+package com.etotem.cfc.unit;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.dto.ProductOrderDTO;
+import com.etotem.cfc.entity.Product;
+import com.etotem.cfc.entity.ProductOrder;
+import com.etotem.cfc.mapper.AfterSalesRequestMapper;
+import com.etotem.cfc.mapper.ProductMapper;
+import com.etotem.cfc.mapper.ProductOrderMapper;
+import com.etotem.cfc.service.InventoryService;
+import com.etotem.cfc.service.PaymentService;
+import com.etotem.cfc.service.ProductOrderService;
+import com.etotem.cfc.service.ProductService;
+import com.etotem.cfc.service.SpecialPriceService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * SC-P-56 订单查询与退款申请 + SC-A-12 平台人工退款处理 契约测试(S-cfc-12,product.order)
+ *
+ * <p>覆盖三类流(纯 Mockito,无 Spring 上下文 / 无 DB):</p>
+ * <ul>
+ *   <li><b>正常流</b>:我的订单列表 / 订单详情(买家)→ 成功;申请退款→ refunding;管理员批准→ refunded(微信原路退款+库存回补);
+ *       管理员拒绝→ 回到 paid;</li>
+ *   <li><b>异常流</b>:不存在的订单;未支付订单申请退款 → 「仅已支付或待发货订单可申请退款」;无待处理申请 → 「没有待处理的退款申请」;</li>
+ *   <li><b>权限流</b>:他人订单申请退款 → 「无权操作此订单」;非买家非供应商查看详情 → 「无权查看」。</li>
+ * </ul>
+ */
+class OrderRefundScP56ScA12ContractTest {
+
+    private ProductOrderService service;
+    private ProductOrderMapper orderMapper;
+    private ProductMapper productMapper;
+    private PaymentService paymentService;
+    private ProductService productService;
+    private InventoryService inventoryService;
+    private SpecialPriceService specialPriceService;
+    private AfterSalesRequestMapper afterSalesRequestMapper;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        service = new ProductOrderService();
+        orderMapper = mock(ProductOrderMapper.class);
+        productMapper = mock(ProductMapper.class);
+        paymentService = mock(PaymentService.class);
+        productService = mock(ProductService.class);
+        inventoryService = mock(InventoryService.class);
+        specialPriceService = mock(SpecialPriceService.class);
+        afterSalesRequestMapper = mock(AfterSalesRequestMapper.class);
+
+        inject(service, "orderMapper", orderMapper);
+        inject(service, "productMapper", productMapper);
+        inject(service, "paymentService", paymentService);
+        inject(service, "productService", productService);
+        inject(service, "inventoryService", inventoryService);
+        inject(service, "specialPriceService", specialPriceService);
+        inject(service, "afterSalesRequestMapper", afterSalesRequestMapper);
+    }
+
+    private static void inject(Object target, String field, Object value) throws Exception {
+        Field f = target.getClass().getDeclaredField(field);
+        f.setAccessible(true);
+        f.set(target, value);
+    }
+
+    private ProductOrder orderOf(String orderNo, String status, Long buyerId) {
+        ProductOrder o = new ProductOrder();
+        o.setId(1L);
+        o.setOrderNo(orderNo);
+        o.setStatus(status);
+        o.setBuyerId(buyerId);
+        o.setProductId(10L);
+        o.setProductName("成长测评");
+        o.setProductType("physical");
+        o.setQuantity(1);
+        o.setMoneyAmount(9900);
+        o.setTotalAmount(9900);
+        o.setPointsUsed(0);
+        return o;
+    }
+
+    // ==================== 正常流(SC-P-56 查询) ====================
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void 正常流_我的订单列表() {
+        List<ProductOrder> list = java.util.Collections.singletonList(orderOf("PO1", "paid", 1L));
+        when(orderMapper.selectList(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(list);
+
+        Result<List<ProductOrderDTO>> result = service.myOrders(1L, "paid");
+
+        assertEquals(200, result.getCode());
+        assertEquals(1, result.getData().size());
+        assertEquals("PO1", result.getData().get(0).getOrderNo());
+    }
+
+    @Test
+    void 正常流_订单详情_买家可查看() {
+        ProductOrder order = orderOf("PO2", "paid", 1L);
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+        Product product = new Product();
+        product.setId(10L);
+        product.setVendorId(7L);
+        when(productMapper.selectById(10L)).thenReturn(product);
+
+        Result<ProductOrderDTO> result = service.detail("PO2", 1L);
+
+        assertEquals(200, result.getCode());
+        assertEquals("PO2", result.getData().getOrderNo());
+        assertEquals(7L, result.getData().getVendorId());
+    }
+
+    // ==================== 正常流(SC-P-56 申请退款) ====================
+
+    @Test
+    void 正常流_申请退款_进入refunding() {
+        ProductOrder order = orderOf("PO3", "paid", 1L);
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+
+        Result<String> result = service.applyRefund("PO3", 1L, "不想要了");
+
+        assertEquals(200, result.getCode(), "申请退款应成功");
+        assertEquals("refunding", order.getStatus());
+        assertEquals(1, order.getRefundStatus().intValue());
+        verify(orderMapper).updateById(order);
+    }
+
+    // ==================== 异常流(SC-P-56 退款) ====================
+
+    @Test
+    void 异常流_申请退款_未支付订单() {
+        ProductOrder order = orderOf("PO4", "pending", 1L);
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+
+        Result<String> result = service.applyRefund("PO4", 1L, "不买了");
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("仅已支付或待发货订单可申请退款"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_申请退款_订单不存在() {
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(null);
+        Result<String> result = service.applyRefund("PO_NOT_EXIST", 1L, "理由");
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("订单不存在"), "实际: " + result.getMessage());
+    }
+
+    // ==================== 权限流(SC-P-56 退款) ====================
+
+    @Test
+    void 权限流_他人订单申请退款_无权操作() {
+        ProductOrder order = orderOf("PO5", "paid", 1L);
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+
+        Result<String> result = service.applyRefund("PO5", 99L, "理由");
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("无权操作此订单"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 权限流_非买家非供应商查看详情_无权查看() {
+        ProductOrder order = orderOf("PO6", "paid", 1L);
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+        Product product = new Product();
+        product.setId(10L);
+        product.setVendorId(7L);
+        when(productMapper.selectById(10L)).thenReturn(product);
+
+        Result<ProductOrderDTO> result = service.detail("PO6", 88L);
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("无权查看"), "实际: " + result.getMessage());
+    }
+
+    // ==================== 正常流(SC-A-12 平台处理) ====================
+
+    @Test
+    void 正常流_管理员批准退款_原路退款并回补库存() {
+        ProductOrder order = orderOf("PO7", "refunding", 1L);
+        order.setRefundStatus(1);
+        order.setRefundReason("不想要了");
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+
+        Result<String> result = service.approveRefund("PO7", 1L);
+
+        assertEquals(200, result.getCode(), "批准退款应成功");
+        assertEquals("refunded", order.getStatus());
+        assertEquals(2, order.getRefundStatus().intValue());
+        verify(paymentService).refund("PO7", 9900, "不想要了");
+        verify(productService).increaseStock(10L, 1);
+        verify(inventoryService).recordRefundInbound(any(), any(), anyInt(), any(), any(), any(), anyString());
+    }
+
+    @Test
+    void 正常流_管理员拒绝退款_回到已支付() {
+        ProductOrder order = orderOf("PO8", "refunding", 1L);
+        order.setRefundStatus(1);
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+
+        Result<String> result = service.rejectRefund("PO8", 1L, "证据不足");
+
+        assertEquals(200, result.getCode(), "拒绝退款应成功");
+        assertEquals("paid", order.getStatus());
+        assertEquals(3, order.getRefundStatus().intValue());
+        verify(paymentService, never()).refund(anyString(), anyInt(), anyString());
+    }
+
+    // ==================== 异常流(SC-A-12 平台处理) ====================
+
+    @Test
+    void 异常流_批准退款_无待处理申请() {
+        ProductOrder order = orderOf("PO9", "paid", 1L);
+        order.setRefundStatus(0);
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+
+        Result<String> result = service.approveRefund("PO9", 1L);
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("没有待处理的退款申请"), "实际: " + result.getMessage());
+        verify(paymentService, never()).refund(anyString(), anyInt(), anyString());
+    }
+
+    @Test
+    void 异常流_拒绝退款_无待处理申请() {
+        ProductOrder order = orderOf("PO10", "paid", 1L);
+        when(orderMapper.selectOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(order);
+        Result<String> result = service.rejectRefund("PO10", 1L, "不批");
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("没有待处理的退款申请"), "实际: " + result.getMessage());
+    }
+}

+ 239 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/ProductBrowseScP52ScG05ContractTest.java

@@ -0,0 +1,239 @@
+package com.etotem.cfc.unit;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.dto.ProductDTO;
+import com.etotem.cfc.dto.ProductListQueryDTO;
+import com.etotem.cfc.entity.Product;
+import com.etotem.cfc.entity.User;
+import com.etotem.cfc.mapper.ProductMapper;
+import com.etotem.cfc.mapper.SupplySystemMemberMapper;
+import com.etotem.cfc.mapper.UserMapper;
+import com.etotem.cfc.service.ContentDimensionThresholdService;
+import com.etotem.cfc.service.FiveDimensionScoreService;
+import com.etotem.cfc.service.GrowthArchiveProductService;
+import com.etotem.cfc.service.MembershipService;
+import com.etotem.cfc.service.ProductGiftRuleService;
+import com.etotem.cfc.service.ProductService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * SC-P-52 商品浏览/搜索 + SC-G-05 游客浏览商城(未登录受限) 契约测试(S-cfc-12,product.browse)
+ *
+ * <p>覆盖三类流(纯 Mockito,无 Spring 上下文 / 无 DB):</p>
+ * <ul>
+ *   <li><b>正常流</b>:家长浏览在架商品列表 / 按关键字搜索 → 返回在架记录;</li>
+ *   <li><b>异常流</b>:无商品可浏览(空列表)→ 空记录 total=0;非法维度码 → 跳过维度过滤不报错;</li>
+ *   <li><b>权限流</b>:游客(未登录)浏览 → 仅可见公开商品(排除会员专属 + 仅 NULL 最低可见级别)。</li>
+ * </ul>
+ */
+class ProductBrowseScP52ScG05ContractTest {
+
+    private ProductService service;
+    private ProductMapper productMapper;
+    private UserMapper userMapper;
+    private SupplySystemMemberMapper supplySystemMemberMapper;
+    private MembershipService membershipService;
+    private ProductGiftRuleService productGiftRuleService;
+    private GrowthArchiveProductService growthArchiveProductService;
+    private FiveDimensionScoreService fiveDimensionScoreService;
+    private ContentDimensionThresholdService contentDimensionThresholdService;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        service = new ProductService();
+        productMapper = mock(ProductMapper.class);
+        userMapper = mock(UserMapper.class);
+        supplySystemMemberMapper = mock(SupplySystemMemberMapper.class);
+        membershipService = mock(MembershipService.class);
+        productGiftRuleService = mock(ProductGiftRuleService.class);
+        growthArchiveProductService = mock(GrowthArchiveProductService.class);
+        fiveDimensionScoreService = mock(FiveDimensionScoreService.class);
+        contentDimensionThresholdService = mock(ContentDimensionThresholdService.class);
+
+        inject(service, "productMapper", productMapper);
+        inject(service, "userMapper", userMapper);
+        inject(service, "supplySystemMemberMapper", supplySystemMemberMapper);
+        inject(service, "membershipService", membershipService);
+        inject(service, "productGiftRuleService", productGiftRuleService);
+        inject(service, "growthArchiveProductService", growthArchiveProductService);
+        inject(service, "fiveDimensionScoreService", fiveDimensionScoreService);
+        inject(service, "contentDimensionThresholdService", contentDimensionThresholdService);
+    }
+
+    private static void inject(Object target, String field, Object value) throws Exception {
+        Field f = target.getClass().getDeclaredField(field);
+        f.setAccessible(true);
+        f.set(target, value);
+    }
+
+    private Product onShelfProduct(Long id, String name, Integer price) {
+        Product p = new Product();
+        p.setId(id);
+        p.setName(name);
+        p.setPrice(price);
+        p.setStatus("on_shelf");
+        p.setProductType("physical");
+        p.setStock(100);
+        return p;
+    }
+
+    private ProductListQueryDTO query(String keyword) {
+        ProductListQueryDTO q = new ProductListQueryDTO();
+        q.setPage(1);
+        q.setSize(10);
+        q.setKeyword(keyword);
+        return q;
+    }
+
+    /** 桩:登录家长(familyId=1),可见等级为空,无供应商体系,家庭平均分为空 */
+    private void stubParentUser() {
+        User user = new User();
+        user.setId(1L);
+        user.setFamilyId(1L);
+        when(userMapper.selectById(1L)).thenReturn(user);
+        when(membershipService.getVisibleMemberLevelCodes(1L)).thenReturn(Collections.emptyList());
+        when(supplySystemMemberMapper.selectList(any(Wrapper.class))).thenReturn(Collections.emptyList());
+        when(fiveDimensionScoreService.getFamilyAverageScores(any())).thenReturn(Collections.emptyMap());
+        when(productGiftRuleService.listActiveByProductIds(any())).thenReturn(Collections.emptyList());
+    }
+
+    // ==================== 正常流(SC-P-52) ====================
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void 正常流_家长浏览在架商品_返回列表() {
+        stubParentUser();
+        List<Product> records = new ArrayList<>();
+        records.add(onShelfProduct(10L, "成长测评", 9900));
+        Page<Product> page = new Page<>(1, 10);
+        page.setRecords(records);
+        page.setTotal(1);
+        when(productMapper.selectPage(any(Page.class), any(Wrapper.class))).thenReturn(page);
+
+        Result<Map<String, Object>> result = service.list(query(null), 1L, "parent");
+
+        assertEquals(200, result.getCode(), "浏览应成功");
+        Map<String, Object> data = result.getData();
+        assertNotNull(data);
+        assertEquals(1L, data.get("total"));
+        List<ProductDTO> dtos = (List<ProductDTO>) data.get("records");
+        assertEquals(1, dtos.size());
+        assertEquals("成长测评", dtos.get(0).getName());
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void 正常流_关键字搜索_命中在架商品() {
+        stubParentUser();
+        List<Product> records = new ArrayList<>();
+        records.add(onShelfProduct(11L, "五维测评", 12900));
+        Page<Product> page = new Page<>(1, 10);
+        page.setRecords(records);
+        page.setTotal(1);
+        when(productMapper.selectPage(any(Page.class), any(Wrapper.class))).thenReturn(page);
+
+        Result<Map<String, Object>> result = service.list(query("五维"), 1L, "parent");
+
+        assertEquals(200, result.getCode());
+        List<ProductDTO> dtos = (List<ProductDTO>) result.getData().get("records");
+        assertEquals(1, dtos.size());
+        assertEquals("五维测评", dtos.get(0).getName());
+    }
+
+    // ==================== 异常流(SC-P-52) ====================
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void 异常流_无商品_返回空列表total0() {
+        stubParentUser();
+        Page<Product> page = new Page<>(1, 10);
+        page.setRecords(Collections.emptyList());
+        page.setTotal(0);
+        when(productMapper.selectPage(any(Page.class), any(Wrapper.class))).thenReturn(page);
+
+        Result<Map<String, Object>> result = service.list(query(null), 1L, "parent");
+
+        assertEquals(200, result.getCode());
+        assertEquals(0L, result.getData().get("total"));
+        assertTrue(((List<?>) result.getData().get("records")).isEmpty());
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void 异常流_非法维度码_跳过维度过滤不报错() {
+        stubParentUser();
+        List<Product> records = new ArrayList<>();
+        records.add(onShelfProduct(12L, "维度商品", 5000));
+        Page<Product> page = new Page<>(1, 10);
+        page.setRecords(records);
+        page.setTotal(1);
+        when(productMapper.selectPage(any(Page.class), any(Wrapper.class))).thenReturn(page);
+
+        ProductListQueryDTO q = query(null);
+        q.setDimensionCode("'; DROP TABLE products; --"); // 注入探针/非法码
+        Result<Map<String, Object>> result = service.list(q, 1L, "parent");
+
+        assertEquals(200, result.getCode(), "非法维度码不应导致 500");
+        assertEquals(1, ((List<?>) result.getData().get("records")).size());
+    }
+
+    // ==================== 权限流(SC-G-05 游客受限) ====================
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void 权限流_游客浏览_仅可见公开商品() {
+        // 游客 userId=null:getMySupplySystemIds 直接返回空,不查供应商表
+        when(fiveDimensionScoreService.getFamilyAverageScores(any())).thenReturn(Collections.emptyMap());
+        when(productGiftRuleService.listActiveByProductIds(any())).thenReturn(Collections.emptyList());
+        List<Product> records = new ArrayList<>();
+        records.add(onShelfProduct(20L, "公开商品", 3000));
+        Page<Product> page = new Page<>(1, 10);
+        page.setRecords(records);
+        page.setTotal(1);
+        when(productMapper.selectPage(any(Page.class), any(Wrapper.class))).thenReturn(page);
+
+        Result<Map<String, Object>> result = service.list(query(null), null, null);
+
+        assertEquals(200, result.getCode(), "游客可浏览公开商品");
+        assertEquals(1, ((List<?>) result.getData().get("records")).size());
+        // 游客过滤口径:member_eligible <> 'yes' 且 min_visible_level IS NULL
+        verify(productMapper).selectPage(any(Page.class), any(Wrapper.class));
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void 权限流_游客浏览_会员专属商品被排除() {
+        when(fiveDimensionScoreService.getFamilyAverageScores(any())).thenReturn(Collections.emptyMap());
+        when(productGiftRuleService.listActiveByProductIds(any())).thenReturn(Collections.emptyList());
+        List<Product> records = new ArrayList<>();
+        records.add(onShelfProduct(21L, "仅公开", 3000));
+        Page<Product> page = new Page<>(1, 10);
+        page.setRecords(records);
+        page.setTotal(1);
+        when(productMapper.selectPage(any(Page.class), any(Wrapper.class))).thenReturn(page);
+
+        Result<Map<String, Object>> result = service.list(query(null), null, null);
+
+        assertEquals(200, result.getCode());
+        // 游客不加入任何供应商体系,仅可见公开商品(vendor_visible IS NULL 或 = false)
+        verify(productMapper).selectPage(any(Page.class), any(Wrapper.class));
+    }
+}

+ 194 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/ProductDetailScP53ContractTest.java

@@ -0,0 +1,194 @@
+package com.etotem.cfc.unit;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.dto.GiftConfigVO;
+import com.etotem.cfc.dto.MembershipLevelDTO;
+import com.etotem.cfc.dto.ProductDTO;
+import com.etotem.cfc.entity.Product;
+import com.etotem.cfc.entity.User;
+import com.etotem.cfc.mapper.ProductMapper;
+import com.etotem.cfc.mapper.UserMapper;
+import com.etotem.cfc.service.AssessmentProductService;
+import com.etotem.cfc.service.GrowthArchiveProductService;
+import com.etotem.cfc.service.MembershipService;
+import com.etotem.cfc.service.NutritionProductService;
+import com.etotem.cfc.service.ProductDeliveryConfigService;
+import com.etotem.cfc.service.ProductGiftRuleService;
+import com.etotem.cfc.service.ProductGiftService;
+import com.etotem.cfc.service.ProductService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * SC-P-53 商品详情 契约测试(S-cfc-12,product.browse)
+ *
+ * <p>覆盖三类流(纯 Mockito,无 Spring 上下文 / 无 DB):</p>
+ * <ul>
+ *   <li><b>正常流</b>:在架/已审核商品详情 → 返回完整商品 DTO;</li>
+ *   <li><b>异常流</b>:商品不存在 → 400 语义错误「商品不存在」;未上架商品 → 「商品未上架」;</li>
+ *   <li><b>权限流</b>:商品详情可见性——未上架/已驳回不对外展示;赠品配置按会员等级可见
+ *       (非会员 FREE 不可见赠品配置,FAMILY 会员可见)。</li>
+ * </ul>
+ */
+class ProductDetailScP53ContractTest {
+
+    private ProductService service;
+    private ProductMapper productMapper;
+    private UserMapper userMapper;
+    private MembershipService membershipService;
+    private ProductGiftService productGiftService;
+    private ProductGiftRuleService productGiftRuleService;
+    private ProductDeliveryConfigService productDeliveryConfigService;
+    private NutritionProductService nutritionProductService;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        service = new ProductService();
+        productMapper = mock(ProductMapper.class);
+        userMapper = mock(UserMapper.class);
+        membershipService = mock(MembershipService.class);
+        productGiftService = mock(ProductGiftService.class);
+        productGiftRuleService = mock(ProductGiftRuleService.class);
+        productDeliveryConfigService = mock(ProductDeliveryConfigService.class);
+        nutritionProductService = mock(NutritionProductService.class);
+
+        inject(service, "productMapper", productMapper);
+        inject(service, "userMapper", userMapper);
+        inject(service, "membershipService", membershipService);
+        inject(service, "productGiftService", productGiftService);
+        inject(service, "productGiftRuleService", productGiftRuleService);
+        inject(service, "productDeliveryConfigService", productDeliveryConfigService);
+        inject(service, "nutritionProductService", nutritionProductService);
+        // 未触达的依赖留空即可(bundle 分支不会走到)
+    }
+
+    private static void inject(Object target, String field, Object value) throws Exception {
+        Field f = target.getClass().getDeclaredField(field);
+        f.setAccessible(true);
+        f.set(target, value);
+    }
+
+    private Product baseProduct(Long id, String status) {
+        Product p = new Product();
+        p.setId(id);
+        p.setName("成长测评");
+        p.setPrice(9900);
+        p.setStatus(status);
+        p.setProductType("physical");
+        return p;
+    }
+
+    private void stubFreeUser() {
+        User user = new User();
+        user.setId(1L);
+        user.setFamilyId(1L);
+        when(userMapper.selectById(1L)).thenReturn(user);
+        MembershipLevelDTO free = new MembershipLevelDTO();
+        free.setLevelCode("FREE");
+        when(membershipService.getCurrentLevel(1L)).thenReturn(free);
+        when(productGiftService.getActiveConfigsByProductAndLevel(any(), any()))
+                .thenReturn(Collections.emptyList());
+    }
+
+    // ==================== 正常流 ====================
+
+    @Test
+    void 正常流_在架商品_返回详情() {
+        when(productMapper.selectById(10L)).thenReturn(baseProduct(10L, "on_shelf"));
+
+        Result<ProductDTO> result = service.detail(10L, null);
+
+        assertEquals(200, result.getCode(), "在架商品应返回详情");
+        assertNotNull(result.getData());
+        assertEquals("成长测评", result.getData().getName());
+        assertEquals(9900, result.getData().getPrice());
+    }
+
+    @Test
+    void 正常流_已审核商品_可查看() {
+        when(productMapper.selectById(11L)).thenReturn(baseProduct(11L, "approved"));
+
+        Result<ProductDTO> result = service.detail(11L, null);
+
+        assertEquals(200, result.getCode(), "已审核待上架商品详情可见");
+        assertEquals("成长测评", result.getData().getName());
+    }
+
+    // ==================== 异常流 ====================
+
+    @Test
+    void 异常流_商品不存在() {
+        when(productMapper.selectById(999L)).thenReturn(null);
+
+        Result<ProductDTO> result = service.detail(999L, null);
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("不存在"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_商品已下架_不可见() {
+        when(productMapper.selectById(12L)).thenReturn(baseProduct(12L, "off_shelf"));
+
+        Result<ProductDTO> result = service.detail(12L, null);
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("未上架"), "实际: " + result.getMessage());
+    }
+
+    // ==================== 权限流 ====================
+
+    @Test
+    void 权限流_已驳回商品_不对外展示() {
+        when(productMapper.selectById(13L)).thenReturn(baseProduct(13L, "rejected"));
+
+        Result<ProductDTO> result = service.detail(13L, null);
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("未上架"), "已驳回商品不应展示,实际: " + result.getMessage());
+    }
+
+    @Test
+    void 权限流_非会员FREE_详情无赠品配置() {
+        stubFreeUser();
+        when(productMapper.selectById(14L)).thenReturn(baseProduct(14L, "on_shelf"));
+
+        Result<ProductDTO> result = service.detail(14L, 1L);
+
+        assertEquals(200, result.getCode());
+        assertNull(result.getData().getGiftConfigs(), "FREE 用户不应拿到赠品配置");
+    }
+
+    @Test
+    void 权限流_FAMILY会员_详情可见赠品配置() {
+        User user = new User();
+        user.setId(2L);
+        user.setFamilyId(1L);
+        when(userMapper.selectById(2L)).thenReturn(user);
+        MembershipLevelDTO family = new MembershipLevelDTO();
+        family.setLevelCode("FAMILY");
+        when(membershipService.getCurrentLevel(1L)).thenReturn(family);
+        GiftConfigVO cfg = new GiftConfigVO();
+        cfg.setId(100L);
+        when(productGiftService.getActiveConfigsByProductAndLevel(14L, "FAMILY"))
+                .thenReturn(Collections.singletonList(cfg));
+        when(productMapper.selectById(14L)).thenReturn(baseProduct(14L, "on_shelf"));
+
+        Result<ProductDTO> result = service.detail(14L, 2L);
+
+        assertEquals(200, result.getCode());
+        assertNotNull(result.getData().getGiftConfigs(), "FAMILY 会员应可见赠品配置");
+        assertEquals(1, result.getData().getGiftConfigs().size());
+    }
+}

+ 200 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/VendorOrderShipConfirmScS03ScS04ContractTest.java

@@ -0,0 +1,200 @@
+package com.etotem.cfc.unit;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.dto.ProductOrderDTO;
+import com.etotem.cfc.entity.Product;
+import com.etotem.cfc.entity.ProductOrder;
+import com.etotem.cfc.mapper.ProductMapper;
+import com.etotem.cfc.mapper.ProductOrderMapper;
+import com.etotem.cfc.mapper.UserMapper;
+import com.etotem.cfc.service.ProductOrderService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * SC-S-03 服务商订单处理(发货/确认完成)+ SC-S-04 到店核销/自提 契约测试(S-cfc-12,vendor.order)
+ *
+ * <p>覆盖三类流(纯 Mockito,无 Spring 上下文 / 无 DB):</p>
+ * <ul>
+ *   <li><b>正常流</b>:快递发货(待收货);供应商确认完成(completed);供应商确认履约(confirmed_by_vendor);自提发货(pending_receipt + 已确认);服务商订单列表;</li>
+ *   <li><b>异常流</b>:未支付订单发货 → 「仅已支付订单可发货」;未支付订单确认完成 → 「仅已支付订单可确认完成」;非待确认状态确认 → 「当前订单状态不可确认」;</li>
+ *   <li><b>权限流</b>:非本商品供应商确认完成 → 「无权操作」。</li>
+ * </ul>
+ */
+class VendorOrderShipConfirmScS03ScS04ContractTest {
+
+    private ProductOrderService service;
+    private ProductOrderMapper orderMapper;
+    private ProductMapper productMapper;
+    private UserMapper userMapper;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        service = new ProductOrderService();
+        orderMapper = mock(ProductOrderMapper.class);
+        productMapper = mock(ProductMapper.class);
+        userMapper = mock(UserMapper.class);
+
+        inject(service, "orderMapper", orderMapper);
+        inject(service, "productMapper", productMapper);
+        inject(service, "userMapper", userMapper);
+    }
+
+    private static void inject(Object target, String field, Object value) throws Exception {
+        Field f = target.getClass().getDeclaredField(field);
+        f.setAccessible(true);
+        f.set(target, value);
+    }
+
+    private ProductOrder order(String orderNo, String status, int deliveryMethod) {
+        ProductOrder o = new ProductOrder();
+        o.setId(1L);
+        o.setOrderNo(orderNo);
+        o.setStatus(status);
+        o.setBuyerId(1L);
+        o.setProductId(10L);
+        o.setProductName("亲子课程");
+        o.setProductType("physical");
+        o.setQuantity(1);
+        o.setDeliveryMethod(deliveryMethod);
+        o.setFulfillStatus("pending");
+        return o;
+    }
+
+    // ==================== 正常流(SC-S-03/04) ====================
+
+    @Test
+    void 正常流_快递发货_待收货() {
+        ProductOrder o = order("VO1", "paid", 1);
+        when(orderMapper.selectOne(any(Wrapper.class))).thenReturn(o);
+        when(userMapper.selectById(1L)).thenReturn(null);
+
+        Result<String> result = service.ship("VO1", "YT999", "圆通");
+
+        assertEquals(200, result.getCode());
+        assertEquals("pending_receipt", o.getStatus());
+        assertEquals("YT999", o.getLogisticsNo());
+        verify(orderMapper).updateById(o);
+    }
+
+    @Test
+    void 正常流_自提发货_标记供应商已确认() {
+        ProductOrder o = order("VO2", "paid", 2); // 自提
+        when(orderMapper.selectOne(any(Wrapper.class))).thenReturn(o);
+        when(userMapper.selectById(1L)).thenReturn(null);
+
+        Result<String> result = service.ship("VO2", "selfPickup", null, null, null, null);
+
+        assertEquals(200, result.getCode());
+        assertEquals("pending_receipt", o.getStatus());
+        assertEquals("confirmed_by_vendor", o.getFulfillStatus(), "自提发货应置供应商已确认");
+    }
+
+    @Test
+    void 正常流_供应商确认履约() {
+        ProductOrder o = order("VO3", "paid", 2);
+        when(orderMapper.selectOne(any(Wrapper.class))).thenReturn(o);
+
+        Result<String> result = service.vendorConfirm("VO3", 7L);
+
+        assertEquals(200, result.getCode(), "供应商可确认发出");
+        assertEquals("confirmed_by_vendor", o.getFulfillStatus());
+        verify(orderMapper).updateById(o);
+    }
+
+    @Test
+    void 正常流_供应商确认完成() {
+        ProductOrder o = order("VO4", "paid", 1);
+        when(orderMapper.selectOne(any(Wrapper.class))).thenReturn(o);
+        Product product = new Product();
+        product.setId(10L);
+        product.setVendorId(7L);
+        when(productMapper.selectById(10L)).thenReturn(product);
+
+        Result<String> result = service.confirm("VO4", 7L);
+
+        assertEquals(200, result.getCode());
+        assertEquals("completed", o.getStatus());
+    }
+
+    @Test
+    void 正常流_服务商订单列表() {
+        Product vendorProduct = new Product();
+        vendorProduct.setId(10L);
+        vendorProduct.setVendorId(7L);
+        when(productMapper.selectList(any(Wrapper.class)))
+                .thenReturn(Collections.singletonList(vendorProduct));
+        ProductOrder o = order("VO5", "paid", 1);
+        when(orderMapper.selectList(any(Wrapper.class))).thenReturn(Collections.singletonList(o));
+
+        Result<List<ProductOrderDTO>> result = service.vendorOrders(7L, "paid");
+
+        assertEquals(200, result.getCode());
+        assertEquals(1, result.getData().size());
+        assertEquals("VO5", result.getData().get(0).getOrderNo());
+    }
+
+    // ==================== 异常流 ====================
+
+    @Test
+    void 异常流_未支付订单_不可发货() {
+        ProductOrder o = order("VO6", "pending", 1);
+        when(orderMapper.selectOne(any(Wrapper.class))).thenReturn(o);
+        Result<String> result = service.ship("VO6", "YT1", "圆通");
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("仅已支付订单可发货"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_未支付订单_不可确认完成() {
+        ProductOrder o = order("VO7", "pending", 1);
+        when(orderMapper.selectOne(any(Wrapper.class))).thenReturn(o);
+        Product product = new Product();
+        product.setId(10L);
+        product.setVendorId(7L);
+        when(productMapper.selectById(10L)).thenReturn(product);
+        Result<String> result = service.confirm("VO7", 7L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("仅已支付订单可确认完成"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_待支付_不可确认履约() {
+        ProductOrder o = order("VO8", "pending", 2);
+        when(orderMapper.selectOne(any(Wrapper.class))).thenReturn(o);
+        Result<String> result = service.vendorConfirm("VO8", 7L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("当前订单状态不可确认"), "实际: " + result.getMessage());
+    }
+
+    // ==================== 权限流 ====================
+
+    @Test
+    void 权限流_非本商品供应商_无权确认完成() {
+        ProductOrder o = order("VO9", "paid", 1);
+        when(orderMapper.selectOne(any(Wrapper.class))).thenReturn(o);
+        Product product = new Product();
+        product.setId(10L);
+        product.setVendorId(7L);
+        when(productMapper.selectById(10L)).thenReturn(product);
+
+        Result<String> result = service.confirm("VO9", 8L); // 供应商 8 ≠ 商品所属 7
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("无权操作"), "实际: " + result.getMessage());
+        verify(orderMapper, never()).updateById(any(ProductOrder.class));
+    }
+}

+ 199 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/VendorProductManageScS02ContractTest.java

@@ -0,0 +1,199 @@
+package com.etotem.cfc.unit;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.dto.ProductDTO;
+import com.etotem.cfc.entity.Product;
+import com.etotem.cfc.entity.User;
+import com.etotem.cfc.mapper.ProductMapper;
+import com.etotem.cfc.mapper.UserMapper;
+import com.etotem.cfc.service.NutritionProductService;
+import com.etotem.cfc.service.ProductService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * SC-S-02 服务商商品管理(发布/编辑/上下架/我的商品) 契约测试(S-cfc-12,vendor.product)
+ *
+ * <p>覆盖三类流(纯 Mockito,无 Spring 上下文 / 无 DB):</p>
+ * <ul>
+ *   <li><b>正常流</b>:审核通过服务商发布商品(pending);编辑商品(pending);上架已审核商品(on_shelf);我的商品列表;</li>
+ *   <li><b>异常流</b>:商品不存在;未审核商品上架 → 「商品未通过审核,无法上架」;</li>
+ *   <li><b>权限流</b>:非审核通过服务商发布 → 「仅审核通过的服务商可发布商品」;他人商品编辑 → 「无权修改此商品」;他人商品上下架 → 「无权操作」。</li>
+ * </ul>
+ */
+class VendorProductManageScS02ContractTest {
+
+    private ProductService service;
+    private ProductMapper productMapper;
+    private UserMapper userMapper;
+    private NutritionProductService nutritionProductService;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        service = new ProductService();
+        productMapper = mock(ProductMapper.class);
+        userMapper = mock(UserMapper.class);
+        nutritionProductService = mock(NutritionProductService.class);
+
+        inject(service, "productMapper", productMapper);
+        inject(service, "userMapper", userMapper);
+        inject(service, "nutritionProductService", nutritionProductService);
+    }
+
+    private static void inject(Object target, String field, Object value) throws Exception {
+        Field f = target.getClass().getDeclaredField(field);
+        f.setAccessible(true);
+        f.set(target, value);
+    }
+
+    private User vendor(Long id, String status) {
+        User v = new User();
+        v.setId(id);
+        v.setNickname("服务商" + id);
+        v.setVendorStatus(status);
+        return v;
+    }
+
+    private Product product(Long id, String status, Long vendorId) {
+        Product p = new Product();
+        p.setId(id);
+        p.setName("亲子课程");
+        p.setPrice(19900);
+        p.setStatus(status);
+        p.setVendorId(vendorId);
+        return p;
+    }
+
+    // ==================== 正常流(SC-S-02) ====================
+
+    @Test
+    void 正常流_审核通过服务商_发布商品() {
+        when(userMapper.selectById(7L)).thenReturn(vendor(7L, "approved"));
+        when(productMapper.insert(any(Product.class))).thenAnswer(inv -> {
+            Product p = inv.getArgument(0);
+            p.setId(100L);
+            return 1;
+        });
+
+        Result<ProductDTO> result = service.create(product(null, null, null), 7L);
+
+        assertEquals(200, result.getCode(), "审核通过服务商可发布");
+        assertEquals("pending", result.getData().getStatus(), "新商品应为待审核");
+        assertEquals(7L, result.getData().getVendorId());
+        verify(productMapper).insert(any(Product.class));
+    }
+
+    @Test
+    void 正常流_编辑商品_重新待审核() {
+        Product existing = product(100L, "on_shelf", 7L);
+        Product afterUpdate = product(100L, "pending", 7L);
+        afterUpdate.setName("亲子课程·改");
+        when(productMapper.selectById(100L)).thenReturn(existing, afterUpdate);
+
+        Product update = new Product();
+        update.setId(100L);
+        update.setName("亲子课程·改");
+        Result<ProductDTO> result = service.update(update, 7L);
+
+        assertEquals(200, result.getCode(), "本人商品可编辑");
+        assertEquals("pending", update.getStatus(), "服务应设置状态为pending");
+        assertEquals("pending", result.getData().getStatus(), "返回的DTO状态应为pending");
+        verify(productMapper).updateById(any(Product.class));
+        verify(nutritionProductService).syncFromProduct(any(Product.class));
+    }
+
+    @Test
+    void 正常流_上架已审核商品() {
+        Product p = product(100L, "approved", 7L);
+        when(productMapper.selectById(100L)).thenReturn(p);
+
+        Result<String> result = service.shelve(100L, 7L, "shelve");
+
+        assertEquals(200, result.getCode(), "已审核商品可上架");
+        assertEquals("on_shelf", p.getStatus());
+        verify(productMapper).updateById(p);
+    }
+
+    @Test
+    void 正常流_我的商品列表() {
+        when(productMapper.selectList(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
+                .thenReturn(Collections.singletonList(product(100L, "on_shelf", 7L)));
+
+        Result<List<ProductDTO>> result = service.myProducts(7L);
+
+        assertEquals(200, result.getCode());
+        assertEquals(1, result.getData().size());
+        assertEquals(100L, result.getData().get(0).getId());
+    }
+
+    // ==================== 异常流(SC-S-02) ====================
+
+    @Test
+    void 异常流_商品不存在_无法编辑() {
+        when(productMapper.selectById(999L)).thenReturn(null);
+        Product update = new Product();
+        update.setId(999L);
+        Result<ProductDTO> result = service.update(update, 7L);
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("不存在"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 异常流_未审核商品_无法上架() {
+        Product p = product(100L, "pending", 7L);
+        when(productMapper.selectById(100L)).thenReturn(p);
+
+        Result<String> result = service.shelve(100L, 7L, "shelve");
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("商品未通过审核"), "实际: " + result.getMessage());
+    }
+
+    // ==================== 权限流(SC-S-02) ====================
+
+    @Test
+    void 权限流_未审核服务商_不可发布() {
+        when(userMapper.selectById(8L)).thenReturn(vendor(8L, "pending"));
+
+        Result<ProductDTO> result = service.create(product(null, null, null), 8L);
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("仅审核通过的服务商"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 权限流_他人商品_无权编辑() {
+        Product existing = product(100L, "on_shelf", 7L);
+        when(productMapper.selectById(100L)).thenReturn(existing);
+        Product update = new Product();
+        update.setId(100L);
+        update.setName("越权改");
+
+        Result<ProductDTO> result = service.update(update, 8L);
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("无权修改此商品"), "实际: " + result.getMessage());
+    }
+
+    @Test
+    void 权限流_他人商品_无权上下架() {
+        Product p = product(100L, "approved", 7L);
+        when(productMapper.selectById(100L)).thenReturn(p);
+
+        Result<String> result = service.shelve(100L, 8L, "shelve");
+
+        assertEquals(500, result.getCode());
+        assertTrue(result.getMessage().contains("无权操作"), "实际: " + result.getMessage());
+    }
+}

+ 42 - 0
docs/tdd/orchestration/tr8-shop-member-contract-evidence-20261107.md

@@ -0,0 +1,42 @@
+# TR-8 商城区块契约测试执行证据(18 SC · 94 用例全绿)
+> 归属:契约补建计划 O-7/TR-8 · 生成 2026-11-07
+> 工作分支:`feature/tr8-shop-member-contract`(base origin/cfclub `8ba3ac14c`)
+
+## 执行方式
+- 测试形态:**纯 Mockito 契约测试**(无 Spring 上下文 / 无 DB),位于 `cfc-backend/src/test/java/com/etotem/cfc/unit/`,沿用 O-3 范式(`mock()` + 反射注入 `@Resource` 字段)。
+- 无 MySQL / 无真实端点 → 无法 Playwright e2e;以 Service 层契约测试实跑三类流,等价覆盖「端点 → 服务方法 → 结果/校验/权限」全部判定分支(Controller 为薄壳,已核对端点映射)。
+- 运行命令:`mvn test -DskipTests=false -Dtest='<11 个类>'` → **Tests run: 94, Failures: 0, Errors: 0, Skipped: 0**。
+- 编译闸门:`mvn compile` + `mvn test-compile` 均 BUILD SUCCESS。
+
+## SC ↔ 契约测试 ↔ 三类流覆盖
+
+| SC | 契约测试类 | 正常流 | 异常流 | 权限流 |
+|----|-----------|--------|--------|--------|
+| SC-P-52 商品浏览/搜索 | `ProductBrowseScP52ScG05ContractTest` | 家长浏览在架列表 / 关键字搜索 | 空列表 total=0 / 非法维度码不 500 | — |
+| SC-G-05 游客浏览受限 | `ProductBrowseScP52ScG05ContractTest` | — | — | 游客仅公开商品 / 会员专属被排除 |
+| SC-P-53 商品详情 | `ProductDetailScP53ContractTest` | 在架 / 已审核详情 | 不存在 / 已下架 | 已驳回不展示 / FREE 无赠品配置 / FAMILY 可见 |
+| SC-X-07 履约闭环 | `OrderCreatePayShipConfirmScX07ContractTest` | create→回调扣库存→ship→confirmReceive 闭环 + 微信支付参数 | 商品不存在/下架/库存不足 / 订单不存在/状态异常 / 发货未支付 / 确认非待收货 | 非本人支付 / 非买家收货 / 未登录下单 |
+| SC-P-55 订单支付 | `OrderCreatePayShipConfirmScX07ContractTest` | wechatPayParams 返回 | 订单不存在 / 订单状态异常 | 非本人订单 |
+| SC-P-56 订单查询/退款 | `OrderRefundScP56ScA12ContractTest` | 我的订单 / 详情(买家)/ 申请退款→refunding | 未支付不可申请 / 订单不存在 | 他人订单无权申请 / 无权查看 |
+| SC-A-12 平台人工退款 | `OrderRefundScP56ScA12ContractTest` | 批准→refunded(原路退款+回补库存)/ 拒绝→paid | 无待处理申请 | — |
+| SC-P-75 优惠券领取 | `CouponUseScP57ScP75ContractTest` | 领取成功 usedCount+1 | 已领完 / 未加入家庭 / 重复领取 | — |
+| SC-P-57 优惠券使用 | `CouponUseScP57ScP75ContractTest` | 满减券 / 折扣券抵扣 | 门槛不足 / 已过期 | 他人家庭券不可用 |
+| SC-A-17 券配置管理 | `CouponUseScP57ScP75ContractTest` | 领券中心模板 / 加入规则列表 | — | — |
+| SC-P-59 会员权益查看 | `MembershipViewScP59ContractTest` | 等级列表 / 有效会员当前等级 / 功能可用 | 无会员回退 FREE / 未知家庭 false | FREE 不可用会员专属功能 |
+| SC-P-60 会员续费 | `MembershipRenewScP60ScP80ContractTest` | 创建会员订单待支付 | 等级不存在 / 无家庭 | — |
+| SC-P-80 会员退款 | `MembershipRenewScP60ScP80ContractTest` | 退款→订单+会员记录 refunded | 订单不存在无操作 | 重复退款幂等跳过 |
+| SC-X-12 会员闭环·支付侧 | `MembershipRenewScP60ScP80ContractTest` + `MembershipViewScP59ContractTest` | 支付回调开通(插 FamilyMembership)/ 权益判定 | 回调订单不存在→false | 重复回调幂等 true |
+| SC-S-02 商品管理 | `VendorProductManageScS02ContractTest` | 发布(pending)/编辑(pending)/上架/我的商品 | 商品不存在 / 未审核不可上架 | 非审核服务商 / 他人商品编辑/上下架 |
+| SC-S-03 订单处理(发货) | `VendorOrderShipConfirmScS03ScS04ContractTest` | 快递发货 / 供应商确认完成 / 服务商订单列表 | 未支付不可发货/确认 | 非本商品供应商 |
+| SC-S-04 订单核销(到店) | `VendorOrderShipConfirmScS03ScS04ContractTest` | 自提发货→pending_receipt+confirmed_by_vendor / 供应商确认履约 | 待支付不可确认履约 | — |
+| SC-S-06 售后处理 | `AfterSalesScS06ContractTest` | 申请(pending+订单refunding)/列表/详情/审核通过/审核拒绝/完成 | 订单不存在 / 未支付不可申请 / 非待审核 / 非已批准 | 他人订单 / 他人售后查看 |
+
+## 关键结果断言(契约口径)
+- 支付/收货/退款/售后权限:非本人 → `无权操作此订单`;非买家非供应商查详情 → `无权查看`
+- 履约状态机:`pending → paid → pending_receipt → completed`;自提需 `confirmed_by_vendor` 方可收货
+- 退款:批准 → 原路 `paymentService.refund` + `increaseStock` + `recordRefundInbound`;拒绝 → 回到 `paid`
+- 优惠券:领取幂等(同家庭同券仅一次);CASH 无门槛、非 CASH 校验 minSpend;他人家庭券不可用
+- 会员:无有效记录回退 FREE;等级不存在/无家庭抛业务异常;回调与退款均幂等
+
+## 产物
+- 10 个契约测试类(94 用例),见下表文件清单;不新增 DB 迁移、不改任何业务实现代码。