统一订单单状态模型

This commit is contained in:
yml2213
2026-07-31 17:02:19 +08:00
parent 677bdbbc1c
commit 04130e5ec8
19 changed files with 300 additions and 345 deletions
+15 -24
View File
@@ -16,28 +16,21 @@ export const errorCodes: ParamSpec[] = [
{ name: '500', type: 'int', desc: '服务端内部错误' },
]
// 订单状态与可履约说明(payment_status / fulfillment_status)。
// 订单状态与可履约说明。
export const orderStatusTable: ParamSpec[] = [
{ name: 'pending', type: 'fulfillment_status', desc: '待履约,可被履约器接单', example: 'can_fulfill=true' },
{ name: 'processing', type: 'fulfillment_status', desc: '履约中', example: 'can_fulfill=false' },
{ name: 'succeeded', type: 'fulfillment_status', desc: '履约成功', example: 'can_fulfill=false' },
{ name: 'failed', type: 'fulfillment_status', desc: '履约失败,可重试', example: 'can_fulfill=true' },
{ name: 'cancelled', type: 'fulfillment_status', desc: '已取消', example: 'can_fulfill=false' },
]
export const paymentStatusTable: ParamSpec[] = [
{ name: 'pending', type: 'payment_status', desc: '待支付' },
{ name: 'paid', type: 'payment_status', desc: '已支付(下单成功即为 paid)' },
{ name: 'refunded', type: 'payment_status', desc: '已退款(取消订单后)' },
{ name: 'cancelled', type: 'payment_status', desc: '已取消' },
{ name: 'pending', type: 'order_status', desc: '待支付(当前无真实支付流程,仅预留)', example: 'can_fulfill=false' },
{ name: 'paid', type: 'order_status', desc: '已支付/已扣款,可发货', example: 'can_fulfill=true' },
{ name: 'delivering', type: 'order_status', desc: '发货中', example: 'can_fulfill=false' },
{ name: 'delivered', type: 'order_status', desc: '已交付', example: 'can_fulfill=false' },
{ name: 'ship_failed', type: 'order_status', desc: '发货失败,可重试', example: 'can_fulfill=true' },
{ name: 'cancelled', type: 'order_status', desc: '已取消', example: 'can_fulfill=false' },
]
// 订单对象公共字段说明,下单/查询/取消响应共用。
const orderFields: ParamSpec[] = [
{ name: 'order_no', type: 'string', required: true, desc: '平台订单号' },
{ name: 'client_order_no', type: 'string', required: true, desc: '调用方传入的幂等单号' },
{ name: 'payment_status', type: 'enum', desc: '支付状态,见「状态说明」' },
{ name: 'fulfillment_status', type: 'enum', desc: '履约状态,见「状态说明」' },
{ name: 'order_status', type: 'enum', desc: '订单状态,见「状态说明」' },
{ name: 'can_fulfill', type: 'bool', desc: '是否允许履约器接单/发货' },
{ name: 'cannot_fulfill_reason', type: 'string', desc: 'can_fulfill=false 时的原因' },
{ name: 'product.sku', type: 'string', desc: '商品标识,履约以此为准' },
@@ -64,8 +57,7 @@ const orderResponseExample = `{
"data": {
"order_no": "FO20260730000123",
"client_order_no": "shop-10001",
"payment_status": "paid",
"fulfillment_status": "pending",
"order_status": "paid",
"can_fulfill": true,
"cannot_fulfill_reason": "",
"product": { "sku": "suit_pink_sheep", "name": "套装-糯粉咩咩" },
@@ -134,7 +126,7 @@ const deliverySubmitResponseExample = `{
"message": "ok",
"data": {
"order_no": "FO20260730000123",
"status": "processing",
"status": "delivering",
"message": "已提交上游发货,等待发货结果回传",
"provider_order_no": "provider-1",
"game_account": {
@@ -222,8 +214,7 @@ export const endpoints: EndpointSpec[] = [
"order": {
"order_no": "FO20260730000123",
"client_order_no": "shop-10001",
"payment_status": "paid",
"fulfillment_status": "pending",
"order_status": "paid",
"can_fulfill": true
}
}
@@ -234,7 +225,7 @@ export const endpoints: EndpointSpec[] = [
],
notes: [
'client_order_no 是唯一幂等单号,请保证同一商户下不重复。',
'下单即扣款(payment_status=paid),余额不足返回 400。',
'当前无真实支付流程,下单成功即扣款并进入 order_status=paid,余额不足返回 400。',
'同一 client_order_no 重复请求不会重复扣款,返回 idempotent=true。',
],
},
@@ -254,7 +245,7 @@ export const endpoints: EndpointSpec[] = [
method: 'POST',
path: '/api/client/v1/orders/{order_no}/cancel',
title: '取消订单',
summary: '取消未履约订单并退款(仅 pending/failed 可取消)',
summary: '取消未发货订单并退款(仅 paid/ship_failed 可取消)',
scope: 'orders:write',
pathParams: [{ name: 'order_no', type: 'string', required: true, desc: '平台订单号', example: 'FO20260730000123' }],
bodyParams: [{ name: 'reason', type: 'string', desc: '取消原因(可选)', example: '买家主动取消' }],
@@ -262,8 +253,8 @@ export const endpoints: EndpointSpec[] = [
responseExample: orderResponseExample,
responseFields: orderFields,
notes: [
'取消成功后 payment_status 变为 refunded,金额退回商户钱包。',
'已进入 processing/succeeded 的订单不可取消,返回 400。',
'取消成功后 order_status 变为 cancelled,金额退回商户钱包。',
'已进入 delivering/delivered 的订单不可取消,返回 400。',
],
},
{