优化撤单处理方式
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
addWorkerWalletCredit,
|
||||
assignWorkOrderToWorker,
|
||||
cancelAssignedWorkOrder,
|
||||
returnAssignedWorkOrderToHall,
|
||||
unassignWorkOrder,
|
||||
countWorkerAcceptedOrders,
|
||||
countWorkerActiveOrders,
|
||||
@@ -1258,7 +1259,10 @@ export async function unassignAdminWorkOrder(workOrderId: number | string) {
|
||||
return { order: mapWorkOrderAdmin(updated) }
|
||||
}
|
||||
|
||||
export async function cancelAdminWorkOrder(workOrderId: number | string) {
|
||||
export async function cancelAdminWorkOrder(
|
||||
workOrderId: number | string,
|
||||
payload: JsonObject = {},
|
||||
) {
|
||||
const workOrder = await getRequiredWorkOrder(workOrderId)
|
||||
if (
|
||||
workOrder.status !== WORK_ORDER_STATUS.IN_PROGRESS ||
|
||||
@@ -1269,10 +1273,29 @@ export async function cancelAdminWorkOrder(workOrderId: number | string) {
|
||||
errorCode: 'work_order_cancel_status_invalid',
|
||||
})
|
||||
}
|
||||
const { order: updated, failureReason } = await cancelAssignedWorkOrder({
|
||||
const action = String(payload.action || '').trim()
|
||||
if (!['return_to_hall', 'cancel_order'].includes(action)) {
|
||||
throw createHttpError('请选择撤单处理方式', {
|
||||
statusCode: 400,
|
||||
errorCode: 'work_order_cancel_action_required',
|
||||
})
|
||||
}
|
||||
const reason = String(payload.reason || '').trim()
|
||||
if (action === 'cancel_order' && !reason) {
|
||||
throw createHttpError('取消订单时请填写退款或撤单原因', {
|
||||
statusCode: 400,
|
||||
errorCode: 'work_order_cancel_reason_required',
|
||||
})
|
||||
}
|
||||
const input = {
|
||||
workOrderId: workOrder.id,
|
||||
now: nowIso(),
|
||||
})
|
||||
reason,
|
||||
}
|
||||
const { order: updated, failureReason } =
|
||||
action === 'return_to_hall'
|
||||
? await returnAssignedWorkOrderToHall(input)
|
||||
: await cancelAssignedWorkOrder(input)
|
||||
if (failureReason === 'work_order_not_in_progress') {
|
||||
throw createHttpError('订单状态已变化,无法撤单', {
|
||||
statusCode: 409,
|
||||
@@ -1291,7 +1314,7 @@ export async function cancelAdminWorkOrder(workOrderId: number | string) {
|
||||
errorCode: 'work_order_cancel_conflict',
|
||||
})
|
||||
}
|
||||
return { order: mapWorkOrderAdmin(updated) }
|
||||
return { order: mapWorkOrderAdmin(updated), action }
|
||||
}
|
||||
|
||||
export async function getAdminWorkerPlatformSummary() {
|
||||
|
||||
Reference in New Issue
Block a user