diff --git a/src/api/shop/shopOrder/model/index.ts b/src/api/shop/shopOrder/model/index.ts index 2ceeb7b..769ad0b 100644 --- a/src/api/shop/shopOrder/model/index.ts +++ b/src/api/shop/shopOrder/model/index.ts @@ -97,9 +97,9 @@ export interface ShopOrder { formId?: number; // 支付的用户id payUserId?: number; - // 0余额支付, 1微信支付,102微信Native,2会员卡支付,3支付宝,4现金,5POS机,6VIP月卡,7VIP年卡,8VIP次卡,9IC月卡,10IC年卡,11IC次卡,12免费,13VIP充值卡,14IC充值卡,15积分支付,16VIP季卡,17IC季卡,18代付 + // 支付方式:0余额支付, 1微信支付, 2支付宝, 3银联, 4现金, 5POS机, 6免费, 7积分支付, 8货到付款 payType?: number; - // 代付支付方式,0余额支付, 1微信支付,102微信Native,2会员卡支付,3支付宝,4现金,5POS机,6VIP月卡,7VIP年卡,8VIP次卡,9IC月卡,10IC年卡,11IC次卡,12免费,13VIP充值卡,14IC充值卡,15积分支付,16VIP季卡,17IC季卡,18代付 + // 代付支付方式 friendPayType?: number; // 0未付款,1已付款 payStatus?: boolean; @@ -187,11 +187,11 @@ export interface OrderCreateRequest { warehouseId?: number; // 收货地址ID addressId?: number; - // 支付方式 + // 支付方式:0余额支付, 1微信支付, 2支付宝, 3银联, 4现金, 5POS机, 6免费, 7积分支付, 8货到付款 payType: number; - // 支付状态(货到付款时传 true 防止定时任务删除) + // 支付状态(仅货到付款时前端传 true,其他支付方式由后端处理) payStatus?: boolean; - // 支付时间(货到付款时传当前时间) + // 支付时间(仅货到付款时前端传当前时间,其他支付方式由后端处理) payTime?: string; // 优惠券ID couponId?: number; diff --git a/src/components/common/OrderCard/index.tsx b/src/components/common/OrderCard/index.tsx index 4e62b19..1dd0c8f 100644 --- a/src/components/common/OrderCard/index.tsx +++ b/src/components/common/OrderCard/index.tsx @@ -10,9 +10,10 @@ interface OrderCardProps { onClick?: () => void } -/** 综合 payStatus + deliveryStatus + orderStatus 计算列表卡片状态文案 */ +/** 综合 payStatus + deliveryStatus + orderStatus + payType 计算列表卡片状态文案 */ const getCardStatus = (order: ShopOrder): { text: string; color: string } => { - const { payStatus, deliveryStatus, orderStatus } = order + const { payStatus, deliveryStatus, orderStatus, payType } = order + const isCod = payType === 8 // 货到付款 if (orderStatus === 2) return { text: '已取消', color: '#999' } if (orderStatus === 3) return { text: '取消中', color: '#ff7d00' } @@ -23,7 +24,9 @@ const getCardStatus = (order: ShopOrder): { text: string; color: string } => { // 终态:orderStatus=1 必须最先判断,盖过 deliveryStatus/payStatus if (orderStatus === 1) return { text: '已完成', color: '#0e932e' } - if (!payStatus) return { text: '待付款', color: '#ee0a24' } + // 货到付款:payStatus=true 直接进入待发货 + if (!payStatus && !isCod) return { text: '待付款', color: '#ee0a24' } + if (isCod && deliveryStatus === 10) return { text: '货到付款·待发货', color: '#4b9cf5' } if (deliveryStatus === 10) return { text: '待发货', color: '#4b9cf5' } if (deliveryStatus === 20) return { text: '待收货', color: '#4b9cf5' } if (deliveryStatus === 30) return { text: '已收货', color: '#0e932e' } diff --git a/src/pages/order/detail.tsx b/src/pages/order/detail.tsx index 0fb367f..d2eb6c0 100644 --- a/src/pages/order/detail.tsx +++ b/src/pages/order/detail.tsx @@ -15,11 +15,15 @@ definePageConfig({ // 支付方式映射 const PAY_TYPE_MAP: Record = { - 0: '货到付款', + 0: '余额支付', 1: '微信支付', - 2: '会员卡支付', - 3: '支付宝', - 15: '积分支付', + 2: '支付宝', + 3: '银联支付', + 4: '现金支付', + 5: 'POS机', + 6: '免费', + 7: '积分支付', + 8: '货到付款', } // 发票状态映射 @@ -38,7 +42,8 @@ const DELIVERY_STATUS_MAP: Record = { /** 根据订单状态计算展示用的状态标签 */ const getOrderDisplayStatus = (order: ShopOrder): { title: string; bgColor: string; subtitle: string } => { - const { payStatus, deliveryStatus, orderStatus } = order + const { payStatus, deliveryStatus, orderStatus, payType } = order + const isCod = payType === 8 // 货到付款 // 退款/取消相关状态 if (orderStatus === OrderStatus.Cancelled) { @@ -58,11 +63,14 @@ const getOrderDisplayStatus = (order: ShopOrder): { title: string; bgColor: stri } // 正常订单流程 - if (!payStatus) { + if (!payStatus && !isCod) { return { bgColor: '#ff7d00', title: '待付款', subtitle: '请尽快完成支付' } } + if (isCod && !payStatus) { + return { bgColor: '#4b9cf5', title: '货到付款·待发货', subtitle: '送达时支付' } + } if (deliveryStatus === 10) { - return { bgColor: '#4b9cf5', title: '待发货', subtitle: '商家正在准备商品' } + return { bgColor: '#4b9cf5', title: isCod ? '货到付款·待发货' : '待发货', subtitle: isCod ? '送达时支付' : '商家正在准备商品' } } if (deliveryStatus === 20 || deliveryStatus === 30) { return { bgColor: '#4b9cf5', title: '待收货', subtitle: '商品运输中,请注意查收' } @@ -82,14 +90,16 @@ const getOrderDisplayStatus = (order: ShopOrder): { title: string; bgColor: stri type OrderPhase = 'unpaid' | 'unshipped' | 'shipped' | 'completed' | 'cancelled' | 'refund' const getOrderPhase = (order: ShopOrder): OrderPhase => { - const { payStatus, deliveryStatus, orderStatus } = order + const { payStatus, deliveryStatus, orderStatus, payType } = order + const isCod = payType === 8 // 货到付款 // 退款/取消 if ([OrderStatus.Cancelled, OrderStatus.Cancelling, OrderStatus.RefundSuccess, OrderStatus.RefundApply, OrderStatus.ClientRefundApply, OrderStatus.RefundRejected].includes(orderStatus as OrderStatus)) { return orderStatus === OrderStatus.Cancelled || orderStatus === OrderStatus.RefundSuccess ? 'cancelled' : 'refund' } - if (!payStatus) return 'unpaid' + // 货到付款订单:payStatus=true 但还未实际付款,直接进入 unshipped 阶段(不需要"立即支付"按钮) + if (!payStatus && !isCod) return 'unpaid' if (deliveryStatus === 10) return 'unshipped' if (deliveryStatus === 20 || deliveryStatus === 30) return 'shipped' if (orderStatus === OrderStatus.Completed) return 'completed' diff --git a/src/pages/shop/checkout.tsx b/src/pages/shop/checkout.tsx index e4f0497..c9a69b9 100644 --- a/src/pages/shop/checkout.tsx +++ b/src/pages/shop/checkout.tsx @@ -125,7 +125,7 @@ const CheckoutPage: React.FC = () => { const [rushBuyProducts, setRushBuyProducts] = useState([]) // 支付方式相关状态 - const [payType, setPayType] = useState(0) // 0: 货到付款 + const [payType, setPayType] = useState(8) // 8: 货到付款 // 从本地存储获取立即购买的数据 const buyNowItems = useMemo(() => { @@ -263,19 +263,11 @@ const CheckoutPage: React.FC = () => { specInfo: item.skuSpec || item.sku?.sku || item.product?.specName, })) - // 格式化当前时间:yyyy-MM-dd HH:mm:ss(与后端 LocalDateTime 兼容) - const now = new Date() - const pad = (n: number) => n.toString().padStart(2, '0') - const payTime = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}` - - // 创建订单 - // 货到付款:直接设置 payStatus=true + payTime,防止后端定时任务自动删除未付款订单 + // 货到付款:后端会自动设置 payStatus=true,无需前端传递 payStatus/payTime const orderParams: OrderCreateRequest = { goodsItems, addressId: defaultAddress.id, payType, - payStatus: true, - payTime, couponId: selectedCoupon?.id ? Number(selectedCoupon.id) : undefined, comments: remarks, deliveryType: 0, // 快递配送