fix(payment): 调整货到付款支付方式及状态逻辑
- 将支付方式默认值修改为8表示货到付款 - 删除前端创建订单时对payStatus和payTime的传递,改为后端自动处理 - 更新订单详情页支付方式映射,新增多种支付方式及货到付款标识 - 修改订单状态展示逻辑,针对货到付款订单调整状态标签和流程判断 - 优化订单列表卡片状态显示,支持货到付款的特殊显示需求 - 更新订单模型注释,统一支付方式编码及对应说明
This commit is contained in:
@@ -15,11 +15,15 @@ definePageConfig({
|
||||
|
||||
// 支付方式映射
|
||||
const PAY_TYPE_MAP: Record<number, string> = {
|
||||
0: '货到付款',
|
||||
0: '余额支付',
|
||||
1: '微信支付',
|
||||
2: '会员卡支付',
|
||||
3: '支付宝',
|
||||
15: '积分支付',
|
||||
2: '支付宝',
|
||||
3: '银联支付',
|
||||
4: '现金支付',
|
||||
5: 'POS机',
|
||||
6: '免费',
|
||||
7: '积分支付',
|
||||
8: '货到付款',
|
||||
}
|
||||
|
||||
// 发票状态映射
|
||||
@@ -38,7 +42,8 @@ const DELIVERY_STATUS_MAP: Record<number, string> = {
|
||||
|
||||
/** 根据订单状态计算展示用的状态标签 */
|
||||
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'
|
||||
|
||||
@@ -125,7 +125,7 @@ const CheckoutPage: React.FC = () => {
|
||||
const [rushBuyProducts, setRushBuyProducts] = useState<ShopGoods[]>([])
|
||||
|
||||
// 支付方式相关状态
|
||||
const [payType, setPayType] = useState<number>(0) // 0: 货到付款
|
||||
const [payType, setPayType] = useState<number>(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, // 快递配送
|
||||
|
||||
Reference in New Issue
Block a user