/** * 陪诊订单状态机(HTTP 接口与管理端 Agent 工具共用同一份规则) * * 之前 Agent 的 escort_record_set 直接改 status,绕过了接口层的迁移校验, * 可以把已完成订单改回进行中。规则集中在这里,任何入口都必须走 canTransition。 */ // 允许的状态迁移;终态不可再变 const STATUS_TRANSITIONS = { pending: ["confirmed", "cancelled"], confirmed: ["in_progress", "cancelled"], in_progress: ["completed"], completed: [], cancelled: [], }; /** * 判断状态迁移是否允许 * @param {string} from 当前状态 * @param {string} to 目标状态 * @returns {boolean} */ function canTransition(from, to) { return (STATUS_TRANSITIONS[from] || []).includes(to); } export { STATUS_TRANSITIONS, canTransition };