完善delivery端状态bug

This commit is contained in:
2026-05-26 18:39:43 +08:00
parent 2f528c049f
commit c26f2c5431
5 changed files with 460 additions and 30 deletions

View File

@@ -207,6 +207,18 @@ function hasMissingColumnError(error: any, columnName: string): boolean {
return errorText.indexOf('could not find the') >= 0 && errorText.indexOf(columnName.toLowerCase()) >= 0
}
let ecServiceRequestCreateUnavailable = false
function shouldBypassEcServiceRequestCreate(error: any): boolean {
if (error == null) {
return false
}
return hasMissingColumnError(error, 'address_snapshot')
|| hasMissingColumnError(error, 'address_snapshot_json')
|| hasMissingColumnError(error, 'contact_name')
|| hasMissingColumnError(error, 'contact_phone')
}
function shouldUseCareTaskPath(orderId: string): boolean {
return isUuidLike(orderId)
}
@@ -244,8 +256,9 @@ function getStaffPriority(staff: any): number {
async function getAutoAssignableStaff(): Promise<any | null> {
const staffResponse = await supa
.from('ml_delivery_staff')
.select('id, uid, station_id, nickname, phone, status, deleted_at, is_active, online_status, updated_at, created_at')
.select('id, uid, station_id, status, deleted_at, is_active, online_status, updated_at, created_at')
.eq('status', 1)
.eq('online_status', 'online')
.execute()
if (staffResponse.error != null || staffResponse.data == null) {
return null
@@ -259,6 +272,9 @@ async function getAutoAssignableStaff(): Promise<any | null> {
if (!isStaffActive(staff)) {
continue
}
if (readString(staff, 'uid') == '') {
continue
}
const score = getStaffPriority(staff)
const timeMark = readFirstString(staff, ['updated_at', 'created_at'])
if (selected == null || score > bestScore || (score == bestScore && timeMark > bestTime)) {
@@ -740,6 +756,9 @@ async function getCareTaskDetail(taskId: string): Promise<ServiceOrderType | nul
}
async function tryCreateCareTask(params: CreateServiceOrderParams): Promise<ServiceOrderType | null> {
if (ecServiceRequestCreateUnavailable) {
return null
}
const userId = getCurrentUserId()
if (userId == '') {
return null
@@ -752,16 +771,28 @@ async function tryCreateCareTask(params: CreateServiceOrderParams): Promise<Serv
let requestResponse = await supa.from('ec_service_requests').insert(
buildEcServiceRequestPayload(params, userId, requestId, createdAt, appointmentTime, true)
).execute()
if (shouldBypassEcServiceRequestCreate(requestResponse.error)) {
ecServiceRequestCreateUnavailable = true
return null
}
if (requestResponse.error != null) {
requestResponse = await supa.from('ec_service_requests').insert(
buildEcServiceRequestPayload(params, userId, requestId, createdAt, appointmentTime, false)
).execute()
}
if (shouldBypassEcServiceRequestCreate(requestResponse.error)) {
ecServiceRequestCreateUnavailable = true
return null
}
if (requestResponse.error != null) {
requestResponse = await supa.from('ec_service_requests').insert(
buildEcServiceRequestPayloadWithoutAddress(params, userId, requestId, createdAt, appointmentTime)
).execute()
}
if (shouldBypassEcServiceRequestCreate(requestResponse.error)) {
ecServiceRequestCreateUnavailable = true
return null
}
if (requestResponse.error != null) {
return null
}