diff --git a/docs/sql/20_rls/delivery/ak_delivery_rls_v2.sql b/docs/sql/20_rls/delivery/ak_delivery_rls_v2.sql index 6e552012..4dd9e327 100644 --- a/docs/sql/20_rls/delivery/ak_delivery_rls_v2.sql +++ b/docs/sql/20_rls/delivery/ak_delivery_rls_v2.sql @@ -11,6 +11,7 @@ ALTER TABLE public.ml_delivery_stations ENABLE ROW LEVEL SECURITY; -- 清理旧策略 DROP POLICY IF EXISTS delivery_staff_self_select ON public.ml_delivery_staff; +DROP POLICY IF EXISTS delivery_staff_assignable_select ON public.ml_delivery_staff; DROP POLICY IF EXISTS delivery_staff_self_update ON public.ml_delivery_staff; DROP POLICY IF EXISTS delivery_stations_select_active ON public.ml_delivery_stations; @@ -29,7 +30,20 @@ CREATE POLICY delivery_staff_self_select ) ); --- 2. 执行人员本人可更新自己的在线状态等自有档案字段 +-- 2. 已登录用户仅可读取可派单的在线服务人员,用于自动派单 +CREATE POLICY delivery_staff_assignable_select + ON public.ml_delivery_staff + FOR SELECT + TO authenticated + USING ( + deleted_at IS NULL + AND status = 1 + AND COALESCE(is_active, true) = true + AND online_status = 'online' + AND uid IS NOT NULL + ); + +-- 3. 执行人员本人可更新自己的在线状态等自有档案字段 CREATE POLICY delivery_staff_self_update ON public.ml_delivery_staff FOR UPDATE @@ -53,11 +67,11 @@ CREATE POLICY delivery_staff_self_update ) ); --- 3. 提货点/机构对前台保持只读,仅返回启用且未删除数据 +-- 4. 提货点/机构对前台保持只读,仅返回启用且未删除数据 CREATE POLICY delivery_stations_select_active ON public.ml_delivery_stations FOR SELECT TO anon, authenticated USING (status = 1 AND deleted_at IS NULL); --- 4. 其余直连写操作默认不开放,管理端统一走 SECURITY DEFINER RPC +-- 5. 其余直连写操作默认不开放,管理端统一走 SECURITY DEFINER RPC diff --git a/mall_sql/migrations/20260515_delivery_staff_v2_minimal.sql b/mall_sql/migrations/20260515_delivery_staff_v2_minimal.sql index 53baa24e..171831eb 100644 --- a/mall_sql/migrations/20260515_delivery_staff_v2_minimal.sql +++ b/mall_sql/migrations/20260515_delivery_staff_v2_minimal.sql @@ -79,6 +79,7 @@ ALTER TABLE public.ml_delivery_staff ENABLE ROW LEVEL SECURITY; ALTER TABLE public.ml_delivery_stations ENABLE ROW LEVEL SECURITY; DROP POLICY IF EXISTS delivery_staff_self_select ON public.ml_delivery_staff; +DROP POLICY IF EXISTS delivery_staff_assignable_select ON public.ml_delivery_staff; DROP POLICY IF EXISTS delivery_staff_self_update ON public.ml_delivery_staff; CREATE POLICY delivery_staff_self_select ON public.ml_delivery_staff @@ -94,6 +95,18 @@ CREATE POLICY delivery_staff_self_select ) ); +CREATE POLICY delivery_staff_assignable_select + ON public.ml_delivery_staff + FOR SELECT + TO authenticated + USING ( + deleted_at IS NULL + AND status = 1 + AND COALESCE(is_active, true) = true + AND online_status = 'online' + AND uid IS NOT NULL + ); + CREATE POLICY delivery_staff_self_update ON public.ml_delivery_staff FOR UPDATE diff --git a/pages/user/profile.uvue b/pages/user/profile.uvue index cf6557c7..33474d46 100644 --- a/pages/user/profile.uvue +++ b/pages/user/profile.uvue @@ -152,7 +152,7 @@ - @@ -1260,7 +1260,7 @@ const buildProfileUpdatePayload = (): UTSJSONObject => { return payload } -const saveProfile = async (): Promise => { +const saveProfile = async (shouldReturn: boolean = false): Promise => { const userid: string = profileRowId.value != '' ? profileRowId.value : (profile.value.id ?? '') const updatePayload = buildProfileUpdatePayload() if (UTSJSONObject.keys(updatePayload).length == 0) { @@ -1289,6 +1289,13 @@ const saveProfile = async (): Promise => { title: '保存成功', icon: 'success' }) + if (shouldReturn) { + setTimeout((): void => { + uni.navigateBack({ + delta: 1 + }) + }, 500) + } } else { console.log('saveProfile update ak_users error:', JSON.stringify(result.error)) uni.showToast({ diff --git a/services/serviceOrderService.uts b/services/serviceOrderService.uts index 6a76a434..b7debd11 100644 --- a/services/serviceOrderService.uts +++ b/services/serviceOrderService.uts @@ -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 { 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 { 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 { + if (ecServiceRequestCreateUnavailable) { + return null + } const userId = getCurrentUserId() if (userId == '') { return null @@ -752,16 +771,28 @@ async function tryCreateCareTask(params: CreateServiceOrderParams): Promise