修复订单显示bug

This commit is contained in:
2026-06-10 20:20:47 +08:00
parent de62513987
commit 9fbc6f8cd1
45 changed files with 7514 additions and 2025 deletions

View File

@@ -739,7 +739,24 @@ async function listWorkerTaskIds(): Promise<Array<string>> {
if (userId == '') {
return [] as Array<string>
}
const careTaskResponse = await supa.from('ec_care_tasks').select('id').eq('assigned_to', userId).order('created_at', { ascending: false }).execute()
// FIX: userId 是 auth.uid(),但 assigned_to / current_staff_id 存的是 ml_delivery_staff.id
// 需要先查出当前用户对应的 staff_id
const staffResponse = await supa.from('ml_delivery_staff')
.select('id')
.eq('uid', userId)
.single()
.execute()
const staffId = (staffResponse.error == null && staffResponse.data != null)
? readString(staffResponse.data as any, 'id')
: ''
if (staffId == '') {
return [] as Array<string>
}
const careTaskResponse = await supa.from('ec_care_tasks').select('id').eq('assigned_to', staffId).order('created_at', { ascending: false }).execute()
if (careTaskResponse.error == null && careTaskResponse.data != null) {
const result = [] as Array<string>
const rows = careTaskResponse.data as Array<any>
@@ -753,16 +770,7 @@ async function listWorkerTaskIds(): Promise<Array<string>> {
return result
}
}
let staffProfileId = ''
const staffResponse = await supa.from('ml_delivery_staff').select('id').eq('uid', userId).limit(1).execute()
if (staffResponse.error == null && staffResponse.data != null) {
const staffRows = staffResponse.data as Array<any>
if (staffRows.length > 0) {
staffProfileId = readString(staffRows[0], 'id')
}
}
const legacyStaffId = staffProfileId != '' ? staffProfileId : userId
const legacyResponse = await supa.from('hss_service_orders').select('id').eq('current_staff_id', legacyStaffId).order('created_at', { ascending: false }).execute()
const legacyResponse = await supa.from('hss_service_orders').select('id').eq('current_staff_id', staffId).order('created_at', { ascending: false }).execute()
if (legacyResponse.error != null || legacyResponse.data == null) {
return [] as Array<string>
}
@@ -783,7 +791,8 @@ async function isCareTask(taskId: string): Promise<boolean> {
}
async function completeWorkerTask(taskId: string): Promise<HomeServiceTaskType | null> {
// LEGACY/TODO: 已切换为调用 rpc_delivery_finish_service
// LEGACY/TODO: 本函数旧逻辑为前端直接 update ec_care_tasks + insert hc_work_order_events
// 已切换为调用 rpc_delivery_finish_servicedelivery 端统一动作 RPC
const { data, error } = await supa.rpc('rpc_delivery_finish_service', {
p_order_id: taskId,
p_payload: {} as any
@@ -953,7 +962,8 @@ export async function advanceWorkerTask(taskId: string): Promise<HomeServiceTask
}
export async function submitWorkerCheckIn(taskId: string, note: string): Promise<HomeServiceTaskType | null> {
// LEGACY/TODO: 已切换为调用 rpc_delivery_checkin_order + rpc_delivery_start_service
// LEGACY/TODO: 本函数旧逻辑为前端直接 insert ec_care_records + update ec_care_tasks + insert hc_work_order_events
// 已切换为调用 rpc_delivery_checkin_order 与 rpc_delivery_start_service。
const checkinResult = await supa.rpc('rpc_delivery_checkin_order', {
p_order_id: taskId,
p_payload: {
@@ -975,7 +985,8 @@ export async function submitWorkerCheckIn(taskId: string, note: string): Promise
}
export async function submitWorkerServiceRecord(taskId: string, summary: string): Promise<HomeServiceTaskType | null> {
// LEGACY/TODO: 已切换为调用 rpc_delivery_save_progress。
// LEGACY/TODO: 本函数旧逻辑为前端直接 upsert ec_care_records + update ec_care_tasks + insert hc_work_order_events。
// 已切换为调用 rpc_delivery_save_progress。
const { data, error } = await supa.rpc('rpc_delivery_save_progress', {
p_order_id: taskId,
p_payload: {
@@ -991,7 +1002,8 @@ export async function submitWorkerServiceRecord(taskId: string, summary: string)
}
export async function submitWorkerException(taskId: string, exceptionType: string, description: string): Promise<HomeServiceTaskType | null> {
// LEGACY/TODO: 已切换为调用 rpc_delivery_submit_exception
// LEGACY/TODO: 本函数旧逻辑为前端直接 insert hc_work_order_exceptions + update ec_care_tasks + insert hc_work_order_events
// 已切换为调用 rpc_delivery_submit_exception。
const { data, error } = await supa.rpc('rpc_delivery_submit_exception', {
p_order_id: taskId,
p_payload: {