feat(M04-B): 完成订单状态机与迁移历史
This commit is contained in:
@@ -97,6 +97,14 @@ export class PricingRepository {
|
||||
VALUES (?, ?, ?)`,
|
||||
[input.tenantId, orderId, input.userId]
|
||||
);
|
||||
await connection.execute(
|
||||
`INSERT INTO qipai_order_status_history
|
||||
(tenant_id, order_id, from_status, to_status, action, actor_type,
|
||||
actor_id, source, reason, trace_id, metadata)
|
||||
VALUES (?, ?, NULL, 'PENDING_PAYMENT', 'CREATED', 'USER', ?,
|
||||
'APP', 'Room hold created', ?, JSON_OBJECT('statusVersion', 1))`,
|
||||
[input.tenantId, orderId, input.userId, `order-created-${orderId}`]
|
||||
);
|
||||
return {
|
||||
orderId,
|
||||
orderNo,
|
||||
@@ -127,12 +135,26 @@ export class PricingRepository {
|
||||
WHERE ${filters.join(' AND ')}`,
|
||||
params
|
||||
);
|
||||
await connection.execute<ResultSetHeader>(
|
||||
`INSERT IGNORE INTO qipai_order_status_history
|
||||
(tenant_id, order_id, from_status, to_status, action, actor_type,
|
||||
actor_id, source, reason, trace_id, metadata)
|
||||
SELECT o.tenant_id, o.id, o.status, 'CLOSED', 'EXPIRED', 'SYSTEM',
|
||||
NULL, 'WORKER', 'Payment hold expired',
|
||||
CONCAT('hold-expired-', o.id), JSON_OBJECT('statusVersion', o.status_version + 1)
|
||||
FROM qipai_room_reservations r
|
||||
INNER JOIN qipai_orders o
|
||||
ON o.id = r.order_id AND o.tenant_id = r.tenant_id
|
||||
WHERE ${filters.join(' AND ')}`,
|
||||
params
|
||||
);
|
||||
await connection.execute<ResultSetHeader>(
|
||||
`UPDATE qipai_room_reservations r
|
||||
INNER JOIN qipai_orders o
|
||||
ON o.id = r.order_id AND o.tenant_id = r.tenant_id
|
||||
SET r.status = 'RELEASED', r.released_at = UTC_TIMESTAMP(3),
|
||||
o.status = 'CLOSED'
|
||||
o.status = 'CLOSED', o.status_version = o.status_version + 1,
|
||||
o.status_updated_at = UTC_TIMESTAMP(3)
|
||||
WHERE ${filters.join(' AND ')}`,
|
||||
params
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user