跑通consumer下单之后派单给delivery2
This commit is contained in:
@@ -173,4 +173,53 @@ $$;
|
||||
REVOKE ALL ON FUNCTION public.rpc_admin_get_delivery_staff_list(TEXT, SMALLINT, INTEGER, INTEGER) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION public.rpc_admin_get_delivery_staff_list(TEXT, SMALLINT, INTEGER, INTEGER) TO authenticated;
|
||||
|
||||
DROP FUNCTION IF EXISTS public.rpc_homecare_dispatch_candidate(TEXT, UUID);
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.rpc_homecare_dispatch_candidate(
|
||||
p_service_code TEXT DEFAULT NULL,
|
||||
p_station_id UUID DEFAULT NULL
|
||||
)
|
||||
RETURNS JSONB
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
DECLARE
|
||||
v_candidate JSONB;
|
||||
BEGIN
|
||||
IF auth.uid() IS NULL OR NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM public.ak_users u
|
||||
WHERE u.auth_id = auth.uid()
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Permission denied';
|
||||
END IF;
|
||||
|
||||
SELECT jsonb_build_object(
|
||||
'id', s.id,
|
||||
'uid', s.uid,
|
||||
'station_id', s.station_id,
|
||||
'status', s.status,
|
||||
'online_status', s.online_status,
|
||||
'updated_at', s.updated_at,
|
||||
'created_at', s.created_at
|
||||
)
|
||||
INTO v_candidate
|
||||
FROM public.ml_delivery_staff s
|
||||
WHERE s.deleted_at IS NULL
|
||||
AND s.status = 1
|
||||
AND COALESCE(s.is_active, TRUE) = TRUE
|
||||
AND s.online_status = 'online'
|
||||
AND s.uid IS NOT NULL
|
||||
AND (p_station_id IS NULL OR s.station_id = p_station_id)
|
||||
ORDER BY COALESCE(s.updated_at, s.created_at) DESC, s.created_at DESC
|
||||
LIMIT 1;
|
||||
|
||||
RETURN v_candidate;
|
||||
END;
|
||||
$$;
|
||||
|
||||
REVOKE ALL ON FUNCTION public.rpc_homecare_dispatch_candidate(TEXT, UUID) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION public.rpc_homecare_dispatch_candidate(TEXT, UUID) TO authenticated;
|
||||
|
||||
COMMIT;
|
||||
Reference in New Issue
Block a user