From 7ba3d313be74d517e5fbc2256da6d8aab052a8fa Mon Sep 17 00:00:00 2001 From: huangzhenbao <17818024429@163.com> Date: Thu, 21 May 2026 11:50:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=A0=8F=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ges.consumer.2026-05-20T00-39-16-812Z.json | 461 ++++++++++ ...ges.consumer.2026-05-21T00-45-52-493Z.json | 117 +++ ...ges.delivery.2026-05-20T08-49-16-858Z.json | 461 ++++++++++ ...ges.delivery.2026-05-20T16-33-05-129Z.json | 179 ++++ ...ges.delivery.2026-05-21T00-45-43-192Z.json | 117 +++ components/home/HomeMallContent.uvue | 29 +- ...cal-mall-product-category-mapping-guide.md | 125 +++ docs/medical-product-image-candidates.md | 36 + .../product/medical_mall_categories_v1.sql | 64 ++ .../medical_mall_categories_rls_v1.sql | 23 + docs/sql/README_EXECUTION_ORDER.md | 483 ++++++----- .../20260521_medical_mall_categories_v1.sql | 269 ++++++ mock/delivery-care.mock.uts | 681 +++++++++++++++ pages.delivery.json | 70 +- pages/main/category.uvue | 51 +- pages/main/index.uvue | 133 +-- pages/mall/delivery/home/index.uvue | 702 ++++++++------- pages/mall/delivery/orders/detail.uvue | 348 ++++++-- pages/mall/delivery/orders/exception.uvue | 250 ++++-- pages/mall/delivery/orders/index.uvue | 459 +++++++--- pages/mall/delivery/profile/index.uvue | 821 ++++-------------- pages/mall/delivery/profile/settings.uvue | 54 +- pages/mall/delivery/service-record/index.uvue | 328 +++++++ services/deliveryService.uts | 224 +++-- ...ical_mall_product_category_first_batch.sql | 130 +++ ...oduct_category_manual_mapping_template.sql | 197 +++++ sql/seed_medical_homepage_data.sql | 576 ++++++++++++ sql/seed_medical_mall_categories.sql | 186 ++++ types/delivery.uts | 110 +++ utils/deliveryAuth.uts | 10 +- utils/deliveryCareUi.uts | 73 ++ utils/supabaseService.uts | 574 ++++++++++++ 32 files changed, 6657 insertions(+), 1684 deletions(-) create mode 100644 .pages-backup/pages.consumer.2026-05-20T00-39-16-812Z.json create mode 100644 .pages-backup/pages.consumer.2026-05-21T00-45-52-493Z.json create mode 100644 .pages-backup/pages.delivery.2026-05-20T08-49-16-858Z.json create mode 100644 .pages-backup/pages.delivery.2026-05-20T16-33-05-129Z.json create mode 100644 .pages-backup/pages.delivery.2026-05-21T00-45-43-192Z.json create mode 100644 docs/medical-mall-product-category-mapping-guide.md create mode 100644 docs/medical-product-image-candidates.md create mode 100644 docs/sql/10_schema/product/medical_mall_categories_v1.sql create mode 100644 docs/sql/20_rls/product/medical_mall_categories_rls_v1.sql create mode 100644 mall_sql/migrations/20260521_medical_mall_categories_v1.sql create mode 100644 mock/delivery-care.mock.uts create mode 100644 pages/mall/delivery/service-record/index.uvue create mode 100644 sql/medical_mall_product_category_first_batch.sql create mode 100644 sql/medical_mall_product_category_manual_mapping_template.sql create mode 100644 sql/seed_medical_homepage_data.sql create mode 100644 sql/seed_medical_mall_categories.sql create mode 100644 utils/deliveryCareUi.uts diff --git a/.pages-backup/pages.consumer.2026-05-20T00-39-16-812Z.json b/.pages-backup/pages.consumer.2026-05-20T00-39-16-812Z.json new file mode 100644 index 00000000..60afb4ad --- /dev/null +++ b/.pages-backup/pages.consumer.2026-05-20T00-39-16-812Z.json @@ -0,0 +1,461 @@ +{ + "pages": [ + { + "path": "pages/main/index", + "style": { + "navigationBarTitleText": "首页", + "navigationStyle": "custom", + "enablePullDownRefresh": false + } + }, + { + "path": "pages/user/boot", + "style": { + "navigationBarTitleText": "" + } + }, + { + "path": "pages/user/login", + "style": { + "navigationBarTitleText": "用户登录", + "navigationStyle": "custom" + } + }, + { + "path": "pages/user/register", + "style": { + "navigationBarTitleText": "注册" + } + }, + { + "path": "pages/user/forgot-password", + "style": { + "navigationBarTitleText": "忘记密码" + } + }, + { + "path": "pages/user/terms", + "style": { + "navigationBarTitleText": "用户协议与隐私政策" + } + }, + { + "path": "pages/user/center", + "style": { + "navigationBarTitleText": "用户中心" + } + }, + { + "path": "pages/user/profile", + "style": { + "navigationBarTitleText": "个人资料" + } + }, + { + "path": "pages/user/change-password", + "style": { + "navigationBarTitleText": "修改密码" + } + }, + { + "path": "pages/user/bind-phone", + "style": { + "navigationBarTitleText": "绑定手机" + } + }, + { + "path": "pages/user/bind-email", + "style": { + "navigationBarTitleText": "绑定邮箱" + } + }, + { + "path": "pages/main/messages", + "style": { + "navigationBarTitleText": "消息", + "enablePullDownRefresh": true + } + }, + { + "path": "pages/main/cart", + "style": { + "navigationBarTitleText": "购物车", + "navigationStyle": "custom" + } + }, + { + "path": "pages/main/profile", + "style": { + "navigationBarTitleText": "我的", + "navigationStyle": "custom" + } + }, + { + "path": "pages/main/category", + "style": { + "navigationBarTitleText": "分类", + "navigationStyle": "custom" + } + } + ], + "subPackages": [ + { + "root": "pages/mall/consumer", + "pages": [ + { + "path": "settings", + "style": { + "navigationBarTitleText": "设置" + } + }, + { + "path": "edit-profile", + "style": { + "navigationBarTitleText": "编辑资料" + } + }, + { + "path": "wallet", + "style": { + "navigationBarTitleText": "我的钱包" + } + }, + { + "path": "withdraw", + "style": { + "navigationBarTitleText": "余额提现" + } + }, + { + "path": "search", + "style": { + "navigationBarTitleText": "搜索", + "navigationStyle": "custom" + } + }, + { + "path": "product-detail", + "style": { + "navigationBarTitleText": "", + "navigationStyle": "custom" + } + }, + { + "path": "channel-detail", + "style": { + "navigationBarTitleText": "频道详情", + "navigationStyle": "custom" + } + }, + { + "path": "shop-detail", + "style": { + "navigationBarTitleText": "店铺详情" + } + }, + { + "path": "coupons", + "style": { + "navigationBarTitleText": "我的优惠券" + } + }, + { + "path": "favorites", + "style": { + "navigationBarTitleText": "我的收藏" + } + }, + { + "path": "footprint", + "style": { + "navigationBarTitleText": "我的足迹" + } + }, + { + "path": "address", + "style": { + "navigationBarTitleText": "地址" + } + }, + { + "path": "address-list", + "style": { + "navigationBarTitleText": "收货地址" + } + }, + { + "path": "address-edit", + "style": { + "navigationBarTitleText": "编辑地址" + } + }, + { + "path": "checkout", + "style": { + "navigationBarTitleText": "确认订单" + } + }, + { + "path": "payment", + "style": { + "navigationBarTitleText": "收银台" + } + }, + { + "path": "payment-success", + "style": { + "navigationBarTitleText": "支付成功", + "navigationStyle": "custom" + } + }, + { + "path": "orders", + "style": { + "navigationBarTitleText": "我的订单", + "enablePullDownRefresh": true + } + }, + { + "path": "order-detail", + "style": { + "navigationBarTitleText": "订单详情" + } + }, + { + "path": "logistics", + "style": { + "navigationBarTitleText": "物流详情" + } + }, + { + "path": "review", + "style": { + "navigationBarTitleText": "评价晒单" + } + }, + { + "path": "refund", + "style": { + "navigationBarTitleText": "退款/售后" + } + }, + { + "path": "apply-refund", + "style": { + "navigationBarTitleText": "申请售后" + } + }, + { + "path": "refund-review", + "style": { + "navigationBarTitleText": "服务评价" + } + }, + { + "path": "chat", + "style": { + "navigationBarTitleText": "客服聊天", + "navigationStyle": "custom" + } + }, + { + "path": "chat_new", + "style": { + "navigationBarTitleText": "客服聊天(新版)" + } + }, + { + "path": "subscription/plan-list", + "style": { + "navigationBarTitleText": "软件订阅" + } + }, + { + "path": "subscription/plan-detail", + "style": { + "navigationBarTitleText": "订阅详情" + } + }, + { + "path": "subscription/subscribe-checkout", + "style": { + "navigationBarTitleText": "确认订阅" + } + }, + { + "path": "subscription/my-subscriptions", + "style": { + "navigationBarTitleText": "我的订阅" + } + }, + { + "path": "subscription/followed-shops", + "style": { + "navigationBarTitleText": "关注店铺" + } + }, + { + "path": "points/index", + "style": { + "navigationBarTitleText": "积分管理" + } + }, + { + "path": "points/signin", + "style": { + "navigationBarTitleText": "签到" + } + }, + { + "path": "points/exchange", + "style": { + "navigationBarTitleText": "积分兑换" + } + }, + { + "path": "points/exchange-records", + "style": { + "navigationBarTitleText": "兑换记录" + } + }, + { + "path": "red-packets/index", + "style": { + "navigationBarTitleText": "我的红包" + } + }, + { + "path": "bank-cards/index", + "style": { + "navigationBarTitleText": "银行卡管理" + } + }, + { + "path": "bank-cards/add", + "style": { + "navigationBarTitleText": "添加银行卡" + } + }, + { + "path": "home-service/index", + "style": { + "navigationBarTitleText": "居家上门服务", + "navigationStyle": "custom" + } + }, + { + "path": "home-service/apply", + "style": { + "navigationBarTitleText": "提交服务申请", + "navigationStyle": "custom" + } + }, + { + "path": "home-service/service-detail", + "style": { + "navigationBarTitleText": "预约服务", + "navigationStyle": "custom" + } + }, + { + "path": "home-service/order-detail", + "style": { + "navigationBarTitleText": "服务单详情", + "navigationStyle": "custom" + } + }, + { + "path": "home-service/feedback", + "style": { + "navigationBarTitleText": "验收反馈", + "navigationStyle": "custom" + } + }, + { + "path": "bank-cards/verify", + "style": { + "navigationBarTitleText": "银行卡验证" + } + }, + { + "path": "balance/index", + "style": { + "navigationBarTitleText": "余额" + } + }, + { + "path": "my-reviews", + "style": { + "navigationBarTitleText": "我的评价" + } + }, + { + "path": "message-detail", + "style": { + "navigationBarTitleText": "消息详情" + } + }, + { + "path": "member/index", + "style": { + "navigationBarTitleText": "会员中心" + } + }, + { + "path": "product-reviews", + "style": { + "navigationBarTitleText": "商品评价" + } + } + ] + } + ], + "tabBar": { + "color": "#999999", + "selectedColor": "#ff5000", + "backgroundColor": "#ffffff", + "borderStyle": "black", + "list": [ + { + "pagePath": "pages/main/index", + "text": "首页", + "iconPath": "static/tabbar/home.png", + "selectedIconPath": "static/tabbar/home-active.png" + }, + { + "pagePath": "pages/main/messages", + "text": "消息", + "iconPath": "static/tabbar/message.png", + "selectedIconPath": "static/tabbar/message.png" + }, + { + "pagePath": "pages/main/cart", + "text": "购物车", + "iconPath": "static/tabbar/cart.png", + "selectedIconPath": "static/tabbar/cart.png" + }, + { + "pagePath": "pages/main/profile", + "text": "我的", + "iconPath": "static/tabbar/user.png", + "selectedIconPath": "static/tabbar/user.png" + } + ] + }, + "globalStyle": { + "navigationBarTextStyle": "black", + "navigationBarTitleText": "mall", + "navigationBarBackgroundColor": "#FFFFFF", + "backgroundColor": "#F8F8F8" + }, + "condition": { + "current": 0, + "list": [ + { + "name": "consumer端", + "path": "pages/main/index", + "query": "role=consumer" + } + ] + } +} diff --git a/.pages-backup/pages.consumer.2026-05-21T00-45-52-493Z.json b/.pages-backup/pages.consumer.2026-05-21T00-45-52-493Z.json new file mode 100644 index 00000000..7d0d4a37 --- /dev/null +++ b/.pages-backup/pages.consumer.2026-05-21T00-45-52-493Z.json @@ -0,0 +1,117 @@ +{ + "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/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-05-20T08-49-16-858Z.json b/.pages-backup/pages.delivery.2026-05-20T08-49-16-858Z.json new file mode 100644 index 00000000..60afb4ad --- /dev/null +++ b/.pages-backup/pages.delivery.2026-05-20T08-49-16-858Z.json @@ -0,0 +1,461 @@ +{ + "pages": [ + { + "path": "pages/main/index", + "style": { + "navigationBarTitleText": "首页", + "navigationStyle": "custom", + "enablePullDownRefresh": false + } + }, + { + "path": "pages/user/boot", + "style": { + "navigationBarTitleText": "" + } + }, + { + "path": "pages/user/login", + "style": { + "navigationBarTitleText": "用户登录", + "navigationStyle": "custom" + } + }, + { + "path": "pages/user/register", + "style": { + "navigationBarTitleText": "注册" + } + }, + { + "path": "pages/user/forgot-password", + "style": { + "navigationBarTitleText": "忘记密码" + } + }, + { + "path": "pages/user/terms", + "style": { + "navigationBarTitleText": "用户协议与隐私政策" + } + }, + { + "path": "pages/user/center", + "style": { + "navigationBarTitleText": "用户中心" + } + }, + { + "path": "pages/user/profile", + "style": { + "navigationBarTitleText": "个人资料" + } + }, + { + "path": "pages/user/change-password", + "style": { + "navigationBarTitleText": "修改密码" + } + }, + { + "path": "pages/user/bind-phone", + "style": { + "navigationBarTitleText": "绑定手机" + } + }, + { + "path": "pages/user/bind-email", + "style": { + "navigationBarTitleText": "绑定邮箱" + } + }, + { + "path": "pages/main/messages", + "style": { + "navigationBarTitleText": "消息", + "enablePullDownRefresh": true + } + }, + { + "path": "pages/main/cart", + "style": { + "navigationBarTitleText": "购物车", + "navigationStyle": "custom" + } + }, + { + "path": "pages/main/profile", + "style": { + "navigationBarTitleText": "我的", + "navigationStyle": "custom" + } + }, + { + "path": "pages/main/category", + "style": { + "navigationBarTitleText": "分类", + "navigationStyle": "custom" + } + } + ], + "subPackages": [ + { + "root": "pages/mall/consumer", + "pages": [ + { + "path": "settings", + "style": { + "navigationBarTitleText": "设置" + } + }, + { + "path": "edit-profile", + "style": { + "navigationBarTitleText": "编辑资料" + } + }, + { + "path": "wallet", + "style": { + "navigationBarTitleText": "我的钱包" + } + }, + { + "path": "withdraw", + "style": { + "navigationBarTitleText": "余额提现" + } + }, + { + "path": "search", + "style": { + "navigationBarTitleText": "搜索", + "navigationStyle": "custom" + } + }, + { + "path": "product-detail", + "style": { + "navigationBarTitleText": "", + "navigationStyle": "custom" + } + }, + { + "path": "channel-detail", + "style": { + "navigationBarTitleText": "频道详情", + "navigationStyle": "custom" + } + }, + { + "path": "shop-detail", + "style": { + "navigationBarTitleText": "店铺详情" + } + }, + { + "path": "coupons", + "style": { + "navigationBarTitleText": "我的优惠券" + } + }, + { + "path": "favorites", + "style": { + "navigationBarTitleText": "我的收藏" + } + }, + { + "path": "footprint", + "style": { + "navigationBarTitleText": "我的足迹" + } + }, + { + "path": "address", + "style": { + "navigationBarTitleText": "地址" + } + }, + { + "path": "address-list", + "style": { + "navigationBarTitleText": "收货地址" + } + }, + { + "path": "address-edit", + "style": { + "navigationBarTitleText": "编辑地址" + } + }, + { + "path": "checkout", + "style": { + "navigationBarTitleText": "确认订单" + } + }, + { + "path": "payment", + "style": { + "navigationBarTitleText": "收银台" + } + }, + { + "path": "payment-success", + "style": { + "navigationBarTitleText": "支付成功", + "navigationStyle": "custom" + } + }, + { + "path": "orders", + "style": { + "navigationBarTitleText": "我的订单", + "enablePullDownRefresh": true + } + }, + { + "path": "order-detail", + "style": { + "navigationBarTitleText": "订单详情" + } + }, + { + "path": "logistics", + "style": { + "navigationBarTitleText": "物流详情" + } + }, + { + "path": "review", + "style": { + "navigationBarTitleText": "评价晒单" + } + }, + { + "path": "refund", + "style": { + "navigationBarTitleText": "退款/售后" + } + }, + { + "path": "apply-refund", + "style": { + "navigationBarTitleText": "申请售后" + } + }, + { + "path": "refund-review", + "style": { + "navigationBarTitleText": "服务评价" + } + }, + { + "path": "chat", + "style": { + "navigationBarTitleText": "客服聊天", + "navigationStyle": "custom" + } + }, + { + "path": "chat_new", + "style": { + "navigationBarTitleText": "客服聊天(新版)" + } + }, + { + "path": "subscription/plan-list", + "style": { + "navigationBarTitleText": "软件订阅" + } + }, + { + "path": "subscription/plan-detail", + "style": { + "navigationBarTitleText": "订阅详情" + } + }, + { + "path": "subscription/subscribe-checkout", + "style": { + "navigationBarTitleText": "确认订阅" + } + }, + { + "path": "subscription/my-subscriptions", + "style": { + "navigationBarTitleText": "我的订阅" + } + }, + { + "path": "subscription/followed-shops", + "style": { + "navigationBarTitleText": "关注店铺" + } + }, + { + "path": "points/index", + "style": { + "navigationBarTitleText": "积分管理" + } + }, + { + "path": "points/signin", + "style": { + "navigationBarTitleText": "签到" + } + }, + { + "path": "points/exchange", + "style": { + "navigationBarTitleText": "积分兑换" + } + }, + { + "path": "points/exchange-records", + "style": { + "navigationBarTitleText": "兑换记录" + } + }, + { + "path": "red-packets/index", + "style": { + "navigationBarTitleText": "我的红包" + } + }, + { + "path": "bank-cards/index", + "style": { + "navigationBarTitleText": "银行卡管理" + } + }, + { + "path": "bank-cards/add", + "style": { + "navigationBarTitleText": "添加银行卡" + } + }, + { + "path": "home-service/index", + "style": { + "navigationBarTitleText": "居家上门服务", + "navigationStyle": "custom" + } + }, + { + "path": "home-service/apply", + "style": { + "navigationBarTitleText": "提交服务申请", + "navigationStyle": "custom" + } + }, + { + "path": "home-service/service-detail", + "style": { + "navigationBarTitleText": "预约服务", + "navigationStyle": "custom" + } + }, + { + "path": "home-service/order-detail", + "style": { + "navigationBarTitleText": "服务单详情", + "navigationStyle": "custom" + } + }, + { + "path": "home-service/feedback", + "style": { + "navigationBarTitleText": "验收反馈", + "navigationStyle": "custom" + } + }, + { + "path": "bank-cards/verify", + "style": { + "navigationBarTitleText": "银行卡验证" + } + }, + { + "path": "balance/index", + "style": { + "navigationBarTitleText": "余额" + } + }, + { + "path": "my-reviews", + "style": { + "navigationBarTitleText": "我的评价" + } + }, + { + "path": "message-detail", + "style": { + "navigationBarTitleText": "消息详情" + } + }, + { + "path": "member/index", + "style": { + "navigationBarTitleText": "会员中心" + } + }, + { + "path": "product-reviews", + "style": { + "navigationBarTitleText": "商品评价" + } + } + ] + } + ], + "tabBar": { + "color": "#999999", + "selectedColor": "#ff5000", + "backgroundColor": "#ffffff", + "borderStyle": "black", + "list": [ + { + "pagePath": "pages/main/index", + "text": "首页", + "iconPath": "static/tabbar/home.png", + "selectedIconPath": "static/tabbar/home-active.png" + }, + { + "pagePath": "pages/main/messages", + "text": "消息", + "iconPath": "static/tabbar/message.png", + "selectedIconPath": "static/tabbar/message.png" + }, + { + "pagePath": "pages/main/cart", + "text": "购物车", + "iconPath": "static/tabbar/cart.png", + "selectedIconPath": "static/tabbar/cart.png" + }, + { + "pagePath": "pages/main/profile", + "text": "我的", + "iconPath": "static/tabbar/user.png", + "selectedIconPath": "static/tabbar/user.png" + } + ] + }, + "globalStyle": { + "navigationBarTextStyle": "black", + "navigationBarTitleText": "mall", + "navigationBarBackgroundColor": "#FFFFFF", + "backgroundColor": "#F8F8F8" + }, + "condition": { + "current": 0, + "list": [ + { + "name": "consumer端", + "path": "pages/main/index", + "query": "role=consumer" + } + ] + } +} diff --git a/.pages-backup/pages.delivery.2026-05-20T16-33-05-129Z.json b/.pages-backup/pages.delivery.2026-05-20T16-33-05-129Z.json new file mode 100644 index 00000000..41ef0c29 --- /dev/null +++ b/.pages-backup/pages.delivery.2026-05-20T16-33-05-129Z.json @@ -0,0 +1,179 @@ +{ + "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/orders/execute", + "style": { + "navigationBarTitleText": "服务执行", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/evidence", + "style": { + "navigationBarTitleText": "证据上传", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/exception", + "style": { + "navigationBarTitleText": "异常上报", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/orders/finish", + "style": { + "navigationBarTitleText": "完成确认", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/records/index", + "style": { + "navigationBarTitleText": "服务记录", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/records/detail", + "style": { + "navigationBarTitleText": "记录详情", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/messages/index", + "style": { + "navigationBarTitleText": "消息中心", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/profile/index", + "style": { + "navigationBarTitleText": "我的", + "navigationStyle": "custom" + } + }, + { + "path": "pages/mall/delivery/profile/certificates", + "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/messages/index", + "text": "消息", + "iconPath": "static/tabbar/message.png", + "selectedIconPath": "static/tabbar/message.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-05-21T00-45-43-192Z.json b/.pages-backup/pages.delivery.2026-05-21T00-45-43-192Z.json new file mode 100644 index 00000000..7d0d4a37 --- /dev/null +++ b/.pages-backup/pages.delivery.2026-05-21T00-45-43-192Z.json @@ -0,0 +1,117 @@ +{ + "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/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/components/home/HomeMallContent.uvue b/components/home/HomeMallContent.uvue index c0adeb0b..f400063f 100644 --- a/components/home/HomeMallContent.uvue +++ b/components/home/HomeMallContent.uvue @@ -4,6 +4,7 @@ @@ -141,7 +142,11 @@ - + + + {{ emptyStateDescription }} + + @@ -204,6 +209,14 @@ const props = defineProps({ showLoadMore: { type: Boolean, default: false + }, + emptyStateTitle: { + type: String, + default: '当前分类暂无商品' + }, + emptyStateDescription: { + type: String, + default: '' } }) @@ -848,6 +861,20 @@ function showMarketPrice(product: Product): boolean { overflow: hidden; } +.hmall-empty-state-extended { + padding-bottom: 32rpx; + align-items: center; +} + +.hmall-empty-desc { + margin-top: -8rpx; + padding: 0 40rpx; + font-size: 24rpx; + line-height: 34rpx; + color: #9a9a9a; + text-align: center; +} + .hmall-loading-text, .hmall-feed-end-text { font-size: 24rpx; diff --git a/docs/medical-mall-product-category-mapping-guide.md b/docs/medical-mall-product-category-mapping-guide.md new file mode 100644 index 00000000..41a9124f --- /dev/null +++ b/docs/medical-mall-product-category-mapping-guide.md @@ -0,0 +1,125 @@ +# 医疗商城商品分类映射说明 + +说明: + +- 本文用于补齐 public.medical_mall_product_categories 的真实商品分类关联。 +- 首页和分类页现在都优先依赖这张关联表;关键词 fallback 只作为临时兜底,不应长期替代真实映射。 +- 推荐配套执行文件见 [mall_sql/migrations/20260521_medical_mall_categories_v1.sql](../mall_sql/migrations/20260521_medical_mall_categories_v1.sql)。 + +## 目标 + +需要补齐三类数据: + +- 主分类映射:每个商品至少挂 1 个最准确的二级分类,且建议设置 1 条 is_primary = true。 +- 扩展分类映射:一个商品可以额外挂多个补充分类,用于“全部”“交叉场景”与推荐流召回。 +- 存量纠偏:清理错误分类、重复主分类和已下架商品的失效映射。 + +## 一级分类与二级分类 + +当前医疗商城一级分类: + +- med_device:医疗器械 +- otc_medicine:家庭常备药 +- rehab_care:康复护理 +- chronic_monitor:慢病监测 +- elderly_aid:适老用品 +- nutrition_health:营养保健 +- protection_disinfection:防护消毒 +- tcm_health:中医保健 +- home_care_daily:居家护理 +- all_medical:全部 + +优先补的二级分类: + +- blood_pressure_monitor:血压计 +- blood_glucose_meter:血糖仪 +- oximeter:血氧仪 +- thermometer:体温计 +- oxygen_concentrator:制氧机 +- nebulizer:雾化器 +- wheelchair_crutch:轮椅拐杖 +- nursing_bed:护理床 +- cold_fever:感冒发烧 +- cough_throat:咳嗽咽喉 +- stomach_medicine:肠胃用药 +- skin_external:皮肤外用 +- eye_ear_nose:眼耳口鼻 +- pain_relief:止痛用药 +- trauma_sprain:跌打损伤 +- child_medicine:儿童用药 +- postop_rehab:术后康复 +- wound_dressing:伤口敷料 +- brace_support:护具支具 +- rehab_training:康复训练器 +- physiotherapy_hot:理疗热敷 +- mobility_training:行动训练 +- hypertension:高血压管理 +- diabetes:糖尿病管理 +- cardiovascular:心脑血管 +- respiratory_health:呼吸健康 +- weight_bodyfat:体重体脂 +- home_testing:家庭检测 +- anti_slip:防滑安全 +- elderly_bathroom:适老卫浴 +- eating_aid:助餐用品 +- bathing_aid:助浴用品 +- incontinence_care:失禁护理 +- daily_living_aid:生活辅助 +- vitamin:维生素 +- calcium:钙铁锌硒 +- protein:蛋白营养 +- elderly_nutrition:老人营养 +- gut_health:肠道益生菌 +- immune_support:免疫支持 +- mask:口罩 +- disinfectant:消毒液 +- alcohol_wipes:酒精湿巾 +- gloves:手套 +- first_aid:急救包 +- dressing_tools:棉签纱布 +- moxibustion:艾灸拔罐 +- herbal_drink:养生茶饮 +- tcm_patch:中医贴敷 +- medicated_diet:药膳滋补 +- massage_tools:按摩理疗 +- foot_bath:泡脚养生 +- wound_care:伤口护理 +- oral_care:口腔护理 +- skin_care:皮肤护理 +- cleaning_care:清洁护理 +- nursing_consumables:护理耗材 +- home_health_tool:家庭健康工具 + +## 建议映射原则 + +1. 一个商品先确定一个最准确的二级分类,写为主分类。 +2. 只有确实横跨多个场景时,再补额外分类,不要为了提高曝光滥挂多个类。 +3. 一级类不直接挂商品,优先挂到二级类;只有“全部”这种聚合入口由前端自动聚合,不需要单独插 all_medical。 +4. OTC、器械、处方隐藏类商品要优先核对 compliance_type,不要把应隐藏的商品映射到公开可见分类。 +5. 已下架、删除、测试商品不要补映射,避免推荐流被污染。 + +## 建议执行顺序 + +1. 先找出当前首页和分类页实际展示的商品。 +2. 给这些商品补主分类。 +3. 再补扩展分类和长尾商品。 +4. 最后执行核对 SQL,清理多余主分类和无效映射。 + +## 需要重点人工核对的商品类型 + +- 通用耗材:如纱布、棉签、消毒棉片,容易在 wound_care、dressing_tools、nursing_consumables 之间混淆。 +- 保健品:如复合维生素、蛋白粉、益生菌,容易在 vitamin、protein、gut_health、immune_support 之间重叠。 +- 康复用品:如护腰、支撑带、热敷贴,可能落在 brace_support、postop_rehab、physiotherapy_hot、tcm_patch。 +- 慢病设备:如血压计、血糖仪、血氧仪,既是器械,也服务于慢病管理,但主分类仍建议落二级商品类本身。 + +## 配套文件 + +- 映射维护模板:[sql/medical_mall_product_category_manual_mapping_template.sql](../sql/medical_mall_product_category_manual_mapping_template.sql) +- 一体化迁移:[mall_sql/migrations/20260521_medical_mall_categories_v1.sql](../mall_sql/migrations/20260521_medical_mall_categories_v1.sql) +- 拆分 seed:[sql/seed_medical_mall_categories.sql](../sql/seed_medical_mall_categories.sql) + +## 当前状态 + +- 现有 seed 只补了少量关键词示例关联。 +- 首页和分类页已经切到 medical_mall 数据源。 +- 如果不补真实映射,线上数据仍会部分依赖关键词 fallback,结果不可控。 diff --git a/docs/medical-product-image-candidates.md b/docs/medical-product-image-candidates.md new file mode 100644 index 00000000..bd46df4b --- /dev/null +++ b/docs/medical-product-image-candidates.md @@ -0,0 +1,36 @@ +# 医疗首页商品候选图片清单 + +说明: +- 当前阶段先整理“商品名 -> 候选图片页”,不直接写回 SQL。 +- 优先使用 Unsplash 内部图片页作为候选来源;少数品类在 Unsplash 内匹配度较低,已标注低置信度。 +- 后续建议:你确认图片后,再上传到 Supabase Storage 或自有图床,再把最终地址回填到 SQL。 + +## 本轮确认结果 + +- 已按你的反馈确认这些商品可继续沿用当前候选:家庭退热护理贴、智能血压监测仪、高钙维D营养片、乳清蛋白营养粉、术后支撑恢复带、肩颈草本热敷贴、折叠助行辅助器、浴室防滑扶手套装。 +- 已按你的要求重找并替换:草本暖胃调理贴、静音雾化护理机、家用艾灸温灸盒。 +- 第 2、8 项已去掉付费来源,改为免费可访问图片页。 +- 无菌伤口护理包本轮未被点名调整,暂保留原候选。 + +## 候选清单 + +| 商品模板 | 候选图片页 | 匹配度 | 备注 | +|---|---|---:|---| +| 家庭退热护理贴 | https://unsplash.com/photos/woman-holding-cooling-gel-patches-for-fever-relief-KZ1r0RrbXdc | 高 | 语义最贴近“退热贴/降温贴” | +| 草本暖胃调理贴 | https://unsplash.com/photos/a-knitted-hot-water-bottle-with-a-green-stopper-4XlKcKpmjwU | 中 | 免费来源。偏腹部热敷/暖胃护理场景,不是贴剂包装图,但比付费候选更适合作为当前免费替代 | +| 智能血压监测仪 | https://unsplash.com/photos/a-person-with-a-blood-pressure-meter-on-their-arm-oi6jf34bQrU | 高 | 与家用电子血压计场景贴近 | +| 静音雾化护理机 | https://unsplash.com/photos/beautiful-sick-boy-inhalation-therapy-by-the-mask-of-inhaler-image-of-a-cute-kid-with-respiratory-problem-or-asthma-view-of-nebulizer-with-smoke-from-oxygen-mask-wLldIFm5E4Q | 高 | 已按你指定的儿童雾化器图片方向替换为具体图片页 | +| 高钙维D营养片 | https://unsplash.com/photos/four-bottles-of-vitamin-supplements-sitting-next-to-a-plant-dY14deLOUGk | 中高 | 更像营养补充剂瓶装商品,适合替代钙片视觉 | +| 乳清蛋白营养粉 | https://unsplash.com/photos/a-jar-of-protein-powder-next-to-a-scoop-of-protein-powder-DvunqLOsKco | 高 | 与蛋白粉罐装商品很贴近 | +| 术后支撑恢复带 | https://unsplash.com/photos/woman-wearing-a-white-ribbed-band-and-denim-shorts-rArjMQ0rT7Y | 中 | 偏腹部支撑带场景,能表达术后支撑语义 | +| 无菌伤口护理包 | https://unsplash.com/photos/first-aid-kit-contents-with-bandages-and-medical-supplies-nGfxoclUgSI | 高 | 与无菌换药/护理包很贴近 | +| 家用艾灸温灸盒 | https://commons.wikimedia.org/wiki/File:Ibuki_moxa_set.jpg | 中高 | 免费来源。Wikimedia Commons 图片页,偏艾灸产品实物/套装展示,比当前能拿到的免费场景图更接近商品本体 | +| 肩颈草本热敷贴 | https://unsplash.com/photos/person-with-patch-on-neck-against-orange-background-HjdjzIrL6GM | 高 | 与肩颈贴敷场景较贴近 | +| 折叠助行辅助器 | https://unsplash.com/photos/elderly-woman-on-a-walker-EbLMgFcCXV4 | 高 | 与长者助行器商品高度贴近 | +| 浴室防滑扶手套装 | https://unsplash.com/photos/a-toilet-with-a-metal-bar-lFDGy3yzCc0 | 高 | 与浴室扶手安装场景贴近 | + +## 当前建议 + +1. 如果这版没问题,我下一步直接把已确认候选回填成 SQL 映射表。 +2. 如果你还想继续压低风险,我可以只对第三方链接生成“待上传素材清单”,不直接写热链。 +3. 正式上线前,仍建议把这些图片上传到你们自己的存储后再回填数据库。 diff --git a/docs/sql/10_schema/product/medical_mall_categories_v1.sql b/docs/sql/10_schema/product/medical_mall_categories_v1.sql new file mode 100644 index 00000000..0d58bcd9 --- /dev/null +++ b/docs/sql/10_schema/product/medical_mall_categories_v1.sql @@ -0,0 +1,64 @@ +-- Schema: 医疗商城独立分类与商品分类关联 +-- 执行阶段: 10_schema + +CREATE TABLE IF NOT EXISTS public.medical_mall_categories ( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + parent_id TEXT NULL REFERENCES public.medical_mall_categories(id), + level INTEGER NOT NULL CHECK (level IN (1, 2)), + sort_order INTEGER NOT NULL DEFAULT 0, + icon TEXT, + image_url TEXT, + description TEXT, + scene TEXT NOT NULL DEFAULT 'medical_mall', + category_type TEXT NOT NULL DEFAULT 'normal', + compliance_type TEXT NOT NULL DEFAULT 'normal', + is_active BOOLEAN NOT NULL DEFAULT TRUE, + deleted_at TIMESTAMPTZ NULL, + deleted_by UUID NULL REFERENCES public.ak_users(id), + restored_at TIMESTAMPTZ NULL, + restored_by UUID NULL REFERENCES public.ak_users(id), + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +COMMENT ON TABLE public.medical_mall_categories IS '医疗商城独立分类表'; +COMMENT ON COLUMN public.medical_mall_categories.scene IS '分类场景,如 medical_mall / home_mall'; +COMMENT ON COLUMN public.medical_mall_categories.category_type IS '分类类型:device / otc / care / rehab / elderly / nutrition / protection / tcm / all'; +COMMENT ON COLUMN public.medical_mall_categories.compliance_type IS '合规类型:normal / otc / device_class_i / device_class_ii / device_class_iii / rx_hidden'; + +CREATE INDEX IF NOT EXISTS idx_medical_mall_categories_parent + ON public.medical_mall_categories(parent_id) + WHERE deleted_at IS NULL; + +CREATE INDEX IF NOT EXISTS idx_medical_mall_categories_level_sort + ON public.medical_mall_categories(level, sort_order) + WHERE deleted_at IS NULL; + +CREATE INDEX IF NOT EXISTS idx_medical_mall_categories_scene_active + ON public.medical_mall_categories(scene, is_active) + WHERE deleted_at IS NULL; + +CREATE TABLE IF NOT EXISTS public.medical_mall_product_categories ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + product_id UUID NOT NULL REFERENCES public.ml_products(id) ON DELETE CASCADE, + category_id TEXT NOT NULL REFERENCES public.medical_mall_categories(id), + is_primary BOOLEAN NOT NULL DEFAULT FALSE, + sort_order INTEGER NOT NULL DEFAULT 0, + deleted_at TIMESTAMPTZ NULL, + deleted_by UUID NULL REFERENCES public.ak_users(id), + restored_at TIMESTAMPTZ NULL, + restored_by UUID NULL REFERENCES public.ak_users(id), + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + UNIQUE (product_id, category_id) +); + +COMMENT ON TABLE public.medical_mall_product_categories IS '医疗商城商品与分类关联表'; + +CREATE INDEX IF NOT EXISTS idx_medical_mall_product_categories_category + ON public.medical_mall_product_categories(category_id, sort_order) + WHERE deleted_at IS NULL; + +CREATE INDEX IF NOT EXISTS idx_medical_mall_product_categories_product + ON public.medical_mall_product_categories(product_id) + WHERE deleted_at IS NULL; \ No newline at end of file diff --git a/docs/sql/20_rls/product/medical_mall_categories_rls_v1.sql b/docs/sql/20_rls/product/medical_mall_categories_rls_v1.sql new file mode 100644 index 00000000..52ee4192 --- /dev/null +++ b/docs/sql/20_rls/product/medical_mall_categories_rls_v1.sql @@ -0,0 +1,23 @@ +-- RLS: 医疗商城独立分类与商品分类关联 +-- 执行阶段: 20_rls + +ALTER TABLE public.medical_mall_categories ENABLE ROW LEVEL SECURITY; +ALTER TABLE public.medical_mall_product_categories ENABLE ROW LEVEL SECURITY; + +DROP POLICY IF EXISTS medical_mall_categories_public_select_active ON public.medical_mall_categories; +CREATE POLICY medical_mall_categories_public_select_active +ON public.medical_mall_categories +FOR SELECT +TO anon, authenticated +USING ( + deleted_at IS NULL + AND is_active = TRUE + AND compliance_type <> 'rx_hidden' +); + +DROP POLICY IF EXISTS medical_mall_product_categories_public_select_active ON public.medical_mall_product_categories; +CREATE POLICY medical_mall_product_categories_public_select_active +ON public.medical_mall_product_categories +FOR SELECT +TO anon, authenticated +USING (deleted_at IS NULL); \ No newline at end of file diff --git a/docs/sql/README_EXECUTION_ORDER.md b/docs/sql/README_EXECUTION_ORDER.md index 80be0895..978b6439 100644 --- a/docs/sql/README_EXECUTION_ORDER.md +++ b/docs/sql/README_EXECUTION_ORDER.md @@ -1,12 +1,15 @@ # SQL 文件执行顺序文档(软删除标准化改造 + Admin 模块全量) ## 目标 + 为本次“软删除标准化改造(Schema + RLS + RPC)”提供**可直接执行**且**顺序准确**的数据库同步步骤,同时整理**全量 Admin 模块**对应的数据库文件,确保: + - 先补齐表字段与索引(避免 RPC/RLS 引用字段失败); - 再应用 RLS(确保查询默认过滤已软删数据); - 最后加载/替换 RPC(确保删除行为变更与审计字段写入生效)。 ## 前置约束 + - 执行账号需具备:`ALTER TABLE`、`CREATE INDEX`、`ALTER POLICY/CREATE POLICY`、`CREATE OR REPLACE FUNCTION` 等权限。 - **禁止并发执行**:建议串行执行,尤其是 RLS/RPC 部分。 - 若生产环境已存在同名对象:本次以 `CREATE OR REPLACE FUNCTION` 与 policy 更新为主,属于“覆盖式更新”。 @@ -14,99 +17,115 @@ --- ## 第一阶段:Schema / Migration(必须先执行) + > 目的:补齐 `deleted_at/deleted_by/restored_at/restored_by` 字段与软删除索引,作为后续 RLS/RPC 的基础依赖。 -| 序号 | 文件路径 | 说明 | -|:--:|:---|:---| -| 1 | [`10_schema/99_soft_delete_migration_v1.sql`](./10_schema/99_soft_delete_migration_v1.sql) | 软删除字段迁移(核心) | +| 序号 | 文件路径 | 说明 | +| :--: | :----------------------------------------------------------------------------------------- | :--------------------- | +| 1 | [`10_schema/99_soft_delete_migration_v1.sql`](./10_schema/99_soft_delete_migration_v1.sql) | 软删除字段迁移(核心) | ### 其他 Schema 文件(按业务域分类) #### Admin 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------- | :--------- | | [`10_schema/admin/ml_system_configs_v1.sql`](./10_schema/admin/ml_system_configs_v1.sql) | 系统配置表 | #### Auth 域 -| 文件路径 | 说明 | -|:---|:---| -| [`10_schema/user/ak_auth_system_v1.sql`](./10_schema/user/ak_auth_system_v1.sql) | 认证系统表(roles/permissions/admin_roles/role_permissions) | -| [`10_schema/user/ak_users_add_phone_real_name_v1.sql`](./10_schema/user/ak_users_add_phone_real_name_v1.sql) | 用户扩展字段 | -| [`10_schema/user/ak_users_finance_fields_v1.sql`](./10_schema/user/ak_users_finance_fields_v1.sql) | 用户财务字段 | -| [`10_schema/user/ak_users_constraints_fix_v1.sql`](./10_schema/user/ak_users_constraints_fix_v1.sql) | 用户表约束修复 | + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------- | +| [`10_schema/user/ak_auth_system_v1.sql`](./10_schema/user/ak_auth_system_v1.sql) | 认证系统表(roles/permissions/admin_roles/role_permissions) | +| [`10_schema/user/ak_users_add_phone_real_name_v1.sql`](./10_schema/user/ak_users_add_phone_real_name_v1.sql) | 用户扩展字段 | +| [`10_schema/user/ak_users_finance_fields_v1.sql`](./10_schema/user/ak_users_finance_fields_v1.sql) | 用户财务字段 | +| [`10_schema/user/ak_users_constraints_fix_v1.sql`](./10_schema/user/ak_users_constraints_fix_v1.sql) | 用户表约束修复 | #### CMS 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------- | :------------- | | [`10_schema/cms/ml_cms_tables_v1.sql`](./10_schema/cms/ml_cms_tables_v1.sql) | CMS 内容管理表 | #### Decoration 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------- | :--------- | | [`10_schema/decoration/ak_diy_pages_v1.sql`](./10_schema/decoration/ak_diy_pages_v1.sql) | DIY 页面表 | #### Delivery 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------- | :--------- | | [`10_schema/delivery/ak_delivery_system_v1.sql`](./10_schema/delivery/ak_delivery_system_v1.sql) | 配送系统表 | #### Distribution 域 -| 文件路径 | 说明 | -|:---|:---| -| [`10_schema/distribution/ak_distribution_agents_v1.sql`](./10_schema/distribution/ak_distribution_agents_v1.sql) | 分销代理表 | -| [`10_schema/distribution/ak_distribution_agent_applications_v1.sql`](./10_schema/distribution/ak_distribution_agent_applications_v1.sql) | 代理申请表 | -| [`10_schema/distribution/ak_distribution_divisions_v1.sql`](./10_schema/distribution/ak_distribution_divisions_v1.sql) | 事业部表 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------------------------------------- | :----------- | +| [`10_schema/distribution/ak_distribution_agents_v1.sql`](./10_schema/distribution/ak_distribution_agents_v1.sql) | 分销代理表 | +| [`10_schema/distribution/ak_distribution_agent_applications_v1.sql`](./10_schema/distribution/ak_distribution_agent_applications_v1.sql) | 代理申请表 | +| [`10_schema/distribution/ak_distribution_divisions_v1.sql`](./10_schema/distribution/ak_distribution_divisions_v1.sql) | 事业部表 | | [`10_schema/distribution/ak_distribution_division_applications_v1.sql`](./10_schema/distribution/ak_distribution_division_applications_v1.sql) | 事业部申请表 | -| [`10_schema/distribution/ak_promoter_relations_v1.sql`](./10_schema/distribution/ak_promoter_relations_v1.sql) | 推广员关系表 | -| [`10_schema/distribution/ak_commission_logs_v1.sql`](./10_schema/distribution/ak_commission_logs_v1.sql) | 佣金日志表 | -| [`10_schema/distribution/ak_distribution_level_v1.sql`](./10_schema/distribution/ak_distribution_level_v1.sql) | 分销等级表 | -| [`10_schema/distribution/ak_distribution_config_v1.sql`](./10_schema/distribution/ak_distribution_config_v1.sql) | 分销配置表 | +| [`10_schema/distribution/ak_promoter_relations_v1.sql`](./10_schema/distribution/ak_promoter_relations_v1.sql) | 推广员关系表 | +| [`10_schema/distribution/ak_commission_logs_v1.sql`](./10_schema/distribution/ak_commission_logs_v1.sql) | 佣金日志表 | +| [`10_schema/distribution/ak_distribution_level_v1.sql`](./10_schema/distribution/ak_distribution_level_v1.sql) | 分销等级表 | +| [`10_schema/distribution/ak_distribution_config_v1.sql`](./10_schema/distribution/ak_distribution_config_v1.sql) | 分销配置表 | #### Finance 域 -| 文件路径 | 说明 | -|:---|:---| -| [`10_schema/finance/ml_invoices_v1.sql`](./10_schema/finance/ml_invoices_v1.sql) | 发票表 | -| [`10_schema/finance/ml_extract_v1.sql`](./10_schema/finance/ml_extract_v1.sql) | 提现表 | + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------- | :--------- | +| [`10_schema/finance/ml_invoices_v1.sql`](./10_schema/finance/ml_invoices_v1.sql) | 发票表 | +| [`10_schema/finance/ml_extract_v1.sql`](./10_schema/finance/ml_extract_v1.sql) | 提现表 | | [`10_schema/finance/ml_user_recharge_v1.sql`](./10_schema/finance/ml_user_recharge_v1.sql) | 用户充值表 | -| [`10_schema/finance/ml_user_bill_v1.sql`](./10_schema/finance/ml_user_bill_v1.sql) | 用户账单表 | +| [`10_schema/finance/ml_user_bill_v1.sql`](./10_schema/finance/ml_user_bill_v1.sql) | 用户账单表 | #### Kefu 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------- | :--------- | | [`10_schema/kefu/ml_kefu_tables_v1.sql`](./10_schema/kefu/ml_kefu_tables_v1.sql) | 客服系统表 | #### Marketing 域 -| 文件路径 | 说明 | -|:---|:---| -| [`10_schema/marketing/ak_lottery_live_v1.sql`](./10_schema/marketing/ak_lottery_live_v1.sql) | 直播抽奖 | -| [`10_schema/marketing/ak_marketing_signin_logs_v1.sql`](./10_schema/marketing/ak_marketing_signin_logs_v1.sql) | 签到日志 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------------- | :------- | +| [`10_schema/marketing/ak_lottery_live_v1.sql`](./10_schema/marketing/ak_lottery_live_v1.sql) | 直播抽奖 | +| [`10_schema/marketing/ak_marketing_signin_logs_v1.sql`](./10_schema/marketing/ak_marketing_signin_logs_v1.sql) | 签到日志 | | [`10_schema/marketing/ak_marketing_newcomer_config_v1.sql`](./10_schema/marketing/ak_marketing_newcomer_config_v1.sql) | 新人配置 | -| [`10_schema/marketing/ak_bargain_groupbuy_v1.sql`](./10_schema/marketing/ak_bargain_groupbuy_v1.sql) | 拼团砍价 | -| [`10_schema/marketing/ak_live_products_v1.sql`](./10_schema/marketing/ak_live_products_v1.sql) | 直播商品 | -| [`10_schema/marketing/ak_advanced_marketing_v1.sql`](./10_schema/marketing/ak_advanced_marketing_v1.sql) | 高级营销 | +| [`10_schema/marketing/ak_bargain_groupbuy_v1.sql`](./10_schema/marketing/ak_bargain_groupbuy_v1.sql) | 拼团砍价 | +| [`10_schema/marketing/ak_live_products_v1.sql`](./10_schema/marketing/ak_live_products_v1.sql) | 直播商品 | +| [`10_schema/marketing/ak_advanced_marketing_v1.sql`](./10_schema/marketing/ak_advanced_marketing_v1.sql) | 高级营销 | | [`10_schema/marketing/ak_marketing_checkin_configs_v1.sql`](./10_schema/marketing/ak_marketing_checkin_configs_v1.sql) | 签到配置 | -| [`10_schema/marketing/ak_recharge_management_v1.sql`](./10_schema/marketing/ak_recharge_management_v1.sql) | 充值管理 | -| [`10_schema/marketing/ak_member_management_v1.sql`](./10_schema/marketing/ak_member_management_v1.sql) | 会员管理 | -| [`10_schema/marketing/ak_signin_configs_v1.sql`](./10_schema/marketing/ak_signin_configs_v1.sql) | 签到配置 | +| [`10_schema/marketing/ak_recharge_management_v1.sql`](./10_schema/marketing/ak_recharge_management_v1.sql) | 充值管理 | +| [`10_schema/marketing/ak_member_management_v1.sql`](./10_schema/marketing/ak_member_management_v1.sql) | 会员管理 | +| [`10_schema/marketing/ak_signin_configs_v1.sql`](./10_schema/marketing/ak_signin_configs_v1.sql) | 签到配置 | #### Order 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------- | :------------- | | [`10_schema/order/ml_orders_schema_update_v1.sql`](./10_schema/order/ml_orders_schema_update_v1.sql) | 订单表结构更新 | #### Product 域 -| 文件路径 | 说明 | -|:---|:---| -| [`10_schema/product/ml_products_ext_v1.sql`](./10_schema/product/ml_products_ext_v1.sql) | 商品扩展表 | -| [`10_schema/product/ak_shipping_templates_v1.sql`](./10_schema/product/ak_shipping_templates_v1.sql) | 运费模板 | -| [`10_schema/product/ak_product_member_prices_v1.sql`](./10_schema/product/ak_product_member_prices_v1.sql) | 会员价 | -| [`10_schema/product/ak_product_protections_v1.sql`](./10_schema/product/ak_product_protections_v1.sql) | 商品保障 | -| [`10_schema/product/ak_product_templates_v1.sql`](./10_schema/product/ak_product_templates_v1.sql) | 商品模板 | -| [`10_schema/product/ak_product_labels_v1.sql`](./10_schema/product/ak_product_labels_v1.sql) | 商品标签 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------ | +| [`../../mall_sql/migrations/20260521_medical_mall_categories_v1.sql`](../../mall_sql/migrations/20260521_medical_mall_categories_v1.sql) | 医疗商城独立分类一体化迁移(含 Schema + RLS + 初始化 Seed,推荐优先执行) | +| [`10_schema/product/ml_products_ext_v1.sql`](./10_schema/product/ml_products_ext_v1.sql) | 商品扩展表 | +| [`10_schema/product/ak_shipping_templates_v1.sql`](./10_schema/product/ak_shipping_templates_v1.sql) | 运费模板 | +| [`10_schema/product/ak_product_member_prices_v1.sql`](./10_schema/product/ak_product_member_prices_v1.sql) | 会员价 | +| [`10_schema/product/ak_product_protections_v1.sql`](./10_schema/product/ak_product_protections_v1.sql) | 商品保障 | +| [`10_schema/product/ak_product_templates_v1.sql`](./10_schema/product/ak_product_templates_v1.sql) | 商品模板 | +| [`10_schema/product/ak_product_labels_v1.sql`](./10_schema/product/ak_product_labels_v1.sql) | 商品标签 | + +> 补充说明:若执行 [`../../mall_sql/migrations/20260521_medical_mall_categories_v1.sql`](../../mall_sql/migrations/20260521_medical_mall_categories_v1.sql),则无需再重复执行 `10_schema/product/medical_mall_categories_v1.sql`、`20_rls/product/medical_mall_categories_rls_v1.sql` 与 `sql/seed_medical_mall_categories.sql` 的拆分版内容。 #### User 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------- | :--------- | | [`10_schema/user/ak_user_labels_v1.sql`](./10_schema/user/ak_user_labels_v1.sql) | 用户标签表 | | [`10_schema/user/ak_user_groups_v1.sql`](./10_schema/user/ak_user_groups_v1.sql) | 用户分组表 | | [`10_schema/user/ak_user_levels_v1.sql`](./10_schema/user/ak_user_levels_v1.sql) | 用户等级表 | @@ -114,63 +133,74 @@ --- ## 第二阶段:RLS(在 Schema 之后执行) + > 目的:将各模块策略统一补齐 `deleted_at IS NULL`,确保默认查询排除已软删记录。 按域执行(域之间无强依赖,可按任意顺序;但**必须在 RPC 之前**执行): ### Auth 域(新增) -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :------------------------------------------------------------------- | :----------------------------------- | | [`20_rls/auth/ak_auth_rls_v1.sql`](./20_rls/auth/ak_auth_rls_v1.sql) | 权限/角色表 RLS 策略(禁止直接访问) | ### Admin 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------- | :----------- | | [`20_rls/admin/ml_system_configs_rls_v1.sql`](./20_rls/admin/ml_system_configs_rls_v1.sql) | 系统配置 RLS | ### CMS 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------- | :----------- | | [`20_rls/cms/ml_cms_rls_v1.sql`](./20_rls/cms/ml_cms_rls_v1.sql) | CMS 内容 RLS | ### Decoration 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------- | :------- | | [`20_rls/decoration/ml_decoration_rls_v1.sql`](./20_rls/decoration/ml_decoration_rls_v1.sql) | 装修 RLS | ### Delivery 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------- | :------- | | [`20_rls/delivery/ak_delivery_rls_v1.sql`](./20_rls/delivery/ak_delivery_rls_v1.sql) | 配送 RLS | ### Distribution 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------- | :------- | | [`20_rls/distribution/ml_distribution_rls_v1.sql`](./20_rls/distribution/ml_distribution_rls_v1.sql) | 分销 RLS | ### Finance 域 -| 文件路径 | 说明 | -|:---|:---| -| [`20_rls/finance/ml_extract_rls_v1.sql`](./20_rls/finance/ml_extract_rls_v1.sql) | 提现 RLS | -| [`20_rls/finance/ml_invoices_rls_v1.sql`](./20_rls/finance/ml_invoices_rls_v1.sql) | 发票 RLS | -| [`20_rls/finance/ml_user_bill_rls_v1.sql`](./20_rls/finance/ml_user_bill_rls_v1.sql) | 用户账单 RLS | + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------- | :----------- | +| [`20_rls/finance/ml_extract_rls_v1.sql`](./20_rls/finance/ml_extract_rls_v1.sql) | 提现 RLS | +| [`20_rls/finance/ml_invoices_rls_v1.sql`](./20_rls/finance/ml_invoices_rls_v1.sql) | 发票 RLS | +| [`20_rls/finance/ml_user_bill_rls_v1.sql`](./20_rls/finance/ml_user_bill_rls_v1.sql) | 用户账单 RLS | | [`20_rls/finance/ml_user_recharge_rls_v1.sql`](./20_rls/finance/ml_user_recharge_rls_v1.sql) | 用户充值 RLS | ### Kefu 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :------------------------------------------------------------------- | :------- | | [`20_rls/kefu/ml_kefu_rls_v1.sql`](./20_rls/kefu/ml_kefu_rls_v1.sql) | 客服 RLS | ### Marketing 域 -| 文件路径 | 说明 | -|:---|:---| -| [`20_rls/marketing/ml_marketing_others_rls_v1.sql`](./20_rls/marketing/ml_marketing_others_rls_v1.sql) | 其他营销 RLS | -| [`20_rls/marketing/ml_marketing_activities_rls_v1.sql`](./20_rls/marketing/ml_marketing_activities_rls_v1.sql) | 营销活动 RLS | -| [`20_rls/marketing/ml_coupon_templates_rls_v1.sql`](./20_rls/marketing/ml_coupon_templates_rls_v1.sql) | 优惠券模板 RLS | + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------------- | :------------- | +| [`20_rls/marketing/ml_marketing_others_rls_v1.sql`](./20_rls/marketing/ml_marketing_others_rls_v1.sql) | 其他营销 RLS | +| [`20_rls/marketing/ml_marketing_activities_rls_v1.sql`](./20_rls/marketing/ml_marketing_activities_rls_v1.sql) | 营销活动 RLS | +| [`20_rls/marketing/ml_coupon_templates_rls_v1.sql`](./20_rls/marketing/ml_coupon_templates_rls_v1.sql) | 优惠券模板 RLS | ### User 域 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------- | :----------- | | [`20_rls/user/ak_user_labels_rls_v1.sql`](./20_rls/user/ak_user_labels_rls_v1.sql) | 用户标签 RLS | | [`20_rls/user/ak_user_groups_rls_v1.sql`](./20_rls/user/ak_user_groups_rls_v1.sql) | 用户分组 RLS | | [`20_rls/user/ak_user_levels_rls_v1.sql`](./20_rls/user/ak_user_levels_rls_v1.sql) | 用户等级 RLS | @@ -178,6 +208,7 @@ --- ## 第三阶段:RPC(最后执行) + > 目的:将“删除”统一切换为软删除(写入 `deleted_at/deleted_by`),并在需要的函数中补齐级联软删。 按域执行(域之间一般无强依赖;但建议按下列顺序,先基础权限/用户,再业务模块): @@ -187,15 +218,17 @@ ### 3.1 Admin 域(系统管理) #### 查询类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/admin/rpc_admin_get_system_info_v1.sql`](./30_rpc/admin/rpc_admin_get_system_info_v1.sql) | 获取系统信息 | + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------------- | :----------- | +| [`30_rpc/admin/rpc_admin_get_system_info_v1.sql`](./30_rpc/admin/rpc_admin_get_system_info_v1.sql) | 获取系统信息 | | [`30_rpc/admin/rpc_admin_get_overall_stats_v1.sql`](./30_rpc/admin/rpc_admin_get_overall_stats_v1.sql) | 获取整体统计 | | [`30_rpc/admin/rpc_admin_system_config_get_v1.sql`](./30_rpc/admin/rpc_admin_system_config_get_v1.sql) | 获取系统配置 | #### 保存/更新类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------- | :----------- | | [`30_rpc/admin/rpc_admin_system_config_save_v1.sql`](./30_rpc/admin/rpc_admin_system_config_save_v1.sql) | 保存系统配置 | --- @@ -203,33 +236,38 @@ ### 3.2 Auth 域(权限认证) #### 权限校验辅助函数(新增) -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------- | :--------------------- | | [`30_rpc/auth/fn_check_admin_permission_v1.sql`](./30_rpc/auth/fn_check_admin_permission_v1.sql) | 通用 RBAC 权限校验函数 | #### 查询类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/auth/rpc_admin_get_permission_list_v1.sql`](./30_rpc/auth/rpc_admin_get_permission_list_v1.sql) | 获取权限列表 | -| [`30_rpc/auth/rpc_admin_get_role_list_v1.sql`](./30_rpc/auth/rpc_admin_get_role_list_v1.sql) | 获取角色列表 | -| [`30_rpc/auth/rpc_admin_get_admin_list_v1.sql`](./30_rpc/auth/rpc_admin_get_admin_list_v1.sql) | 获取管理员列表 | -| [`30_rpc/auth/get_current_user_role_v1.sql`](./30_rpc/auth/get_current_user_role_v1.sql) | 获取当前用户角色 | + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------- | :--------------- | +| [`30_rpc/auth/rpc_admin_get_permission_list_v1.sql`](./30_rpc/auth/rpc_admin_get_permission_list_v1.sql) | 获取权限列表 | +| [`30_rpc/auth/rpc_admin_get_role_list_v1.sql`](./30_rpc/auth/rpc_admin_get_role_list_v1.sql) | 获取角色列表 | +| [`30_rpc/auth/rpc_admin_get_admin_list_v1.sql`](./30_rpc/auth/rpc_admin_get_admin_list_v1.sql) | 获取管理员列表 | +| [`30_rpc/auth/get_current_user_role_v1.sql`](./30_rpc/auth/get_current_user_role_v1.sql) | 获取当前用户角色 | #### 保存/更新类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------- | :------- | | [`30_rpc/auth/rpc_admin_save_permission_v1.sql`](./30_rpc/auth/rpc_admin_save_permission_v1.sql) | 保存权限 | -| [`30_rpc/auth/rpc_admin_save_role_v1.sql`](./30_rpc/auth/rpc_admin_save_role_v1.sql) | 保存角色 | +| [`30_rpc/auth/rpc_admin_save_role_v1.sql`](./30_rpc/auth/rpc_admin_save_role_v1.sql) | 保存角色 | #### 删除类(软删除) -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------- | :----------------- | | [`30_rpc/auth/rpc_admin_delete_permission_v1.sql`](./30_rpc/auth/rpc_admin_delete_permission_v1.sql) | 删除权限(软删除) | -| [`30_rpc/auth/rpc_admin_delete_role_v1.sql`](./30_rpc/auth/rpc_admin_delete_role_v1.sql) | 删除角色(软删除) | +| [`30_rpc/auth/rpc_admin_delete_role_v1.sql`](./30_rpc/auth/rpc_admin_delete_role_v1.sql) | 删除角色(软删除) | #### 用户处理类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------- | :------------ | | [`30_rpc/auth/handle_new_user_v3.sql`](./30_rpc/auth/handle_new_user_v3.sql) | 处理新用户 v3 | | [`30_rpc/auth/handle_new_user_v2.sql`](./30_rpc/auth/handle_new_user_v2.sql) | 处理新用户 v2 | @@ -238,28 +276,32 @@ ### 3.3 CMS 域(内容管理) #### 查询类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/cms/rpc_admin_article_list_v1.sql`](./30_rpc/cms/rpc_admin_article_list_v1.sql) | 获取文章列表 | -| [`30_rpc/cms/rpc_admin_article_get_detail_v1.sql`](./30_rpc/cms/rpc_admin_article_get_detail_v1.sql) | 获取文章详情 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------- | :--------------- | +| [`30_rpc/cms/rpc_admin_article_list_v1.sql`](./30_rpc/cms/rpc_admin_article_list_v1.sql) | 获取文章列表 | +| [`30_rpc/cms/rpc_admin_article_get_detail_v1.sql`](./30_rpc/cms/rpc_admin_article_get_detail_v1.sql) | 获取文章详情 | | [`30_rpc/cms/rpc_admin_article_category_list_v1.sql`](./30_rpc/cms/rpc_admin_article_category_list_v1.sql) | 获取文章分类列表 | #### 保存/更新类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/cms/rpc_admin_article_save_v1.sql`](./30_rpc/cms/rpc_admin_article_save_v1.sql) | 保存文章 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------- | :----------- | +| [`30_rpc/cms/rpc_admin_article_save_v1.sql`](./30_rpc/cms/rpc_admin_article_save_v1.sql) | 保存文章 | | [`30_rpc/cms/rpc_admin_article_category_save_v1.sql`](./30_rpc/cms/rpc_admin_article_category_save_v1.sql) | 保存文章分类 | #### 删除类(软删除) -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/cms/rpc_admin_article_delete_v1.sql`](./30_rpc/cms/rpc_admin_article_delete_v1.sql) | 删除文章(软删除) | + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------------- | :--------------------- | +| [`30_rpc/cms/rpc_admin_article_delete_v1.sql`](./30_rpc/cms/rpc_admin_article_delete_v1.sql) | 删除文章(软删除) | | [`30_rpc/cms/rpc_admin_article_category_delete_v1.sql`](./30_rpc/cms/rpc_admin_article_category_delete_v1.sql) | 删除文章分类(软删除) | #### 状态管理类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/cms/rpc_admin_article_set_status_v1.sql`](./30_rpc/cms/rpc_admin_article_set_status_v1.sql) | 设置文章状态 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------------- | :--------------- | +| [`30_rpc/cms/rpc_admin_article_set_status_v1.sql`](./30_rpc/cms/rpc_admin_article_set_status_v1.sql) | 设置文章状态 | | [`30_rpc/cms/rpc_admin_article_category_set_status_v1.sql`](./30_rpc/cms/rpc_admin_article_category_set_status_v1.sql) | 设置文章分类状态 | --- @@ -267,19 +309,22 @@ ### 3.4 Decoration 域(装修管理) #### 查询类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------- | :---------------- | | [`30_rpc/decoration/rpc_admin_get_diy_page_list_v1.sql`](./30_rpc/decoration/rpc_admin_get_diy_page_list_v1.sql) | 获取 DIY 页面列表 | #### 保存/更新类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------- | :------------ | | [`30_rpc/decoration/rpc_admin_save_diy_page_v1.sql`](./30_rpc/decoration/rpc_admin_save_diy_page_v1.sql) | 保存 DIY 页面 | -| [`30_rpc/decoration/rpc_admin_set_home_page_v1.sql`](./30_rpc/decoration/rpc_admin_set_home_page_v1.sql) | 设置首页 | +| [`30_rpc/decoration/rpc_admin_set_home_page_v1.sql`](./30_rpc/decoration/rpc_admin_set_home_page_v1.sql) | 设置首页 | #### 删除类(软删除) -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------------------- | :---------------------- | | [`30_rpc/decoration/rpc_admin_delete_diy_page_v1.sql`](./30_rpc/decoration/rpc_admin_delete_diy_page_v1.sql) | 删除 DIY 页面(软删除) | --- @@ -287,21 +332,24 @@ ### 3.5 Delivery 域(配送管理) #### 查询类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/delivery/rpc_admin_get_delivery_staff_list_v1.sql`](./30_rpc/delivery/rpc_admin_get_delivery_staff_list_v1.sql) | 获取配送员列表 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------------------- | :--------------- | +| [`30_rpc/delivery/rpc_admin_get_delivery_staff_list_v1.sql`](./30_rpc/delivery/rpc_admin_get_delivery_staff_list_v1.sql) | 获取配送员列表 | | [`30_rpc/delivery/rpc_admin_get_delivery_station_list_v1.sql`](./30_rpc/delivery/rpc_admin_get_delivery_station_list_v1.sql) | 获取配送站点列表 | #### 保存/更新类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/delivery/rpc_admin_save_delivery_staff_v1.sql`](./30_rpc/delivery/rpc_admin_save_delivery_staff_v1.sql) | 保存配送员 | + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------------------- | :----------- | +| [`30_rpc/delivery/rpc_admin_save_delivery_staff_v1.sql`](./30_rpc/delivery/rpc_admin_save_delivery_staff_v1.sql) | 保存配送员 | | [`30_rpc/delivery/rpc_admin_save_delivery_station_v1.sql`](./30_rpc/delivery/rpc_admin_save_delivery_station_v1.sql) | 保存配送站点 | #### 删除类(软删除) -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/delivery/rpc_admin_delete_delivery_staff_v1.sql`](./30_rpc/delivery/rpc_admin_delete_delivery_staff_v1.sql) | 删除配送员(软删除) | + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------------------------------- | :--------------------- | +| [`30_rpc/delivery/rpc_admin_delete_delivery_staff_v1.sql`](./30_rpc/delivery/rpc_admin_delete_delivery_staff_v1.sql) | 删除配送员(软删除) | | [`30_rpc/delivery/rpc_admin_delete_delivery_station_v1.sql`](./30_rpc/delivery/rpc_admin_delete_delivery_station_v1.sql) | 删除配送站点(软删除) | --- @@ -309,28 +357,32 @@ ### 3.6 Distribution 域(分销管理) #### 查询类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/distribution/rpc_admin_get_agent_list_v1.sql`](./30_rpc/distribution/rpc_admin_get_agent_list_v1.sql) | 获取代理列表 | + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------------------------- | :--------------- | +| [`30_rpc/distribution/rpc_admin_get_agent_list_v1.sql`](./30_rpc/distribution/rpc_admin_get_agent_list_v1.sql) | 获取代理列表 | | [`30_rpc/distribution/rpc_admin_get_agent_apply_list_v1.sql`](./30_rpc/distribution/rpc_admin_get_agent_apply_list_v1.sql) | 获取代理申请列表 | -| [`30_rpc/distribution/rpc_admin_get_division_list_v1.sql`](./30_rpc/distribution/rpc_admin_get_division_list_v1.sql) | 获取事业部列表 | -| [`30_rpc/distribution/rpc_admin_get_promoter_list_v1.sql`](./30_rpc/distribution/rpc_admin_get_promoter_list_v1.sql) | 获取推广员列表 | +| [`30_rpc/distribution/rpc_admin_get_division_list_v1.sql`](./30_rpc/distribution/rpc_admin_get_division_list_v1.sql) | 获取事业部列表 | +| [`30_rpc/distribution/rpc_admin_get_promoter_list_v1.sql`](./30_rpc/distribution/rpc_admin_get_promoter_list_v1.sql) | 获取推广员列表 | #### 保存/更新类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/distribution/rpc_admin_save_agent_v1.sql`](./30_rpc/distribution/rpc_admin_save_agent_v1.sql) | 保存代理 | + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------------------- | :--------- | +| [`30_rpc/distribution/rpc_admin_save_agent_v1.sql`](./30_rpc/distribution/rpc_admin_save_agent_v1.sql) | 保存代理 | | [`30_rpc/distribution/rpc_admin_save_division_v1.sql`](./30_rpc/distribution/rpc_admin_save_division_v1.sql) | 保存事业部 | #### 删除类(软删除) -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/distribution/rpc_admin_delete_agent_v1.sql`](./30_rpc/distribution/rpc_admin_delete_agent_v1.sql) | 删除代理(软删除) | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------- | :------------------- | +| [`30_rpc/distribution/rpc_admin_delete_agent_v1.sql`](./30_rpc/distribution/rpc_admin_delete_agent_v1.sql) | 删除代理(软删除) | | [`30_rpc/distribution/rpc_admin_delete_division_v1.sql`](./30_rpc/distribution/rpc_admin_delete_division_v1.sql) | 删除事业部(软删除) | #### 处理/审核类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------------------------------- | :----------- | | [`30_rpc/distribution/rpc_admin_process_agent_apply_v1.sql`](./30_rpc/distribution/rpc_admin_process_agent_apply_v1.sql) | 处理代理申请 | --- @@ -338,68 +390,75 @@ ### 3.7 Finance 域(财务管理) #### 查询/统计类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/finance/rpc_admin_balance_stats_v1.sql`](./30_rpc/finance/rpc_admin_balance_stats_v1.sql) | 余额统计 | -| [`30_rpc/finance/rpc_admin_balance_distribution_v1.sql`](./30_rpc/finance/rpc_admin_balance_distribution_v1.sql) | 余额分布 | -| [`30_rpc/finance/rpc_admin_balance_trend_v1.sql`](./30_rpc/finance/rpc_admin_balance_trend_v1.sql) | 余额趋势 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------- | :----------- | +| [`30_rpc/finance/rpc_admin_balance_stats_v1.sql`](./30_rpc/finance/rpc_admin_balance_stats_v1.sql) | 余额统计 | +| [`30_rpc/finance/rpc_admin_balance_distribution_v1.sql`](./30_rpc/finance/rpc_admin_balance_distribution_v1.sql) | 余额分布 | +| [`30_rpc/finance/rpc_admin_balance_trend_v1.sql`](./30_rpc/finance/rpc_admin_balance_trend_v1.sql) | 余额趋势 | | [`30_rpc/finance/rpc_admin_finance_bill_summary_v1.sql`](./30_rpc/finance/rpc_admin_finance_bill_summary_v1.sql) | 财务账单汇总 | -| [`30_rpc/finance/rpc_admin_finance_overview_v1.sql`](./30_rpc/finance/rpc_admin_finance_overview_v1.sql) | 财务概览 | -| [`30_rpc/finance/rpc_admin_invoice_list_v1.sql`](./30_rpc/finance/rpc_admin_invoice_list_v1.sql) | 发票列表 | -| [`30_rpc/finance/rpc_admin_user_bill_list_v1.sql`](./30_rpc/finance/rpc_admin_user_bill_list_v1.sql) | 用户账单列表 | -| [`30_rpc/finance/rpc_admin_recharge_list_v1.sql`](./30_rpc/finance/rpc_admin_recharge_list_v1.sql) | 充值列表 | -| [`30_rpc/finance/rpc_admin_extract_list_v1.sql`](./30_rpc/finance/rpc_admin_extract_list_v1.sql) | 提现列表 | +| [`30_rpc/finance/rpc_admin_finance_overview_v1.sql`](./30_rpc/finance/rpc_admin_finance_overview_v1.sql) | 财务概览 | +| [`30_rpc/finance/rpc_admin_invoice_list_v1.sql`](./30_rpc/finance/rpc_admin_invoice_list_v1.sql) | 发票列表 | +| [`30_rpc/finance/rpc_admin_user_bill_list_v1.sql`](./30_rpc/finance/rpc_admin_user_bill_list_v1.sql) | 用户账单列表 | +| [`30_rpc/finance/rpc_admin_recharge_list_v1.sql`](./30_rpc/finance/rpc_admin_recharge_list_v1.sql) | 充值列表 | +| [`30_rpc/finance/rpc_admin_extract_list_v1.sql`](./30_rpc/finance/rpc_admin_extract_list_v1.sql) | 提现列表 | #### 处理/审核类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------------- | :------- | | [`30_rpc/finance/rpc_admin_invoice_process_v1.sql`](./30_rpc/finance/rpc_admin_invoice_process_v1.sql) | 处理发票 | -| [`30_rpc/finance/rpc_admin_recharge_audit_v1.sql`](./30_rpc/finance/rpc_admin_recharge_audit_v1.sql) | 审核充值 | -| [`30_rpc/finance/rpc_admin_extract_review_v1.sql`](./30_rpc/finance/rpc_admin_extract_review_v1.sql) | 审核提现 | +| [`30_rpc/finance/rpc_admin_recharge_audit_v1.sql`](./30_rpc/finance/rpc_admin_recharge_audit_v1.sql) | 审核充值 | +| [`30_rpc/finance/rpc_admin_extract_review_v1.sql`](./30_rpc/finance/rpc_admin_extract_review_v1.sql) | 审核提现 | --- ### 3.8 Kefu 域(客服管理) #### 查询类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/kefu/rpc_admin_kefu_account_list_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_account_list_v1.sql) | 获取客服账号列表 | -| [`30_rpc/kefu/rpc_admin_kefu_auto_reply_list_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_auto_reply_list_v1.sql) | 获取自动回复列表 | -| [`30_rpc/kefu/rpc_admin_kefu_word_list_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_word_list_v1.sql) | 获取客服话术列表 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------- | :--------------- | +| [`30_rpc/kefu/rpc_admin_kefu_account_list_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_account_list_v1.sql) | 获取客服账号列表 | +| [`30_rpc/kefu/rpc_admin_kefu_auto_reply_list_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_auto_reply_list_v1.sql) | 获取自动回复列表 | +| [`30_rpc/kefu/rpc_admin_kefu_word_list_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_word_list_v1.sql) | 获取客服话术列表 | | [`30_rpc/kefu/rpc_admin_kefu_word_category_list_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_word_category_list_v1.sql) | 获取话术分类列表 | -| [`30_rpc/kefu/rpc_admin_kefu_feedback_list_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_feedback_list_v1.sql) | 获取反馈列表 | +| [`30_rpc/kefu/rpc_admin_kefu_feedback_list_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_feedback_list_v1.sql) | 获取反馈列表 | #### 保存/更新类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/kefu/rpc_admin_kefu_account_save_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_account_save_v1.sql) | 保存客服账号 | -| [`30_rpc/kefu/rpc_admin_kefu_auto_reply_save_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_auto_reply_save_v1.sql) | 保存自动回复 | -| [`30_rpc/kefu/rpc_admin_kefu_word_save_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_word_save_v1.sql) | 保存客服话术 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------- | :----------- | +| [`30_rpc/kefu/rpc_admin_kefu_account_save_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_account_save_v1.sql) | 保存客服账号 | +| [`30_rpc/kefu/rpc_admin_kefu_auto_reply_save_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_auto_reply_save_v1.sql) | 保存自动回复 | +| [`30_rpc/kefu/rpc_admin_kefu_word_save_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_word_save_v1.sql) | 保存客服话术 | | [`30_rpc/kefu/rpc_admin_kefu_word_category_save_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_word_category_save_v1.sql) | 保存话术分类 | #### 删除类(软删除) -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/kefu/rpc_admin_kefu_account_delete_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_account_delete_v1.sql) | 删除客服账号(软删除) | -| [`30_rpc/kefu/rpc_admin_kefu_auto_reply_delete_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_auto_reply_delete_v1.sql) | 删除自动回复(软删除) | -| [`30_rpc/kefu/rpc_admin_kefu_word_delete_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_word_delete_v1.sql) | 删除客服话术(软删除) | + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------------------- | :--------------------- | +| [`30_rpc/kefu/rpc_admin_kefu_account_delete_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_account_delete_v1.sql) | 删除客服账号(软删除) | +| [`30_rpc/kefu/rpc_admin_kefu_auto_reply_delete_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_auto_reply_delete_v1.sql) | 删除自动回复(软删除) | +| [`30_rpc/kefu/rpc_admin_kefu_word_delete_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_word_delete_v1.sql) | 删除客服话术(软删除) | | [`30_rpc/kefu/rpc_admin_kefu_word_category_delete_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_word_category_delete_v1.sql) | 删除话术分类(软删除) | #### 状态/处理类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/kefu/rpc_admin_kefu_account_set_status_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_account_set_status_v1.sql) | 设置客服账号状态 | + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------------- | :--------------- | +| [`30_rpc/kefu/rpc_admin_kefu_account_set_status_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_account_set_status_v1.sql) | 设置客服账号状态 | | [`30_rpc/kefu/rpc_admin_kefu_auto_reply_set_status_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_auto_reply_set_status_v1.sql) | 设置自动回复状态 | -| [`30_rpc/kefu/rpc_admin_kefu_feedback_process_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_feedback_process_v1.sql) | 处理客服反馈 | +| [`30_rpc/kefu/rpc_admin_kefu_feedback_process_v1.sql`](./30_rpc/kefu/rpc_admin_kefu_feedback_process_v1.sql) | 处理客服反馈 | --- ### 3.9 Marketing 域(营销管理) #### 查询/统计类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------------------- | :----------- | | [`30_rpc/marketing/rpc_admin_get_integral_stats_v1.sql`](./30_rpc/marketing/rpc_admin_get_integral_stats_v1.sql) | 获取积分统计 | --- @@ -407,32 +466,35 @@ ### 3.10 Order 域(订单管理) #### 查询/统计类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/order/rpc_admin_order_list_v1.sql`](./30_rpc/order/rpc_admin_order_list_v1.sql) | 获取订单列表 | -| [`30_rpc/order/rpc_admin_order_source_stats_v1.sql`](./30_rpc/order/rpc_admin_order_source_stats_v1.sql) | 订单来源统计 | -| [`30_rpc/order/rpc_admin_order_type_stats_v1.sql`](./30_rpc/order/rpc_admin_order_type_stats_v1.sql) | 订单类型统计 | -| [`30_rpc/order/rpc_admin_order_stats_v1.sql`](./30_rpc/order/rpc_admin_order_stats_v1.sql) | 订单统计 | -| [`30_rpc/order/rpc_admin_order_trend_v1.sql`](./30_rpc/order/rpc_admin_order_trend_v1.sql) | 订单趋势 | + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------------- | :----------- | +| [`30_rpc/order/rpc_admin_order_list_v1.sql`](./30_rpc/order/rpc_admin_order_list_v1.sql) | 获取订单列表 | +| [`30_rpc/order/rpc_admin_order_source_stats_v1.sql`](./30_rpc/order/rpc_admin_order_source_stats_v1.sql) | 订单来源统计 | +| [`30_rpc/order/rpc_admin_order_type_stats_v1.sql`](./30_rpc/order/rpc_admin_order_type_stats_v1.sql) | 订单类型统计 | +| [`30_rpc/order/rpc_admin_order_stats_v1.sql`](./30_rpc/order/rpc_admin_order_stats_v1.sql) | 订单统计 | +| [`30_rpc/order/rpc_admin_order_trend_v1.sql`](./30_rpc/order/rpc_admin_order_trend_v1.sql) | 订单趋势 | | [`30_rpc/order/rpc_admin_write_off_record_list_v1.sql`](./30_rpc/order/rpc_admin_write_off_record_list_v1.sql) | 核销记录列表 | -| [`30_rpc/order/rpc_admin_refund_order_list_v1.sql`](./30_rpc/order/rpc_admin_refund_order_list_v1.sql) | 退款订单列表 | -| [`30_rpc/order/rpc_admin_cashier_order_list_v1.sql`](./30_rpc/order/rpc_admin_cashier_order_list_v1.sql) | 收银订单列表 | +| [`30_rpc/order/rpc_admin_refund_order_list_v1.sql`](./30_rpc/order/rpc_admin_refund_order_list_v1.sql) | 退款订单列表 | +| [`30_rpc/order/rpc_admin_cashier_order_list_v1.sql`](./30_rpc/order/rpc_admin_cashier_order_list_v1.sql) | 收银订单列表 | --- ### 3.11 Product 域(商品管理) #### 查询/统计类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------------- | :----------- | | [`30_rpc/product/rpc_admin_get_product_reviews_v1.sql`](./30_rpc/product/rpc_admin_get_product_reviews_v1.sql) | 获取商品评价 | | [`30_rpc/product/rpc_admin_product_count_stats_v1.sql`](./30_rpc/product/rpc_admin_product_count_stats_v1.sql) | 商品数量统计 | -| [`30_rpc/product/rpc_admin_product_analytics_v1.sql`](./30_rpc/product/rpc_admin_product_analytics_v1.sql) | 商品分析 | -| [`30_rpc/product/rpc_admin_product_trend_v1.sql`](./30_rpc/product/rpc_admin_product_trend_v1.sql) | 商品趋势 | +| [`30_rpc/product/rpc_admin_product_analytics_v1.sql`](./30_rpc/product/rpc_admin_product_analytics_v1.sql) | 商品分析 | +| [`30_rpc/product/rpc_admin_product_trend_v1.sql`](./30_rpc/product/rpc_admin_product_trend_v1.sql) | 商品趋势 | #### 删除类(软删除) -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------------- | :--------------------- | | [`30_rpc/product/rpc_admin_category_delete_v1.sql`](./30_rpc/product/rpc_admin_category_delete_v1.sql) | 删除商品分类(软删除) | --- @@ -440,45 +502,50 @@ ### 3.12 User 域(用户管理) #### 查询类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------- | :--------------- | | [`30_rpc/user/rpc_admin_user_label_list_v1.sql`](./30_rpc/user/rpc_admin_user_label_list_v1.sql) | 获取用户标签列表 | | [`30_rpc/user/rpc_admin_user_group_list_v1.sql`](./30_rpc/user/rpc_admin_user_group_list_v1.sql) | 获取用户分组列表 | | [`30_rpc/user/rpc_admin_user_level_list_v1.sql`](./30_rpc/user/rpc_admin_user_level_list_v1.sql) | 获取用户等级列表 | #### 保存/更新类 -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------- | :----------- | | [`30_rpc/user/rpc_admin_user_label_save_v1.sql`](./30_rpc/user/rpc_admin_user_label_save_v1.sql) | 保存用户标签 | | [`30_rpc/user/rpc_admin_user_group_save_v1.sql`](./30_rpc/user/rpc_admin_user_group_save_v1.sql) | 保存用户分组 | | [`30_rpc/user/rpc_admin_user_level_save_v1.sql`](./30_rpc/user/rpc_admin_user_level_save_v1.sql) | 保存用户等级 | #### 删除类(软删除) -| 文件路径 | 说明 | -|:---|:---| + +| 文件路径 | 说明 | +| :--------------------------------------------------------------------------------------------------- | :--------------------- | | [`30_rpc/user/rpc_admin_user_label_delete_v1.sql`](./30_rpc/user/rpc_admin_user_label_delete_v1.sql) | 删除用户标签(软删除) | | [`30_rpc/user/rpc_admin_user_group_delete_v1.sql`](./30_rpc/user/rpc_admin_user_group_delete_v1.sql) | 删除用户分组(软删除) | | [`30_rpc/user/rpc_admin_user_level_delete_v1.sql`](./30_rpc/user/rpc_admin_user_level_delete_v1.sql) | 删除用户等级(软删除) | #### 状态/可见性管理类 -| 文件路径 | 说明 | -|:---|:---| -| [`30_rpc/user/rpc_admin_user_label_set_status_v1.sql`](./30_rpc/user/rpc_admin_user_label_set_status_v1.sql) | 设置用户标签状态 | -| [`30_rpc/user/rpc_admin_user_group_set_status_v1.sql`](./30_rpc/user/rpc_admin_user_group_set_status_v1.sql) | 设置用户分组状态 | -| [`30_rpc/user/rpc_admin_user_level_set_status_v1.sql`](./30_rpc/user/rpc_admin_user_level_set_status_v1.sql) | 设置用户等级状态 | + +| 文件路径 | 说明 | +| :------------------------------------------------------------------------------------------------------------- | :----------------- | +| [`30_rpc/user/rpc_admin_user_label_set_status_v1.sql`](./30_rpc/user/rpc_admin_user_label_set_status_v1.sql) | 设置用户标签状态 | +| [`30_rpc/user/rpc_admin_user_group_set_status_v1.sql`](./30_rpc/user/rpc_admin_user_group_set_status_v1.sql) | 设置用户分组状态 | +| [`30_rpc/user/rpc_admin_user_level_set_status_v1.sql`](./30_rpc/user/rpc_admin_user_level_set_status_v1.sql) | 设置用户等级状态 | | [`30_rpc/user/rpc_admin_user_level_set_visible_v1.sql`](./30_rpc/user/rpc_admin_user_level_set_visible_v1.sql) | 设置用户等级可见性 | --- ### 3.13 Analytics 域(数据分析) -| 文件路径 | 说明 | -|:---|:---| +| 文件路径 | 说明 | +| :----------------------------------------------------------------------------------------------------------------------------------- | :--------------- | | [`30_rpc/analytics/rpc_analytics_user_gender_distribution_v1.sql`](./30_rpc/analytics/rpc_analytics_user_gender_distribution_v1.sql) | 用户性别分布分析 | --- ## 执行后验证清单 + - 字段存在性:抽查任一涉及表,确认 `deleted_at/deleted_by` 字段存在。 - 索引存在性:确认 `idx__soft_delete` 存在。 - RLS 生效:软删一条数据后,使用正常查询路径确认该条记录不可见。 diff --git a/mall_sql/migrations/20260521_medical_mall_categories_v1.sql b/mall_sql/migrations/20260521_medical_mall_categories_v1.sql new file mode 100644 index 00000000..6e8a6484 --- /dev/null +++ b/mall_sql/migrations/20260521_medical_mall_categories_v1.sql @@ -0,0 +1,269 @@ +-- Medical mall categories migration +-- Includes: schema + RLS + initial seed + +BEGIN; + +CREATE TABLE IF NOT EXISTS public.medical_mall_categories ( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + parent_id TEXT NULL REFERENCES public.medical_mall_categories(id), + level INTEGER NOT NULL CHECK (level IN (1, 2)), + sort_order INTEGER NOT NULL DEFAULT 0, + icon TEXT, + image_url TEXT, + description TEXT, + scene TEXT NOT NULL DEFAULT 'medical_mall', + category_type TEXT NOT NULL DEFAULT 'normal', + compliance_type TEXT NOT NULL DEFAULT 'normal', + is_active BOOLEAN NOT NULL DEFAULT TRUE, + deleted_at TIMESTAMPTZ NULL, + deleted_by UUID NULL REFERENCES public.ak_users(id), + restored_at TIMESTAMPTZ NULL, + restored_by UUID NULL REFERENCES public.ak_users(id), + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +COMMENT ON TABLE public.medical_mall_categories IS '医疗商城独立分类表'; +COMMENT ON COLUMN public.medical_mall_categories.scene IS '分类场景,如 medical_mall / home_mall'; +COMMENT ON COLUMN public.medical_mall_categories.category_type IS '分类类型:device / otc / care / rehab / elderly / nutrition / protection / tcm / all'; +COMMENT ON COLUMN public.medical_mall_categories.compliance_type IS '合规类型:normal / otc / device_class_i / device_class_ii / device_class_iii / rx_hidden'; + +CREATE INDEX IF NOT EXISTS idx_medical_mall_categories_parent + ON public.medical_mall_categories(parent_id) + WHERE deleted_at IS NULL; + +CREATE INDEX IF NOT EXISTS idx_medical_mall_categories_level_sort + ON public.medical_mall_categories(level, sort_order) + WHERE deleted_at IS NULL; + +CREATE INDEX IF NOT EXISTS idx_medical_mall_categories_scene_active + ON public.medical_mall_categories(scene, is_active) + WHERE deleted_at IS NULL; + +CREATE TABLE IF NOT EXISTS public.medical_mall_product_categories ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + product_id UUID NOT NULL REFERENCES public.ml_products(id) ON DELETE CASCADE, + category_id TEXT NOT NULL REFERENCES public.medical_mall_categories(id), + is_primary BOOLEAN NOT NULL DEFAULT FALSE, + sort_order INTEGER NOT NULL DEFAULT 0, + deleted_at TIMESTAMPTZ NULL, + deleted_by UUID NULL REFERENCES public.ak_users(id), + restored_at TIMESTAMPTZ NULL, + restored_by UUID NULL REFERENCES public.ak_users(id), + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + UNIQUE (product_id, category_id) +); + +COMMENT ON TABLE public.medical_mall_product_categories IS '医疗商城商品与分类关联表'; + +CREATE INDEX IF NOT EXISTS idx_medical_mall_product_categories_category + ON public.medical_mall_product_categories(category_id, sort_order) + WHERE deleted_at IS NULL; + +CREATE INDEX IF NOT EXISTS idx_medical_mall_product_categories_product + ON public.medical_mall_product_categories(product_id) + WHERE deleted_at IS NULL; + +ALTER TABLE public.medical_mall_categories ENABLE ROW LEVEL SECURITY; +ALTER TABLE public.medical_mall_product_categories ENABLE ROW LEVEL SECURITY; + +DROP POLICY IF EXISTS medical_mall_categories_public_select_active ON public.medical_mall_categories; +CREATE POLICY medical_mall_categories_public_select_active +ON public.medical_mall_categories +FOR SELECT +TO anon, authenticated +USING ( + deleted_at IS NULL + AND is_active = TRUE + AND compliance_type <> 'rx_hidden' +); + +DROP POLICY IF EXISTS medical_mall_product_categories_public_select_active ON public.medical_mall_product_categories; +CREATE POLICY medical_mall_product_categories_public_select_active +ON public.medical_mall_product_categories +FOR SELECT +TO anon, authenticated +USING (deleted_at IS NULL); + +INSERT INTO public.medical_mall_categories ( + id, name, parent_id, level, sort_order, icon, image_url, description, scene, category_type, compliance_type, is_active, created_at, updated_at +) +VALUES +('med_device', '医疗器械', NULL, 1, 10, '🩺', NULL, '家庭监测与基础器械', 'medical_mall', 'device', 'device_class_i', TRUE, NOW(), NOW()), +('otc_medicine', '家庭常备药', NULL, 1, 20, '💊', NULL, 'OTC 家庭常备药与应急用药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('rehab_care', '康复护理', NULL, 1, 30, '🩹', NULL, '术后恢复、敷料护具与护理用品', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), +('chronic_monitor', '慢病监测', NULL, 1, 40, '📈', NULL, '高血压、糖尿病与家庭检测场景', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('elderly_aid', '适老用品', NULL, 1, 50, '🧓', NULL, '长者安全辅助与居家适老用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('nutrition_health', '营养保健', NULL, 1, 60, '🥛', NULL, '维生素、钙片、蛋白营养等保健品', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('protection_disinfection', '防护消毒', NULL, 1, 70, '😷', NULL, '口罩、消毒、急救与防护耗材', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('tcm_health', '中医保健', NULL, 1, 80, '🌿', NULL, '艾灸、贴敷、按摩理疗与草本养护', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('home_care_daily', '居家护理', NULL, 1, 90, '🏠', NULL, '伤口、口腔、皮肤与家庭健康工具', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('all_medical', '全部', NULL, 1, 100, '🧺', NULL, '查看全部康养医疗商品', 'medical_mall', 'all', 'normal', TRUE, NOW(), NOW()), + +('blood_pressure_monitor', '血压计', 'med_device', 2, 11, '🫀', NULL, '家庭血压监测设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('blood_glucose_meter', '血糖仪', 'med_device', 2, 12, '🩸', NULL, '家庭血糖检测设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('oximeter', '血氧仪', 'med_device', 2, 13, '💗', NULL, '指夹式血氧监测设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('thermometer', '体温计', 'med_device', 2, 14, '🌡️', NULL, '额温枪与电子体温计', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('oxygen_concentrator', '制氧机', 'med_device', 2, 15, '🫁', NULL, '家庭制氧与吸氧辅助设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('nebulizer', '雾化器', 'med_device', 2, 16, '💨', NULL, '家用雾化护理设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('wheelchair_crutch', '轮椅拐杖', 'med_device', 2, 17, '🦽', NULL, '轮椅、拐杖与行动辅助器具', 'medical_mall', 'device', 'device_class_i', TRUE, NOW(), NOW()), +('nursing_bed', '护理床', 'med_device', 2, 18, '🛏️', NULL, '护理床与居家照护床具', 'medical_mall', 'device', 'device_class_i', TRUE, NOW(), NOW()), + +('cold_fever', '感冒发烧', 'otc_medicine', 2, 21, '🤒', NULL, '感冒、退热与家庭常备药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('cough_throat', '咳嗽咽喉', 'otc_medicine', 2, 22, '🗣️', NULL, '咳嗽、咽喉与润喉护理', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('stomach_medicine', '肠胃用药', 'otc_medicine', 2, 23, '🥣', NULL, '肠胃调理与胃肠常备药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('skin_external', '皮肤外用', 'otc_medicine', 2, 24, '🧴', NULL, '皮肤喷剂、软膏与外用护理', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('eye_ear_nose', '眼耳口鼻', 'otc_medicine', 2, 25, '👁️', NULL, '眼耳鼻喉口腔常备用品', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('pain_relief', '止痛用药', 'otc_medicine', 2, 26, '🩹', NULL, '止痛、舒缓与应急常备药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('trauma_sprain', '跌打损伤', 'otc_medicine', 2, 27, '🦴', NULL, '跌打扭伤与运动损伤护理', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('child_medicine', '儿童用药', 'otc_medicine', 2, 28, '🧒', NULL, '儿童常备药与护理用品', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), + +('postop_rehab', '术后康复', 'rehab_care', 2, 31, '🩺', NULL, '术后恢复与支撑护理', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), +('wound_dressing', '伤口敷料', 'rehab_care', 2, 32, '🩹', NULL, '敷料、纱布与换药护理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('brace_support', '护具支具', 'rehab_care', 2, 33, '🦵', NULL, '护腰、护膝与支撑固定用品', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), +('rehab_training', '康复训练器', 'rehab_care', 2, 34, '🏋️', NULL, '康复训练与恢复辅助设备', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), +('physiotherapy_hot', '理疗热敷', 'rehab_care', 2, 35, '🔥', NULL, '热敷理疗与家庭舒缓护理', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), +('mobility_training', '行动训练', 'rehab_care', 2, 36, '🚶', NULL, '恢复行动能力的辅助训练用品', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), + +('hypertension', '高血压管理', 'chronic_monitor', 2, 41, '❤️', NULL, '高血压居家管理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('diabetes', '糖尿病管理', 'chronic_monitor', 2, 42, '🩸', NULL, '血糖监测与糖尿病管理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('cardiovascular', '心脑血管', 'chronic_monitor', 2, 43, '🫀', NULL, '心脑血管健康管理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('respiratory_health', '呼吸健康', 'chronic_monitor', 2, 44, '🫁', NULL, '呼吸道护理与呼吸健康', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('weight_bodyfat', '体重体脂', 'chronic_monitor', 2, 45, '⚖️', NULL, '体重与体脂监测', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('home_testing', '家庭检测', 'chronic_monitor', 2, 46, '🧪', NULL, '家庭常用健康检测用品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), + +('anti_slip', '防滑安全', 'elderly_aid', 2, 51, '🧱', NULL, '长者防滑与跌倒预防', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('elderly_bathroom', '适老卫浴', 'elderly_aid', 2, 52, '🚿', NULL, '浴室扶手与适老卫浴辅助', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('eating_aid', '助餐用品', 'elderly_aid', 2, 53, '🍽️', NULL, '适老助餐与餐具辅助', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('bathing_aid', '助浴用品', 'elderly_aid', 2, 54, '🛁', NULL, '助浴椅与洗护辅助用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('incontinence_care', '失禁护理', 'elderly_aid', 2, 55, '🧻', NULL, '长者失禁护理用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('daily_living_aid', '生活辅助', 'elderly_aid', 2, 56, '🪑', NULL, '日常起居与生活辅助用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), + +('vitamin', '维生素', 'nutrition_health', 2, 61, '🍊', NULL, '复合维生素与维 C 等营养补充', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('calcium', '钙铁锌硒', 'nutrition_health', 2, 62, '🦴', NULL, '钙铁锌硒等基础营养', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('protein', '蛋白营养', 'nutrition_health', 2, 63, '🥛', NULL, '蛋白粉与恢复期营养', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('elderly_nutrition', '老人营养', 'nutrition_health', 2, 64, '👴', NULL, '适合长者的专用营养补充', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('gut_health', '肠道益生菌', 'nutrition_health', 2, 65, '🦠', NULL, '益生菌与肠胃营养补充', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('immune_support', '免疫支持', 'nutrition_health', 2, 66, '🛡️', NULL, '免疫支持与日常补给', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), + +('mask', '口罩', 'protection_disinfection', 2, 71, '😷', NULL, '日常口罩与防护耗材', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('disinfectant', '消毒液', 'protection_disinfection', 2, 72, '🧴', NULL, '家庭与环境消毒用品', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('alcohol_wipes', '酒精湿巾', 'protection_disinfection', 2, 73, '🧻', NULL, '酒精湿巾与便携消毒', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('gloves', '手套', 'protection_disinfection', 2, 74, '🧤', NULL, '检查手套与护理手套', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('first_aid', '急救包', 'protection_disinfection', 2, 75, '🧰', NULL, '家庭急救包与应急护理', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('dressing_tools', '棉签纱布', 'protection_disinfection', 2, 76, '🧺', NULL, '棉签纱布与护理耗材', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), + +('moxibustion', '艾灸拔罐', 'tcm_health', 2, 81, '🔥', NULL, '艾灸、拔罐与温灸理疗', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('herbal_drink', '养生茶饮', 'tcm_health', 2, 82, '🍵', NULL, '草本茶饮与养生冲饮', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('tcm_patch', '中医贴敷', 'tcm_health', 2, 83, '🩹', NULL, '中医贴敷与草本热敷', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('medicated_diet', '药膳滋补', 'tcm_health', 2, 84, '🥣', NULL, '药膳汤料与滋补调养', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('massage_tools', '按摩理疗', 'tcm_health', 2, 85, '💆', NULL, '按摩仪、刮痧与理疗工具', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('foot_bath', '泡脚养生', 'tcm_health', 2, 86, '🪣', NULL, '泡脚包与足浴理疗用品', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), + +('wound_care', '伤口护理', 'home_care_daily', 2, 91, '🩹', NULL, '创面处理与换药护理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('oral_care', '口腔护理', 'home_care_daily', 2, 92, '🦷', NULL, '口腔护理与清洁用品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('skin_care', '皮肤护理', 'home_care_daily', 2, 93, '🧴', NULL, '皮肤护理与修护用品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('cleaning_care', '清洁护理', 'home_care_daily', 2, 94, '🫧', NULL, '清洁护理与日常消耗品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('nursing_consumables', '护理耗材', 'home_care_daily', 2, 95, '📦', NULL, '棉签、纱布、护理垫等耗材', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('home_health_tool', '家庭健康工具', 'home_care_daily', 2, 96, '🧰', NULL, '家庭健康小工具与辅具', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()) +ON CONFLICT (id) DO UPDATE SET + name = EXCLUDED.name, + parent_id = EXCLUDED.parent_id, + level = EXCLUDED.level, + sort_order = EXCLUDED.sort_order, + icon = EXCLUDED.icon, + image_url = EXCLUDED.image_url, + description = EXCLUDED.description, + scene = EXCLUDED.scene, + category_type = EXCLUDED.category_type, + compliance_type = EXCLUDED.compliance_type, + is_active = EXCLUDED.is_active, + deleted_at = NULL, + updated_at = NOW(); + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'blood_pressure_monitor', TRUE, 10, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%血压计%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'blood_glucose_meter', TRUE, 10, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%血糖仪%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'thermometer', TRUE, 10, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%体温计%' OR p.name ILIKE '%额温枪%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'oxygen_concentrator', TRUE, 10, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%制氧机%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'nebulizer', TRUE, 10, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%雾化器%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'mask', TRUE, 20, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%口罩%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'disinfectant', TRUE, 20, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%消毒%' OR p.name ILIKE '%酒精%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'wound_care', TRUE, 20, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%创可贴%' OR p.name ILIKE '%纱布%' OR p.name ILIKE '%敷料%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'wheelchair_crutch', TRUE, 20, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%轮椅%' OR p.name ILIKE '%拐杖%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'nursing_bed', TRUE, 20, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%护理床%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'calcium', TRUE, 30, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%钙片%' OR p.name ILIKE '%钙铁锌%' OR p.name ILIKE '%补钙%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'vitamin', TRUE, 30, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%维生素%' OR p.name ILIKE '%维C%' OR p.name ILIKE '%维D%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'protein', TRUE, 30, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%蛋白%' OR p.name ILIKE '%蛋白粉%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'cold_fever', TRUE, 40, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%感冒%' OR p.name ILIKE '%退热%' OR p.name ILIKE '%发烧%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +COMMIT; \ No newline at end of file diff --git a/mock/delivery-care.mock.uts b/mock/delivery-care.mock.uts new file mode 100644 index 00000000..16b5288f --- /dev/null +++ b/mock/delivery-care.mock.uts @@ -0,0 +1,681 @@ +import type { + DeliveryAbnormalReportType, + DeliveryDashboardType, + DeliveryExceptionPayloadType, + DeliveryInfoType, + DeliveryLocationType, + DeliveryOnlineStatus, + DeliveryOrderStatus, + DeliveryOrderType, + DeliveryRecordType, + DeliveryServiceItemType, + DeliveryServiceRecordType, + DeliveryStatusLogType, + DeliveryTimelineItemType +} from '@/types/delivery.uts' + +const PROFILE_KEY = 'delivery_care_profile' +const ORDER_KEY = 'delivery_care_orders' + +function nowText(): string { + return new Date().toISOString().replace('T', ' ').substring(0, 19) +} + +function cloneProfile(profile: DeliveryInfoType): DeliveryInfoType { + return JSON.parse(JSON.stringify(profile)) as DeliveryInfoType +} + +function cloneOrder(order: DeliveryOrderType): DeliveryOrderType { + return JSON.parse(JSON.stringify(order)) as DeliveryOrderType +} + +function cloneOrders(orders: Array): Array { + return JSON.parse(JSON.stringify(orders)) as Array +} + +function createStatusText(status: DeliveryOrderStatus): string { + if (status == 'pending_assignment' || status == 'pending_accept') return '待接单' + if (status == 'accepted') return '已接单' + if (status == 'waiting_departure') return '待出发' + if (status == 'departed' || status == 'on_the_way') return '已出发' + if (status == 'arrived') return '已到达' + if (status == 'checked_in') return '已签到' + if (status == 'in_service' || status == 'serving') return '服务中' + if (status == 'pending_confirm' || status == 'pending_acceptance' || status == 'pending_submit') return '待确认' + if (status == 'completed') return '已完成' + if (status == 'rejected') return '已拒单' + if (status == 'cancelled') return '已取消' + if (status == 'abnormal' || status == 'exception_pending') return '异常上报' + if (status == 'terminated') return '服务终止' + return '已归档' +} + +function createStatusTone(status: DeliveryOrderStatus): string { + if (status == 'pending_assignment' || status == 'pending_accept' || status == 'pending_confirm' || status == 'pending_acceptance' || status == 'pending_submit') return 'warning' + if (status == 'completed') return 'success' + if (status == 'rejected' || status == 'cancelled' || status == 'terminated') return 'neutral' + if (status == 'abnormal' || status == 'exception_pending') return 'danger' + return 'primary' +} + +function createStatusLog(orderId: string, fromStatus: DeliveryOrderStatus, toStatus: DeliveryOrderStatus, remark: string): DeliveryStatusLogType { + return { + id: orderId + '-log-' + nowText().replace(/[-: ]/g, ''), + orderId, + fromStatus, + toStatus, + operatorRole: 'service_staff', + operatorId: 'mock-staff-001', + remark, + createdAt: nowText() + } as DeliveryStatusLogType +} + +function createTimeline(title: string, description: string): DeliveryTimelineItemType { + return { + id: 'timeline-' + nowText().replace(/[-: ]/g, ''), + title, + time: nowText(), + description + } as DeliveryTimelineItemType +} + +function createServiceItems(orderId: string): Array { + return [ + { + id: orderId + '-item-1', + name: '生命体征监测', + required: true, + completed: false, + incompleteReason: '', + remark: '', + updatedAt: '' + } as DeliveryServiceItemType, + { + id: orderId + '-item-2', + name: '基础照护服务', + required: true, + completed: false, + incompleteReason: '', + remark: '', + updatedAt: '' + } as DeliveryServiceItemType, + { + id: orderId + '-item-3', + name: '家属沟通与宣教', + required: false, + completed: false, + incompleteReason: '', + remark: '', + updatedAt: '' + } as DeliveryServiceItemType + ] +} + +function createProfile(): DeliveryInfoType { + return { + id: 'mock-staff-001', + userId: 'mock-delivery-user-001', + staffNo: 'CARE-202605-001', + name: '陈护理', + phone: '13600001111', + role: 'care_worker', + status: 'active', + organizationId: 'org-care-001', + organizationName: '梅江区居家康护中心', + certificates: [] as Array, + certificateStatus: 'valid', + certificateExpireAt: '2027-12-31', + onlineStatus: 'online', + serviceArea: '梅江区 / 梅县区', + skills: ['上门助浴', '康复陪护', '慢病随访', '居家照护'], + avatarUrl: '', + todayAccepted: 2, + todayServing: 1, + todayCompleted: 1, + usesMock: true + } as DeliveryInfoType +} + +function createOrder( + orderId: string, + serviceName: string, + serviceType: string, + status: DeliveryOrderStatus, + appointmentTime: string, + duration: number, + price: number, + staffIncome: number, + elderName: string, + elderGender: string, + elderAge: number, + elderPhone: string, + contactName: string, + contactPhone: string, + contactRelation: string, + address: string, + addressDetail: string, + distance: string, + riskTags: Array, + healthTags: Array, + needFamilyPresent: boolean, + needMaterials: boolean, + remark: string +): DeliveryOrderType { + const statusText = createStatusText(status) + const items = createServiceItems(orderId) + return { + id: orderId, + orderNo: 'CARE-' + orderId.toUpperCase(), + serviceType, + serviceName, + serviceCategory: serviceType, + serviceItems: items, + serviceContentOptions: ['基础护理', '生命体征监测', '安全巡视', '家属沟通'], + elderId: 'elder-' + orderId, + elderName, + elderNameMasked: elderName.substring(0, 1) + '**', + elderGender, + elderAge, + elderPhone, + elderPhoneMasked: elderPhone.substring(0, 3) + '****' + elderPhone.substring(elderPhone.length - 4), + fullElderName: elderName, + fullPhone: elderPhone, + contactName, + contactPhone, + contactRelation, + addressSummary: address, + address, + addressDetail, + fullAddress: address + ' ' + addressDetail, + latitude: 24.2898, + longitude: 116.1179, + appointmentTime, + appointmentStartTime: appointmentTime, + appointmentEndTime: appointmentTime, + duration, + estimatedDuration: duration, + price, + staffIncome, + distance, + actualStartTime: '', + actualEndTime: '', + status, + statusText, + statusTone: createStatusTone(status), + riskTags, + healthTags, + careLevel: '护理二级', + needFamilyPresent, + needMaterials, + remark, + merchantId: 'merchant-care-001', + merchantName: '梅江区居家康护中心', + deliveryStaffId: 'mock-staff-001', + deliveryStaffName: '陈护理', + acceptTime: '', + rejectTime: '', + departTime: '', + arriveTime: '', + checkinTime: '', + startServiceTime: '', + finishTime: '', + cancelReason: '', + exceptionType: '', + exceptionDesc: '', + evidenceList: [] as Array, + signatureUrl: '', + signatureName: '', + satisfactionStatus: '待确认', + settlementStatus: '待结算', + archiveStatus: '未归档', + createdAt: nowText(), + updatedAt: nowText(), + notices: ['请提前 15 分钟电话联系', '如遇突发异常先上报再处置'], + timeline: [createTimeline('订单已生成', '平台已生成上门服务订单')], + statusLog: [createStatusLog(orderId, status, status, '初始化 mock 订单')], + serviceSummary: '', + progressNote: '', + distanceKm: distance, + allowCheckinRadiusMeters: 120, + lastLocation: null, + trackPoints: [] as Array, + serviceRecord: null, + abnormalReport: null + } as DeliveryOrderType +} + +function createDefaultOrders(): Array { + const orders = [ + createOrder('mock-care-001', '上门助浴', '生活照护', 'pending_assignment', '2026-05-20 09:00', 90, 199, 128, '李秀珍', '女', 79, '13800131024', '李晓兰', '13900139000', '女儿', '梅江区江南路 18 号', '2 栋 602 室', '2.4km', ['高龄', '行动不便'], ['高血压'], true, true, '请准备防滑垫和浴后保暖衣物'), + createOrder('mock-care-002', '康复陪护', '康复护理', 'pending_assignment', '2026-05-20 10:30', 120, 260, 160, '张志坤', '男', 83, '13700132233', '张春梅', '13600136666', '女儿', '梅县区新城锦绣花园 5 栋', '1403 室', '5.8km', ['需家属在场'], ['术后恢复'], true, true, '需携带弹力带与康复手册'), + createOrder('mock-care-003', '陪诊服务', '陪诊陪护', 'accepted', '2026-05-20 13:00', 180, 320, 220, '黄玉英', '女', 76, '13500135566', '黄晓娟', '13500130088', '女儿', '梅江区学海路康养公寓 A 座', '907 室', '1.1km', ['高龄'], ['糖尿病'], false, false, '就诊前需先核对病历资料'), + createOrder('mock-care-004', '慢病随访', '健康管理', 'departed', '2026-05-20 14:30', 60, 168, 108, '陈国辉', '男', 81, '13900133301', '陈丽芳', '13800136660', '妻子', '梅县区扶老社区 11 栋', '203 室', '3.6km', ['行动不便'], ['高血压', '冠心病'], false, true, '重点测量血压并复核药盒'), + createOrder('mock-care-005', '居家照护', '长期照护', 'in_service', '2026-05-20 15:00', 120, 288, 190, '王月兰', '女', 87, '13400137744', '王秀玲', '13600139922', '女儿', '梅江区东汇城旁康颐楼 3 单元', '1204 室', '4.2km', ['失能', '需家属在场'], ['血糖异常'], true, true, '服务中注意翻身护理与进食观察'), + createOrder('mock-care-006', '上门护理', '护理服务', 'completed', '2026-05-19 16:00', 90, 230, 150, '刘建华', '男', 72, '13300136655', '刘敏', '13300998877', '儿子', '梅江区和顺苑 9 栋', '401 室', '6.0km', ['术后恢复'], ['低蛋白'], false, false, '完成换药与术后宣教') + ] + orders[2].acceptTime = '2026-05-20 11:40:00' + orders[2].timeline.unshift(createTimeline('已接单', '服务人员已确认接单')) + orders[2].statusLog.unshift(createStatusLog(orders[2].id, 'pending_assignment', 'accepted', '手动接单')) + orders[3].acceptTime = '2026-05-20 12:00:00' + orders[3].departTime = '2026-05-20 13:58:00' + orders[3].timeline.unshift(createTimeline('已出发', '服务人员已从机构出发')) + orders[3].statusLog.unshift(createStatusLog(orders[3].id, 'accepted', 'departed', '已出发')) + orders[4].acceptTime = '2026-05-20 13:00:00' + orders[4].departTime = '2026-05-20 14:00:00' + orders[4].arriveTime = '2026-05-20 14:40:00' + orders[4].checkinTime = '2026-05-20 14:45:00' + orders[4].startServiceTime = '2026-05-20 14:50:00' + orders[4].actualStartTime = '2026-05-20 14:50:00' + orders[4].serviceItems[0].completed = true + orders[4].serviceItems[0].remark = '血压 132/82,心率 76 次/分' + orders[4].serviceItems[0].updatedAt = '2026-05-20 15:10:00' + orders[4].timeline.unshift(createTimeline('开始服务', '已进入服务执行阶段')) + orders[4].statusLog.unshift(createStatusLog(orders[4].id, 'checked_in', 'in_service', '开始服务')) + orders[5].acceptTime = '2026-05-19 14:30:00' + orders[5].departTime = '2026-05-19 15:10:00' + orders[5].arriveTime = '2026-05-19 15:48:00' + orders[5].checkinTime = '2026-05-19 15:52:00' + orders[5].startServiceTime = '2026-05-19 15:55:00' + orders[5].finishTime = '2026-05-19 17:18:00' + orders[5].actualStartTime = '2026-05-19 15:55:00' + orders[5].actualEndTime = '2026-05-19 17:18:00' + orders[5].serviceSummary = '已完成换药、伤口巡视和家属宣教。' + orders[5].serviceRecord = { + id: 'record-' + orders[5].id, + orderId: orders[5].id, + startTime: '2026-05-19 15:55:00', + endTime: '2026-05-19 17:18:00', + actualDurationMinutes: 83, + serviceItems: orders[5].serviceItems, + serviceContent: ['换药护理', '伤口观察', '家属宣教'], + processNote: '服务过程平稳,老人配合良好。', + elderStatus: '精神状态稳定,伤口恢复良好。', + healthMetrics: { + bloodPressure: '126/80', + heartRate: '74', + bloodSugar: '', + bloodOxygen: '98' + }, + materialsUsed: '无菌敷料 2 片,棉签 4 支', + abnormalNote: '', + photos: ['mock-photo-1'], + staffRemark: '建议继续保持每日换药。', + familyConfirmation: { + method: 'sms_code', + code: '652318', + signatureName: '刘敏', + signatureUrl: '', + confirmedAt: '2026-05-19 17:20:00' + }, + createdAt: '2026-05-19 17:18:00', + updatedAt: '2026-05-19 17:18:00' + } as DeliveryServiceRecordType + return orders +} + +function readProfileStore(): DeliveryInfoType { + const cached = uni.getStorageSync(PROFILE_KEY) as DeliveryInfoType | null + if (cached != null && cached.id != null && cached.id != '') { + return cloneProfile(cached) + } + const created = createProfile() + uni.setStorageSync(PROFILE_KEY, cloneProfile(created)) + return created +} + +function writeProfileStore(profile: DeliveryInfoType): DeliveryInfoType { + uni.setStorageSync(PROFILE_KEY, cloneProfile(profile)) + return profile +} + +function readOrderStore(): Array { + const cached = uni.getStorageSync(ORDER_KEY) as Array | null + if (cached != null && cached.length > 0) { + return cloneOrders(cached) + } + const created = createDefaultOrders() + uni.setStorageSync(ORDER_KEY, cloneOrders(created)) + return created +} + +function writeOrderStore(orders: Array): Array { + uni.setStorageSync(ORDER_KEY, cloneOrders(orders)) + return orders +} + +function sortOrdersByAppointment(orders: Array): Array { + return orders.sort((left, right) => left.appointmentTime.localeCompare(right.appointmentTime)) +} + +function isPendingStatus(status: DeliveryOrderStatus): boolean { + return status == 'pending_assignment' || status == 'pending_accept' +} + +function isHistoryStatus(status: DeliveryOrderStatus): boolean { + return status == 'completed' || status == 'rejected' || status == 'cancelled' || status == 'abnormal' || status == 'terminated' || status == 'archived' +} + +function isTodayStatus(status: DeliveryOrderStatus): boolean { + return !isPendingStatus(status) && !isHistoryStatus(status) +} + +function refreshOrderMeta(order: DeliveryOrderType): void { + order.statusText = createStatusText(order.status) + order.statusTone = createStatusTone(order.status) + order.updatedAt = nowText() + order.distanceKm = order.distance + order.fullAddress = order.address + ' ' + order.addressDetail + order.fullElderName = order.elderName + order.fullPhone = order.elderPhone + order.elderNameMasked = order.elderName.substring(0, 1) + '**' + order.elderPhoneMasked = order.elderPhone.substring(0, 3) + '****' + order.elderPhone.substring(order.elderPhone.length - 4) + order.timeline.unshift(createTimeline(order.statusText, '订单状态已更新为' + order.statusText)) +} + +function findOrderIndex(orders: Array, orderId: string): number { + for (let i = 0; i < orders.length; i++) { + if (orders[i].id == orderId) { + return i + } + } + return -1 +} + +export function getDeliveryCareProfile(): DeliveryInfoType { + return readProfileStore() +} + +export function updateDeliveryCareOnlineStatus(status: DeliveryOnlineStatus): DeliveryInfoType { + const profile = readProfileStore() + profile.onlineStatus = status + return cloneProfile(writeProfileStore(profile)) +} + +export function getDeliveryCareDashboard(): DeliveryDashboardType { + const profile = readProfileStore() + const orders = sortOrdersByAppointment(readOrderStore()) + let pendingCount = 0 + let todayCount = 0 + let pendingDepartCount = 0 + let servingCount = 0 + let completedCount = 0 + let exceptionCount = 0 + let expectedIncome = 0 + let nextOrder: DeliveryOrderType | null = null + const recentOrders: Array = [] + for (let i = 0; i < orders.length; i++) { + const item = orders[i] + if (isPendingStatus(item.status)) { + pendingCount += 1 + } + if (isTodayStatus(item.status) || item.status == 'completed') { + todayCount += 1 + } + if (item.status == 'accepted' || item.status == 'waiting_departure') { + pendingDepartCount += 1 + } + if (item.status == 'in_service' || item.status == 'serving') { + servingCount += 1 + } + if (item.status == 'completed') { + completedCount += 1 + } + if (item.status == 'abnormal' || item.status == 'exception_pending') { + exceptionCount += 1 + } + if (!isHistoryStatus(item.status) && item.status != 'rejected' && item.status != 'cancelled') { + expectedIncome += item.staffIncome + } + if (nextOrder == null && !isHistoryStatus(item.status)) { + nextOrder = cloneOrder(item) + } + if (recentOrders.length < 4) { + recentOrders.push(cloneOrder(item)) + } + } + profile.todayAccepted = pendingDepartCount + profile.todayServing = servingCount + profile.todayCompleted = completedCount + writeProfileStore(profile) + return { + pendingAssignmentCount: pendingCount, + pendingAcceptCount: pendingCount, + todayOrderCount: todayCount, + pendingDepartCount, + servingCount, + completedCount, + exceptionCount, + expectedIncome, + onlineStatus: profile.onlineStatus, + nextOrder, + recentOrders + } as DeliveryDashboardType +} + +export function getPendingCareOrders(): Array { + const orders = sortOrdersByAppointment(readOrderStore()) + const result: Array = [] + for (let i = 0; i < orders.length; i++) { + if (isPendingStatus(orders[i].status)) { + result.push(cloneOrder(orders[i])) + } + } + return result +} + +export function getTodayCareOrders(): Array { + const orders = sortOrdersByAppointment(readOrderStore()) + const result: Array = [] + for (let i = 0; i < orders.length; i++) { + if (isTodayStatus(orders[i].status)) { + result.push(cloneOrder(orders[i])) + } + } + return result +} + +export function getHistoryCareOrders(): Array { + const orders = sortOrdersByAppointment(readOrderStore()) + const result: Array = [] + for (let i = 0; i < orders.length; i++) { + if (isHistoryStatus(orders[i].status)) { + result.push(cloneOrder(orders[i])) + } + } + return result +} + +export function getCareOrderDetail(orderId: string): DeliveryOrderType | null { + const orders = readOrderStore() + const index = findOrderIndex(orders, orderId) + if (index < 0) { + return null + } + return cloneOrder(orders[index]) +} + +export function updateCareOrderStatus(orderId: string, nextStatus: DeliveryOrderStatus, remark: string): DeliveryOrderType | null { + const orders = readOrderStore() + const index = findOrderIndex(orders, orderId) + if (index < 0) { + return null + } + const target = orders[index] + const fromStatus = target.status + target.status = nextStatus + if (nextStatus == 'accepted') { + target.acceptTime = nowText() + } + if (nextStatus == 'rejected') { + target.rejectTime = nowText() + } + if (nextStatus == 'departed') { + target.departTime = nowText() + } + if (nextStatus == 'arrived') { + target.arriveTime = nowText() + } + if (nextStatus == 'checked_in') { + target.checkinTime = nowText() + } + if (nextStatus == 'in_service') { + target.startServiceTime = nowText() + target.actualStartTime = target.startServiceTime != null ? target.startServiceTime : nowText() + } + if (nextStatus == 'completed') { + target.finishTime = nowText() + target.actualEndTime = target.finishTime + } + target.statusLog.unshift(createStatusLog(orderId, fromStatus, nextStatus, remark)) + refreshOrderMeta(target) + writeOrderStore(orders) + return cloneOrder(target) +} + +export function acceptCareOrder(orderId: string): DeliveryOrderType | null { + return updateCareOrderStatus(orderId, 'accepted', '接单成功') +} + +export function rejectCareOrder(orderId: string, reason: string): DeliveryOrderType | null { + const order = updateCareOrderStatus(orderId, 'rejected', reason) + if (order != null) { + const orders = readOrderStore() + const index = findOrderIndex(orders, orderId) + if (index >= 0) { + orders[index].cancelReason = reason + writeOrderStore(orders) + return cloneOrder(orders[index]) + } + } + return order +} + +export function markCareOrderDeparted(orderId: string): DeliveryOrderType | null { + return updateCareOrderStatus(orderId, 'departed', '服务人员已出发') +} + +export function markCareOrderArrived(orderId: string): DeliveryOrderType | null { + return updateCareOrderStatus(orderId, 'arrived', '服务人员已到达') +} + +export function checkInCareOrder(orderId: string, location: DeliveryLocationType | null, note: string): DeliveryOrderType | null { + const order = updateCareOrderStatus(orderId, 'checked_in', note != '' ? note : '到达签到') + if (order == null) { + return null + } + const orders = readOrderStore() + const index = findOrderIndex(orders, orderId) + if (index >= 0) { + orders[index].lastLocation = location + writeOrderStore(orders) + return cloneOrder(orders[index]) + } + return order +} + +export function startCareService(orderId: string): DeliveryOrderType | null { + return updateCareOrderStatus(orderId, 'in_service', '开始服务') +} + +export function submitCareServiceRecord(orderId: string, record: DeliveryServiceRecordType): DeliveryOrderType | null { + const orders = readOrderStore() + const index = findOrderIndex(orders, orderId) + if (index < 0) { + return null + } + orders[index].serviceRecord = cloneOrder({ + ...orders[index], + serviceRecord: record + } as DeliveryOrderType).serviceRecord + orders[index].serviceSummary = record.processNote + orders[index].progressNote = record.staffRemark + orders[index].serviceItems = record.serviceItems + orders[index].status = 'pending_confirm' + orders[index].statusLog.unshift(createStatusLog(orderId, 'in_service', 'pending_confirm', '已提交服务记录')) + refreshOrderMeta(orders[index]) + writeOrderStore(orders) + return cloneOrder(orders[index]) +} + +export function completeCareOrder(orderId: string): DeliveryOrderType | null { + const orders = readOrderStore() + const index = findOrderIndex(orders, orderId) + if (index < 0) { + return null + } + if (orders[index].serviceRecord == null) { + return null + } + orders[index].statusLog.unshift(createStatusLog(orderId, orders[index].status, 'completed', '完成服务')) + orders[index].status = 'completed' + orders[index].finishTime = nowText() + orders[index].actualEndTime = orders[index].finishTime + refreshOrderMeta(orders[index]) + writeOrderStore(orders) + return cloneOrder(orders[index]) +} + +export function submitCareAbnormalReport(orderId: string, payload: DeliveryExceptionPayloadType): DeliveryOrderType | null { + const orders = readOrderStore() + const index = findOrderIndex(orders, orderId) + if (index < 0) { + return null + } + orders[index].abnormalReport = { + id: 'abnormal-' + orderId, + orderId, + type: payload.exceptionType, + description: payload.description, + occurredAt: payload.occurredAt != null ? payload.occurredAt : nowText(), + locationText: payload.locationText != null ? payload.locationText : '当前位置 mock', + images: payload.images, + needPlatformIntervention: payload.needPlatformIntervention === true, + requestCancelOrder: payload.requestCancelOrder === true, + requestReschedule: payload.requestReschedule === true, + createdAt: nowText() + } as DeliveryAbnormalReportType + orders[index].exceptionType = payload.exceptionType + orders[index].exceptionDesc = payload.description + orders[index].statusLog.unshift(createStatusLog(orderId, orders[index].status, 'abnormal', '提交异常上报')) + orders[index].status = 'abnormal' + refreshOrderMeta(orders[index]) + writeOrderStore(orders) + return cloneOrder(orders[index]) +} + +export function getCareRecords(): Array { + const orders = readOrderStore() + const result: Array = [] + for (let i = 0; i < orders.length; i++) { + const item = orders[i] + if (item.serviceRecord != null || item.status == 'completed') { + result.push({ + id: 'record-list-' + item.id, + orderId: item.id, + orderNo: item.orderNo, + serviceName: item.serviceName, + elderName: item.elderName, + elderNameMasked: item.elderNameMasked, + status: item.status, + statusText: item.statusText, + appointmentStartTime: item.appointmentStartTime, + appointmentTime: item.appointmentTime, + actualStartTime: item.actualStartTime, + actualEndTime: item.actualEndTime, + staffIncome: item.staffIncome, + settlementStatus: item.settlementStatus, + acceptanceStatus: item.satisfactionStatus, + exceptionDesc: item.exceptionDesc, + ratingText: item.satisfactionStatus, + hasServiceRecord: item.serviceRecord != null + } as DeliveryRecordType) + } + } + return result +} + +export function resetCareOrderStore(): void { + uni.removeStorageSync(ORDER_KEY) + uni.removeStorageSync(PROFILE_KEY) +} \ No newline at end of file diff --git a/pages.delivery.json b/pages.delivery.json index 41ef0c29..7d0d4a37 100644 --- a/pages.delivery.json +++ b/pages.delivery.json @@ -38,35 +38,14 @@ { "path": "pages/mall/delivery/orders/detail", "style": { - "navigationBarTitleText": "工单详情", + "navigationBarTitleText": "订单详情", "navigationStyle": "custom" } }, { - "path": "pages/mall/delivery/orders/route", + "path": "pages/mall/delivery/service-record/index", "style": { - "navigationBarTitleText": "出发与导航", - "navigationStyle": "custom" - } - }, - { - "path": "pages/mall/delivery/orders/checkin", - "style": { - "navigationBarTitleText": "到达签到", - "navigationStyle": "custom" - } - }, - { - "path": "pages/mall/delivery/orders/execute", - "style": { - "navigationBarTitleText": "服务执行", - "navigationStyle": "custom" - } - }, - { - "path": "pages/mall/delivery/orders/evidence", - "style": { - "navigationBarTitleText": "证据上传", + "navigationBarTitleText": "服务记录", "navigationStyle": "custom" } }, @@ -77,34 +56,6 @@ "navigationStyle": "custom" } }, - { - "path": "pages/mall/delivery/orders/finish", - "style": { - "navigationBarTitleText": "完成确认", - "navigationStyle": "custom" - } - }, - { - "path": "pages/mall/delivery/records/index", - "style": { - "navigationBarTitleText": "服务记录", - "navigationStyle": "custom" - } - }, - { - "path": "pages/mall/delivery/records/detail", - "style": { - "navigationBarTitleText": "记录详情", - "navigationStyle": "custom" - } - }, - { - "path": "pages/mall/delivery/messages/index", - "style": { - "navigationBarTitleText": "消息中心", - "navigationStyle": "custom" - } - }, { "path": "pages/mall/delivery/profile/index", "style": { @@ -112,13 +63,6 @@ "navigationStyle": "custom" } }, - { - "path": "pages/mall/delivery/profile/certificates", - "style": { - "navigationBarTitleText": "资质证书", - "navigationStyle": "custom" - } - }, { "path": "pages/mall/delivery/profile/settings", "style": { @@ -148,16 +92,10 @@ }, { "pagePath": "pages/mall/delivery/orders/index", - "text": "工单", + "text": "订单", "iconPath": "static/tabbar/cart.png", "selectedIconPath": "static/tabbar/cart.png" }, - { - "pagePath": "pages/mall/delivery/messages/index", - "text": "消息", - "iconPath": "static/tabbar/message.png", - "selectedIconPath": "static/tabbar/message.png" - }, { "pagePath": "pages/mall/delivery/profile/index", "text": "我的", diff --git a/pages/main/category.uvue b/pages/main/category.uvue index 88275b1d..ff0270ad 100644 --- a/pages/main/category.uvue +++ b/pages/main/category.uvue @@ -201,6 +201,15 @@ const currentCategoryDesc = ref('') // 页面参数 const pageParams = ref({}) +function normalizeSelectedMedicalCategoryId(categoryId: string): string { + if (categoryId == 'device') return 'med_device' + if (categoryId == 'external') return 'home_care_daily' + if (categoryId == 'cold') return 'otc_medicine' + if (categoryId == 'medicine') return 'otc_medicine' + if (categoryId == 'care') return 'home_care_daily' + return categoryId +} + function getProductCover(product: Product): string { if (product.main_image_url != null && product.main_image_url !== '') return product.main_image_url if (product.images != null && product.images.length > 0 && product.images[0] !== '') return product.images[0] @@ -272,7 +281,7 @@ async function loadProducts(): Promise { loading.value = true try { console.log('开始加载商品,分类ID:', activePrimary.value, '页码:', currentPage.value) - const response = await supabaseService.getProductsByCategory(activePrimary.value, currentPage.value) + const response = await supabaseService.getMedicalMallProductsByCategory(activePrimary.value, currentPage.value, 20) console.log('商品加载结果:', { dataCount: response.data.length, total: response.total, @@ -324,7 +333,7 @@ async function loadProducts(): Promise { async function loadSubCategories(parentId: string): Promise { console.log('加载二级分类,父级ID:', parentId) try { - const subCats = await supabaseService.getSubCategories(parentId) + const subCats = await supabaseService.getMedicalMallSubCategories(parentId) console.log('获取到二级分类数量:', subCats.length) const categories: LocalCategory[] = [] @@ -379,9 +388,10 @@ async function selectSubCategory(subCategoryId: string): Promise { // originalCategoryId: 可能是一级分类ID,也可能是二级分类ID async function selectPrimaryCategory(originalCategoryId: string): Promise { console.log('=== selectPrimaryCategory函数开始执行 ===') - console.log('传入的categoryId:', originalCategoryId) + const normalizedCategoryId = normalizeSelectedMedicalCategoryId(originalCategoryId) + console.log('传入的categoryId:', originalCategoryId, '归一化后:', normalizedCategoryId) - if (originalCategoryId == '') { + if (normalizedCategoryId == '') { console.error('categoryId为空,尝试使用第一个分类') if (primaryCategories.value.length > 0) { originalCategoryId = primaryCategories.value[0].id @@ -397,8 +407,9 @@ async function selectPrimaryCategory(originalCategoryId: string): Promise console.log('当前一级分类列表长度:', primaryCategories.value.length) let foundInPrimary: LocalCategory | null = null for (let i = 0; i < primaryCategories.value.length; i++) { - if (primaryCategories.value[i].id == originalCategoryId) { + if (primaryCategories.value[i].id == normalizedCategoryId) { foundInPrimary = primaryCategories.value[i] + targetParentId = normalizedCategoryId break } } @@ -410,7 +421,7 @@ async function selectPrimaryCategory(originalCategoryId: string): Promise // 从服务器获取分类信息以确定父级 try { - const categoryInfo = await supabaseService.getCategoryById(originalCategoryId) + const categoryInfo = await supabaseService.getMedicalMallCategoryById(normalizedCategoryId) if (categoryInfo != null && categoryInfo.parent_id != null && categoryInfo.parent_id != '') { console.log('找到父级分类ID:', categoryInfo.parent_id) @@ -427,7 +438,7 @@ async function selectPrimaryCategory(originalCategoryId: string): Promise if (parentInPrimary != null) { console.log('父级分类在列表中找到:', parentInPrimary.name) targetParentId = categoryInfo.parent_id! - targetSubId = originalCategoryId // 记住要选中的二级分类 + targetSubId = normalizedCategoryId // 记住要选中的二级分类 } else { console.log('父级分类不在列表中,使用第一个分类') // 打印当前列表中的所有分类ID @@ -530,21 +541,13 @@ async function selectPrimaryCategory(originalCategoryId: string): Promise async function loadCategories(): Promise { try { - // 只获取一级分类(parent_id 为 null 的分类) - const categoriesData = await supabaseService.getParentCategories() + const categoriesData = await supabaseService.getMedicalMallParentCategories() console.log('加载一级分类数据成功,数量:', categoriesData.length) - // 映射数据并添加默认颜色,防止选中时背景透明导致文字看不清 - // 过滤掉医药健康相关分类 const categories: LocalCategory[] = [] for (let i = 0; i < categoriesData.length; i++) { const cat = categoriesData[i] - const name = cat.name - console.log('一级分类:', cat.id, name) - if (name.includes('医药') || name.includes('健康')) { - console.log('过滤掉分类:', name) - continue - } + console.log('一级分类:', cat.id, cat.name) categories.push({ id: cat.id, name: cat.name, @@ -572,16 +575,16 @@ async function loadCategories(): Promise { // 检查是否有预设的分类ID if (activePrimary.value != '') { console.log('有预设的分类ID:', activePrimary.value) - const target = categories.find((c: LocalCategory): boolean => c.id == activePrimary.value) + const normalizedCategoryId = normalizeSelectedMedicalCategoryId(activePrimary.value) + const target = categories.find((c: LocalCategory): boolean => c.id == normalizedCategoryId) if (target != null) { console.log('找到目标分类,执行选中:', target.name) - selectPrimaryCategory(activePrimary.value) + selectPrimaryCategory(normalizedCategoryId) return } } - // 默认选中第一个分类或"厨具"分类 - const defaultCategory = categories.find((c: LocalCategory): boolean => c.name.includes('厨具')) ?? categories[0] + const defaultCategory = categories.find((c: LocalCategory): boolean => c.id == 'all_medical') ?? categories[0] if (defaultCategory != null) { console.log('设置默认分类:', defaultCategory.name) selectPrimaryCategory(defaultCategory.id) @@ -622,7 +625,7 @@ onShow(() => { console.log('onShow检查Storage:', savedCategoryId) if (savedCategoryId != null && savedCategoryId != '') { - const targetId = savedCategoryId as string + const targetId = normalizeSelectedMedicalCategoryId(savedCategoryId as string) console.log('onShow发现存储的分类ID:', targetId) // 清除存储,避免下次进入默认选中 @@ -679,7 +682,7 @@ onLoad((options: any) => { const optObj = (options instanceof UTSJSONObject) ? (options as UTSJSONObject) : (JSON.parse(JSON.stringify(options ?? {})) as UTSJSONObject) const optCategoryId = optObj.getString('categoryId') ?? '' if (optCategoryId !== '') { - categoryId = optCategoryId + categoryId = normalizeSelectedMedicalCategoryId(optCategoryId) categoryName = optObj.getString('name') ?? '' console.log('✅ onLoad中找到分类参数:', categoryId, categoryName) } @@ -694,7 +697,7 @@ onLoad((options: any) => { const pageOptObj = (rawPageOptions instanceof UTSJSONObject) ? (rawPageOptions as UTSJSONObject) : (JSON.parse(JSON.stringify(rawPageOptions)) as UTSJSONObject) const pageCategoryId = pageOptObj.getString('categoryId') ?? '' if (pageCategoryId !== '') { - categoryId = pageCategoryId + categoryId = normalizeSelectedMedicalCategoryId(pageCategoryId) categoryName = pageOptObj.getString('name') ?? '' console.log('✅ 从getCurrentPages()找到分类参数:', categoryId, categoryName) } diff --git a/pages/main/index.uvue b/pages/main/index.uvue index a7309323..dbcc0b87 100644 --- a/pages/main/index.uvue +++ b/pages/main/index.uvue @@ -20,6 +20,7 @@ { if (activeTopModule.value == 'service') { return '居家护理 / 康复照护 / 血压计 / 助餐服务' } - return currentPlaceholderKeyword.value != '' ? currentPlaceholderKeyword.value : '感冒药 / 康复护理 / 居家护理 / 血压计' + return currentPlaceholderKeyword.value != '' ? currentPlaceholderKeyword.value : '血压计 / 血糖仪 / 制氧机 / 维生素' }) type HomeCareCategoryType = { @@ -641,11 +644,16 @@ const showSubCategories = ref(false) // 首页占位词轮播相关 const placeholderKeywords = ref([ - 'neo2无人机', - '华为mate50', + '血压计', + '血糖仪', + '体温计', + '制氧机', + '口罩', + '创可贴', + '维生素', '钙片', - '感冒药', - '维生素C', + '康复护具', + '护理床', ]) const currentPlaceholderIndex = ref(0) @@ -655,6 +663,20 @@ const placeholderAnimating = ref(false) let placeholderTimer: number = 0 let placeholderAnimationTimer: number = 0 +const homeEmptyStateTitle = computed((): string => { + if (currentFeedCategoryId.value == 'recommend') { + return '康养医疗商品正在完善中' + } + return '当前分类暂无商品' +}) + +const homeEmptyStateDescription = computed((): string => { + if (currentFeedCategoryId.value == 'recommend') { + return '可先查看居家服务或稍后再试' + } + return '' +}) + const syncNextPlaceholderKeyword = () => { const total = placeholderKeywords.value.length if (total <= 1) { @@ -1114,7 +1136,7 @@ const handleSecondaryCategoryClick = async (category: Category): Promise = hasMore.value = true loading.value = true try { - const result = await supabaseService.getProductsByCategory(category.id, 1, defaultLoadLimit) + const result = await supabaseService.getMedicalMallProductsByCategory(category.id, 1, defaultLoadLimit) failedProductImageIds.value = [] setHotProducts(result.data) hasMore.value = result.hasmore @@ -1165,9 +1187,9 @@ const healthNews = [ ] // 获取一级分类数据 -const loadCategories = async (): Promise => { +const loadMedicalMallCategories = async (): Promise => { try { - const categoriesData = await supabaseService.getParentCategories() + const categoriesData = await supabaseService.getMedicalMallParentCategories() parentCategories.value = categoriesData // 兼容其他使用 categories 的地方 categories.value = categoriesData @@ -1190,7 +1212,7 @@ const loadCategories = async (): Promise => { async function loadSubCategories(parentId: string): Promise { try { console.log('[loadSubCategories] 开始加载二级分类, parentId:', parentId) - const subData = await supabaseService.getSubCategories(parentId) + const subData = await supabaseService.getMedicalMallSubCategories(parentId) console.log('[loadSubCategories] 获取到二级分类数量:', subData.length) console.log('[loadSubCategories] 二级分类数据:', JSON.stringify(subData)) subCategories.value = subData @@ -1315,6 +1337,15 @@ function getCategoryLabelById(categoryId: string): string { return '精选' } +function normalizeSelectedMedicalCategoryId(categoryId: string): string { + if (categoryId == 'device') return 'med_device' + if (categoryId == 'external') return 'home_care_daily' + if (categoryId == 'cold') return 'otc_medicine' + if (categoryId == 'medicine') return 'otc_medicine' + if (categoryId == 'care') return 'home_care_daily' + return categoryId +} + async function consumeSelectedCategoryFromStorage(): Promise { if (activeTopModule.value != 'home' || categoryList.value.length == 0) { return false @@ -1328,14 +1359,15 @@ async function consumeSelectedCategoryFromStorage(): Promise { return false } uni.removeStorageSync('selectedCategory') - const matchedItem = categoryList.value.find((item: CategoryItem): boolean => item.id == nextCategoryId) + const normalizedCategoryId = normalizeSelectedMedicalCategoryId(nextCategoryId) + const matchedItem = categoryList.value.find((item: CategoryItem): boolean => item.id == normalizedCategoryId) if (matchedItem != null) { await refreshHomeCategory(matchedItem) return true } await refreshHomeCategory({ - id: nextCategoryId, - name: getCategoryLabelById(nextCategoryId) + id: normalizedCategoryId, + name: getCategoryLabelById(normalizedCategoryId) }) return true } @@ -1364,17 +1396,17 @@ const fetchSortedProductsPage = async (page: number, limit: number): Promise { } try { - const subData = await supabaseService.getSubCategories(categoryId) + const subData = await supabaseService.getMedicalMallSubCategories(categoryId) subCategories.value = subData } catch (error) { console.error('加载子分类数据失败:', error) @@ -1444,33 +1476,7 @@ async function loadCategoryGoods(categoryId: string): Promise { await syncCategoryLayout(categoryId) if (categoryId === 'recommend') { try { - let result: PaginatedResponse - switch (activeSort.value) { - case 'sales': - result = await supabaseService.getProductsBySales(1, defaultLoadLimit) - break - case 'price': - result = await supabaseService.getProductsByPrice(1, defaultLoadLimit, priceAscending.value) - break - case 'new': - result = await supabaseService.getProductsByNewest(1, defaultLoadLimit) - break - case 'discount': { - const products = await supabaseService.getDiscountProducts(defaultLoadLimit) - result = { - data: products, - total: products.length, - page: 1, - limit: defaultLoadLimit, - hasmore: false - } - break - } - case 'recommend': - default: - result = await supabaseService.getSmartRecommendations(1, defaultLoadLimit) - break - } + const result = await supabaseService.getMedicalMallSmartRecommendations(1, defaultLoadLimit) failedProductImageIds.value = [] setHotProducts(result.data) hasMore.value = result.hasmore @@ -1483,7 +1489,7 @@ async function loadCategoryGoods(categoryId: string): Promise { } else { try { loading.value = true - const result = await supabaseService.getProductsByCategory(categoryId, 1, defaultLoadLimit) + const result = await supabaseService.getMedicalMallProductsByCategory(categoryId, 1, defaultLoadLimit) failedProductImageIds.value = [] setHotProducts(result.data) hasMore.value = result.hasmore @@ -1514,7 +1520,7 @@ async function refreshHomeCategory(item: CategoryItem): Promise { secondaryCategoryDisplay.value = buildSecondaryCategoryDisplay(item.id) applyChannelDisplay(item.id) try { - const result = await supabaseService.getSmartRecommendations(1, defaultLoadLimit) + const result = await supabaseService.getMedicalMallSmartRecommendations(1, defaultLoadLimit) setHotProducts(result.data) hasMore.value = result.hasmore } catch (error) { @@ -1528,7 +1534,7 @@ async function refreshHomeCategory(item: CategoryItem): Promise { } try { - const subData = await supabaseService.getSubCategories(item.id) + const subData = await supabaseService.getMedicalMallSubCategories(item.id) subCategories.value = subData } catch (error) { console.error('加载子分类数据失败:', error) @@ -1537,7 +1543,7 @@ async function refreshHomeCategory(item: CategoryItem): Promise { secondaryCategoryDisplay.value = buildSecondaryCategoryDisplay(item.id) applyChannelDisplay(item.id) try { - const result = await supabaseService.getProductsByCategory(item.id, 1, defaultLoadLimit) + const result = await supabaseService.getMedicalMallProductsByCategory(item.id, 1, defaultLoadLimit) setHotProducts(result.data) hasMore.value = result.hasmore } catch (error) { @@ -1559,7 +1565,8 @@ function selectCategoryFromPanel(item: CategoryItem): void { } const loadRecommendedProducts = async (limit: number): Promise => { - recommendedProducts.value = await supabaseService.getRecommendedProducts(limit) + const result = await supabaseService.getMedicalMallSmartRecommendations(1, limit) + recommendedProducts.value = result.data } // 加载热搜词 @@ -1592,7 +1599,7 @@ const initData = async () => { } catch (error) { console.error('加载用户资料失败:', error) } - await loadCategories() + await loadMedicalMallCategories() await loadBrands() await loadHotKeywords() await loadServiceHomeData() @@ -1613,7 +1620,7 @@ const familyItems = [ desc: '伤口护理', icon: '🩹', color: '#FF5722', - categoryId: 'external' + categoryId: 'wound_care' }, { id: 'family2', @@ -1621,7 +1628,7 @@ const familyItems = [ desc: '健康监测', icon: '🌡️', color: '#2196F3', - categoryId: 'device' + categoryId: 'thermometer' }, { id: 'family3', @@ -1629,7 +1636,7 @@ const familyItems = [ desc: '环境消毒', icon: '🧪', color: '#ff5000', - categoryId: 'external' + categoryId: 'disinfectant' }, { id: 'family4', @@ -1637,7 +1644,7 @@ const familyItems = [ desc: '日常防护', icon: '😷', color: '#607D8B', - categoryId: 'device' + categoryId: 'mask' }, { id: 'family5', @@ -1645,7 +1652,7 @@ const familyItems = [ desc: '物理降温', icon: '🧊', color: '#00BCD4', - categoryId: 'cold' + categoryId: 'cold_fever' }, { id: 'family6', @@ -1653,7 +1660,7 @@ const familyItems = [ desc: '伤口处理', icon: '🩹', color: '#FF9800', - categoryId: 'external' + categoryId: 'dressing_tools' } ] @@ -1931,7 +1938,7 @@ const loadMore = async () => { currentPage.value = nextPage } } else { - const result = await supabaseService.getProductsByCategory(currentFeedCategoryId.value, nextPage, defaultLoadLimit) + const result = await supabaseService.getMedicalMallProductsByCategory(currentFeedCategoryId.value, nextPage, defaultLoadLimit) if (result.data.length == 0) { hasMore.value = false } else { diff --git a/pages/mall/delivery/home/index.uvue b/pages/mall/delivery/home/index.uvue index 26c5709c..2452c0b0 100644 --- a/pages/mall/delivery/home/index.uvue +++ b/pages/mall/delivery/home/index.uvue @@ -1,363 +1,433 @@ + + console.log('[deliveryHome] loadData complete, elapsed=' + (Date.now() - startedAt)) } diff --git a/pages/mall/delivery/orders/detail.uvue b/pages/mall/delivery/orders/detail.uvue index 9e5680d8..9e0d39e1 100644 --- a/pages/mall/delivery/orders/detail.uvue +++ b/pages/mall/delivery/orders/detail.uvue @@ -1,82 +1,214 @@ \ No newline at end of file diff --git a/pages/mall/delivery/orders/exception.uvue b/pages/mall/delivery/orders/exception.uvue index c1caa622..66cb44e3 100644 --- a/pages/mall/delivery/orders/exception.uvue +++ b/pages/mall/delivery/orders/exception.uvue @@ -1,84 +1,104 @@ \ No newline at end of file diff --git a/pages/mall/delivery/orders/index.uvue b/pages/mall/delivery/orders/index.uvue index 45a1ce2c..1cbe3f0c 100644 --- a/pages/mall/delivery/orders/index.uvue +++ b/pages/mall/delivery/orders/index.uvue @@ -1,164 +1,371 @@ + + } function consumeStoredTab(): void { diff --git a/pages/mall/delivery/profile/index.uvue b/pages/mall/delivery/profile/index.uvue index bcbaeed4..62adfe9d 100644 --- a/pages/mall/delivery/profile/index.uvue +++ b/pages/mall/delivery/profile/index.uvue @@ -1,313 +1,72 @@ \ No newline at end of file diff --git a/pages/mall/delivery/profile/settings.uvue b/pages/mall/delivery/profile/settings.uvue index a35fa01c..74cba9fd 100644 --- a/pages/mall/delivery/profile/settings.uvue +++ b/pages/mall/delivery/profile/settings.uvue @@ -8,20 +8,22 @@ 资质状态:{{ deliveryInfo.certificateStatus }} - + 消息提醒 - - - - 语音播报 - + 定位权限提示 - 请确保 Android 和小程序侧授权开启 + 定位轨迹仅做字段预留,当前为 mock + + + 图片上传 + 当前仅占位,不做真实上传 + + 退出登录 @@ -32,10 +34,9 @@ import ServicePageScaffold from '@/components/homeService/ServicePageScaffold.uv import ServicePanel from '@/components/homeService/ServicePanel.uvue' import type { DeliveryInfoType } from '@/types/delivery.uts' import { getDeliveryProfile } from '@/services/deliveryService.uts' -import { requireDeliveryAuth } from '@/utils/deliveryAuth.uts' +import { logoutDelivery, requireDeliveryAuth } from '@/utils/deliveryAuth.uts' const messageEnabled = ref(true) -const voiceEnabled = ref(false) const deliveryInfo = ref(null) function displayOrganizationName(): string { @@ -62,9 +63,7 @@ function displayStaffNo(): string { function restoreSettings() { const msg = uni.getStorageSync('delivery_setting_message') as boolean | null - const voice = uni.getStorageSync('delivery_setting_voice') as boolean | null messageEnabled.value = msg == null ? true : msg - voiceEnabled.value = voice == null ? false : voice } function toggleMessage(event: any) { @@ -72,9 +71,17 @@ function toggleMessage(event: any) { uni.setStorageSync('delivery_setting_message', messageEnabled.value) } -function toggleVoice(event: any) { - voiceEnabled.value = event.detail.value === true - uni.setStorageSync('delivery_setting_voice', voiceEnabled.value) +function confirmLogout() { + uni.showModal({ + title: '退出登录', + content: '退出后将清除服务人员信息并返回登录页。', + success: async (result) => { + if (result.confirm) { + await logoutDelivery() + uni.reLaunch({ url: '/pages/user/login?mode=delivery' }) + } + } + }) } async function loadData() { @@ -100,6 +107,10 @@ onShow(() => { align-items: center; } +.setting-row-last { + border-bottom-width: 0; +} + .info-text { display: block; margin-top: 12rpx; @@ -120,4 +131,19 @@ onShow(() => { text-align: right; width: 60%; } + +.logout-btn { + margin-top: 24rpx; + padding: 20rpx 0; + border-radius: 18rpx; + background-color: #fff1f2; + align-items: center; + justify-content: center; +} + +.logout-text { + font-size: 28rpx; + font-weight: 700; + color: #dc2626; +} \ No newline at end of file diff --git a/pages/mall/delivery/service-record/index.uvue b/pages/mall/delivery/service-record/index.uvue new file mode 100644 index 00000000..9aecc250 --- /dev/null +++ b/pages/mall/delivery/service-record/index.uvue @@ -0,0 +1,328 @@ + + + + + \ No newline at end of file diff --git a/services/deliveryService.uts b/services/deliveryService.uts index 558fdff2..1033c8be 100644 --- a/services/deliveryService.uts +++ b/services/deliveryService.uts @@ -1,60 +1,53 @@ +import { getDeliveryProfileByUserId, loginDelivery as loginDeliveryApi } from '@/api/delivery.uts' import { - acceptDeliveryOrderById, - arriveOrderById, - checkinOrderById, - finishServiceById, - getDeliveryDashboardByStaffId, - getDeliveryMessagesList, - getDeliveryOrderDetailById, - getDeliveryOrdersByStaffId, - getDeliveryProfileByUserId, - getDeliveryRecordsByStaffId, - loginDelivery as loginDeliveryApi, - rejectDeliveryOrderById, - retryEvidenceById, - saveServiceProgressById, - startDepartById, - startServiceById, - submitExceptionById, - updateDeliveryOnlineStatusByStaffId, - uploadEvidenceById -} from '@/api/delivery.uts' -import { getDeliveryInfo, getUserInfo, requireDeliveryAuth } from '@/utils/deliveryAuth.uts' + acceptCareOrder, + checkInCareOrder, + completeCareOrder, + getCareOrderDetail, + getCareRecords, + getDeliveryCareDashboard, + getDeliveryCareProfile, + getHistoryCareOrders, + getPendingCareOrders, + getTodayCareOrders, + markCareOrderArrived, + markCareOrderDeparted, + rejectCareOrder, + startCareService, + submitCareAbnormalReport, + submitCareServiceRecord, + updateCareOrderStatus, + updateDeliveryCareOnlineStatus +} from '@/mock/delivery-care.mock.uts' +import { getUserInfo, requireDeliveryAuth } from '@/utils/deliveryAuth.uts' import type { + DeliveryAbnormalReportType, DeliveryCheckinPayloadType, DeliveryDashboardType, DeliveryExceptionPayloadType, - DeliveryFinishPayloadType, DeliveryInfoType, DeliveryLocationType, DeliveryLoginPayloadType, DeliveryLoginResultType, DeliveryMessageType, DeliveryOrderQueryType, + DeliveryOrderStatus, DeliveryOrderType, DeliveryProgressPayloadType, DeliveryRecordType, - DeliveryEvidenceRecordType + DeliveryServiceRecordType } from '@/types/delivery.uts' -function getCurrentStaffId(): string { - const info = getDeliveryInfo() - if (info != null) { - return info.id - } - return '' -} - export async function loginDelivery(payload: DeliveryLoginPayloadType): Promise { return await loginDeliveryApi(payload) } export async function getDeliveryProfile(): Promise { - const userInfo = getUserInfo() - if (userInfo == null || userInfo.id == null || userInfo.id == '') { + const authResult = await requireDeliveryAuth({ redirectOnFail: false, toastOnFail: false }) + if (!authResult.ok) { return null } - return await getDeliveryProfileByUserId(userInfo.id) + return getDeliveryCareProfile() } export async function getDeliveryByUserId(userId: string): Promise { @@ -75,69 +68,192 @@ export async function checkDeliveryAuth(): Promise { } export async function getDeliveryDashboard(): Promise { - return await getDeliveryDashboardByStaffId(getCurrentStaffId()) + return getDeliveryCareDashboard() } export async function getDeliveryOrders(params: DeliveryOrderQueryType): Promise> { - return await getDeliveryOrdersByStaffId(getCurrentStaffId(), params) + if (params.tab == 'pending' || params.tab == 'pending_assignment' || params.tab == 'pending_accept') { + return getPendingCareOrders() + } + if (params.tab == 'history' || params.tab == 'completed' || params.tab == 'archive') { + return getHistoryCareOrders() + } + return getTodayCareOrders() } export async function getDeliveryOrderDetail(id: string): Promise { - return await getDeliveryOrderDetailById(id) + return getCareOrderDetail(id) } export async function acceptDeliveryOrder(id: string): Promise { - return await acceptDeliveryOrderById(id) + return acceptCareOrder(id) } export async function rejectDeliveryOrder(id: string, reason: string): Promise { - return await rejectDeliveryOrderById(id, reason) + return rejectCareOrder(id, reason) } export async function startDepart(id: string, location: DeliveryLocationType): Promise { - return await startDepartById(id, location) + const order = markCareOrderDeparted(id) + if (order != null) { + order.lastLocation = location + } + return order } export async function arriveOrder(id: string, location: DeliveryLocationType): Promise { - return await arriveOrderById(id, location) + const order = markCareOrderArrived(id) + if (order != null) { + order.lastLocation = location + } + return order } export async function checkinOrder(id: string, payload: DeliveryCheckinPayloadType): Promise { - return await checkinOrderById(id, payload) + return checkInCareOrder(id, payload.location, payload.note) } export async function startService(id: string): Promise { - return await startServiceById(id) + return startCareService(id) } export async function saveServiceProgress(id: string, payload: DeliveryProgressPayloadType): Promise { - return await saveServiceProgressById(id, payload) + const current = getCareOrderDetail(id) + if (current == null) { + return null + } + current.serviceItems = payload.items + current.progressNote = payload.progressNote + current.serviceSummary = payload.serviceSummary + return current } -export async function uploadEvidence(id: string, phase: string, files: Array): Promise> { - return await uploadEvidenceById(id, phase, files) +export async function uploadEvidence(id: string, phase: string, files: Array): Promise> { + return files.map((item, index) => ({ + id: id + '-evidence-' + String(index + 1), + orderId: id, + phase, + fileType: 'image', + name: 'mock-image-' + String(index + 1), + url: '', + localPath: item, + status: 'success', + progress: 100, + retryable: false, + createdAt: new Date().toISOString().replace('T', ' ').substring(0, 19) + })) as Array } -export async function retryUploadEvidence(id: string, evidenceId: string): Promise { - return await retryEvidenceById(id, evidenceId) +export async function retryUploadEvidence(id: string, evidenceId: string): Promise { + return { + id: evidenceId, + orderId: id, + phase: 'service', + fileType: 'image', + name: 'mock-retry', + url: '', + localPath: '', + status: 'success', + progress: 100, + retryable: false, + createdAt: new Date().toISOString().replace('T', ' ').substring(0, 19) + } as any } export async function submitException(id: string, payload: DeliveryExceptionPayloadType): Promise { - return await submitExceptionById(id, payload) + return submitCareAbnormalReport(id, payload) } -export async function finishService(id: string, payload: DeliveryFinishPayloadType): Promise { - return await finishServiceById(id, payload) +export async function finishService(id: string): Promise { + return completeCareOrder(id) } export async function getDeliveryRecords(): Promise> { - return await getDeliveryRecordsByStaffId(getCurrentStaffId()) + return getCareRecords() } export async function getDeliveryMessages(): Promise> { - return await getDeliveryMessagesList() + return [ + { + id: 'delivery-msg-01', + title: '今日待服务提醒', + content: '请优先处理上午 9:00 的上门助浴订单。', + type: 'workbench', + createdAt: new Date().toISOString().replace('T', ' ').substring(0, 19), + read: false, + orderId: 'mock-care-001' + } as DeliveryMessageType + ] } export async function updateDeliveryOnlineStatus(status: string): Promise { - return await updateDeliveryOnlineStatusByStaffId(getCurrentStaffId(), status) + if (status == 'online' || status == 'resting' || status == 'busy') { + return updateDeliveryCareOnlineStatus(status) + } + return getDeliveryCareProfile() +} + +export async function getDeliveryDashboardStats(): Promise { + return getDeliveryCareDashboard() +} + +export async function getPendingServiceOrders(): Promise> { + return getPendingCareOrders() +} + +export async function getTodayServiceOrders(): Promise> { + return getTodayCareOrders() +} + +export async function getHistoryServiceOrders(): Promise> { + return getHistoryCareOrders() +} + +export async function getServiceOrderDetail(orderId: string): Promise { + return getCareOrderDetail(orderId) +} + +export async function acceptServiceOrder(orderId: string): Promise { + return acceptCareOrder(orderId) +} + +export async function rejectServiceOrder(orderId: string, reason: string): Promise { + return rejectCareOrder(orderId, reason) +} + +export async function markDeparted(orderId: string): Promise { + return markCareOrderDeparted(orderId) +} + +export async function markArrived(orderId: string): Promise { + return markCareOrderArrived(orderId) +} + +export async function checkInServiceOrder(orderId: string, note: string, location: DeliveryLocationType | null = null): Promise { + return checkInCareOrder(orderId, location, note) +} + +export async function startServiceOrder(orderId: string): Promise { + return startCareService(orderId) +} + +export async function submitServiceRecord(orderId: string, record: DeliveryServiceRecordType): Promise { + return submitCareServiceRecord(orderId, record) +} + +export async function completeServiceOrder(orderId: string): Promise { + return completeCareOrder(orderId) +} + +export async function submitAbnormalReport(orderId: string, report: DeliveryExceptionPayloadType): Promise { + return submitCareAbnormalReport(orderId, report) +} + +export async function updateOrderStatus(orderId: string, nextStatus: DeliveryOrderStatus, extraRemark: string = ''): Promise { + return updateCareOrderStatus(orderId, nextStatus, extraRemark) +} + +export async function getAbnormalReport(orderId: string): Promise { + const order = getCareOrderDetail(orderId) + return order != null ? order.abnormalReport : null } \ No newline at end of file diff --git a/sql/medical_mall_product_category_first_batch.sql b/sql/medical_mall_product_category_first_batch.sql new file mode 100644 index 00000000..46ace38b --- /dev/null +++ b/sql/medical_mall_product_category_first_batch.sql @@ -0,0 +1,130 @@ +-- 医疗商城首批商品分类映射 +-- 用途:为 seed_medical_homepage_data.sql 中的首批医疗商品写入正式分类关联 +-- 前提:已执行 20260521_medical_mall_categories_v1.sql + +BEGIN; + +-- 1. 主分类映射 +INSERT INTO public.medical_mall_product_categories ( + product_id, + category_id, + is_primary, + sort_order, + created_at +) +SELECT p.id, mapping.category_id, TRUE, mapping.sort_order, NOW() +FROM public.ml_products p +JOIN ( + VALUES + ('家庭退热护理贴', 'cold_fever', 10), + ('草本暖胃调理贴', 'tcm_patch', 20), + ('智能血压监测仪', 'blood_pressure_monitor', 30), + ('静音雾化护理机', 'nebulizer', 40), + ('高钙维D营养片', 'calcium', 50), + ('乳清蛋白营养粉', 'protein', 60), + ('术后支撑恢复带', 'postop_rehab', 70), + ('无菌伤口护理包', 'wound_dressing', 80), + ('家用艾灸温灸盒', 'moxibustion', 90), + ('肩颈草本热敷贴', 'tcm_patch', 100), + ('折叠助行辅助器', 'wheelchair_crutch', 110), + ('浴室防滑扶手套装', 'elderly_bathroom', 120) +) AS mapping(product_name, category_id, sort_order) + ON p.name = mapping.product_name +WHERE p.status = '1' +ON CONFLICT (product_id, category_id) DO UPDATE SET + is_primary = EXCLUDED.is_primary, + sort_order = EXCLUDED.sort_order, + deleted_at = NULL; + +-- 2. 扩展分类映射 +INSERT INTO public.medical_mall_product_categories ( + product_id, + category_id, + is_primary, + sort_order, + created_at +) +SELECT p.id, mapping.category_id, FALSE, mapping.sort_order, NOW() +FROM public.ml_products p +JOIN ( + VALUES + ('家庭退热护理贴', 'child_medicine', 210), + ('草本暖胃调理贴', 'physiotherapy_hot', 220), + ('智能血压监测仪', 'hypertension', 230), + ('静音雾化护理机', 'respiratory_health', 240), + ('高钙维D营养片', 'vitamin', 250), + ('乳清蛋白营养粉', 'immune_support', 260), + ('术后支撑恢复带', 'brace_support', 270), + ('无菌伤口护理包', 'wound_care', 280), + ('家用艾灸温灸盒', 'physiotherapy_hot', 290), + ('肩颈草本热敷贴', 'physiotherapy_hot', 300), + ('折叠助行辅助器', 'daily_living_aid', 310), + ('浴室防滑扶手套装', 'anti_slip', 320) +) AS mapping(product_name, category_id, sort_order) + ON p.name = mapping.product_name +WHERE p.status = '1' +ON CONFLICT (product_id, category_id) DO UPDATE SET + is_primary = EXCLUDED.is_primary, + sort_order = EXCLUDED.sort_order, + deleted_at = NULL; + +-- 3. 清理这些商品可能存在的重复主分类 +WITH duplicate_primary AS ( + SELECT + mmc.id, + ROW_NUMBER() OVER ( + PARTITION BY mmc.product_id + ORDER BY mmc.sort_order ASC, mmc.created_at ASC, mmc.id ASC + ) AS row_num + FROM public.medical_mall_product_categories mmc + JOIN public.ml_products p ON p.id = mmc.product_id + WHERE mmc.deleted_at IS NULL + AND mmc.is_primary = TRUE + AND p.name IN ( + '家庭退热护理贴', + '草本暖胃调理贴', + '智能血压监测仪', + '静音雾化护理机', + '高钙维D营养片', + '乳清蛋白营养粉', + '术后支撑恢复带', + '无菌伤口护理包', + '家用艾灸温灸盒', + '肩颈草本热敷贴', + '折叠助行辅助器', + '浴室防滑扶手套装' + ) +) +UPDATE public.medical_mall_product_categories mmc +SET deleted_at = NOW() +FROM duplicate_primary dp +WHERE mmc.id = dp.id + AND dp.row_num > 1; + +-- 4. 校验结果 +SELECT + p.product_code, + p.name, + STRING_AGG(mmc.category_id || CASE WHEN mmc.is_primary THEN ' [P]' ELSE '' END, ', ' ORDER BY mmc.is_primary DESC, mmc.sort_order ASC) AS mapped_categories +FROM public.ml_products p +LEFT JOIN public.medical_mall_product_categories mmc + ON mmc.product_id = p.id + AND mmc.deleted_at IS NULL +WHERE p.name IN ( + '家庭退热护理贴', + '草本暖胃调理贴', + '智能血压监测仪', + '静音雾化护理机', + '高钙维D营养片', + '乳清蛋白营养粉', + '术后支撑恢复带', + '无菌伤口护理包', + '家用艾灸温灸盒', + '肩颈草本热敷贴', + '折叠助行辅助器', + '浴室防滑扶手套装' +) +GROUP BY p.product_code, p.name +ORDER BY p.product_code ASC; + +COMMIT; \ No newline at end of file diff --git a/sql/medical_mall_product_category_manual_mapping_template.sql b/sql/medical_mall_product_category_manual_mapping_template.sql new file mode 100644 index 00000000..f3e97a44 --- /dev/null +++ b/sql/medical_mall_product_category_manual_mapping_template.sql @@ -0,0 +1,197 @@ +-- 医疗商城商品分类手工映射模板 +-- 用途:批量补齐 public.medical_mall_product_categories 的真实数据 +-- 前提:已执行 20260521_medical_mall_categories_v1.sql 或拆分版 schema + RLS + seed + +BEGIN; + +-- 1. 查看当前未映射商品 +SELECT + p.id, + p.name, + p.product_code, + p.subtitle, + p.category_id, + p.status, + p.created_at +FROM public.ml_products p +LEFT JOIN public.medical_mall_product_categories mmc + ON mmc.product_id = p.id + AND mmc.deleted_at IS NULL +WHERE p.status = '1' + AND mmc.product_id IS NULL +ORDER BY p.created_at DESC; + +-- 1.1 按商品名/编码查 UUID +-- 用途:先定位商品 UUID,再回填到下面的手工映射段。 +SELECT + p.id, + p.product_code, + p.name, + p.subtitle, + p.sale_count, + p.created_at +FROM public.ml_products p +WHERE p.status = '1' + AND FALSE + -- 示例:AND (p.name ILIKE '%血压计%' OR p.product_code = 'BP001') +ORDER BY p.sale_count DESC, p.created_at DESC; + +-- 2. 插入主分类映射 +-- 建议:每个商品只保留 1 条 is_primary = true +-- 默认使用 WHERE FALSE 保持模板可执行;填入真实数据后,删除 WHERE FALSE 即可。 +INSERT INTO public.medical_mall_product_categories ( + product_id, + category_id, + is_primary, + sort_order, + created_at +) +SELECT * +FROM ( + VALUES + ('00000000-0000-0000-0000-000000000000'::uuid, 'blood_pressure_monitor', TRUE, 10, NOW()) + -- 示例:, ('商品UUID'::uuid, 'nebulizer', TRUE, 10, NOW()) + -- 示例:, ('商品UUID'::uuid, 'wound_care', TRUE, 20, NOW()) +) AS seed_rows(product_id, category_id, is_primary, sort_order, created_at) +WHERE FALSE +ON CONFLICT (product_id, category_id) DO UPDATE SET + is_primary = EXCLUDED.is_primary, + sort_order = EXCLUDED.sort_order, + deleted_at = NULL; + +-- 2.1 直接按商品名/编码插入主分类映射 +-- 用途:不手填 UUID,直接从 ml_products 查出商品后写入映射。 +INSERT INTO public.medical_mall_product_categories ( + product_id, + category_id, + is_primary, + sort_order, + created_at +) +SELECT + p.id, + 'blood_pressure_monitor', + TRUE, + 10, + NOW() +FROM public.ml_products p +WHERE p.status = '1' + AND FALSE + -- 示例:AND (p.name ILIKE '%血压计%' OR p.product_code = 'BP001') +ON CONFLICT (product_id, category_id) DO UPDATE SET + is_primary = EXCLUDED.is_primary, + sort_order = EXCLUDED.sort_order, + deleted_at = NULL; + +-- 3. 插入扩展分类映射 +-- 默认使用 WHERE FALSE 保持模板可执行;填入真实数据后,删除 WHERE FALSE 即可。 +INSERT INTO public.medical_mall_product_categories ( + product_id, + category_id, + is_primary, + sort_order, + created_at +) +SELECT * +FROM ( + VALUES + ('00000000-0000-0000-0000-000000000000'::uuid, 'hypertension', FALSE, 30, NOW()) + -- 示例:, ('商品UUID'::uuid, 'elderly_bathroom', FALSE, 30, NOW()) +) AS extra_rows(product_id, category_id, is_primary, sort_order, created_at) +WHERE FALSE +ON CONFLICT (product_id, category_id) DO UPDATE SET + is_primary = EXCLUDED.is_primary, + sort_order = EXCLUDED.sort_order, + deleted_at = NULL; + +-- 3.1 直接按商品名/编码插入扩展分类映射 +INSERT INTO public.medical_mall_product_categories ( + product_id, + category_id, + is_primary, + sort_order, + created_at +) +SELECT + p.id, + 'hypertension', + FALSE, + 30, + NOW() +FROM public.ml_products p +WHERE p.status = '1' + AND FALSE + -- 示例:AND (p.name ILIKE '%电子血压计%' OR p.product_code = 'BP001') +ON CONFLICT (product_id, category_id) DO UPDATE SET + is_primary = EXCLUDED.is_primary, + sort_order = EXCLUDED.sort_order, + deleted_at = NULL; + +-- 4. 软删除错误映射 +UPDATE public.medical_mall_product_categories +SET deleted_at = NOW() +WHERE deleted_at IS NULL + AND ( + -- 示例:product_id = '商品UUID' AND category_id = '错误分类ID' + FALSE + ); + +-- 5. 检查是否存在多个主分类 +SELECT + product_id, + COUNT(*) AS primary_count +FROM public.medical_mall_product_categories +WHERE deleted_at IS NULL + AND is_primary = TRUE +GROUP BY product_id +HAVING COUNT(*) > 1; + +-- 6. 查看分类覆盖情况 +SELECT + c.id AS category_id, + c.name AS category_name, + COUNT(mmc.product_id) AS mapped_products +FROM public.medical_mall_categories c +LEFT JOIN public.medical_mall_product_categories mmc + ON mmc.category_id = c.id + AND mmc.deleted_at IS NULL +WHERE c.deleted_at IS NULL +GROUP BY c.id, c.name, c.sort_order +ORDER BY c.sort_order ASC, c.id ASC; + +-- 7. 查看仍依赖 fallback 风险较高的商品 +SELECT + p.id, + p.name, + p.subtitle, + p.sale_count, + p.created_at +FROM public.ml_products p +LEFT JOIN public.medical_mall_product_categories mmc + ON mmc.product_id = p.id + AND mmc.deleted_at IS NULL +WHERE p.status = '1' + AND mmc.product_id IS NULL + AND ( + p.name ILIKE '%血压%' OR + p.name ILIKE '%血糖%' OR + p.name ILIKE '%血氧%' OR + p.name ILIKE '%体温%' OR + p.name ILIKE '%雾化%' OR + p.name ILIKE '%制氧%' OR + p.name ILIKE '%轮椅%' OR + p.name ILIKE '%拐杖%' OR + p.name ILIKE '%护理床%' OR + p.name ILIKE '%感冒%' OR + p.name ILIKE '%退热%' OR + p.name ILIKE '%创可贴%' OR + p.name ILIKE '%纱布%' OR + p.name ILIKE '%钙片%' OR + p.name ILIKE '%维生素%' OR + p.name ILIKE '%蛋白%' OR + p.name ILIKE '%艾灸%' OR + p.name ILIKE '%热敷%' + ) +ORDER BY p.sale_count DESC, p.created_at DESC; + +COMMIT; \ No newline at end of file diff --git a/sql/seed_medical_homepage_data.sql b/sql/seed_medical_homepage_data.sql new file mode 100644 index 00000000..d874c806 --- /dev/null +++ b/sql/seed_medical_homepage_data.sql @@ -0,0 +1,576 @@ +-- 医疗项目首页种子数据 +-- 目标:补齐首页分类栏 + 首页商品流所需的基础数据 +-- 适用:public.ml_categories / public.ml_brands / public.ml_products / public.ml_shops / public.ak_users +-- 说明: +-- 1. 首页分类栏读取 ml_categories +-- 2. 首页商品流主要读取 ml_products_detail_view(底层为 ml_products 联表) +-- 3. 本脚本可重复执行,使用固定 UUID + ON CONFLICT 保持幂等 +-- 4. 服务首页当前仍是本地 mock,本脚本只覆盖“商城首页”数据 + +BEGIN; + +DO $$ +DECLARE + v_has_role BOOLEAN := FALSE; + v_has_email BOOLEAN := FALSE; + v_has_username BOOLEAN := FALSE; + v_has_phone BOOLEAN := FALSE; + v_has_avatar_url BOOLEAN := FALSE; + v_has_status BOOLEAN := FALSE; + v_has_registration_source BOOLEAN := FALSE; + v_has_nickname BOOLEAN := FALSE; + v_has_real_name BOOLEAN := FALSE; + v_has_created_at BOOLEAN := FALSE; + v_has_updated_at BOOLEAN := FALSE; + v_cols TEXT; + v_vals TEXT; + v_index INTEGER; + v_merchant_ids UUID[] := ARRAY[ + '5f0e7c4d-7c8a-4f6f-9a16-100000000001'::uuid, + '5f0e7c4d-7c8a-4f6f-9a16-100000000002'::uuid, + '5f0e7c4d-7c8a-4f6f-9a16-100000000003'::uuid, + '5f0e7c4d-7c8a-4f6f-9a16-100000000004'::uuid, + '5f0e7c4d-7c8a-4f6f-9a16-100000000005'::uuid, + '5f0e7c4d-7c8a-4f6f-9a16-100000000006'::uuid + ]; + v_usernames TEXT[] := ARRAY['医疗首页商家01', '医疗首页商家02', '医疗首页商家03', '医疗首页商家04', '医疗首页商家05', '医疗首页商家06']; + v_nicknames TEXT[] := ARRAY['康养精选商家', '慢病管理商家', '营养保健商家', '康复护理商家', '本草调理商家', '银龄照护商家']; + v_real_names TEXT[] := ARRAY['康养医疗馆', '慢病健康馆', '营养优选馆', '康复护理馆', '本草调理馆', '银龄照护馆']; + v_emails TEXT[] := ARRAY['seed.medical.home01@local.test', 'seed.medical.home02@local.test', 'seed.medical.home03@local.test', 'seed.medical.home04@local.test', 'seed.medical.home05@local.test', 'seed.medical.home06@local.test']; + v_phones TEXT[] := ARRAY['13900000001', '13900000002', '13900000003', '13900000004', '13900000005', '13900000006']; +BEGIN + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'role' + ) INTO v_has_role; + + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'email' + ) INTO v_has_email; + + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'username' + ) INTO v_has_username; + + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'phone' + ) INTO v_has_phone; + + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'avatar_url' + ) INTO v_has_avatar_url; + + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'status' + ) INTO v_has_status; + + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'registration_source' + ) INTO v_has_registration_source; + + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'nickname' + ) INTO v_has_nickname; + + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'real_name' + ) INTO v_has_real_name; + + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'created_at' + ) INTO v_has_created_at; + + SELECT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'ak_users' AND column_name = 'updated_at' + ) INTO v_has_updated_at; + + FOR v_index IN 1..array_length(v_merchant_ids, 1) LOOP + v_cols := 'id'; + v_vals := quote_literal(v_merchant_ids[v_index]::text) || '::uuid'; + + IF v_has_email THEN + v_cols := v_cols || ', email'; + v_vals := v_vals || ', ' || quote_literal(v_emails[v_index]); + END IF; + + IF v_has_username THEN + v_cols := v_cols || ', username'; + v_vals := v_vals || ', ' || quote_literal(v_usernames[v_index]); + END IF; + + IF v_has_nickname THEN + v_cols := v_cols || ', nickname'; + v_vals := v_vals || ', ' || quote_literal(v_nicknames[v_index]); + END IF; + + IF v_has_real_name THEN + v_cols := v_cols || ', real_name'; + v_vals := v_vals || ', ' || quote_literal(v_real_names[v_index]); + END IF; + + IF v_has_role THEN + v_cols := v_cols || ', role'; + v_vals := v_vals || ', ''merchant'''; + END IF; + + IF v_has_phone THEN + v_cols := v_cols || ', phone'; + v_vals := v_vals || ', ' || quote_literal(v_phones[v_index]); + END IF; + + IF v_has_avatar_url THEN + v_cols := v_cols || ', avatar_url'; + v_vals := v_vals || ', ' || quote_literal('https://picsum.photos/seed/medical-merchant-avatar-' || v_index::text || '/240/240'); + END IF; + + IF v_has_status THEN + v_cols := v_cols || ', status'; + v_vals := v_vals || ', ''active'''; + END IF; + + IF v_has_registration_source THEN + v_cols := v_cols || ', registration_source'; + v_vals := v_vals || ', ''seed'''; + END IF; + + IF v_has_created_at THEN + v_cols := v_cols || ', created_at'; + v_vals := v_vals || ', NOW()'; + END IF; + + IF v_has_updated_at THEN + v_cols := v_cols || ', updated_at'; + v_vals := v_vals || ', NOW()'; + END IF; + + EXECUTE 'INSERT INTO public.ak_users (' || v_cols || ') VALUES (' || v_vals || ') ON CONFLICT (id) DO NOTHING'; + END LOOP; +END $$; + +INSERT INTO public.ml_shops ( + merchant_id, + shop_name, + shop_logo, + description, + contact_name, + contact_phone, + status, + product_count, + rating_avg, + rating_count, + created_at, + updated_at +) +VALUES +('5f0e7c4d-7c8a-4f6f-9a16-100000000001', '康养医疗精选馆', 'https://picsum.photos/seed/medical-shop-logo-01/320/320', '主打家庭常备药与家用监测器械。', '康养精选商家', '13900000001', 1, 10, 4.8, 268, NOW(), NOW()), +('5f0e7c4d-7c8a-4f6f-9a16-100000000002', '安心慢病管理馆', 'https://picsum.photos/seed/medical-shop-logo-02/320/320', '覆盖慢病监测、呼吸护理与居家健康管理。', '慢病管理商家', '13900000002', 1, 10, 4.7, 196, NOW(), NOW()), +('5f0e7c4d-7c8a-4f6f-9a16-100000000003', '益寿营养保健馆', 'https://picsum.photos/seed/medical-shop-logo-03/320/320', '面向骨骼营养、免疫支持与恢复期补充。', '营养保健商家', '13900000003', 1, 10, 4.8, 212, NOW(), NOW()), +('5f0e7c4d-7c8a-4f6f-9a16-100000000004', '术后康复护理馆', 'https://picsum.photos/seed/medical-shop-logo-04/320/320', '提供术后恢复、伤口护理和家庭康复用品。', '康复护理商家', '13900000004', 1, 10, 4.9, 184, NOW(), NOW()), +('5f0e7c4d-7c8a-4f6f-9a16-100000000005', '本草理疗调养馆', 'https://picsum.photos/seed/medical-shop-logo-05/320/320', '主打艾灸理疗、草本贴敷和中式调理商品。', '本草调理商家', '13900000005', 1, 10, 4.7, 173, NOW(), NOW()), +('5f0e7c4d-7c8a-4f6f-9a16-100000000006', '银龄居家照护馆', 'https://picsum.photos/seed/medical-shop-logo-06/320/320', '覆盖长者行动辅助和居家安全防护商品。', '银龄照护商家', '13900000006', 1, 10, 4.8, 205, NOW(), NOW()) +ON CONFLICT (merchant_id) DO UPDATE SET + shop_name = EXCLUDED.shop_name, + shop_logo = EXCLUDED.shop_logo, + description = EXCLUDED.description, + contact_name = EXCLUDED.contact_name, + contact_phone = EXCLUDED.contact_phone, + status = EXCLUDED.status, + product_count = EXCLUDED.product_count, + rating_avg = EXCLUDED.rating_avg, + rating_count = EXCLUDED.rating_count, + updated_at = NOW(); + +INSERT INTO public.ml_brands (id, name, logo_url, description, website, is_active, created_at, updated_at) +VALUES +('6f0e7c4d-7c8a-4f6f-9a16-200000000001', '康宁健康', 'https://picsum.photos/seed/brand-kangning/240/240', '家庭医疗器械与健康监测品牌', 'https://example.com/brands/kangning', TRUE, NOW(), NOW()), +('6f0e7c4d-7c8a-4f6f-9a16-200000000002', '益寿本草', 'https://picsum.photos/seed/brand-yishou/240/240', '中医调理与养护品牌', 'https://example.com/brands/yishou', TRUE, NOW(), NOW()), +('6f0e7c4d-7c8a-4f6f-9a16-200000000003', '安护优选', 'https://picsum.photos/seed/brand-anhu/240/240', '康复护理与长者照护品牌', 'https://example.com/brands/anhu', TRUE, NOW(), NOW()), +('6f0e7c4d-7c8a-4f6f-9a16-200000000004', '呼吸康泰', 'https://picsum.photos/seed/brand-huxi/240/240', '呼吸护理与慢病监测设备品牌', 'https://example.com/brands/huxi', TRUE, NOW(), NOW()), +('6f0e7c4d-7c8a-4f6f-9a16-200000000005', '乐龄守护', 'https://picsum.photos/seed/brand-laoling/240/240', '银龄照护与辅助出行品牌', 'https://example.com/brands/laoling', TRUE, NOW(), NOW()), +('6f0e7c4d-7c8a-4f6f-9a16-200000000006', '家庭医伴', 'https://picsum.photos/seed/brand-yiban/240/240', '家庭常备药与日用健康用品品牌', 'https://example.com/brands/yiban', TRUE, NOW(), NOW()) +ON CONFLICT (id) DO UPDATE SET + name = EXCLUDED.name, + logo_url = EXCLUDED.logo_url, + description = EXCLUDED.description, + website = EXCLUDED.website, + is_active = EXCLUDED.is_active, + updated_at = NOW(); + +INSERT INTO public.ml_categories ( + id, parent_id, name, slug, description, icon_url, banner_url, sort_order, level, path, is_active, seo_title, seo_description, created_at, updated_at +) +VALUES +('7f0e7c4d-7c8a-4f6f-9a16-300000000001', NULL, '常用药品', 'medical-common-medicine', '面向家庭常备、感冒发热、肠胃不适等常见场景的药品分类', 'https://picsum.photos/seed/cat-common-med/200/200', 'https://picsum.photos/seed/cat-common-med-banner/1200/400', 10, 1, ARRAY['常用药品'], TRUE, '常用药品分类', '家庭常备药、感冒发热、肠胃常用药', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000002', NULL, '医疗器械', 'medical-devices', '覆盖血压计、血糖仪、雾化器等家庭监测设备', 'https://picsum.photos/seed/cat-devices/200/200', 'https://picsum.photos/seed/cat-devices-banner/1200/400', 20, 1, ARRAY['医疗器械'], TRUE, '医疗器械分类', '血压计、血糖仪、雾化器等家庭器械', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000003', NULL, '营养保健', 'nutrition-care', '适合免疫增强、骨关节与长者营养补充的保健类商品', 'https://picsum.photos/seed/cat-nutrition/200/200', 'https://picsum.photos/seed/cat-nutrition-banner/1200/400', 30, 1, ARRAY['营养保健'], TRUE, '营养保健分类', '蛋白粉、钙片、维生素等营养保健品', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000004', NULL, '康复护理', 'rehab-care', '适合术后恢复、慢病管理和家庭护理的康复用品', 'https://picsum.photos/seed/cat-rehab/200/200', 'https://picsum.photos/seed/cat-rehab-banner/1200/400', 40, 1, ARRAY['康复护理'], TRUE, '康复护理分类', '术后恢复、压疮护理、日常护理用品', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000005', NULL, '中医调理', 'tcm-care', '包含理疗贴、艾灸养护和中式调理产品', 'https://picsum.photos/seed/cat-tcm/200/200', 'https://picsum.photos/seed/cat-tcm-banner/1200/400', 50, 1, ARRAY['中医调理'], TRUE, '中医调理分类', '艾灸、穴位贴、草本调理产品', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000006', NULL, '老年照护', 'elder-care', '适合长者居家照护、安全防护和辅助生活的商品', 'https://picsum.photos/seed/cat-elder/200/200', 'https://picsum.photos/seed/cat-elder-banner/1200/400', 60, 1, ARRAY['老年照护'], TRUE, '老年照护分类', '轮椅、助行器、防跌用品等长者照护商品', NOW(), NOW()), + +('7f0e7c4d-7c8a-4f6f-9a16-300000000101', '7f0e7c4d-7c8a-4f6f-9a16-300000000001', '感冒发热', 'cold-fever', '退热、止痛、感冒常备药', 'https://picsum.photos/seed/sub-cold-fever/200/200', NULL, 11, 2, ARRAY['常用药品','感冒发热'], TRUE, '感冒发热用药', '适用于家庭常备的感冒发热场景', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000102', '7f0e7c4d-7c8a-4f6f-9a16-300000000001', '肠胃调理', 'digestive-care', '适合肠胃不适和日常调理', 'https://picsum.photos/seed/sub-digestive/200/200', NULL, 12, 2, ARRAY['常用药品','肠胃调理'], TRUE, '肠胃调理用药', '肠胃调理及胃肠不适场景用药', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000201', '7f0e7c4d-7c8a-4f6f-9a16-300000000002', '血压监测', 'blood-pressure-monitoring', '家庭血压监测设备', 'https://picsum.photos/seed/sub-bp/200/200', NULL, 21, 2, ARRAY['医疗器械','血压监测'], TRUE, '血压监测设备', '适用于家庭与长者的血压监测设备', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000202', '7f0e7c4d-7c8a-4f6f-9a16-300000000002', '呼吸理疗', 'respiratory-care', '雾化与呼吸辅助设备', 'https://picsum.photos/seed/sub-respiratory/200/200', NULL, 22, 2, ARRAY['医疗器械','呼吸理疗'], TRUE, '呼吸理疗设备', '雾化器、制氧及呼吸辅助商品', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000301', '7f0e7c4d-7c8a-4f6f-9a16-300000000003', '骨骼营养', 'bone-nutrition', '钙、维生素 D 等骨骼关节营养商品', 'https://picsum.photos/seed/sub-bone/200/200', NULL, 31, 2, ARRAY['营养保健','骨骼营养'], TRUE, '骨骼营养补充', '适合中老年与骨骼健康场景', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000302', '7f0e7c4d-7c8a-4f6f-9a16-300000000003', '免疫支持', 'immune-support', '蛋白、维生素与免疫支持产品', 'https://picsum.photos/seed/sub-immune/200/200', NULL, 32, 2, ARRAY['营养保健','免疫支持'], TRUE, '免疫支持营养', '适合日常营养补充与免疫支持', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000401', '7f0e7c4d-7c8a-4f6f-9a16-300000000004', '术后恢复', 'post-surgery-recovery', '适用于术后恢复阶段的护理产品', 'https://picsum.photos/seed/sub-postop/200/200', NULL, 41, 2, ARRAY['康复护理','术后恢复'], TRUE, '术后恢复护理', '术后康复、恢复期护理场景', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000402', '7f0e7c4d-7c8a-4f6f-9a16-300000000004', '伤口护理', 'wound-care', '敷料、护理包和伤口辅助用品', 'https://picsum.photos/seed/sub-wound/200/200', NULL, 42, 2, ARRAY['康复护理','伤口护理'], TRUE, '伤口护理用品', '家庭和术后伤口护理场景用品', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000501', '7f0e7c4d-7c8a-4f6f-9a16-300000000005', '艾灸理疗', 'moxa-therapy', '艾灸盒、艾条和温灸护理商品', 'https://picsum.photos/seed/sub-moxa/200/200', NULL, 51, 2, ARRAY['中医调理','艾灸理疗'], TRUE, '艾灸理疗用品', '家庭艾灸、温灸理疗商品', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000502', '7f0e7c4d-7c8a-4f6f-9a16-300000000005', '草本贴敷', 'herbal-patch', '草本热敷、穴位贴与理疗贴', 'https://picsum.photos/seed/sub-herbal-patch/200/200', NULL, 52, 2, ARRAY['中医调理','草本贴敷'], TRUE, '草本贴敷用品', '肩颈腰腿舒缓与理疗贴类商品', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000601', '7f0e7c4d-7c8a-4f6f-9a16-300000000006', '行动辅助', 'mobility-aid', '轮椅、助行器和起身辅助用品', 'https://picsum.photos/seed/sub-mobility/200/200', NULL, 61, 2, ARRAY['老年照护','行动辅助'], TRUE, '行动辅助用品', '长者安全出行与行动辅助商品', NOW(), NOW()), +('7f0e7c4d-7c8a-4f6f-9a16-300000000602', '7f0e7c4d-7c8a-4f6f-9a16-300000000006', '居家防护', 'home-safety', '防滑、防跌和床旁安全辅助用品', 'https://picsum.photos/seed/sub-home-safety/200/200', NULL, 62, 2, ARRAY['老年照护','居家防护'], TRUE, '居家防护用品', '适合长者家庭安全防护场景', NOW(), NOW()) +ON CONFLICT (id) DO UPDATE SET + parent_id = EXCLUDED.parent_id, + name = EXCLUDED.name, + slug = EXCLUDED.slug, + description = EXCLUDED.description, + icon_url = EXCLUDED.icon_url, + banner_url = EXCLUDED.banner_url, + sort_order = EXCLUDED.sort_order, + level = EXCLUDED.level, + path = EXCLUDED.path, + is_active = EXCLUDED.is_active, + seo_title = EXCLUDED.seo_title, + seo_description = EXCLUDED.seo_description, + updated_at = NOW(); + +WITH seed_templates AS ( + SELECT * + FROM ( + VALUES + (1, '5f0e7c4d-7c8a-4f6f-9a16-100000000001'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000006'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000101'::uuid, '家庭退热护理贴', '家庭常备退热护理,适合儿童与成人', '常用药品', 29.90, 4.50, 0.12, ARRAY['退热护理','家庭常备','首页推荐']::text[], '8片/盒', '直接贴敷于额头或太阳穴附近', '皮肤破损处慎用', '24个月', '阴凉干燥处保存', '粤械注准20261', '夜间应急降温与陪护', '儿童发热、成人低烧与家庭药箱场景', '家庭药箱、值班陪护、夜间临时应对', '贴敷型物理护理,不占用口服用药节奏'), + (2, '5f0e7c4d-7c8a-4f6f-9a16-100000000001'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000006'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000102'::uuid, '草本暖胃调理贴', '腹部热敷舒缓,适合肠胃日常调理', '常用药品', 42.00, 5.00, 0.10, ARRAY['肠胃调理','草本贴敷','居家护理']::text[], '6贴/盒', '贴于腹部不适区域,每次4至6小时', '避免高温环境使用', '24个月', '阴凉处保存', '粤械注准20262', '餐后腹部热敷与换季调理', '久坐人群、饮食不规律人群与女性日常护理', '办公室抽屉、宿舍常备、出差随身护理', '贴敷型胃腹护理,更适合连续日常使用'), + (3, '5f0e7c4d-7c8a-4f6f-9a16-100000000002'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000001'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000201'::uuid, '智能血压监测仪', '语音播报与大屏显示,适合居家监测', '医疗器械', 199.00, 18.00, 0.85, ARRAY['血压监测','家用器械','老人适用']::text[], '1台/盒', '绑好袖带后按开始键测量', '测量前请静坐5分钟', '长期', '干燥处保存', '粤械注准20263', '居家晨晚双时段血压记录', '长者家庭、慢病管理用户与社区随访场景', '卧室床头、客厅药柜、社区义诊随身箱', '适合作为家庭监测主设备,强调读数稳定和易读性'), + (4, '5f0e7c4d-7c8a-4f6f-9a16-100000000002'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000004'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000202'::uuid, '静音雾化护理机', '家庭呼吸理疗,适合儿童与长者', '医疗器械', 239.00, 22.00, 1.20, ARRAY['呼吸护理','静音雾化','家庭理疗']::text[], '1台/盒', '加注溶液后按说明启动', '使用后及时清洁雾化杯', '长期', '干燥处保存', '粤械注准20264', '换季敏感期与夜间呼吸护理', '儿童鼻咽不适、长者呼吸护理与家庭理疗用户', '床旁护理区、儿童房、家庭护理角', '雾化颗粒更细,适合家庭安静环境连续使用'), + (5, '5f0e7c4d-7c8a-4f6f-9a16-100000000003'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000002'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000301'::uuid, '高钙维D营养片', '骨骼营养补充,适合中老年日常使用', '营养保健', 79.00, 7.00, 0.28, ARRAY['骨骼营养','维D补充','长者营养']::text[], '60片/瓶', '每日1至2片,咀嚼后吞服', '勿超过推荐量服用', '24个月', '阴凉干燥处保存', '食健备G20265', '骨骼基础营养与长期补给', '中老年、久坐办公族与骨密度关注人群', '早餐后补充、家庭常备营养角、长周期回购', '更适合做月度补给型商品,强调长期规律使用'), + (6, '5f0e7c4d-7c8a-4f6f-9a16-100000000003'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000006'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000302'::uuid, '乳清蛋白营养粉', '恢复期与长者补充营养更省心', '营养保健', 168.00, 15.00, 0.90, ARRAY['免疫支持','高蛋白','恢复期']::text[], '900g/罐', '温水冲调,每次20至30g', '开封后尽快食用', '18个月', '密封避光保存', '食健备G20266', '术后恢复与日常增补蛋白', '恢复期、体质偏弱、食量不足与长者营养支持人群', '早餐代餐、术后陪护、营养加餐和睡前补给', '更适合搭配恢复期护理场景,强调蛋白摄入效率'), + (7, '5f0e7c4d-7c8a-4f6f-9a16-100000000004'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000003'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000401'::uuid, '术后支撑恢复带', '弹性支撑设计,辅助日常活动恢复', '康复护理', 128.00, 12.00, 0.42, ARRAY['术后恢复','支撑护具','康复护理']::text[], '1件/盒', '按说明固定于腰腹或术后恢复部位', '过紧佩戴会影响舒适度', '长期', '干燥通风处保存', '粤械注准20267', '术后起身支撑与短程活动辅助', '腹部术后、产后恢复与腰腹支撑需求人群', '住院陪护包、居家恢复期、复查往返途中', '更适合作为恢复阶段核心护理单品,强调支撑稳定'), + (8, '5f0e7c4d-7c8a-4f6f-9a16-100000000004'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000003'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000402'::uuid, '无菌伤口护理包', '含敷料与清洁耗材,家庭护理更方便', '康复护理', 58.00, 6.00, 0.22, ARRAY['伤口护理','无菌敷料','家庭护理']::text[], '1包/套', '按说明进行伤口清洁与覆盖', '严重伤口请及时就医', '24个月', '阴凉干燥处保存', '粤械注准20268', '换药清洁与创面日常防护', '轻度创面护理、术后换药与家庭备用耗材需求人群', '居家药箱、门诊复诊、旅行应急护理包', '耗材组合更完整,适合作为高频消耗型护理商品'), + (9, '5f0e7c4d-7c8a-4f6f-9a16-100000000005'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000002'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000501'::uuid, '家用艾灸温灸盒', '居家温灸理疗,适合肩颈腰腿舒缓', '中医调理', 88.00, 8.00, 0.35, ARRAY['艾灸理疗','居家调理','肩颈舒缓']::text[], '1套/盒', '放入艾柱后按说明固定使用', '避免直接接触烫伤', '长期', '干燥处保存', '粤械注准20269', '肩颈腰腿温灸放松与日常养护', '久坐办公族、居家理疗人群与中式养护偏好用户', '晚间放松、周末理疗、家庭保健角', '理疗氛围感更强,适合作为中式调养类主推单品'), + (10, '5f0e7c4d-7c8a-4f6f-9a16-100000000005'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000002'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000502'::uuid, '肩颈草本热敷贴', '办公居家适用,帮助肩颈腰背舒缓', '中医调理', 49.90, 5.50, 0.16, ARRAY['草本贴敷','肩颈护理','居家理疗']::text[], '10贴/盒', '直接贴于肩颈腰背部位', '睡眠时不建议长时间贴敷', '24个月', '密封避光保存', '粤械注准20270', '久坐肩颈热敷与午后舒缓', '办公久坐、伏案学习与轻度劳损舒缓人群', '办公桌抽屉、车载收纳、差旅随行护理包', '贴敷便捷,适合作为通勤和办公场景高频复购商品'), + (11, '5f0e7c4d-7c8a-4f6f-9a16-100000000006'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000005'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000601'::uuid, '折叠助行辅助器', '轻便稳固,适合长者居家外出', '老年照护', 268.00, 16.00, 2.80, ARRAY['行动辅助','长者照护','安全出行']::text[], '1台/件', '展开后调节合适高度使用', '地面湿滑时请减速慢行', '长期', '干燥环境保存', '粤械注准20271', '长者短距离行走与外出辅助', '腿脚无力长者、术后康复期与家庭陪护人群', '客厅日常使用、社区散步、医院复诊外出', '更适合作为银龄照护大件主推,强调折叠与稳固兼顾'), + (12, '5f0e7c4d-7c8a-4f6f-9a16-100000000006'::uuid, '6f0e7c4d-7c8a-4f6f-9a16-200000000005'::uuid, '7f0e7c4d-7c8a-4f6f-9a16-300000000602'::uuid, '浴室防滑扶手套装', '长者洗浴与走道区域安全防护', '老年照护', 139.00, 11.00, 1.15, ARRAY['居家防护','防跌安全','长者必备']::text[], '2件/套', '安装于浴室或走道墙面', '安装前确认墙面承重', '长期', '常温保存', '粤械注准20272', '洗浴区起身借力与走道安全防护', '居家长者、术后行动不稳人群与家庭照护用户', '卫生间、卧室过道、床边起身点位', '更适合作为居家改造类商品,强调安装场景和防跌价值') + ) AS t(template_index, merchant_id, brand_id, category_id, product_prefix, subtitle_base, scene_name, base_price, price_step, base_weight, tags, specification, usage, precautions, expiry_date, storage_conditions, approval_prefix, care_focus, audience_focus, usage_scene, merch_focus) +), +image_map AS ( + SELECT * + FROM ( + VALUES + (1, 'https://upload.wikimedia.org/wikipedia/commons/2/20/Applying_transdermal_patch.jpg'), + (2, 'https://images.unsplash.com/photo-1773747608435-0fa80d11a32f?q=80&w=627&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'), + (3, 'https://images.unsplash.com/photo-1631815584191-0ed1723f0ead?q=80&w=678&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'), + (4, 'https://images.unsplash.com/photo-1645273474824-1facac10c30c?q=80&w=687&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'), + (5, 'https://images.unsplash.com/photo-1729700985369-c04bb4557431?q=80&w=687&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'), + (6, 'https://images.unsplash.com/photo-1704650311190-7eeb9c4f6e11?q=80&w=1170&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'), + (7, 'https://images.unsplash.com/photo-1768839725129-98df1d51e4b7?q=80&w=1170&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'), + (8, 'https://images.unsplash.com/photo-1765996796562-ce301df337a0?q=80&w=1170&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'), + (9, 'https://upload.wikimedia.org/wikipedia/commons/f/f2/Ibuki_moxa_set.jpg'), + (10, 'https://upload.wikimedia.org/wikipedia/commons/1/18/Kinesio_taping_on_neck.jpg'), + (11, 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Medical_Walker.JPG'), + (12, 'https://images.unsplash.com/photo-1656646523834-dd1cc57d33c9?q=80&w=1170&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D') + ) AS t(template_index, image_url) +), +seed_products AS ( + SELECT + ('8f0e7c4d-7c8a-4f6f-9a16-' || LPAD((((template_index - 1) * 5) + seq)::text, 12, '0'))::uuid AS id, + merchant_id, + category_id, + brand_id, + format('MEDHOME-20260520-%s', LPAD((((template_index - 1) * 5) + seq)::text, 3, '0')) AS product_code, + product_prefix || CASE seq + WHEN 1 THEN ' 标准款' + WHEN 2 THEN ' 家庭常备装' + WHEN 3 THEN ' 舒适加强款' + WHEN 4 THEN ' 便携随行装' + ELSE ' 臻选礼盒装' + END AS name, + subtitle_base || CASE seq + WHEN 1 THEN ',适合作为日常基础护理选择' + WHEN 2 THEN ',更适合居家储备与多人使用' + WHEN 3 THEN ',覆盖更集中的护理与调理需求' + WHEN 4 THEN ',适合通勤、陪护或外出携带' + ELSE ',兼顾体验感与送礼陈列场景' + END AS subtitle, + scene_name || CASE seq + WHEN 1 THEN '场景常规推荐款,适合门店首页稳定陈列与日常转化。' + WHEN 2 THEN '场景家庭囤货款,强调使用周期更长、备货更省心。' + WHEN 3 THEN '场景强化护理款,适合症状较集中或恢复阶段的重点选择。' + WHEN 4 THEN '场景轻便出行款,方便通勤、探视、陪护和短期外带。' + ELSE '场景升级体验款,适合首页活动位、礼赠位或高客单展示。' + END || ' 核心关注:' || care_focus || '。适用人群:' || audience_focus || '。' AS description, + image_map.image_url AS main_image_url, + jsonb_build_array(image_map.image_url) AS image_urls, + '[]'::jsonb AS video_urls, + ROUND((base_price + ( + CASE seq + WHEN 1 THEN 0 + WHEN 2 THEN price_step * 2.2 + WHEN 3 THEN price_step * 4.8 + WHEN 4 THEN price_step * 1.1 + ELSE price_step * 7.4 + END + ))::numeric, 2)::numeric(10,2) AS base_price, + ROUND((base_price + ( + CASE seq + WHEN 1 THEN price_step * 2.8 + WHEN 2 THEN price_step * 5.2 + WHEN 3 THEN price_step * 8.0 + WHEN 4 THEN price_step * 3.9 + ELSE price_step * 11.4 + END + ))::numeric, 2)::numeric(10,2) AS market_price, + ROUND((base_price + ( + CASE seq + WHEN 1 THEN 0 + WHEN 2 THEN price_step * 2.2 + WHEN 3 THEN price_step * 4.8 + WHEN 4 THEN price_step * 1.1 + ELSE price_step * 7.4 + END + )) * 0.58, 2)::numeric(10,2) AS cost_price, + CASE seq + WHEN 1 THEN 160 + (template_index * 18) + WHEN 2 THEN 240 + (template_index * 24) + WHEN 3 THEN 130 + (template_index * 16) + WHEN 4 THEN 210 + (template_index * 20) + ELSE 96 + (template_index * 12) + END AS total_stock, + CASE seq + WHEN 1 THEN 148 + (template_index * 16) + WHEN 2 THEN 222 + (template_index * 20) + WHEN 3 THEN 118 + (template_index * 14) + WHEN 4 THEN 192 + (template_index * 18) + ELSE 84 + (template_index * 10) + END AS available_stock, + 1 AS min_order_qty, + CASE seq + WHEN 1 THEN 3 + WHEN 2 THEN 6 + WHEN 3 THEN 2 + WHEN 4 THEN 2 + ELSE 1 + END AS max_order_qty, + (base_weight + ( + CASE seq + WHEN 1 THEN 0.00 + WHEN 2 THEN 0.18 + WHEN 3 THEN 0.32 + WHEN 4 THEN -0.05 + ELSE 0.46 + END + ))::numeric(10,2) AS weight, + jsonb_build_object( + 'length', 16 + template_index + CASE seq WHEN 2 THEN 4 WHEN 3 THEN 2 WHEN 4 THEN -1 ELSE 5 END, + 'width', 10 + CASE seq WHEN 2 THEN 3 WHEN 3 THEN 2 WHEN 4 THEN 0 ELSE 4 END, + 'height', 4 + CASE seq WHEN 2 THEN 2 WHEN 3 THEN 1 WHEN 4 THEN 0 ELSE 3 END + (template_index / 3) + ) AS dimensions, + 1 AS status, + CASE WHEN seq IN (1, 2) THEN TRUE ELSE FALSE END AS is_featured, + CASE WHEN seq IN (2, 4, 5) THEN TRUE ELSE FALSE END AS is_new, + CASE WHEN seq IN (1, 3) THEN TRUE ELSE FALSE END AS is_hot, + 1200 + (template_index * 280) + (seq * 160) AS view_count, + 260 + (template_index * 80) + (seq * 45) AS sale_count, + 48 + (template_index * 18) + (seq * 9) AS favorite_count, + LEAST(4.9, 4.5 + (template_index * 0.02) + (seq * 0.05))::numeric(3,1) AS rating_avg, + 60 + (template_index * 14) + (seq * 8) AS rating_count, + tags || ARRAY[ + CASE seq + WHEN 1 THEN '标准护理' + WHEN 2 THEN '家庭常备' + WHEN 3 THEN '加强调理' + WHEN 4 THEN '便携随行' + ELSE '臻选礼盒' + END, + CASE + WHEN scene_name = '常用药品' THEN '家庭药箱' + WHEN scene_name = '医疗器械' THEN '居家监测' + WHEN scene_name = '营养保健' THEN '营养补给' + WHEN scene_name = '康复护理' THEN '恢复护理' + WHEN scene_name = '中医调理' THEN '理疗养护' + ELSE '银龄照护' + END, + '医疗首页' + ] AS full_tags, + jsonb_build_object( + 'specification', specification || CASE seq + WHEN 1 THEN ',标准单元配置,适合首次购买与基础日常使用' + WHEN 2 THEN ',家庭周期装,单次备货覆盖时间更长' + WHEN 3 THEN ',加强护理配置,核心用量或强度做了上调' + WHEN 4 THEN ',便携小规格配置,适合外出或复诊随身携带' + ELSE ',礼盒陈列配置,更适合作为高客单或送礼选择' + END, + 'usage', usage || CASE seq + WHEN 1 THEN ',适合日常基础使用频率。' + WHEN 2 THEN ',建议放置于家庭常用药箱、护理柜或床旁储物区。' + WHEN 3 THEN ',适合恢复期、症状较集中阶段或连续护理周期使用。' + WHEN 4 THEN ',适合外出、复诊、短期陪护或车载随手包场景携带。' + ELSE ',适合首页活动展示、礼赠组合或高意向用户选购。' + END, + 'side_effects', CASE seq + WHEN 3 THEN '个别人群可能出现短时不适,建议先小量体验' + WHEN 5 THEN '首次使用建议阅读说明或咨询专业人员' + ELSE '一般耐受良好' + END, + 'precautions', precautions || CASE seq + WHEN 2 THEN ',启封后建议尽快按周期用完。' + WHEN 4 THEN ',随身携带时注意防潮防压。' + WHEN 5 THEN ',升级配置请结合实际需求选择。' + ELSE '。' + END, + 'expiry_date', expiry_date, + 'storage_conditions', storage_conditions, + 'approval_number', approval_prefix || LPAD((((template_index - 1) * 5) + seq)::text, 4, '0'), + 'target_population', CASE seq + WHEN 1 THEN audience_focus || ',偏基础护理与首次购买' + WHEN 2 THEN audience_focus || ',偏家庭常备与多人共享' + WHEN 3 THEN audience_focus || ',偏重点护理与连续使用' + WHEN 4 THEN audience_focus || ',偏短期外带与移动场景' + ELSE audience_focus || ',偏礼赠、升级体验与高意向消费' + END, + 'selling_points', jsonb_build_array( + CASE seq + WHEN 1 THEN '入门门槛低,适合首页常规爆款位与首次下单' + WHEN 2 THEN '容量与周期更长,适合家庭储备和周期补货' + WHEN 3 THEN '重点场景更聚焦,适合恢复期或强化护理转化' + WHEN 4 THEN '规格更轻便,适合外带、复诊包和临时使用' + ELSE '陈列感更强,适合活动位、礼赠位与高客单展示' + END, + '支持医疗首页分类流与推荐流展示', + scene_name || '场景匹配度高', + merch_focus, + CASE seq + WHEN 1 THEN '价格带适合作为基础转化款' + WHEN 2 THEN '价格带适合作为家庭囤货款' + WHEN 3 THEN '价格带适合作为强化护理款' + WHEN 4 THEN '价格带适合作为便携补充款' + ELSE '价格带适合作为高价值展示款' + END + ), + 'price_band', CASE seq + WHEN 1 THEN '基础入门' + WHEN 2 THEN '家庭常备' + WHEN 3 THEN '加强护理' + WHEN 4 THEN '便携补充' + ELSE '礼盒升级' + END, + 'stock_strategy', CASE seq + WHEN 1 THEN '稳定补货' + WHEN 2 THEN '高库存常备' + WHEN 3 THEN '中库存重点护理' + WHEN 4 THEN '中高库存便携周转' + ELSE '低库存陈列展示' + END, + 'care_focus', care_focus, + 'usage_scene', usage_scene, + 'merch_focus', merch_focus + ) AS attributes, + LOWER(REPLACE(product_prefix, ' ', '-')) AS slug_base + FROM seed_templates + INNER JOIN image_map ON image_map.template_index = seed_templates.template_index + CROSS JOIN generate_series(1, 5) AS seq +) +INSERT INTO public.ml_products ( + id, merchant_id, category_id, brand_id, product_code, name, subtitle, description, + main_image_url, image_urls, video_urls, + base_price, market_price, cost_price, + total_stock, available_stock, min_order_qty, max_order_qty, + weight, dimensions, + status, is_featured, is_new, is_hot, + view_count, sale_count, favorite_count, rating_avg, rating_count, + seo_title, seo_description, seo_keywords, slug, tags, attributes, + created_at, updated_at, published_at +) +SELECT + id, + merchant_id, + category_id, + brand_id, + product_code, + name, + subtitle, + description, + main_image_url, + image_urls, + video_urls, + base_price, + market_price, + cost_price, + total_stock, + available_stock, + min_order_qty, + max_order_qty, + weight, + dimensions, + status, + is_featured, + is_new, + is_hot, + view_count, + sale_count, + favorite_count, + rating_avg, + rating_count, + name AS seo_title, + description AS seo_description, + full_tags, + slug_base || '-' || RIGHT(product_code, 3), + full_tags, + attributes, + NOW(), + NOW(), + NOW() +FROM seed_products +ON CONFLICT (id) DO UPDATE SET + merchant_id = EXCLUDED.merchant_id, + category_id = EXCLUDED.category_id, + brand_id = EXCLUDED.brand_id, + product_code = EXCLUDED.product_code, + name = EXCLUDED.name, + subtitle = EXCLUDED.subtitle, + description = EXCLUDED.description, + main_image_url = EXCLUDED.main_image_url, + image_urls = EXCLUDED.image_urls, + video_urls = EXCLUDED.video_urls, + base_price = EXCLUDED.base_price, + market_price = EXCLUDED.market_price, + cost_price = EXCLUDED.cost_price, + total_stock = EXCLUDED.total_stock, + available_stock = EXCLUDED.available_stock, + min_order_qty = EXCLUDED.min_order_qty, + max_order_qty = EXCLUDED.max_order_qty, + weight = EXCLUDED.weight, + dimensions = EXCLUDED.dimensions, + status = EXCLUDED.status, + is_featured = EXCLUDED.is_featured, + is_new = EXCLUDED.is_new, + is_hot = EXCLUDED.is_hot, + view_count = EXCLUDED.view_count, + sale_count = EXCLUDED.sale_count, + favorite_count = EXCLUDED.favorite_count, + rating_avg = EXCLUDED.rating_avg, + rating_count = EXCLUDED.rating_count, + seo_title = EXCLUDED.seo_title, + seo_description = EXCLUDED.seo_description, + seo_keywords = EXCLUDED.seo_keywords, + slug = EXCLUDED.slug, + tags = EXCLUDED.tags, + attributes = EXCLUDED.attributes, + updated_at = NOW(), + published_at = EXCLUDED.published_at; + +COMMIT; + +-- 执行完成后可运行以下校验语句: +-- SELECT id, name, level, parent_id FROM public.ml_categories WHERE slug LIKE 'medical-%' OR slug IN ('cold-fever','digestive-care','blood-pressure-monitoring','respiratory-care','bone-nutrition','immune-support','post-surgery-recovery','wound-care','moxa-therapy','herbal-patch','mobility-aid','home-safety') ORDER BY sort_order; +-- SELECT product_code, name, base_price, sale_count, is_featured, is_new, is_hot FROM public.ml_products WHERE product_code LIKE 'MEDHOME-%' ORDER BY product_code; +-- SELECT category_name, brand_name, shop_name, merchant_name, name FROM public.ml_products_detail_view WHERE product_code LIKE 'MEDHOME-%' ORDER BY product_code; \ No newline at end of file diff --git a/sql/seed_medical_mall_categories.sql b/sql/seed_medical_mall_categories.sql new file mode 100644 index 00000000..437a1468 --- /dev/null +++ b/sql/seed_medical_mall_categories.sql @@ -0,0 +1,186 @@ +-- Seed: 医疗商城首页分类与示例商品关联 +-- 依赖: public.medical_mall_categories / public.medical_mall_product_categories / public.ml_products + +BEGIN; + +INSERT INTO public.medical_mall_categories ( + id, name, parent_id, level, sort_order, icon, image_url, description, scene, category_type, compliance_type, is_active, created_at, updated_at +) +VALUES +('med_device', '医疗器械', NULL, 1, 10, '🩺', NULL, '家庭监测与基础器械', 'medical_mall', 'device', 'device_class_i', TRUE, NOW(), NOW()), +('otc_medicine', '家庭常备药', NULL, 1, 20, '💊', NULL, 'OTC 家庭常备药与应急用药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('rehab_care', '康复护理', NULL, 1, 30, '🩹', NULL, '术后恢复、敷料护具与护理用品', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), +('chronic_monitor', '慢病监测', NULL, 1, 40, '📈', NULL, '高血压、糖尿病与家庭检测场景', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('elderly_aid', '适老用品', NULL, 1, 50, '🧓', NULL, '长者安全辅助与居家适老用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('nutrition_health', '营养保健', NULL, 1, 60, '🥛', NULL, '维生素、钙片、蛋白营养等保健品', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('protection_disinfection', '防护消毒', NULL, 1, 70, '😷', NULL, '口罩、消毒、急救与防护耗材', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('tcm_health', '中医保健', NULL, 1, 80, '🌿', NULL, '艾灸、贴敷、按摩理疗与草本养护', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('home_care_daily', '居家护理', NULL, 1, 90, '🏠', NULL, '伤口、口腔、皮肤与家庭健康工具', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('all_medical', '全部', NULL, 1, 100, '🧺', NULL, '查看全部康养医疗商品', 'medical_mall', 'all', 'normal', TRUE, NOW(), NOW()), + +('blood_pressure_monitor', '血压计', 'med_device', 2, 11, '🫀', NULL, '家庭血压监测设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('blood_glucose_meter', '血糖仪', 'med_device', 2, 12, '🩸', NULL, '家庭血糖检测设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('oximeter', '血氧仪', 'med_device', 2, 13, '💗', NULL, '指夹式血氧监测设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('thermometer', '体温计', 'med_device', 2, 14, '🌡️', NULL, '额温枪与电子体温计', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('oxygen_concentrator', '制氧机', 'med_device', 2, 15, '🫁', NULL, '家庭制氧与吸氧辅助设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('nebulizer', '雾化器', 'med_device', 2, 16, '💨', NULL, '家用雾化护理设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()), +('wheelchair_crutch', '轮椅拐杖', 'med_device', 2, 17, '🦽', NULL, '轮椅、拐杖与行动辅助器具', 'medical_mall', 'device', 'device_class_i', TRUE, NOW(), NOW()), +('nursing_bed', '护理床', 'med_device', 2, 18, '🛏️', NULL, '护理床与居家照护床具', 'medical_mall', 'device', 'device_class_i', TRUE, NOW(), NOW()), + +('cold_fever', '感冒发烧', 'otc_medicine', 2, 21, '🤒', NULL, '感冒、退热与家庭常备药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('cough_throat', '咳嗽咽喉', 'otc_medicine', 2, 22, '🗣️', NULL, '咳嗽、咽喉与润喉护理', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('stomach_medicine', '肠胃用药', 'otc_medicine', 2, 23, '🥣', NULL, '肠胃调理与胃肠常备药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('skin_external', '皮肤外用', 'otc_medicine', 2, 24, '🧴', NULL, '皮肤喷剂、软膏与外用护理', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('eye_ear_nose', '眼耳口鼻', 'otc_medicine', 2, 25, '👁️', NULL, '眼耳鼻喉口腔常备用品', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('pain_relief', '止痛用药', 'otc_medicine', 2, 26, '🩹', NULL, '止痛、舒缓与应急常备药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('trauma_sprain', '跌打损伤', 'otc_medicine', 2, 27, '🦴', NULL, '跌打扭伤与运动损伤护理', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), +('child_medicine', '儿童用药', 'otc_medicine', 2, 28, '🧒', NULL, '儿童常备药与护理用品', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()), + +('postop_rehab', '术后康复', 'rehab_care', 2, 31, '🩺', NULL, '术后恢复与支撑护理', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), +('wound_dressing', '伤口敷料', 'rehab_care', 2, 32, '🩹', NULL, '敷料、纱布与换药护理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('brace_support', '护具支具', 'rehab_care', 2, 33, '🦵', NULL, '护腰、护膝与支撑固定用品', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), +('rehab_training', '康复训练器', 'rehab_care', 2, 34, '🏋️', NULL, '康复训练与恢复辅助设备', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), +('physiotherapy_hot', '理疗热敷', 'rehab_care', 2, 35, '🔥', NULL, '热敷理疗与家庭舒缓护理', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), +('mobility_training', '行动训练', 'rehab_care', 2, 36, '🚶', NULL, '恢复行动能力的辅助训练用品', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()), + +('hypertension', '高血压管理', 'chronic_monitor', 2, 41, '❤️', NULL, '高血压居家管理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('diabetes', '糖尿病管理', 'chronic_monitor', 2, 42, '🩸', NULL, '血糖监测与糖尿病管理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('cardiovascular', '心脑血管', 'chronic_monitor', 2, 43, '🫀', NULL, '心脑血管健康管理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('respiratory_health', '呼吸健康', 'chronic_monitor', 2, 44, '🫁', NULL, '呼吸道护理与呼吸健康', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('weight_bodyfat', '体重体脂', 'chronic_monitor', 2, 45, '⚖️', NULL, '体重与体脂监测', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('home_testing', '家庭检测', 'chronic_monitor', 2, 46, '🧪', NULL, '家庭常用健康检测用品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), + +('anti_slip', '防滑安全', 'elderly_aid', 2, 51, '🧱', NULL, '长者防滑与跌倒预防', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('elderly_bathroom', '适老卫浴', 'elderly_aid', 2, 52, '🚿', NULL, '浴室扶手与适老卫浴辅助', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('eating_aid', '助餐用品', 'elderly_aid', 2, 53, '🍽️', NULL, '适老助餐与餐具辅助', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('bathing_aid', '助浴用品', 'elderly_aid', 2, 54, '🛁', NULL, '助浴椅与洗护辅助用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('incontinence_care', '失禁护理', 'elderly_aid', 2, 55, '🧻', NULL, '长者失禁护理用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), +('daily_living_aid', '生活辅助', 'elderly_aid', 2, 56, '🪑', NULL, '日常起居与生活辅助用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()), + +('vitamin', '维生素', 'nutrition_health', 2, 61, '🍊', NULL, '复合维生素与维 C 等营养补充', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('calcium', '钙铁锌硒', 'nutrition_health', 2, 62, '🦴', NULL, '钙铁锌硒等基础营养', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('protein', '蛋白营养', 'nutrition_health', 2, 63, '🥛', NULL, '蛋白粉与恢复期营养', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('elderly_nutrition', '老人营养', 'nutrition_health', 2, 64, '👴', NULL, '适合长者的专用营养补充', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('gut_health', '肠道益生菌', 'nutrition_health', 2, 65, '🦠', NULL, '益生菌与肠胃营养补充', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), +('immune_support', '免疫支持', 'nutrition_health', 2, 66, '🛡️', NULL, '免疫支持与日常补给', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()), + +('mask', '口罩', 'protection_disinfection', 2, 71, '😷', NULL, '日常口罩与防护耗材', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('disinfectant', '消毒液', 'protection_disinfection', 2, 72, '🧴', NULL, '家庭与环境消毒用品', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('alcohol_wipes', '酒精湿巾', 'protection_disinfection', 2, 73, '🧻', NULL, '酒精湿巾与便携消毒', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('gloves', '手套', 'protection_disinfection', 2, 74, '🧤', NULL, '检查手套与护理手套', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('first_aid', '急救包', 'protection_disinfection', 2, 75, '🧰', NULL, '家庭急救包与应急护理', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), +('dressing_tools', '棉签纱布', 'protection_disinfection', 2, 76, '🧺', NULL, '棉签纱布与护理耗材', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()), + +('moxibustion', '艾灸拔罐', 'tcm_health', 2, 81, '🔥', NULL, '艾灸、拔罐与温灸理疗', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('herbal_drink', '养生茶饮', 'tcm_health', 2, 82, '🍵', NULL, '草本茶饮与养生冲饮', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('tcm_patch', '中医贴敷', 'tcm_health', 2, 83, '🩹', NULL, '中医贴敷与草本热敷', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('medicated_diet', '药膳滋补', 'tcm_health', 2, 84, '🥣', NULL, '药膳汤料与滋补调养', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('massage_tools', '按摩理疗', 'tcm_health', 2, 85, '💆', NULL, '按摩仪、刮痧与理疗工具', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), +('foot_bath', '泡脚养生', 'tcm_health', 2, 86, '🪣', NULL, '泡脚包与足浴理疗用品', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()), + +('wound_care', '伤口护理', 'home_care_daily', 2, 91, '🩹', NULL, '创面处理与换药护理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('oral_care', '口腔护理', 'home_care_daily', 2, 92, '🦷', NULL, '口腔护理与清洁用品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('skin_care', '皮肤护理', 'home_care_daily', 2, 93, '🧴', NULL, '皮肤护理与修护用品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('cleaning_care', '清洁护理', 'home_care_daily', 2, 94, '🫧', NULL, '清洁护理与日常消耗品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('nursing_consumables', '护理耗材', 'home_care_daily', 2, 95, '📦', NULL, '棉签、纱布、护理垫等耗材', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()), +('home_health_tool', '家庭健康工具', 'home_care_daily', 2, 96, '🧰', NULL, '家庭健康小工具与辅具', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()) +ON CONFLICT (id) DO UPDATE SET + name = EXCLUDED.name, + parent_id = EXCLUDED.parent_id, + level = EXCLUDED.level, + sort_order = EXCLUDED.sort_order, + icon = EXCLUDED.icon, + image_url = EXCLUDED.image_url, + description = EXCLUDED.description, + scene = EXCLUDED.scene, + category_type = EXCLUDED.category_type, + compliance_type = EXCLUDED.compliance_type, + is_active = EXCLUDED.is_active, + deleted_at = NULL, + updated_at = NOW(); + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'blood_pressure_monitor', TRUE, 10, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%血压计%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'blood_glucose_meter', TRUE, 10, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%血糖仪%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'thermometer', TRUE, 10, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%体温计%' OR p.name ILIKE '%额温枪%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'oxygen_concentrator', TRUE, 10, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%制氧机%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'nebulizer', TRUE, 10, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%雾化器%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'mask', TRUE, 20, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%口罩%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'disinfectant', TRUE, 20, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%消毒%' OR p.name ILIKE '%酒精%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'wound_care', TRUE, 20, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%创可贴%' OR p.name ILIKE '%纱布%' OR p.name ILIKE '%敷料%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'wheelchair_crutch', TRUE, 20, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%轮椅%' OR p.name ILIKE '%拐杖%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'nursing_bed', TRUE, 20, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%护理床%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'calcium', TRUE, 30, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%钙片%' OR p.name ILIKE '%钙铁锌%' OR p.name ILIKE '%补钙%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'vitamin', TRUE, 30, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%维生素%' OR p.name ILIKE '%维C%' OR p.name ILIKE '%维D%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'protein', TRUE, 30, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%蛋白%' OR p.name ILIKE '%蛋白粉%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at) +SELECT p.id, 'cold_fever', TRUE, 40, NOW() +FROM public.ml_products p +WHERE p.name ILIKE '%感冒%' OR p.name ILIKE '%退热%' OR p.name ILIKE '%发烧%' +ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL; + +COMMIT; \ No newline at end of file diff --git a/types/delivery.uts b/types/delivery.uts index 457b73e3..12874658 100644 --- a/types/delivery.uts +++ b/types/delivery.uts @@ -7,21 +7,35 @@ export type DeliveryAccountStatus = 'active' | 'disabled' | 'locked' | 'suspende export type DeliveryCertificateStatus = 'valid' | 'expired' | 'pending' export type DeliveryOrderStatus = + 'pending_assignment' | 'pending_accept' | 'accepted' | + 'waiting_departure' | + 'departed' | 'on_the_way' | 'arrived' | 'checked_in' | + 'in_service' | 'serving' | + 'pending_confirm' | 'pending_submit' | 'pending_acceptance' | 'completed' | + 'rejected' | + 'abnormal' | + 'terminated' | 'exception_pending' | 'cancelled' | 'settled' | 'archived' export type DeliveryExceptionType = + 'cannot_contact_user' | + 'user_not_home' | + 'family_uncooperative' | + 'outside_service_scope' | + 'staff_cannot_continue' | + 'complaint_dispute' | 'cannot_contact_elder' | 'cannot_enter_home' | 'wrong_address' | @@ -47,6 +61,17 @@ export type DeliveryTimelineItemType = { description: string } +export type DeliveryStatusLogType = { + id: string + orderId: string + fromStatus: DeliveryOrderStatus + toStatus: DeliveryOrderStatus + operatorRole: string + operatorId: string + remark: string + createdAt: string +} + export type DeliveryServiceItemType = { id: string name: string @@ -71,39 +96,108 @@ export type DeliveryEvidenceRecordType = { createdAt: string } +export type DeliveryHealthMetricsType = { + bloodPressure: string + heartRate: string + bloodSugar: string + bloodOxygen: string +} + +export type DeliveryConfirmationType = { + method: 'sms_code' | 'signature' | 'none' + code: string + signatureName: string + signatureUrl: string + confirmedAt: string +} + +export type DeliveryServiceRecordType = { + id: string + orderId: string + startTime: string + endTime: string + actualDurationMinutes: number + serviceItems: Array + serviceContent: Array + processNote: string + elderStatus: string + healthMetrics: DeliveryHealthMetricsType + materialsUsed: string + abnormalNote: string + photos: Array + staffRemark: string + familyConfirmation: DeliveryConfirmationType + createdAt: string + updatedAt: string +} + +export type DeliveryAbnormalReportType = { + id: string + orderId: string + type: DeliveryExceptionType + description: string + occurredAt: string + locationText: string + images: Array + needPlatformIntervention: boolean + requestCancelOrder: boolean + requestReschedule: boolean + createdAt: string +} + export type DeliveryOrderType = { id: string orderNo: string serviceType: string serviceName: string + serviceCategory: string serviceItems: Array + serviceContentOptions?: Array elderId: string + elderName: string elderNameMasked: string + elderGender: string + elderAge: number + elderPhone: string elderPhoneMasked: string fullElderName: string fullPhone: string + contactRelation: string addressSummary: string + address: string + addressDetail: string fullAddress: string latitude: number longitude: number + appointmentTime: string appointmentStartTime: string appointmentEndTime: string + duration: number estimatedDuration: number + price: number + staffIncome: number + distance: string actualStartTime: string actualEndTime: string status: DeliveryOrderStatus statusText: string statusTone: string riskTags: Array + healthTags: Array careLevel: string + needFamilyPresent: boolean + needMaterials: boolean + remark: string merchantId: string merchantName: string deliveryStaffId: string deliveryStaffName: string acceptTime: string + rejectTime?: string departTime: string arriveTime: string checkinTime: string + startServiceTime?: string finishTime: string cancelReason: string exceptionType: string @@ -120,12 +214,15 @@ export type DeliveryOrderType = { contactPhone: string notices: Array timeline: Array + statusLog: Array serviceSummary: string progressNote: string distanceKm: string allowCheckinRadiusMeters: number lastLocation: DeliveryLocationType | null trackPoints: Array + serviceRecord: DeliveryServiceRecordType | null + abnormalReport: DeliveryAbnormalReportType | null } export type DeliveryCertificateType = { @@ -161,12 +258,16 @@ export type DeliveryInfoType = { } export type DeliveryDashboardType = { + pendingAssignmentCount: number pendingAcceptCount: number + todayOrderCount: number pendingDepartCount: number servingCount: number completedCount: number exceptionCount: number + expectedIncome: number onlineStatus: DeliveryOnlineStatus + nextOrder: DeliveryOrderType | null recentOrders: Array } @@ -185,16 +286,20 @@ export type DeliveryRecordType = { orderId: string orderNo: string serviceName: string + elderName: string elderNameMasked: string status: string statusText: string appointmentStartTime: string + appointmentTime: string actualStartTime: string actualEndTime: string + staffIncome: number settlementStatus: string acceptanceStatus: string exceptionDesc: string ratingText: string + hasServiceRecord: boolean } export type DeliveryLoginPayloadType = { @@ -237,4 +342,9 @@ export type DeliveryExceptionPayloadType = { exceptionType: DeliveryExceptionType description: string images: Array + occurredAt?: string + locationText?: string + needPlatformIntervention?: boolean + requestCancelOrder?: boolean + requestReschedule?: boolean } \ No newline at end of file diff --git a/utils/deliveryAuth.uts b/utils/deliveryAuth.uts index f039a823..891b4e8e 100644 --- a/utils/deliveryAuth.uts +++ b/utils/deliveryAuth.uts @@ -25,8 +25,7 @@ const DELIVERY_HOME_PATH = '/pages/mall/delivery/home/index' const DELIVERY_USER_KEY = 'delivery_user_info' const DELIVERY_INFO_KEY = 'delivery_info' const DELIVERY_TOKEN_KEY = 'delivery_token' -const DELIVERY_ROLE = 'delivery' -const DELIVERY_ROLE_ALIAS = 'Deliverer' +const DELIVERY_ROLE_LIST = ['delivery', 'Deliverer', 'deliverer', 'service_staff', 'care_worker'] as Array let redirectingToDeliveryLogin = false @@ -169,7 +168,12 @@ export function isDelivererRole(userInfo: UserProfile | null): boolean { return false } const role = userInfo.role != null ? userInfo.role : '' - return role == DELIVERY_ROLE || role == DELIVERY_ROLE_ALIAS + for (let i = 0; i < DELIVERY_ROLE_LIST.length; i++) { + if (role == DELIVERY_ROLE_LIST[i]) { + return true + } + } + return false } export async function checkDeliveryAccount(userInfo: UserProfile): Promise { diff --git a/utils/deliveryCareUi.uts b/utils/deliveryCareUi.uts new file mode 100644 index 00000000..e1e01b5f --- /dev/null +++ b/utils/deliveryCareUi.uts @@ -0,0 +1,73 @@ +import type { DeliveryOrderStatus, DeliveryOrderType } from '@/types/delivery.uts' + +export type DeliveryTabOptionType = { + label: string + value: string +} + +export function getDeliveryOrderTabs(): Array { + return [ + { label: '待接单', value: 'pending' } as DeliveryTabOptionType, + { label: '今日订单', value: 'today' } as DeliveryTabOptionType, + { label: '历史订单', value: 'history' } as DeliveryTabOptionType + ] +} + +export function isHistoryStatus(status: DeliveryOrderStatus): boolean { + return status == 'completed' || status == 'rejected' || status == 'cancelled' || status == 'abnormal' || status == 'terminated' || status == 'archived' +} + +export function getDeliveryStatusLabel(status: DeliveryOrderStatus): string { + if (status == 'pending_assignment' || status == 'pending_accept') return '待接单' + if (status == 'accepted') return '已接单' + if (status == 'waiting_departure') return '待出发' + if (status == 'departed' || status == 'on_the_way') return '已出发' + if (status == 'arrived') return '已到达' + if (status == 'checked_in') return '已签到' + if (status == 'in_service' || status == 'serving') return '服务中' + if (status == 'pending_confirm' || status == 'pending_acceptance' || status == 'pending_submit') return '待确认' + if (status == 'completed') return '已完成' + if (status == 'rejected') return '已拒单' + if (status == 'cancelled') return '已取消' + if (status == 'abnormal' || status == 'exception_pending') return '异常上报' + if (status == 'terminated') return '服务终止' + return '已归档' +} + +export function getPrimaryActionText(status: DeliveryOrderStatus): string { + if (status == 'pending_assignment' || status == 'pending_accept') return '接单' + if (status == 'accepted' || status == 'waiting_departure') return '我已出发' + if (status == 'departed' || status == 'on_the_way') return '我已到达' + if (status == 'arrived') return '签到' + if (status == 'checked_in') return '开始服务' + if (status == 'in_service' || status == 'serving') return '填写记录' + if (status == 'pending_confirm' || status == 'pending_acceptance' || status == 'pending_submit') return '完成服务' + if (status == 'completed') return '查看记录' + if (status == 'abnormal' || status == 'exception_pending') return '查看异常' + return '查看详情' +} + +export function getNextStepText(status: DeliveryOrderStatus): string { + if (status == 'pending_assignment' || status == 'pending_accept') return '确认是否接单' + if (status == 'accepted' || status == 'waiting_departure') return '前往服务对象地址' + if (status == 'departed' || status == 'on_the_way') return '到达服务地点' + if (status == 'arrived') return '完成签到确认' + if (status == 'checked_in') return '开始本次上门服务' + if (status == 'in_service' || status == 'serving') return '补充服务记录' + if (status == 'pending_confirm' || status == 'pending_acceptance' || status == 'pending_submit') return '确认并完成订单' + if (status == 'completed') return '查看历史记录' + if (status == 'abnormal' || status == 'exception_pending') return '跟进异常处置' + return '查看订单详情' +} + +export function getStatusClass(status: DeliveryOrderStatus): string { + if (status == 'pending_assignment' || status == 'pending_accept' || status == 'pending_confirm' || status == 'pending_acceptance' || status == 'pending_submit') return 'warning' + if (status == 'completed') return 'success' + if (status == 'abnormal' || status == 'exception_pending') return 'danger' + if (status == 'rejected' || status == 'cancelled' || status == 'terminated') return 'muted' + return 'primary' +} + +export function needsServiceRecord(order: DeliveryOrderType): boolean { + return order.serviceRecord == null +} \ No newline at end of file diff --git a/utils/supabaseService.uts b/utils/supabaseService.uts index ee426809..b5a87bcf 100644 --- a/utils/supabaseService.uts +++ b/utils/supabaseService.uts @@ -175,6 +175,8 @@ function parseProductFromRaw(item: any): Product { const result: Product = { id: safeGetString(itemObj, 'id'), name: safeGetString(itemObj, 'name'), + short_title: safeGetString(itemObj, 'short_title'), + subtitle: safeGetString(itemObj, 'subtitle'), description: safeGetString(itemObj, 'description'), base_price: safeGetNumber(itemObj, 'base_price'), price: safeGetNumber(itemObj, 'base_price'), @@ -193,6 +195,12 @@ function parseProductFromRaw(item: any): Product { is_featured: safeGetBoolean(itemObj, 'is_featured'), is_new: safeGetBoolean(itemObj, 'is_new'), is_hot: safeGetBoolean(itemObj, 'is_hot'), + card_tags: safeGetStringArray(itemObj, 'card_tags'), + service_tags: safeGetStringArray(itemObj, 'service_tags'), + selling_points: safeGetStringArray(itemObj, 'selling_points'), + display_sales_text: safeGetString(itemObj, 'display_sales_text'), + compliance_type: safeGetString(itemObj, 'compliance_type'), + device_class: safeGetString(itemObj, 'device_class'), specification: safeGetString(itemObj, 'specification'), usage: safeGetString(itemObj, 'usage'), side_effects: safeGetString(itemObj, 'side_effects'), @@ -256,6 +264,12 @@ export type Category = { parent_id?: string level?: number slug?: string + sort_order?: number + image_url?: string + scene?: string + category_type?: string + compliance_type?: string + is_active?: boolean created_at?: string } @@ -290,6 +304,13 @@ export type Product = { shop_id?: string tags?: string attributes?: string + short_title?: string + card_tags?: string[] + service_tags?: string[] + selling_points?: string[] + display_sales_text?: string + compliance_type?: string + device_class?: string specification?: string usage?: string side_effects?: string @@ -491,6 +512,192 @@ function emptyProductPage(page: number, limit: number): PaginatedResponse() + for (let i = 0; i < products.length; i++) { + productMap.set(products[i].id, products[i]) + } + const sorted: Product[] = [] + for (let i = 0; i < orderedIds.length; i++) { + const item = productMap.get(orderedIds[i]) + if (item != null) { + sorted.push(item) + } + } + return sorted +} + +function dedupeProducts(products: Product[]): Product[] { + const deduped: Product[] = [] + const seenIds: string[] = [] + for (let i = 0; i < products.length; i++) { + const productId = products[i].id + if (productId != '' && seenIds.indexOf(productId) != -1) { + continue + } + if (productId != '') { + seenIds.push(productId) + } + deduped.push(products[i]) + } + return deduped +} + export type ShopOrderResponse = { success: boolean orderIds: string[] @@ -946,6 +1153,373 @@ class SupabaseService { } } + async getMedicalMallParentCategories(): Promise { + try { + if (!logConsumerQueryStart('getMedicalMallParentCategories', 'medical_mall_categories', '*')) { + return [] + } + const response = await supa + .from('medical_mall_categories') + .select('*') + .is('parent_id', null) + .eq('is_active', true) + .is('deleted_at', null) + .order('sort_order', { ascending: true }) + .execute() + + if (response.error != null || response.data == null) { + logConsumerQueryFailure('getMedicalMallParentCategories', 'medical_mall_categories', response.error) + return [] + } + + const rows = response.data as UTSJSONObject[] + const categories: Category[] = [] + for (let i = 0; i < rows.length; i++) { + categories.push(parseMedicalMallCategory(JSON.parse(JSON.stringify(rows[i])) as UTSJSONObject)) + } + logConsumerQuerySuccess('getMedicalMallParentCategories', 'medical_mall_categories', categories.length) + return categories + } catch (error) { + logConsumerQueryFailure('getMedicalMallParentCategories', 'medical_mall_categories', error) + return [] + } + } + + async getMedicalMallCategoryById(categoryId: string): Promise { + try { + if (categoryId == '') { + return null + } + const response = await supa + .from('medical_mall_categories') + .select('*') + .eq('id', categoryId) + .eq('is_active', true) + .is('deleted_at', null) + .limit(1) + .execute() + + if (response.error != null || response.data == null) { + logConsumerQueryFailure('getMedicalMallCategoryById', 'medical_mall_categories', response.error) + return null + } + + const rows = response.data as UTSJSONObject[] + if (rows.length == 0) { + return null + } + + return parseMedicalMallCategory(JSON.parse(JSON.stringify(rows[0])) as UTSJSONObject) + } catch (error) { + logConsumerQueryFailure('getMedicalMallCategoryById', 'medical_mall_categories', error) + return null + } + } + + async getMedicalMallSubCategories(parentId: string): Promise { + try { + if (!logConsumerQueryStart('getMedicalMallSubCategories', 'medical_mall_categories', '*')) { + return [] + } + const response = await supa + .from('medical_mall_categories') + .select('*') + .eq('parent_id', parentId) + .eq('is_active', true) + .is('deleted_at', null) + .order('sort_order', { ascending: true }) + .execute() + + if (response.error != null || response.data == null) { + logConsumerQueryFailure('getMedicalMallSubCategories', 'medical_mall_categories', response.error) + return [] + } + + const rows = response.data as UTSJSONObject[] + const categories: Category[] = [] + for (let i = 0; i < rows.length; i++) { + categories.push(parseMedicalMallCategory(JSON.parse(JSON.stringify(rows[i])) as UTSJSONObject)) + } + logConsumerQuerySuccess('getMedicalMallSubCategories', 'medical_mall_categories', categories.length) + return categories + } catch (error) { + logConsumerQueryFailure('getMedicalMallSubCategories', 'medical_mall_categories', error) + return [] + } + } + + async getMedicalMallCategoryChildrenIds(parentId: string): Promise { + try { + let response: any + if (parentId == 'all_medical') { + response = await supa + .from('medical_mall_categories') + .select('id') + .eq('is_active', true) + .is('deleted_at', null) + .eq('level', 2) + .order('sort_order', { ascending: true }) + .execute() + } else { + response = await supa + .from('medical_mall_categories') + .select('id') + .eq('parent_id', parentId) + .eq('is_active', true) + .is('deleted_at', null) + .order('sort_order', { ascending: true }) + .execute() + } + + if (response.error != null || response.data == null) { + return [] + } + + const rows = response.data as UTSJSONObject[] + const ids: string[] = [] + for (let i = 0; i < rows.length; i++) { + const row = JSON.parse(JSON.stringify(rows[i])) as UTSJSONObject + const id = safeGetString(row, 'id') + if (id != '') { + ids.push(id) + } + } + return ids + } catch (error) { + console.error('获取医疗商城子分类 ID 失败:', error) + return [] + } + } + + async getMedicalMallProductsByCategory(categoryId: string, page: number = 1, limit: number = 20): Promise> { + try { + if (categoryId == 'recommend') { + return await this.getMedicalMallSmartRecommendations(page, limit) + } + if (!logConsumerQueryStart('getMedicalMallProductsByCategory', 'medical_mall_product_categories', '*')) { + return emptyProductPage(page, limit) + } + + const targetCategoryIds: string[] = [] + if (categoryId == 'all_medical') { + const allChildren = await this.getMedicalMallCategoryChildrenIds('all_medical') + for (let i = 0; i < allChildren.length; i++) { + targetCategoryIds.push(allChildren[i]) + } + } else { + const categoryResponse = await supa + .from('medical_mall_categories') + .select('id, level') + .eq('id', categoryId) + .eq('is_active', true) + .is('deleted_at', null) + .limit(1) + .execute() + + targetCategoryIds.push(categoryId) + if (categoryResponse.error == null && categoryResponse.data != null) { + const categoryRows = categoryResponse.data as UTSJSONObject[] + if (categoryRows.length > 0) { + const categoryObj = JSON.parse(JSON.stringify(categoryRows[0])) as UTSJSONObject + if (safeGetNumber(categoryObj, 'level') == 1) { + const childIds = await this.getMedicalMallCategoryChildrenIds(categoryId) + for (let i = 0; i < childIds.length; i++) { + if (targetCategoryIds.indexOf(childIds[i]) == -1) { + targetCategoryIds.push(childIds[i]) + } + } + } + } + } + } + + const linkedIds: string[] = [] + if (targetCategoryIds.length > 0) { + const linkResponse = await supa + .from('medical_mall_product_categories') + .select('product_id, sort_order, created_at') + .in('category_id', buildAnyStringList(targetCategoryIds)) + .is('deleted_at', null) + .order('sort_order', { ascending: true }) + .order('created_at', { ascending: false }) + .limit(500) + .execute() + + if (linkResponse.error == null && linkResponse.data != null) { + const linkRows = linkResponse.data as UTSJSONObject[] + for (let i = 0; i < linkRows.length; i++) { + const row = JSON.parse(JSON.stringify(linkRows[i])) as UTSJSONObject + const productId = safeGetString(row, 'product_id') + if (productId != '' && linkedIds.indexOf(productId) == -1) { + linkedIds.push(productId) + } + } + } + } + + let finalProducts: Product[] = [] + if (linkedIds.length > 0) { + const productResponse = await supa + .from('ml_products_detail_view') + .select('*') + .in('id', buildAnyStringList(linkedIds)) + .eq('status', '1') + .execute() + + if (productResponse.error == null && productResponse.data != null) { + const rows = productResponse.data as any[] + const parsed: Product[] = [] + for (let i = 0; i < rows.length; i++) { + const rowObj = JSON.parse(JSON.stringify(rows[i])) as UTSJSONObject + if (isRxHiddenProduct(rowObj)) { + continue + } + parsed.push(parseProductFromRaw(rows[i])) + } + finalProducts = sortProductsByIdOrder(parsed, linkedIds) + } + } + + if (finalProducts.length == 0) { + const fallbackResponse = await supa + .from('ml_products_detail_view') + .select('*') + .eq('status', '1') + .order('sale_count', { ascending: false }) + .order('created_at', { ascending: false }) + .limit(300) + .execute() + + if (fallbackResponse.error == null && fallbackResponse.data != null) { + const fallbackRows = fallbackResponse.data as any[] + for (let i = 0; i < fallbackRows.length; i++) { + const rowObj = JSON.parse(JSON.stringify(fallbackRows[i])) as UTSJSONObject + if (!matchesMedicalMallFallback(rowObj, categoryId)) { + continue + } + finalProducts.push(parseProductFromRaw(fallbackRows[i])) + } + } + } + + const deduped = dedupeProducts(finalProducts) + const startIndex = (page - 1) * limit + const endIndex = startIndex + limit + return { + data: deduped.slice(startIndex, endIndex), + total: deduped.length, + page, + limit, + hasmore: deduped.length > endIndex + } + } catch (error) { + logConsumerQueryFailure('getMedicalMallProductsByCategory', 'medical_mall_product_categories', error) + console.error('获取医疗商城分类商品失败:', error) + return emptyProductPage(page, limit) + } + } + + async getMedicalMallSmartRecommendations(page: number = 1, limit: number = 10): Promise> { + try { + if (!logConsumerQueryStart('getMedicalMallSmartRecommendations', 'medical_mall_product_categories', '*')) { + return emptyProductPage(page, limit) + } + + const linkedIds: string[] = [] + const linkResponse = await supa + .from('medical_mall_product_categories') + .select('product_id, is_primary, sort_order, created_at') + .is('deleted_at', null) + .order('is_primary', { ascending: false }) + .order('sort_order', { ascending: true }) + .order('created_at', { ascending: false }) + .limit(500) + .execute() + + if (linkResponse.error == null && linkResponse.data != null) { + const linkRows = linkResponse.data as UTSJSONObject[] + for (let i = 0; i < linkRows.length; i++) { + const row = JSON.parse(JSON.stringify(linkRows[i])) as UTSJSONObject + const productId = safeGetString(row, 'product_id') + if (productId != '' && linkedIds.indexOf(productId) == -1) { + linkedIds.push(productId) + } + } + } + + const merged: Product[] = [] + const addedIds = new Set() + + if (linkedIds.length > 0) { + const linkedProductResponse = await supa + .from('ml_products_detail_view') + .select('*') + .in('id', buildAnyStringList(linkedIds)) + .eq('status', '1') + .execute() + + if (linkedProductResponse.error == null && linkedProductResponse.data != null) { + const rows = linkedProductResponse.data as any[] + const parsed: Product[] = [] + for (let i = 0; i < rows.length; i++) { + const rowObj = JSON.parse(JSON.stringify(rows[i])) as UTSJSONObject + if (isRxHiddenProduct(rowObj)) { + continue + } + parsed.push(parseProductFromRaw(rows[i])) + } + const ordered = sortProductsByIdOrder(parsed, linkedIds) + for (let i = 0; i < ordered.length; i++) { + if (!addedIds.has(ordered[i].id)) { + merged.push(ordered[i]) + addedIds.add(ordered[i].id) + } + } + } + } + + if (merged.length < page * limit + limit) { + const fallbackResponse = await supa + .from('ml_products_detail_view') + .select('*') + .eq('status', '1') + .order('sale_count', { ascending: false }) + .order('created_at', { ascending: false }) + .limit(300) + .execute() + + if (fallbackResponse.error == null && fallbackResponse.data != null) { + const rows = fallbackResponse.data as any[] + for (let i = 0; i < rows.length; i++) { + const rowObj = JSON.parse(JSON.stringify(rows[i])) as UTSJSONObject + if (!matchesMedicalMallFallback(rowObj, 'recommend')) { + continue + } + const product = parseProductFromRaw(rows[i]) + if (!addedIds.has(product.id)) { + merged.push(product) + addedIds.add(product.id) + } + } + } + } + + const startIndex = (page - 1) * limit + const endIndex = startIndex + limit + return { + data: merged.slice(startIndex, endIndex), + total: merged.length, + page, + limit, + hasmore: merged.length > endIndex + } + } catch (error) { + logConsumerQueryFailure('getMedicalMallSmartRecommendations', 'medical_mall_product_categories', error) + console.error('获取医疗商城推荐商品失败:', error) + return emptyProductPage(page, limit) + } + } + // 根据商品ID获取SKU列表 async getProductSkus(productId: string): Promise { try {