dingdanquanliucheng/backend/migrations/versions/20260623_0002_create_pending_service_binding.py
wsb1224 1d12d061e0 接入微信服务号模板消息,修复通知链路重复发送和静默失败
小程序订阅消息每订阅一次只能发一条,用户无法持续收到通知。改为接入微信
服务号模板消息,用户关注服务号后可无限次接收推送通知。

新增功能:
- ServiceAccountNotificationService:服务号模板消息发送服务
- 服务号事件回调(subscribe/unsubscribe)+ 手机号验证绑定流程
- PendingServiceBinding 模型:存储关注者的 openid 待绑定记录
- 小程序 bind-service 页面:输入手机号完成绑定
- 三个详情页(审批/任务/发厂)增加"绑定微信通知"入口
- web-sales NotificationBell 增加服务号关注引导
- web-admin SystemPage/ConfigPage 增加服务号绑定状态和模板配置展示

修复问题:
- EventBus 和 _notify_status_change 重复发送微信消息(业务员收到2条)
- EventBus order_status_changed 事件缺少模板映射导致微信通知静默丢失
- 所有微信发送失败被 except Exception: pass 静默吞掉,增加日志
- 定时任务(欠款/沉默客户/物流超时)不触发 WebSocket 实时通知
- reminder_method 配置未生效

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-23 17:17:06 +08:00

27 lines
979 B
Python

"""create pending_service_binding table"""
from alembic import op
import sqlalchemy as sa
revision = "20260623_0002"
down_revision = "20260623_0001"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
"pending_service_binding",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column("service_open_id", sa.String(length=128), nullable=False),
sa.Column("bound", sa.Boolean(), nullable=False, server_default=sa.text("0")),
sa.Column("created_at", sa.DateTime(), server_default=sa.func.now()),
sa.Column("updated_at", sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now()),
)
op.create_index("ix_pending_service_binding_service_open_id", "pending_service_binding", ["service_open_id"], unique=True)
def downgrade() -> None:
op.drop_index("ix_pending_service_binding_service_open_id", table_name="pending_service_binding")
op.drop_table("pending_service_binding")