feature/order-refund-coupon-improvementsE:/tmp/family-cart(严禁触碰主工作树 E:/cfc)ProductOrder 状态流转:paid / shipped / pending_receipt → 申请售后后 status="refunding"、refundStatus=1(申请中)。AfterSalesService.create():插入 AfterSalesRequest(status="pending"),同时把订单置为 refunding + refundStatus=1,写 refundReason/refundAmount。AfterSalesRequest.status 只有 pending→approved→completed / rejected,无 cancelled);② ProductOrder 没有保存退款前的订单状态 → 取消后无法回滚。新增 cfc-backend/src/main/resources/db/migration/V254__add_refund_before_state_to_product_orders.sql:
ALTER TABLE `product_orders`
ADD COLUMN `refund_before_status` varchar(32) DEFAULT NULL COMMENT '退款前订单状态(售后取消回滚用)' AFTER `refund_status`,
ADD COLUMN `refund_before_refund_status` tinyint(1) DEFAULT 0 COMMENT '退款前退款状态(售后取消回滚用)' AFTER `refund_before_status`;
ProductOrder.java新增字段:
private String refundBeforeStatus;private Integer refundBeforeRefundStatus;AfterSalesService.create():写快照在把订单置为 refunding 之前:
order.setRefundBeforeStatus(order.getStatus()); // paid / shipped / pending_receipt
order.setRefundBeforeRefundStatus(order.getRefundStatus()); // 通常为 0
AfterSalesService.cancel(...)签名:Result<String> cancel(Long requestId, Long userId)(按售后申请单取消)或 Result<String> cancelByOrderId(Long orderId, Long userId)。
推荐按 requestId 取消 + 前端把 requestId 传过来;若前端只有 orderId,则实现 cancelByOrderId。两者可同时提供,核心逻辑一致:
1. 校验售后单存在,且 request.userId == userId,否则「无权操作」;
2. 校验 request.status == "pending",否则「后台已处理,无法取消(仅待审核的申请可取消)」;
3. 校验订单 status == "refunding" 且 refundStatus == 1,否则返回「当前状态不可取消」;
4. 售后单 status → "cancelled",更新 updatedAt;
5. 订单回滚:
order.status = order.getRefundBeforeStatus() != null ? refundBeforeStatus : "paid" 兜底;
order.refundStatus = refundBeforeRefundStatus != null ? refundBeforeRefundStatus : 0;
清空 refundReason / refundAmount / refundTime;更新 updatedAt;
6. log.info 记录取消售后单 + 订单回滚。
AfterSalesController 新增端点POST /api/shop/after-sales/cancel{ "requestId": 123 }(或 { "orderId": 456 },取决于 4 的选型)Result<String>:「已取消退款申请,订单已恢复」。order-detail.vue(必要)order.refundStatus === 1 时(现已有「退款申请处理中,请耐心等待」),在其下方增加按钮 「取消退款申请」(refundStatus===1 且 order.status==='refunding' 时显示)。uni.showModal:「确定取消退款申请吗?将恢复订单原状态」)→ 调 cancelRefund(orderId) API:
uni.showToast('已取消') → 重新拉取订单详情刷新;AfterSalesRequest.id;更简单:前端用 orderId 调用 cancelByOrderId,后端查该订单最新 pending 售后单。after-sales.vue(建议,可选)status==='pending' 的申请卡片增加「取消退款」按钮(复用同一接口)。order-detail.vue onBuyAgain():仅 uni.navigateTo 商品详情页(/pages/discover-detail/product-detail/product-detail?id=...),用户需再点购买 + 进结算,体验断链。checkout.vue onLoad:已支持从 storage checkoutItems 读商品列表(数组 [{productId, productName, coverImage, unitPrice, quantity}]),读后 calcAmount()。ProductOrderDTO.from(order),含 productId / productName / coverImage / unitPrice / quantity(实体 ProductOrder 有这些字段)。order-detail.vue onBuyAgain() 改为直接进结算页:
onBuyAgain() {
// 构造结算项:与购物车进入结算的 items 结构一致
const items = [{
productId: this.order.productId,
productName: this.order.productName,
coverImage: this.order.coverImage,
unitPrice: this.order.unitPrice || this.order.price || 0, // 分
quantity: this.order.quantity || 1
}]
uni.setStorageSync('checkoutItems', items)
uni.navigateTo({ url: '/pages/shop/checkout/checkout' })
}
注意:
checkoutItems 是一次性消费的 storage(checkout onLoad 读取后不影响购物车数据源——购物车路径走的是另一通道,二者不冲突);try/catch 或根据订单状态判断);order.status === 'completed' 显示「再次购买」)——如需对 paid/shipped/pending_receipt 也放开,可加判断,但不在本次范围,避免与「申请售后」歧义。checkout.vue 已有:ownedCoupons computed(按 商品类型/满减门槛/金额 过滤)、优惠券 picker、selectCoupon() → applyCouponDiscount()(服务端 /api/coupon/apply 重算抵扣,展示与落库一致)。autoSelectCoupon():仅在 from=coupon&couponId=xxx 深链场景生效,不覆盖「当前商品本来就可用多张券」的常规场景。checkout.vue:
loadCoupons() 成功后调用一次,逻辑:
_autoCouponId 深链优先(现有逻辑保留);ownedCoupons 非空且用户本次未手动取消过券(data._couponDismissed !== true),
从 ownedCoupons 中挑 value 最大(同 value 取 minSpend 最小)的一张,this.selectCoupon(best);_autoSelected = true,空窗期避免重复触发。/api/coupon/apply 计算,与现有一致。coupon-section 未选券(!selectedCoupon)且 ownedCoupons.length > 0 时:
-¥X + 券名),并在券区域标题旁加小字 已按最优自动选择;有 N 张优惠券可抵,点击选择(突出可用券数),加醒目样式。removeCoupon() 时置 _couponDismissed = true(本次结算会话内生效,页面关掉自然重置——data 属性即可)。后端:
cfc-backend/src/main/resources/db/migration/V254__add_refund_before_state_to_product_orders.sql(新增)cfc-backend/src/main/java/com/etotem/cfc/entity/ProductOrder.java(+2 字段)cfc-backend/src/main/java/com/etotem/cfc/service/AfterSalesService.java(create 快照 + cancel/cancelByOrderId)cfc-backend/src/main/java/com/etotem/cfc/controller/shop/AfterSalesController.java(+cancel 端点)前端:
cfc-frontend/pages/shop/order-detail/order-detail.vue(取消退款按钮 + 再买一单直进结算)cfc-frontend/pages/shop/after-sales/after-sales.vue(可选:pending 卡片取消按钮)cfc-frontend/api/shop.js(或对应 api 文件,新增 cancelRefund 调用)cfc-frontend/pages/shop/checkout/checkout.vue(自动最优券 + 提示条)E:/tmp/family-cart)工作;git 只在本分支 feature/order-refund-coupon-improvements;禁对主工作树 E:/cfc 任何写操作(禁 reset --hard / checkout -- . / clean / stash / add -A)。cfc-backend 模块 mvn clean compile 必须通过(在 E:/tmp/family-cart/cfc-backend 下执行)。npx eslint <改动的文件>(PowerShell 环境,不要用 wc -l 等 bash 命令;统计用 Measure-Object -Line)。git add <paths> → git diff --cached --name-only | Measure-Object -Line 校验变更数 → git commit(消息前缀 feat(order-refund)/feat(shop))→ git push -u origin feature/order-refund-coupon-improvements。.tdd/ 与主工作树。refundStatus===1 时点「取消退款申请」,售后单变 cancelled,订单恢复原 status(paid/shipped/pending_receipt)且 refundStatus=0,refundReason/refundAmount/refundTime 清空;from=coupon 场景不受影响;