Align avatar recharge plan IDs with WeChat virtual products
This commit is contained in:
@@ -9,7 +9,7 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from apscheduler.triggers.interval import IntervalTrigger
|
||||
|
||||
from database import engine, init_db, SessionLocal
|
||||
from models import Avatar, Authorization, Organization, TokenAccount, TokenPlan, User
|
||||
from models import Avatar, Authorization, Organization, TokenAccount, TokenPaymentOrder, TokenPlan, User
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
import routers.avatars
|
||||
import routers.tokens
|
||||
@@ -90,18 +90,28 @@ def seed():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
plan_specs = [
|
||||
{"id": "1", "name": "基础套餐", "amount": 2_000_000, "price": 10, "badge": "", "desc": "2M 积分"},
|
||||
{"id": "2", "name": "标准套餐", "amount": 20_000_000, "price": 100, "badge": "常用", "desc": "20M 积分"},
|
||||
{"id": "3", "name": "专业套餐", "amount": 250_000_000, "price": 1000, "badge": "加赠25%", "desc": "250M 积分"},
|
||||
{"id": "4", "name": "企业套餐", "amount": 2_500_000_000, "price": 10000, "badge": "企业推荐", "desc": "2500M 积分"},
|
||||
{"id": "Basic", "legacy_id": "1", "name": "基础套餐", "amount": 2_000_000, "price": 10, "badge": "", "desc": "2M 积分"},
|
||||
{"id": "Standard", "legacy_id": "2", "name": "标准套餐", "amount": 20_000_000, "price": 100, "badge": "常用", "desc": "20M 积分"},
|
||||
{"id": "Professional", "legacy_id": "3", "name": "专业套餐", "amount": 250_000_000, "price": 1000, "badge": "加赠25%", "desc": "250M 积分"},
|
||||
{"id": "Enterprise", "legacy_id": "4", "name": "企业套餐", "amount": 2_500_000_000, "price": 10000, "badge": "企业推荐", "desc": "2500M 积分"},
|
||||
]
|
||||
for spec in plan_specs:
|
||||
plan = db.query(TokenPlan).filter(TokenPlan.id == spec["id"]).first()
|
||||
legacy = db.query(TokenPlan).filter(TokenPlan.id == spec["legacy_id"]).first()
|
||||
if legacy is not None and plan is None:
|
||||
legacy.id = spec["id"]
|
||||
plan = legacy
|
||||
db.flush()
|
||||
if legacy is not None and legacy is not plan:
|
||||
db.delete(legacy)
|
||||
db.query(TokenPaymentOrder).filter(TokenPaymentOrder.plan_id == spec["legacy_id"]).update(
|
||||
{TokenPaymentOrder.plan_id: spec["id"]}, synchronize_session=False
|
||||
)
|
||||
if plan is None:
|
||||
db.add(TokenPlan(**spec))
|
||||
db.add(TokenPlan(**{key: value for key, value in spec.items() if key != "legacy_id"}, virtual_product_id=spec["id"]))
|
||||
else:
|
||||
for key, value in spec.items():
|
||||
setattr(plan, key, value)
|
||||
plan.name = spec["name"]
|
||||
plan.virtual_product_id = spec["id"]
|
||||
|
||||
for user in db.query(User).all():
|
||||
account = db.query(TokenAccount).filter(TokenAccount.user_id == user.id).first()
|
||||
|
||||
Reference in New Issue
Block a user