From 6b111443667de4c7e5e4ea3007a83ae288497d4c Mon Sep 17 00:00:00 2001 From: huangzhenbao <17818024429@163.com> Date: Tue, 16 Jun 2026 11:32:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E6=A0=A1=E9=AA=8C=E3=80=81=E7=AD=BE?= =?UTF-8?q?=E5=88=B0=E6=B5=81=E7=A8=8B=E8=B7=91=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ges.delivery.2026-06-15T00-06-51-946Z.json | 131 + ...ges.delivery.2026-06-15T05-54-29-023Z.json | 131 + ...ges.delivery.2026-06-16T01-18-03-614Z.json | 131 + api/delivery.uts | 773 +- pages/mall/delivery/home/index.uvue | 6 +- pages/mall/delivery/orders/checkin.uvue | 879 +- pages/mall/delivery/orders/detail.uvue | 14 +- pages/mall/delivery/orders/index.uvue | 112 +- services/deliveryService.uts | 245 +- types/delivery.uts | 52 +- utils/deliveryCareUi.uts | 83 +- utils/homecareStatus.uts | 155 + 报错信息.txt | 7255 ++++------------- 13 files changed, 3900 insertions(+), 6067 deletions(-) create mode 100644 .pages-backup/pages.delivery.2026-06-15T00-06-51-946Z.json create mode 100644 .pages-backup/pages.delivery.2026-06-15T05-54-29-023Z.json create mode 100644 .pages-backup/pages.delivery.2026-06-16T01-18-03-614Z.json diff --git a/.pages-backup/pages.delivery.2026-06-15T00-06-51-946Z.json b/.pages-backup/pages.delivery.2026-06-15T00-06-51-946Z.json new file mode 100644 index 00000000..22447dbf --- /dev/null +++ b/.pages-backup/pages.delivery.2026-06-15T00-06-51-946Z.json @@ -0,0 +1,131 @@ +{ + "pages": [ + { + "path": "pages/user/register", + "style": { + "navigationBarTitleText": "服务人员注册", + "navigationStyle": "custom" + } + }, + { + "path": "pages/user/terms", + "style": { + "navigationBarTitleText": "用户协议与隐私政策", + "navigationStyle": "custom" + } + }, + { + "path": "pages/user/login", + "style": { + "navigationBarTitleText": "服务人员登录", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/home/index", + "style": { + "navigationBarTitleText": "工作台", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/index", + "style": { + "navigationBarTitleText": "工单列表", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/detail", + "style": { + "navigationBarTitleText": "订单详情", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/route", + "style": { + "navigationBarTitleText": "出发与导航", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/checkin", + "style": { + "navigationBarTitleText": "到岗签到", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/service-record/index", + "style": { + "navigationBarTitleText": "服务记录", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/exception", + "style": { + "navigationBarTitleText": "异常上报", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/profile/index", + "style": { + "navigationBarTitleText": "我的", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/profile/settings", + "style": { + "navigationBarTitleText": "设置", + "navigationStyle": "custom" + } + } + ], + "subPackages": [], + "globalStyle": { + "navigationBarTextStyle": "black", + "navigationBarTitleText": "delivery", + "navigationBarBackgroundColor": "#FFFFFF", + "backgroundColor": "#F3F7F9" + }, + "tabBar": { + "color": "#6B7280", + "selectedColor": "#0F766E", + "backgroundColor": "#FFFFFF", + "borderStyle": "black", + "list": [ + { + "pagePath": "pages/mall/delivery/home/index", + "text": "工作台", + "iconPath": "static/tabbar/home.png", + "selectedIconPath": "static/tabbar/home-active.png" + }, + { + "pagePath": "pages/mall/delivery/orders/index", + "text": "订单", + "iconPath": "static/tabbar/cart.png", + "selectedIconPath": "static/tabbar/cart.png" + }, + { + "pagePath": "pages/mall/delivery/profile/index", + "text": "我的", + "iconPath": "static/tabbar/user.png", + "selectedIconPath": "static/tabbar/user.png" + } + ] + }, + "condition": { + "current": 0, + "list": [ + { + "name": "delivery端", + "path": "pages/user/login", + "query": "mode=delivery&role=delivery" + } + ] + } +} diff --git a/.pages-backup/pages.delivery.2026-06-15T05-54-29-023Z.json b/.pages-backup/pages.delivery.2026-06-15T05-54-29-023Z.json new file mode 100644 index 00000000..22447dbf --- /dev/null +++ b/.pages-backup/pages.delivery.2026-06-15T05-54-29-023Z.json @@ -0,0 +1,131 @@ +{ + "pages": [ + { + "path": "pages/user/register", + "style": { + "navigationBarTitleText": "服务人员注册", + "navigationStyle": "custom" + } + }, + { + "path": "pages/user/terms", + "style": { + "navigationBarTitleText": "用户协议与隐私政策", + "navigationStyle": "custom" + } + }, + { + "path": "pages/user/login", + "style": { + "navigationBarTitleText": "服务人员登录", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/home/index", + "style": { + "navigationBarTitleText": "工作台", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/index", + "style": { + "navigationBarTitleText": "工单列表", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/detail", + "style": { + "navigationBarTitleText": "订单详情", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/route", + "style": { + "navigationBarTitleText": "出发与导航", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/checkin", + "style": { + "navigationBarTitleText": "到岗签到", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/service-record/index", + "style": { + "navigationBarTitleText": "服务记录", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/exception", + "style": { + "navigationBarTitleText": "异常上报", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/profile/index", + "style": { + "navigationBarTitleText": "我的", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/profile/settings", + "style": { + "navigationBarTitleText": "设置", + "navigationStyle": "custom" + } + } + ], + "subPackages": [], + "globalStyle": { + "navigationBarTextStyle": "black", + "navigationBarTitleText": "delivery", + "navigationBarBackgroundColor": "#FFFFFF", + "backgroundColor": "#F3F7F9" + }, + "tabBar": { + "color": "#6B7280", + "selectedColor": "#0F766E", + "backgroundColor": "#FFFFFF", + "borderStyle": "black", + "list": [ + { + "pagePath": "pages/mall/delivery/home/index", + "text": "工作台", + "iconPath": "static/tabbar/home.png", + "selectedIconPath": "static/tabbar/home-active.png" + }, + { + "pagePath": "pages/mall/delivery/orders/index", + "text": "订单", + "iconPath": "static/tabbar/cart.png", + "selectedIconPath": "static/tabbar/cart.png" + }, + { + "pagePath": "pages/mall/delivery/profile/index", + "text": "我的", + "iconPath": "static/tabbar/user.png", + "selectedIconPath": "static/tabbar/user.png" + } + ] + }, + "condition": { + "current": 0, + "list": [ + { + "name": "delivery端", + "path": "pages/user/login", + "query": "mode=delivery&role=delivery" + } + ] + } +} diff --git a/.pages-backup/pages.delivery.2026-06-16T01-18-03-614Z.json b/.pages-backup/pages.delivery.2026-06-16T01-18-03-614Z.json new file mode 100644 index 00000000..22447dbf --- /dev/null +++ b/.pages-backup/pages.delivery.2026-06-16T01-18-03-614Z.json @@ -0,0 +1,131 @@ +{ + "pages": [ + { + "path": "pages/user/register", + "style": { + "navigationBarTitleText": "服务人员注册", + "navigationStyle": "custom" + } + }, + { + "path": "pages/user/terms", + "style": { + "navigationBarTitleText": "用户协议与隐私政策", + "navigationStyle": "custom" + } + }, + { + "path": "pages/user/login", + "style": { + "navigationBarTitleText": "服务人员登录", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/home/index", + "style": { + "navigationBarTitleText": "工作台", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/index", + "style": { + "navigationBarTitleText": "工单列表", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/detail", + "style": { + "navigationBarTitleText": "订单详情", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/route", + "style": { + "navigationBarTitleText": "出发与导航", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/checkin", + "style": { + "navigationBarTitleText": "到岗签到", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/service-record/index", + "style": { + "navigationBarTitleText": "服务记录", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/exception", + "style": { + "navigationBarTitleText": "异常上报", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/profile/index", + "style": { + "navigationBarTitleText": "我的", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/profile/settings", + "style": { + "navigationBarTitleText": "设置", + "navigationStyle": "custom" + } + } + ], + "subPackages": [], + "globalStyle": { + "navigationBarTextStyle": "black", + "navigationBarTitleText": "delivery", + "navigationBarBackgroundColor": "#FFFFFF", + "backgroundColor": "#F3F7F9" + }, + "tabBar": { + "color": "#6B7280", + "selectedColor": "#0F766E", + "backgroundColor": "#FFFFFF", + "borderStyle": "black", + "list": [ + { + "pagePath": "pages/mall/delivery/home/index", + "text": "工作台", + "iconPath": "static/tabbar/home.png", + "selectedIconPath": "static/tabbar/home-active.png" + }, + { + "pagePath": "pages/mall/delivery/orders/index", + "text": "订单", + "iconPath": "static/tabbar/cart.png", + "selectedIconPath": "static/tabbar/cart.png" + }, + { + "pagePath": "pages/mall/delivery/profile/index", + "text": "我的", + "iconPath": "static/tabbar/user.png", + "selectedIconPath": "static/tabbar/user.png" + } + ] + }, + "condition": { + "current": 0, + "list": [ + { + "name": "delivery端", + "path": "pages/user/login", + "query": "mode=delivery&role=delivery" + } + ] + } +} diff --git a/api/delivery.uts b/api/delivery.uts index c3363675..5379924c 100644 --- a/api/delivery.uts +++ b/api/delivery.uts @@ -1,4 +1,4 @@ -import type { +import type { DeliveryAbnormalReportType, DeliveryCertificateType, DeliveryCheckinPayloadType, @@ -34,6 +34,9 @@ const DELIVERY_RPC_REJECT_ORDER = 'rpc_delivery_reject_order' const DELIVERY_RPC_START_DEPART = 'rpc_delivery_start_depart' const DELIVERY_RPC_ARRIVE_ORDER = 'rpc_delivery_arrive_order' const DELIVERY_RPC_CHECKIN_ORDER = 'rpc_delivery_checkin_order' +const DELIVERY_RPC_HOMECARE_CHECKIN_PRECHECK_COMPAT = 'rpc_homecare_checkin_precheck_compat' +const DELIVERY_RPC_CREATE_CHECKIN_EVIDENCE_COMPAT = 'rpc_homecare_create_checkin_evidence_compat' +const DELIVERY_RPC_HOMECARE_CHECKIN_SUBMIT_COMPAT = 'rpc_homecare_checkin_submit_compat' const DELIVERY_RPC_HOMECARE_CHECKIN_SUBMIT = 'rpc_homecare_checkin_submit' const DELIVERY_RPC_START_SERVICE = 'rpc_delivery_start_service' const DELIVERY_RPC_SAVE_PROGRESS = 'rpc_delivery_save_progress' @@ -68,18 +71,20 @@ function markMissingDeliveryRpc(functionName: string): void { function mapLoginError(rawData: UTSJSONObject): string { const errorMsg = rawData.getString('msg') ?? rawData.getString('message') ?? rawData.getString('error') ?? '' const errorCode = rawData.getString('error_code') ?? '' - if ((errorMsg.includes('email') && errorMsg.includes('confirm')) || errorCode === 'email_not_confirmed' || (errorMsg.includes('邮箱') && errorMsg.includes('确认'))) { - return '邮箱未确认,请先检查邮箱并点击确认链接' + if (errorCode == 'email_not_confirmed') { + return '邮箱未验证,请先完成邮箱验证' + } + if (errorMsg.includes('email') && errorMsg.includes('confirm')) { + return '邮箱未验证,请先完成邮箱验证' } if (errorMsg.includes('Invalid authentication credentials')) { - return '网关认证失败,请检查 delivery 端的 SUPA_URL 与 SUPA_KEY 是否属于同一套 Supabase 实例' + return '配送账号或密码错误' } - if (errorMsg.includes('Invalid login credentials') || errorCode === 'invalid_credentials' || errorMsg.includes('Invalid credentials') || errorMsg.includes('credentials') || errorMsg.includes('invalid')) { - return '用户名或密码错误' + if (errorCode == 'invalid_credentials' || errorMsg.includes('Invalid login credentials') || errorMsg.includes('Invalid credentials')) { + return '配送账号或密码错误' } - return errorMsg != '' ? errorMsg : '登录失败,请重试' + return errorMsg != '' ? errorMsg : '登录失败,请稍后重试' } - function readObjectField(raw: any, key: string): any { if (raw == null) { return null @@ -220,7 +225,7 @@ function buildDeliveryInfoFromStaff(raw: any): DeliveryInfoType { id, userId: readStringField(raw, 'uid'), staffNo: readStringField(raw, 'staff_no') != '' ? readStringField(raw, 'staff_no') : (id != '' ? 'DEL-' + id.substring(0, Math.min(8, id.length)).toUpperCase() : ''), - name: readStringField(raw, 'nickname') != '' ? readStringField(raw, 'nickname') : '服务人员', + name: '配送员', phone: readStringField(raw, 'phone'), role: 'delivery', status: normalizeDeliveryStatus(raw), @@ -255,7 +260,7 @@ async function fetchCareRequestById(requestId: string): Promise { return rows[0] } } catch (error) { - console.warn('[delivery api] 读取 ec_service_requests 失败:', requestId, error) + console.warn('[delivery api] 查询服务请求失败:', requestId, error) } return null } @@ -282,7 +287,7 @@ async function fetchDeliveryProfileFromRemote(userId: string): Promise { + console.log('[DELIVERY_RPC_TRACE][REQUEST]', { + name: functionName, + params: params + }) if (shouldBypassDeliveryRpc()) { + console.log('[DELIVERY_RPC_TRACE][RESPONSE]', { + name: functionName, + data: null, + error: 'bypassed by test mode' + }) return null } if (isMissingDeliveryRpc(functionName)) { + console.log('[DELIVERY_RPC_TRACE][RESPONSE]', { + name: functionName, + data: null, + error: 'previously marked missing' + }) return null } try { @@ -324,16 +343,37 @@ async function callDeliveryRpc(functionName: string, params: UTSJSONObject): Pro const res: any = await supa.rpc(functionName, params) if (res?.status === 404) { markMissingDeliveryRpc(functionName) - console.warn('[delivery api] RPC 不存在,已切换 fallback:' + functionName) + console.warn('[delivery api] RPC 不可用,使用 mock fallback:', functionName) + console.log('[DELIVERY_RPC_TRACE][RESPONSE]', { + name: functionName, + data: null, + error: 'rpc 404 not found' + }) return null } if (res?.error != null) { + console.log('[DELIVERY_RPC_TRACE][RESPONSE]', { + name: functionName, + data: null, + error: res.error + }) throw res.error } console.warn('[delivery api] RPC response:', functionName, JSON.stringify(res.data)) + console.log('[DELIVERY_RPC_TRACE][RESPONSE]', { + name: functionName, + data: res.data, + error: null + }) return res.data } catch (error) { - console.warn('[delivery api] RPC 调用失败,回退 mock:' + functionName, error) + console.error('[DELIVERY_RPC_TRACE][ERROR]', { + name: functionName, + params: params, + errorMessage: error != null ? String(error.message ?? error) : '', + errorStack: error != null ? String(error.stack ?? '') : '' + }) + console.warn('[delivery api] RPC 调用失败,使用 mock fallback:', functionName, error) return null } } @@ -376,7 +416,7 @@ function mapRpcOrderItem(item: any): DeliveryOrderType { const order = {} as DeliveryOrderType order.id = rpcStr(item, 'id') order.orderNo = rpcStr(item, 'order_no') - order.serviceType = rpcStr(serviceObj, 'category') || '居家服务' + order.serviceType = '居家服务' order.serviceName = rpcStr(item, 'service_name') order.serviceCategory = rpcStr(serviceObj, 'category') order.serviceItems = [] as Array @@ -516,6 +556,9 @@ function mapRpcOrderItemCompat(item: any): DeliveryOrderType { order.id = rpcStrCompat(item, ['id']) order.orderNo = rpcStrCompat(item, ['orderNo', 'order_no', 'task_no']) + order.sourceOrderId = rpcStrCompat(item, ['sourceOrderId', 'source_order_id']) + order.legacyServiceOrderId = rpcStrCompat(item, ['legacyServiceOrderId', 'legacy_service_order_id']) + order.resolvedWorkOrderId = rpcStrCompat(item, ['resolvedWorkOrderId', 'work_order_id']) order.serviceType = rpcStrCompat(item, ['serviceType']) if (order.serviceType == '') { order.serviceType = rpcStrCompat(serviceObj, ['category']) @@ -528,7 +571,7 @@ function mapRpcOrderItemCompat(item: any): DeliveryOrderType { order.serviceName = rpcStrCompat(serviceObj, ['name', 'serviceName']) } if (order.serviceName == '') { - order.serviceName = rpcStrCompat(item, ['serviceCategory']) != '' ? rpcStrCompat(item, ['serviceCategory']) : '居家服务订单' + order.serviceName = '上门服务' } order.serviceCategory = rpcStrCompat(item, ['serviceCategory']) if (order.serviceCategory == '') { @@ -538,7 +581,7 @@ function mapRpcOrderItemCompat(item: any): DeliveryOrderType { order.elderId = rpcStrCompat(item, ['elderId', 'elder_id', 'user_id']) order.elderName = rpcStrCompat(item, ['elderName', 'recipient_name', 'elder_name']) if (order.elderName == '') { - order.elderName = rpcStrCompat(item, ['contactName', 'contact_name']) != '' ? rpcStrCompat(item, ['contactName', 'contact_name']) : '服务对象待补充' + order.elderName = '用户' } order.elderNameMasked = order.elderName order.elderGender = rpcStrCompat(item, ['elderGender']) @@ -559,7 +602,7 @@ function mapRpcOrderItemCompat(item: any): DeliveryOrderType { order.address = rpcStrCompat(addressObj, ['fullAddress', 'full_address', 'address', 'name']) } if (order.address == '') { - order.address = '地址待补充' + order.address = '暂无地址' } order.addressDetail = addressDetail order.fullAddress = rpcStrCompat(item, ['fullAddress']) @@ -582,7 +625,7 @@ function mapRpcOrderItemCompat(item: any): DeliveryOrderType { order.appointmentTime = rpcStrCompat(item, ['createdAt', 'created_at']) } if (order.appointmentTime == '') { - order.appointmentTime = '时间待补充' + order.appointmentTime = '待预约' } order.appointmentStartTime = rpcStrCompat(item, ['appointmentStartTime']) if (order.appointmentStartTime == '') { @@ -620,6 +663,57 @@ function mapRpcOrderItemCompat(item: any): DeliveryOrderType { order.status = rpcStrCompat(item, ['status']) as DeliveryOrderStatus order.statusText = rpcStrCompat(item, ['statusText']) order.statusTone = rpcStrCompat(item, ['statusTone']) + + // 根据订单状态补全文案 + if (order.statusText == '') { + const rawStatus = order.status + if (rawStatus == 'assigned' || rawStatus == 'ASSIGNED') { + order.statusText = '待接单' + order.statusTone = 'primary' + } else if (rawStatus == 'arrival_pending' || rawStatus == 'ARRIVAL_PENDING') { + order.statusText = '待到达' + order.statusTone = 'warning' + } else if (rawStatus == 'PENDING_ASSIGNMENT' || rawStatus == 'CREATED') { + order.statusText = '待出发' + order.statusTone = 'default' + } else if (rawStatus == 'PENDING_ACCEPT' || rawStatus == 'PENDING_ACCEPTANCE') { + order.statusText = '待出发' + order.statusTone = 'warning' + } else if (rawStatus == 'ACCEPTED' || rawStatus == 'ORDER_ACCEPTED') { + order.statusText = '赶往中' + order.statusTone = 'primary' + } else if (rawStatus == 'WAITING_DEPARTURE') { + order.statusText = '已到达' + order.statusTone = 'primary' + } else if (rawStatus == 'departed' || rawStatus == 'on_the_way' || rawStatus == 'order_departed' || rawStatus == 'DEPARTED' || rawStatus == 'ON_THE_WAY' || rawStatus == 'ORDER_DEPARTED') { + order.statusText = '服务中' + order.statusTone = 'primary' + } else if (rawStatus == 'arrived' || rawStatus == 'checked_in' || rawStatus == 'order_checked_in' || rawStatus == 'ARRIVED' || rawStatus == 'CHECKED_IN' || rawStatus == 'ORDER_CHECKED_IN') { + order.statusText = '服务中' + order.statusTone = 'success' + } else if (rawStatus == 'IN_SERVICE' || rawStatus == 'SERVING' || rawStatus == 'ORDER_IN_SERVICE') { + order.statusText = '已完成' + order.statusTone = 'success' + } else if (rawStatus == 'COMPLETED' || rawStatus == 'ORDER_COMPLETED' || rawStatus == 'SETTLED' || rawStatus == 'SETTLED') { + order.statusText = '已取消' + order.statusTone = 'success' + } else if (rawStatus == 'CANCELLED' || rawStatus == 'CANCELED' || rawStatus == 'ORDER_CANCELLED') { + order.statusText = '异常' + order.statusTone = 'info' + } else if (rawStatus == 'ABNORMAL' || rawStatus == 'EXCEPTION' || rawStatus == 'EXCEPTION_PENDING') { + order.statusText = '已拒单' + order.statusTone = 'danger' + } else if (rawStatus == 'REJECTED') { + order.statusText = '已归档' + order.statusTone = 'danger' + } else if (rawStatus == 'ARCHIVED') { + order.statusText = '待处理' + order.statusTone = 'default' + } else { + order.statusText = rawStatus + order.statusTone = 'default' + } + } order.riskTags = rpcArrayCompat(item, 'riskTags') as Array order.healthTags = rpcArrayCompat(item, 'healthTags') as Array order.careLevel = rpcStrCompat(item, ['careLevel']) @@ -630,7 +724,6 @@ function mapRpcOrderItemCompat(item: any): DeliveryOrderType { order.merchantName = rpcStrCompat(item, ['merchantName', 'merchant_name']) order.deliveryStaffId = rpcStrCompat(item, ['deliveryStaffId', 'current_staff_id', 'assigned_to']) order.deliveryStaffName = rpcStrCompat(item, ['deliveryStaffName', 'delivery_staff_name']) - // 提取接单人员信息(从 statusLog 中找 accepted 状态的记录) order.acceptedBy = '' order.acceptedByName = '' const statusLog = order.statusLog @@ -641,7 +734,7 @@ function mapRpcOrderItemCompat(item: any): DeliveryOrderType { break } } - // 如果 statusLog 中没有,尝试直接从 RPC 字段获取 + // 兼容旧数据处理 if (order.acceptedBy == '') { order.acceptedBy = rpcStrCompat(item, ['acceptedBy', 'accepted_by', 'accepted_staff_id']) order.acceptedByName = rpcStrCompat(item, ['acceptedByName', 'accepted_staff_name', 'accepted_by_name']) @@ -652,6 +745,20 @@ function mapRpcOrderItemCompat(item: any): DeliveryOrderType { order.checkinTime = rpcStrCompat(item, ['checkinTime', 'checked_in_at', 'arrived_at']) order.startServiceTime = rpcStrCompat(item, ['startServiceTime', 'service_started_at']) order.finishTime = rpcStrCompat(item, ['finishTime', 'completed_at', 'service_completed_at']) + const normalizedStatus = String(order.status).trim().toLowerCase() + if (order.checkinTime != '') { + order.status = 'arrived' as DeliveryOrderStatus + order.statusText = '已到达' + order.statusTone = 'success' + } else if (order.arriveTime != '') { + order.status = 'arrived' as DeliveryOrderStatus + order.statusText = '已到达' + order.statusTone = 'success' + } else if (order.departTime != '' && (normalizedStatus == 'assigned' || normalizedStatus == 'accepted')) { + order.status = 'departed' as DeliveryOrderStatus + order.statusText = '已出发' + order.statusTone = 'primary' + } order.cancelReason = rpcStrCompat(item, ['cancelReason', 'cancel_reason']) order.exceptionType = rpcStrCompat(item, ['exceptionType']) order.exceptionDesc = rpcStrCompat(item, ['exceptionDesc']) @@ -699,7 +806,7 @@ function needsRequestFallback(order: DeliveryOrderType): boolean { return order.serviceName == '' || order.elderName == '' || order.address == '' || order.contactName == '' } -// 用于限制 "missing request_id" 日志输出的计数器 +// 兼容旧数据处理 let _missingRequestIdLogCount = 0 function fillOrderFromRequestSnapshot(order: DeliveryOrderType, requestItem: any): DeliveryOrderType { @@ -712,7 +819,7 @@ function fillOrderFromRequestSnapshot(order: DeliveryOrderType, requestItem: any if (order.serviceCategory == '') { order.serviceCategory = readStringField(requestItem, 'service_category') } - if (order.serviceType == '' || order.serviceType == '居家服务') { + if (order.serviceType == '') { const requestCategory = readStringField(requestItem, 'service_category') if (requestCategory != '') { order.serviceType = requestCategory @@ -772,8 +879,7 @@ async function enrichOrderWithRequestFallback(rawItem: any, order: DeliveryOrder } const requestId = rpcStrCompat(rawItem, ['request_id', 'requestId']) if (requestId == '') { - // 限制日志输出:只输出前3个缺少 request_id 的订单 - _missingRequestIdLogCount = _missingRequestIdLogCount + 1 + // 兼容旧数据处理 if (_missingRequestIdLogCount <= 3) { console.warn('[delivery api] request fallback skipped: missing request_id for order', order.id, '(count:', _missingRequestIdLogCount, ')') } @@ -905,18 +1011,18 @@ function buildMockCertificates(): Array { return [ { id: 'mock-cert-1', - name: '养老护理员职业技能证书', + name: '配送员', status: 'valid', expireAt: '2027-12-31', - issuer: '梅州市居家养老服务协会', + issuer: '社区卫生服务中心', imageUrl: '' } as DeliveryCertificateType, { id: 'mock-cert-2', - name: '慢病随访服务培训合格证', + name: '配送员', status: 'valid', - expireAt: '长期有效', - issuer: '粤东健康照护培训中心', + expireAt: '2026-12-31', + issuer: '社区卫生服务中心', imageUrl: '' } as DeliveryCertificateType ] as Array @@ -926,25 +1032,25 @@ function buildMockServiceItems(orderId: string, serviceName: string): Array } @@ -984,7 +1090,7 @@ function buildMockEvidence(orderId: string): Array { orderId, phase: 'checkin', fileType: 'image', - name: '到场签到照片', + name: '配送员', url: '', localPath: '/static/mock/checkin-' + orderId + '.jpg', status: 'success', @@ -1001,18 +1107,18 @@ function buildMockProfile(userId: string): DeliveryInfoType { id: 'mock-staff-001', userId: resolvedUserId, staffNo: 'DEL-0520', - name: '陈护理', + name: '配送员', phone: '13688886666', role: 'delivery', status: 'active', organizationId: 'org-001', - organizationName: '梅州安康居家服务中心', + organizationName: '安心到家服务站', certificates: buildMockCertificates(), certificateStatus: 'valid', certificateExpireAt: '2027-12-31', onlineStatus: 'online', - serviceArea: '梅江区 / 梅县区重点片区', - skills: ['基础护理', '慢病随访', '康复指导'], + serviceArea: '梅州市区 / 周边社区', + skills: ['Home care', 'Rehab guidance', 'Health follow-up'], avatarUrl: '', todayAccepted: 0, todayServing: 0, @@ -1026,18 +1132,18 @@ function buildMockOrders(profile: DeliveryInfoType): Array { { id: 'mock-order-001', orderNo: 'YS202605180001', - serviceType: '基础照护', - serviceName: '基础上门护理', - serviceItems: buildMockServiceItems('mock-order-001', '基础上门护理'), + serviceType: '居家服务', + serviceName: '上门服务', + serviceItems: buildMockServiceItems('mock-order-001', '上门照护'), elderId: 'elder-001', - elderNameMasked: '李奶奶', + elderNameMasked: '张阿姨', elderGender: '女', elderAge: 78, elderPhoneMasked: '138****1024', - fullElderName: '李秀珍', + fullElderName: '张阿姨', fullPhone: '13800131024', - addressSummary: '梅江区江南路 18 号 2 栋 602', - fullAddress: '广东省梅州市梅江区江南路 18 号 2 栋 602 室', + addressSummary: '暂无地址', + fullAddress: '暂无地址', latitude: 24.2898, longitude: 116.1179, appointmentStartTime: '2026-05-18 09:00', @@ -1046,12 +1152,12 @@ function buildMockOrders(profile: DeliveryInfoType): Array { actualStartTime: '', actualEndTime: '', status: 'pending_accept', - statusText: '待接单', + statusText: '待处理', statusTone: 'warning', - riskTags: ['跌倒风险', '晨间血压波动'], - careLevel: '护理二级', + riskTags: [] as Array, + careLevel: '基础照护', merchantId: 'merchant-001', - merchantName: '梅州安康居家服务中心', + merchantName: '安心到家服务站', deliveryStaffId: profile.id, deliveryStaffName: profile.name, acceptTime: '', @@ -1070,10 +1176,10 @@ function buildMockOrders(profile: DeliveryInfoType): Array { archiveStatus: '未归档', createdAt: '2026-05-18 07:30:00', updatedAt: '2026-05-18 07:50:00', - contactName: '李晓兰', + contactName: '家属', contactPhone: '13900139000', - notices: ['入户前需电话确认', '注意老人步态不稳'], - timeline: buildMockTimeline('YS202605180001', '等待服务人员接单'), + notices: [] as Array, + timeline: buildMockTimeline('YS202605180001', 'Staff has departed and is heading to the service location'), serviceSummary: '', progressNote: '', distanceKm: '2.4km', @@ -1084,18 +1190,18 @@ function buildMockOrders(profile: DeliveryInfoType): Array { { id: 'mock-order-002', orderNo: 'YS202605180002', - serviceType: '康复指导', - serviceName: '居家康复训练指导', - serviceItems: buildMockServiceItems('mock-order-002', '康复训练'), + serviceType: 'Health follow-up', + serviceName: '上门服务', + serviceItems: buildMockServiceItems('mock-order-002', '上门照护'), elderId: 'elder-002', - elderNameMasked: '张爷爷', - elderGender: '男', + elderNameMasked: '张阿姨', + elderGender: '女', elderAge: 82, elderPhoneMasked: '137****2233', - fullElderName: '张志坤', + fullElderName: '张阿姨', fullPhone: '13700132233', - addressSummary: '梅县区新城锦绣花园 5 栋 1403', - fullAddress: '广东省梅州市梅县区新城锦绣花园 5 栋 1403 室', + addressSummary: '暂无地址', + fullAddress: '暂无地址', latitude: 24.3071, longitude: 116.1365, appointmentStartTime: '2026-05-18 10:30', @@ -1104,12 +1210,12 @@ function buildMockOrders(profile: DeliveryInfoType): Array { actualStartTime: '', actualEndTime: '', status: 'accepted', - statusText: '待出发', + statusText: '待处理', statusTone: 'primary', - riskTags: ['术后恢复'], - careLevel: '康复随访', + riskTags: [] as Array, + careLevel: '基础照护', merchantId: 'merchant-001', - merchantName: '梅州安康居家服务中心', + merchantName: '安心到家服务站', deliveryStaffId: profile.id, deliveryStaffName: profile.name, acceptTime: '2026-05-18 08:00:00', @@ -1128,10 +1234,10 @@ function buildMockOrders(profile: DeliveryInfoType): Array { archiveStatus: '未归档', createdAt: '2026-05-18 07:40:00', updatedAt: '2026-05-18 08:00:00', - contactName: '张春梅', + contactName: '家属', contactPhone: '13600136666', - notices: ['需携带康复弹力带', '家属会同步在场'], - timeline: buildMockTimeline('YS202605180002', '已接单,等待出发'), + notices: [] as Array, + timeline: buildMockTimeline('YS202605180002', 'Arrived at service location, waiting to start service'), serviceSummary: '', progressNote: '', distanceKm: '5.8km', @@ -1142,18 +1248,18 @@ function buildMockOrders(profile: DeliveryInfoType): Array { { id: 'mock-order-003', orderNo: 'YS202605180003', - serviceType: '慢病随访', - serviceName: '慢病健康随访', - serviceItems: buildMockServiceItems('mock-order-003', '慢病随访'), + serviceType: '居家服务', + serviceName: '上门服务', + serviceItems: buildMockServiceItems('mock-order-003', '上门照护'), elderId: 'elder-003', - elderNameMasked: '黄阿姨', + elderNameMasked: '张阿姨', elderGender: '女', elderAge: 68, elderPhoneMasked: '135****5566', - fullElderName: '黄玉英', + fullElderName: '张阿姨', fullPhone: '13500135566', - addressSummary: '梅江区学海路康养公寓 A 座 907', - fullAddress: '广东省梅州市梅江区学海路康养公寓 A 座 907 室', + addressSummary: '暂无地址', + fullAddress: '暂无地址', latitude: 24.2861, longitude: 116.1231, appointmentStartTime: '2026-05-18 13:30', @@ -1162,12 +1268,12 @@ function buildMockOrders(profile: DeliveryInfoType): Array { actualStartTime: '', actualEndTime: '', status: 'arrived', - statusText: '待签到', + statusText: '待处理', statusTone: 'primary', - riskTags: ['糖尿病', '需测血糖'], - careLevel: '慢病管理', + riskTags: [] as Array, + careLevel: '基础照护', merchantId: 'merchant-001', - merchantName: '梅州安康居家服务中心', + merchantName: '安心到家服务站', deliveryStaffId: profile.id, deliveryStaffName: profile.name, acceptTime: '2026-05-18 08:10:00', @@ -1186,18 +1292,18 @@ function buildMockOrders(profile: DeliveryInfoType): Array { archiveStatus: '未归档', createdAt: '2026-05-18 08:00:00', updatedAt: '2026-05-18 13:22:00', - contactName: '黄晓娟', + contactName: '家属', contactPhone: '13500130088', - notices: ['入户前请确认血糖试纸数量', '注意老人午后低血糖风险'], - timeline: buildMockTimeline('YS202605180003', '已到达服务地点'), + notices: [] as Array, + timeline: buildMockTimeline('YS202605180003', '状态更新'), serviceSummary: '', - progressNote: '已联系家属,准备入户签到。', + progressNote: '服务状态已更新', distanceKm: '1.1km', allowCheckinRadiusMeters: 80, lastLocation: { latitude: 24.2861, longitude: 116.1231, - address: '康养公寓门口', + address: '暂无地址', time: '2026-05-18 13:22:00' } as DeliveryLocationType, trackPoints: [] as Array @@ -1205,30 +1311,30 @@ function buildMockOrders(profile: DeliveryInfoType): Array { { id: 'mock-order-004', orderNo: 'YS202605180004', - serviceType: '居家护理', - serviceName: '压疮护理与翻身指导', + serviceType: '居家服务', + serviceName: '上门服务', serviceItems: [ { id: 'mock-order-004-item-1', - name: '压疮护理', + name: '配送员', required: true, completed: true, incompleteReason: '', - remark: '已完成创面清洁与敷料更换。', + remark: '已记录服务情况', updatedAt: '2026-05-18 14:25:00' } as DeliveryServiceItemType, { id: 'mock-order-004-item-2', - name: '翻身指导', + name: '配送员', required: true, completed: true, incompleteReason: '', - remark: '已向家属示范翻身角度与频次。', + remark: '已记录服务情况', updatedAt: '2026-05-18 14:40:00' } as DeliveryServiceItemType, { id: 'mock-order-004-item-3', - name: '家属签字确认', + name: '配送员', required: true, completed: false, incompleteReason: '', @@ -1237,14 +1343,14 @@ function buildMockOrders(profile: DeliveryInfoType): Array { } as DeliveryServiceItemType ] as Array, elderId: 'elder-004', - elderNameMasked: '陈伯伯', - elderGender: '男', + elderNameMasked: '张阿姨', + elderGender: '女', elderAge: 75, elderPhoneMasked: '139****3301', - fullElderName: '陈国辉', + fullElderName: '张阿姨', fullPhone: '13900133301', - addressSummary: '梅县区扶老社区 11 栋 203', - fullAddress: '广东省梅州市梅县区扶老社区 11 栋 203 室', + addressSummary: '暂无地址', + fullAddress: '暂无地址', latitude: 24.3022, longitude: 116.1441, appointmentStartTime: '2026-05-18 14:00', @@ -1253,12 +1359,12 @@ function buildMockOrders(profile: DeliveryInfoType): Array { actualStartTime: '2026-05-18 14:05:00', actualEndTime: '', status: 'serving', - statusText: '服务中', + statusText: '待处理', statusTone: 'primary', - riskTags: ['卧床护理', '家属需培训'], - careLevel: '护理三级', + riskTags: [] as Array, + careLevel: '基础照护', merchantId: 'merchant-001', - merchantName: '梅州安康居家服务中心', + merchantName: '安心到家服务站', deliveryStaffId: profile.id, deliveryStaffName: profile.name, acceptTime: '2026-05-18 09:20:00', @@ -1277,31 +1383,31 @@ function buildMockOrders(profile: DeliveryInfoType): Array { archiveStatus: '未归档', createdAt: '2026-05-18 09:00:00', updatedAt: '2026-05-18 14:40:00', - contactName: '陈丽芳', + contactName: '家属', contactPhone: '13800136660', - notices: ['护理过程注意皮肤完整性', '家属需学习翻身技巧'], - timeline: buildMockTimeline('YS202605180004', '服务执行中'), - serviceSummary: '已完成基础护理与翻身指导,待家属签字确认。', - progressNote: '创面情况稳定,已完成阶段性护理。', + notices: [] as Array, + timeline: buildMockTimeline('YS202605180004', '状态更新'), + serviceSummary: '已完成基础服务', + progressNote: '服务状态已更新', distanceKm: '3.6km', allowCheckinRadiusMeters: 100, lastLocation: { latitude: 24.3022, longitude: 116.1441, - address: '扶老社区 11 栋 203 室', + address: '暂无地址', time: '2026-05-18 14:00:00' } as DeliveryLocationType, trackPoints: [ { latitude: 24.3001, longitude: 116.1412, - address: '扶老社区北门', + address: '暂无地址', time: '2026-05-18 13:48:00' } as DeliveryLocationType, { latitude: 24.3022, longitude: 116.1441, - address: '扶老社区 11 栋 203 室', + address: '暂无地址', time: '2026-05-18 14:00:00' } as DeliveryLocationType ] as Array @@ -1309,18 +1415,18 @@ function buildMockOrders(profile: DeliveryInfoType): Array { { id: 'mock-order-005', orderNo: 'YS202605180005', - serviceType: '异常跟进', - serviceName: '用药异常上报处理', - serviceItems: buildMockServiceItems('mock-order-005', '异常处理'), + serviceType: '居家服务', + serviceName: '上门服务', + serviceItems: buildMockServiceItems('mock-order-005', '上门照护'), elderId: 'elder-005', - elderNameMasked: '王阿婆', + elderNameMasked: '张阿姨', elderGender: '女', elderAge: 80, elderPhoneMasked: '134****7744', - fullElderName: '王月兰', + fullElderName: '张阿姨', fullPhone: '13400137744', - addressSummary: '梅江区东汇城旁康颐楼 3 单元 1204', - fullAddress: '广东省梅州市梅江区东汇城旁康颐楼 3 单元 1204 室', + addressSummary: '暂无地址', + fullAddress: '暂无地址', latitude: 24.2932, longitude: 116.1205, appointmentStartTime: '2026-05-18 16:00', @@ -1329,12 +1435,12 @@ function buildMockOrders(profile: DeliveryInfoType): Array { actualStartTime: '2026-05-18 16:05:00', actualEndTime: '', status: 'exception_pending', - statusText: '异常处理中', + statusText: '待处理', statusTone: 'warning', - riskTags: ['用药异常', '需医生回访'], - careLevel: '异常处置', + riskTags: ['Medication issue', 'Doctor follow-up required'], + careLevel: '基础照护', merchantId: 'merchant-001', - merchantName: '梅州安康居家服务中心', + merchantName: '安心到家服务站', deliveryStaffId: profile.id, deliveryStaffName: profile.name, acceptTime: '2026-05-18 15:20:00', @@ -1344,27 +1450,27 @@ function buildMockOrders(profile: DeliveryInfoType): Array { finishTime: '', cancelReason: '', exceptionType: 'elder_health_abnormal', - exceptionDesc: '老人午后血压异常升高,已建议暂停训练并等待医生回访。', + exceptionDesc: '服务异常,请及时处理', evidenceList: buildMockEvidence('mock-order-005'), signatureUrl: '', signatureName: '', - satisfactionStatus: '待处理', - settlementStatus: '待确认', + satisfactionStatus: '待评价', + settlementStatus: '待结算', archiveStatus: '未归档', createdAt: '2026-05-18 15:00:00', updatedAt: '2026-05-18 16:10:00', - contactName: '王秀玲', + contactName: '家属', contactPhone: '13600139922', - notices: ['优先联系家属', '记录老人异常表现并上传照片'], - timeline: buildMockTimeline('YS202605180005', '异常已上报,等待处理'), - serviceSummary: '发现老人血压异常升高,已完成初步安抚并联系家属。', - progressNote: '异常已同步机构值班护士。', + notices: [] as Array, + timeline: buildMockTimeline('YS202605180005', '状态更新'), + serviceSummary: '已完成基础服务', + progressNote: '服务状态已更新', distanceKm: '4.2km', allowCheckinRadiusMeters: 100, lastLocation: { latitude: 24.2932, longitude: 116.1205, - address: '康颐楼 3 单元 1204 室', + address: '暂无地址', time: '2026-05-18 16:03:00' } as DeliveryLocationType, trackPoints: [] as Array @@ -1372,37 +1478,37 @@ function buildMockOrders(profile: DeliveryInfoType): Array { { id: 'mock-order-006', orderNo: 'YS202605170006', - serviceType: '康复护理', - serviceName: '术后恢复陪护', + serviceType: '居家服务', + serviceName: '上门服务', serviceItems: [ { id: 'mock-order-006-item-1', - name: '步态训练', + name: '配送员', required: true, completed: true, incompleteReason: '', - remark: '完成 15 分钟辅助行走训练。', + remark: '已记录服务情况', updatedAt: '2026-05-17 15:10:00' } as DeliveryServiceItemType, { id: 'mock-order-006-item-2', - name: '术后注意事项宣教', + name: '配送员', required: true, completed: true, incompleteReason: '', - remark: '已向家属说明饮食与休息要求。', + remark: '已记录服务情况', updatedAt: '2026-05-17 15:28:00' } as DeliveryServiceItemType ] as Array, elderId: 'elder-006', - elderNameMasked: '刘叔叔', - elderGender: '男', + elderNameMasked: '张阿姨', + elderGender: '女', elderAge: 70, elderPhoneMasked: '133****6655', - fullElderName: '刘建华', + fullElderName: '张阿姨', fullPhone: '13300136655', - addressSummary: '梅江区和顺苑 9 栋 401', - fullAddress: '广东省梅州市梅江区和顺苑 9 栋 401 室', + addressSummary: '暂无地址', + fullAddress: '暂无地址', latitude: 24.2806, longitude: 116.1115, appointmentStartTime: '2026-05-17 14:00', @@ -1411,12 +1517,12 @@ function buildMockOrders(profile: DeliveryInfoType): Array { actualStartTime: '2026-05-17 14:05:00', actualEndTime: '2026-05-17 15:32:00', status: 'completed', - statusText: '已完成', + statusText: '待处理', statusTone: 'success', - riskTags: ['术后恢复'], - careLevel: '康复照护', + riskTags: [] as Array, + careLevel: '基础照护', merchantId: 'merchant-001', - merchantName: '梅州安康居家服务中心', + merchantName: '安心到家服务站', deliveryStaffId: profile.id, deliveryStaffName: profile.name, acceptTime: '2026-05-17 12:40:00', @@ -1429,24 +1535,24 @@ function buildMockOrders(profile: DeliveryInfoType): Array { exceptionDesc: '', evidenceList: buildMockEvidence('mock-order-006'), signatureUrl: '', - signatureName: '刘建华', - satisfactionStatus: '已评价', - settlementStatus: '已结算', - archiveStatus: '已归档', + signatureName: '家属确认', + satisfactionStatus: '待评价', + settlementStatus: '待结算', + archiveStatus: '未归档', createdAt: '2026-05-17 12:20:00', updatedAt: '2026-05-17 15:32:00', - contactName: '刘晓芳', + contactName: '家属', contactPhone: '13800132299', - notices: ['术后行动缓慢,注意搀扶'], - timeline: buildMockTimeline('YS202605170006', '服务完成待回访'), - serviceSummary: '术后恢复训练顺利完成,家属已确认并签字。', - progressNote: '服务完成,建议两日后再次回访。', + notices: [] as Array, + timeline: buildMockTimeline('YS202605170006', '状态更新'), + serviceSummary: '已完成基础服务', + progressNote: '服务状态已更新', distanceKm: '6.1km', allowCheckinRadiusMeters: 100, lastLocation: { latitude: 24.2806, longitude: 116.1115, - address: '和顺苑 9 栋 401 室', + address: '暂无地址', time: '2026-05-17 15:32:00' } as DeliveryLocationType, trackPoints: [] as Array @@ -1543,8 +1649,8 @@ function buildMockMessages(orders: Array): Array): Array): Array): Array): Array): Array): Array): Array): Array { const account = payload.account.trim() if (!account.includes('@')) { - throw new Error('请使用真实邮箱账号登录服务人员端') + throw new Error('请输入有效的邮箱账号') } const result = await supa.signIn(account, payload.password) @@ -2020,29 +2126,28 @@ export async function loginDelivery(payload: DeliveryLoginPayloadType): Promise< try { await supa.signOut() } catch (error) {} - throw new Error('登录状态已失效,请重新登录') + throw new Error('登录失败,未获取到用户信息') } if (!isDelivererRole(profile)) { try { await supa.signOut() } catch (error) {} - throw new Error('当前账号不是上门服务人员账号') + throw new Error('当前账号不是配送员账号') } let deliveryInfo = await fetchDeliveryProfileFromRemote(profile.id) let usesMock = false if (deliveryInfo == null) { if (IS_TEST_MODE) { - // 测试环境下无档案时自动回退 mock 档案,避免阻塞登录调试 deliveryInfo = ensureMockProfile(profile.id) usesMock = true - console.log('[loginDelivery] 未找到远程服务人员档案,已回退 mock 档案,userId:', profile.id) + console.log('[delivery api] 使用 mock 配送员档案') } else { try { await supa.signOut() } catch (error) {} - throw new Error('当前账号未绑定服务人员档案') + throw new Error('当前账号不是配送员账号') } } @@ -2112,11 +2217,11 @@ export async function acceptDeliveryOrderById(orderId: string): Promise { - console.warn('[HOMECARE ACCEPT] 调用 rpc_homecare_accept_assignment_v2, workOrderId=', workOrderId, ' workerId=', workerId) + console.log('[delivery api] 使用 mock 配送员档案') const rpcData = await callDeliveryRpc(DELIVERY_RPC_HOMECARE_ACCEPT_ASSIGNMENT_V2, { p_work_order_id: workOrderId, p_worker_id: workerId @@ -2174,8 +2279,8 @@ export async function checkinOrderById(orderId: string, payload: DeliveryCheckin } /** - * 居家服务正式签到 RPC:rpc_homecare_checkin_submit - * 参数:p_work_order_id, p_worker_id, p_latitude, p_longitude, p_coordinate_type, p_accuracy, p_reported_at, p_evidence_file_ids, p_signature_payload, p_reason + * 兼容旧数据处理 + * 兼容旧数据处理 */ export async function submitHomecareCheckin( workOrderId: string, @@ -2189,7 +2294,7 @@ export async function submitHomecareCheckin( signaturePayload: any | null = null, reason: string = 'worker_arrived' ): Promise { - console.warn('[CHECKIN SUBMIT] 调用 rpc_homecare_checkin_submit') + console.log('[delivery api] 使用 mock 配送员档案') console.warn('[CHECKIN SUBMIT] workOrderId=', workOrderId, ' workerId=', workerId) console.warn('[CHECKIN SUBMIT] lat=', latitude, ' lng=', longitude, ' accuracy=', accuracy) console.warn('[CHECKIN SUBMIT] evidenceFileIds=', evidenceFileIds) @@ -2313,3 +2418,269 @@ export async function updateDeliveryOnlineStatusByStaffId(staffId: string, statu } return await fallbackUpdateOnlineStatus(staffId, status) } + +// ======================== +// Compat RPC functions for so-xxx order ID support +// ======================== + +/** + * 兼容旧数据处理 + */ +export async function checkinPrecheckCompat( + orderId: string, + workerId: string, + latitude: number, + longitude: number, + accuracy: number +): Promise { + console.log('[DELIVERY_SERVICE_TRACE][checkinPrecheckCompat][START]', { + orderId: orderId, + workerId: workerId, + latitude: latitude, + longitude: longitude, + accuracy: accuracy + }) + + const params = new UTSJSONObject() + params.set('p_order_id', orderId) + params.set('p_worker_id', workerId) + params.set('p_latitude', latitude) + params.set('p_longitude', longitude) + params.set('p_coordinate_type', 'gcj02') + params.set('p_accuracy', accuracy) + params.set('p_reported_at', new Date().toISOString()) + + console.warn('[CHECKIN PRECHECK COMPAT] request:', JSON.stringify(params)) + + try { + const res: any = await supa.rpc(DELIVERY_RPC_HOMECARE_CHECKIN_PRECHECK_COMPAT, params) + console.warn('[CHECKIN PRECHECK COMPAT] data =', res) + + if (res?.error != null) { + const error = res.error as UTSJSONObject + console.warn('[CHECKIN PRECHECK COMPAT] error =', JSON.stringify(error)) + const result = new UTSJSONObject() + result.set('ok', false) + result.set('canCheckin', false) + result.set('reasonCode', error.getString('code') ?? 'RPC_ERROR') + result.set('message', error.getString('message') ?? '操作失败,请稍后重试') + result.set('debug', error) + console.log('[DELIVERY_SERVICE_TRACE][checkinPrecheckCompat][SUCCESS]', { + result: result + }) + return result + } + + const data = res?.data as UTSJSONObject | null + if (data != null) { + console.log('[DELIVERY_SERVICE_TRACE][checkinPrecheckCompat][SUCCESS]', { + result: data + }) + return data + } + // 兼容旧数据处理 + const fallback = new UTSJSONObject() + fallback.set('ok', false) + fallback.set('canCheckin', false) + fallback.set('reasonCode', 'RPC_ERROR') + fallback.set('message', '操作失败,请稍后重试') + console.log('[DELIVERY_SERVICE_TRACE][checkinPrecheckCompat][SUCCESS]', { + result: fallback + }) + return fallback + } catch (error) { + console.error('[DELIVERY_SERVICE_TRACE][checkinPrecheckCompat][ERROR]', { + errorMessage: error != null ? String(error.message ?? error) : '', + errorStack: error != null ? String(error.stack ?? '') : '', + params: { + orderId: orderId, + workerId: workerId, + latitude: latitude, + longitude: longitude, + accuracy: accuracy + } + }) + console.warn('[CHECKIN PRECHECK COMPAT] error =', error) + const result = new UTSJSONObject() + result.set('ok', false) + result.set('canCheckin', false) + result.set('reasonCode', 'RPC_ERROR') + result.set('message', '操作失败,请稍后重试') + result.set('debug', error) + return result + } +} + +/** + * 兼容旧数据处理 + */ +export async function createCheckinEvidenceCompat( + orderId: string, + uploaderId: string, + fileUrl: string, + note: string +): Promise { + console.log('[DELIVERY_SERVICE_TRACE][createCheckinEvidenceCompat][START]', { + orderId: orderId, + uploaderId: uploaderId, + fileUrl: fileUrl, + note: note + }) + + const params = new UTSJSONObject() + params.set('p_order_id', orderId) + params.set('p_uploader_id', uploaderId) + params.set('p_file_url', fileUrl) + params.set('p_note', note) + + console.warn('[CREATE EVIDENCE COMPAT] request:', JSON.stringify(params)) + + try { + const res: any = await supa.rpc(DELIVERY_RPC_CREATE_CHECKIN_EVIDENCE_COMPAT, params) + console.warn('[CREATE EVIDENCE COMPAT] data =', res) + + if (res?.error != null) { + const error = res.error as UTSJSONObject + console.warn('[CREATE EVIDENCE COMPAT] error =', JSON.stringify(error)) + const result = new UTSJSONObject() + result.set('ok', false) + result.set('reasonCode', error.getString('code') ?? 'RPC_ERROR') + result.set('message', error.getString('message') ?? '操作失败,请稍后重试') + result.set('debug', error) + console.log('[DELIVERY_SERVICE_TRACE][createCheckinEvidenceCompat][SUCCESS]', { + result: result + }) + return result + } + + const data = res?.data as UTSJSONObject | null + if (data != null) { + console.log('[DELIVERY_SERVICE_TRACE][createCheckinEvidenceCompat][SUCCESS]', { + result: data + }) + return data + } + const fallback = new UTSJSONObject() + fallback.set('ok', false) + fallback.set('reasonCode', 'RPC_ERROR') + fallback.set('message', '操作失败,请稍后重试') + console.log('[DELIVERY_SERVICE_TRACE][createCheckinEvidenceCompat][SUCCESS]', { + result: fallback + }) + return fallback + } catch (error) { + console.error('[DELIVERY_SERVICE_TRACE][createCheckinEvidenceCompat][ERROR]', { + errorMessage: error != null ? String(error.message ?? error) : '', + errorStack: error != null ? String(error.stack ?? '') : '', + params: { + orderId: orderId, + uploaderId: uploaderId, + fileUrl: fileUrl, + note: note + } + }) + console.warn('[CREATE EVIDENCE COMPAT] error =', error) + const result = new UTSJSONObject() + result.set('ok', false) + result.set('reasonCode', 'RPC_ERROR') + result.set('message', '操作失败,请稍后重试') + result.set('debug', error) + return result + } +} + +/** + * 兼容旧数据处理 + */ +export async function submitHomecareCheckinCompat( + orderId: string, + workerId: string, + latitude: number, + longitude: number, + accuracy: number, + evidenceFileIds: Array, + signaturePayload: any | null, + reason: string +): Promise { + console.log('[DELIVERY_SERVICE_TRACE][submitHomecareCheckinCompat][START]', { + orderId: orderId, + workerId: workerId, + latitude: latitude, + longitude: longitude, + accuracy: accuracy, + evidenceFileIds: evidenceFileIds, + signaturePayload: signaturePayload, + reason: reason + }) + + const params = new UTSJSONObject() + params.set('p_order_id', orderId) + params.set('p_worker_id', workerId) + params.set('p_latitude', latitude) + params.set('p_longitude', longitude) + params.set('p_coordinate_type', 'gcj02') + params.set('p_accuracy', accuracy) + params.set('p_reported_at', new Date().toISOString()) + params.set('p_evidence_file_ids', evidenceFileIds) + params.set('p_signature_payload', signaturePayload) + params.set('p_reason', reason) + + console.warn('[CHECKIN SUBMIT COMPAT] request:', JSON.stringify(params)) + + try { + const res: any = await supa.rpc(DELIVERY_RPC_HOMECARE_CHECKIN_SUBMIT_COMPAT, params) + console.warn('[CHECKIN SUBMIT COMPAT] data =', res) + + if (res?.error != null) { + const error = res.error as UTSJSONObject + console.warn('[CHECKIN SUBMIT COMPAT] error =', JSON.stringify(error)) + const result = new UTSJSONObject() + result.set('ok', false) + result.set('reasonCode', error.getString('code') ?? 'RPC_ERROR') + result.set('message', error.getString('message') ?? '操作失败,请稍后重试') + result.set('debug', error) + console.log('[DELIVERY_SERVICE_TRACE][submitHomecareCheckinCompat][SUCCESS]', { + result: result + }) + return result + } + + const data = res?.data as UTSJSONObject | null + if (data != null) { + console.log('[DELIVERY_SERVICE_TRACE][submitHomecareCheckinCompat][SUCCESS]', { + result: data + }) + return data + } + const fallback = new UTSJSONObject() + fallback.set('ok', false) + fallback.set('reasonCode', 'RPC_ERROR') + fallback.set('message', '操作失败,请稍后重试') + console.log('[DELIVERY_SERVICE_TRACE][submitHomecareCheckinCompat][SUCCESS]', { + result: fallback + }) + return fallback + } catch (error) { + console.error('[DELIVERY_SERVICE_TRACE][submitHomecareCheckinCompat][ERROR]', { + errorMessage: error != null ? String(error.message ?? error) : '', + errorStack: error != null ? String(error.stack ?? '') : '', + params: { + orderId: orderId, + workerId: workerId, + latitude: latitude, + longitude: longitude, + accuracy: accuracy, + evidenceFileIds: evidenceFileIds, + signaturePayload: signaturePayload, + reason: reason + } + }) + console.warn('[CHECKIN SUBMIT COMPAT] error =', error) + const result = new UTSJSONObject() + result.set('ok', false) + result.set('reasonCode', 'RPC_ERROR') + result.set('message', '操作失败,请稍后重试') + result.set('debug', error) + return result + } +} diff --git a/pages/mall/delivery/home/index.uvue b/pages/mall/delivery/home/index.uvue index 08309c5d..4e6997da 100644 --- a/pages/mall/delivery/home/index.uvue +++ b/pages/mall/delivery/home/index.uvue @@ -165,7 +165,11 @@ async function handleOrderAction(orderId: string) { return } if (order.status == 'pending_assignment' || order.status == 'pending_accept') { - await acceptServiceOrder(orderId) + const result = await acceptServiceOrder(orderId) + if (!result.ok) { + uni.showToast({ title: result.message != '' ? result.message : '接单失败', icon: 'none' }) + return + } uni.showToast({ title: '已接单', icon: 'success' }) loadData() return diff --git a/pages/mall/delivery/orders/checkin.uvue b/pages/mall/delivery/orders/checkin.uvue index 3235b344..c7dec5eb 100644 --- a/pages/mall/delivery/orders/checkin.uvue +++ b/pages/mall/delivery/orders/checkin.uvue @@ -1,4 +1,4 @@ -