refactor(escort): 取消状态与 status 解耦
- 新增 cancelStatus(none/requested/cancelled),status 只描述服务生命周期 - record_state 拆分 canCancelTransition 与 CANCEL_TRANSITIONS - 管理端 Agent 工具、查询工具与接口层统一走取消状态机 - 列表默认隐藏已取消订单,支持 cancelStatus / includeCancelled 筛选
This commit is contained in:
+28
-7
@@ -3,21 +3,32 @@
|
||||
*
|
||||
* 之前 Agent 的 escort_record_set 直接改 status,绕过了接口层的迁移校验,
|
||||
* 可以把已完成订单改回进行中。规则集中在这里,任何入口都必须走 canTransition。
|
||||
*
|
||||
* status 只描述服务生命周期;取消由独立的 cancelStatus 表达:
|
||||
* - none → requested:用户对已确认/已收款订单提交取消申请,等陪诊师或管理员确认
|
||||
* - none / requested → cancelled:正式取消
|
||||
*/
|
||||
|
||||
// 允许的状态迁移;终态不可再变
|
||||
// cancel_requested:用户对已确认/已收款订单提交的取消申请,等陪诊师或管理员确认
|
||||
// 允许的服务状态迁移;completed 不可再变
|
||||
const STATUS_TRANSITIONS = {
|
||||
pending: ["confirmed", "cancel_requested", "cancelled"],
|
||||
confirmed: ["in_progress", "cancel_requested", "cancelled"],
|
||||
cancel_requested: ["cancelled"],
|
||||
pending: ["confirmed"],
|
||||
confirmed: ["in_progress"],
|
||||
in_progress: ["completed"],
|
||||
completed: [],
|
||||
};
|
||||
|
||||
// 取消状态迁移;cancelled 不可再变
|
||||
const CANCEL_TRANSITIONS = {
|
||||
none: ["requested", "cancelled"],
|
||||
requested: ["cancelled"],
|
||||
cancelled: [],
|
||||
};
|
||||
|
||||
// 取消状态枚举,供接口参数校验复用
|
||||
const CANCEL_STATUS_VALUES = Object.keys(CANCEL_TRANSITIONS);
|
||||
|
||||
/**
|
||||
* 判断状态迁移是否允许
|
||||
* 判断服务状态迁移是否允许
|
||||
* @param {string} from 当前状态
|
||||
* @param {string} to 目标状态
|
||||
* @returns {boolean}
|
||||
@@ -26,4 +37,14 @@ function canTransition(from, to) {
|
||||
return (STATUS_TRANSITIONS[from] || []).includes(to);
|
||||
}
|
||||
|
||||
export { STATUS_TRANSITIONS, canTransition };
|
||||
/**
|
||||
* 判断取消状态迁移是否允许
|
||||
* @param {string} from 当前取消状态
|
||||
* @param {string} to 目标取消状态
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function canCancelTransition(from, to) {
|
||||
return (CANCEL_TRANSITIONS[from] || []).includes(to);
|
||||
}
|
||||
|
||||
export { STATUS_TRANSITIONS, CANCEL_TRANSITIONS, CANCEL_STATUS_VALUES, canTransition, canCancelTransition };
|
||||
|
||||
Reference in New Issue
Block a user