Files
xiaoxia-saas/packages/adapters/sqlalchemy_impl/commerce_models.py
T
Xiaoxia Agent db39feed74
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m8s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m6s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m12s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Validate - Security (pull_request) Successful in 4m54s
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 5m4s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 5m46s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 6m11s
AI Code Review / AI Code Review (pull_request) Successful in 6m46s
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
feat(membership): 微信支付年卡购买/回调履约/积分包下单
- 微信支付V3适配层: JSAPI下单、JSAPI调起签名、回调验签、AES-GCM解密、平台证书缓存
- PaymentService: 会员年卡/积分包下单、回调幂等履约(激活365天+年赠12个月积分+流水)
- 新增接口: POST /subscription/create-order, GET /subscription/orders,
  GET /subscription/orders/{id}, POST /points/create-order, POST /payment/wechat/notify
- 积分订单增加out_trade_no等微信字段, 迁移094
- P1: 订阅到期实时判断、取消订阅完善、会员身份实时判断
- requirements增加cryptography
2026-10-03 15:27:50 +08:00

56 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""商业交易模型 —— 与 xiaoxia-admin 共享表的 ORM 映射。
xiaoxia-admin(管理后台)与 xiaoxia-saas(用户端)共享同一个数据库:
- plans / subscriptions 表由 admin 的 alembic 迁移创建(admin_alembic_version)
- 用户端在支付链路中需要读取套餐、写入订阅,因此在此做最小映射
注意:不要在此给这些表建迁移;表结构变更走 xiaoxia-admin 仓库。
"""
from __future__ import annotations
from datetime import UTC, datetime
from sqlalchemy import Boolean, Column, DateTime, Integer, Numeric, String, Text
from sqlalchemy.orm import declarative_base
CommerceBase: Any = declarative_base()
def _now() -> datetime:
return datetime.now(UTC)
class PlanModel(CommerceBase):
"""admin 端 plans 套餐表(只读映射)。"""
__tablename__ = "plans"
id = Column(String(36), primary_key=True)
level_id = Column(String(36), nullable=True)
plan_key = Column(String(50), nullable=False)
name = Column(String(100), nullable=False)
description = Column(Text, nullable=True)
monthly_price = Column(Numeric(10, 2), nullable=False, default=0)
yearly_price = Column(Numeric(10, 2), nullable=False, default=0)
is_enabled = Column(Boolean, nullable=False, default=True)
display_order = Column(Integer, default=0)
created_at = Column(DateTime, default=_now)
class SubscriptionRecordModel(CommerceBase):
"""admin 端 subscriptions 订阅记录表(支付成功后写入)。"""
__tablename__ = "subscriptions"
id = Column(String(36), primary_key=True)
user_id = Column(String(36), nullable=False, index=True)
plan_id = Column(String(36), nullable=False, index=True)
status = Column(String(20), nullable=False, default="active")
billing_cycle = Column(String(10), nullable=False)
start_date = Column(DateTime, nullable=False)
end_date = Column(DateTime, nullable=False)
cancelled_at = Column(DateTime, nullable=True)
created_at = Column(DateTime, default=_now)
updated_at = Column(DateTime, default=_now)