Files
2026-04-13 14:22:31 +08:00

81 lines
3.5 KiB
Python
Raw Permalink 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.

from sqlalchemy.orm import Session
from app.models import User, Setting, ProductCategory
from app.config import get_settings
from passlib.context import CryptContext
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
settings = get_settings()
def init_default_data(db: Session):
"""初始化默认数据"""
# 1. 创建默认管理员账号
admin = db.query(User).filter(User.username == "admin").first()
if not admin:
admin = User(
username="admin",
password_hash=pwd_context.hash("admin123"),
role="admin",
name="系统管理员",
status=1
)
db.add(admin)
db.commit()
print("✅ 默认管理员账号已创建")
print(" 用户名: admin")
print(" 密码: admin123")
# 2. 初始化默认配置
default_settings = [
("salary_base_min", str(settings.DEFAULT_SALARY_BASE_MIN), "底薪范围最小值(元)", "salary"),
("salary_base_max", str(settings.DEFAULT_SALARY_BASE_MAX), "底薪范围最大值(元)", "salary"),
("salary_performance", str(settings.DEFAULT_SALARY_PERFORMANCE), "绩效奖金基数(元)", "salary"),
("salary_performance_threshold", str(settings.DEFAULT_SALARY_PERFORMANCE_THRESHOLD), "绩效完成率阈值(%", "salary"),
("commission_ai_model", str(settings.DEFAULT_COMMISSION_AI_MODEL), "大模型类产品提成比例", "commission"),
("commission_cloud_base", str(settings.DEFAULT_COMMISSION_CLOUD_BASE), "云基础类产品提成比例", "commission"),
("commission_main_product", str(settings.DEFAULT_COMMISSION_MAIN_PRODUCT), "主推产品提成比例", "commission"),
("agent_employee_commission", str(settings.DEFAULT_AGENT_EMPLOYEE_COMMISSION), "员工二级代理提成比例", "agent"),
("agent_profit_share_min", str(settings.DEFAULT_AGENT_PROFIT_SHARE_MIN), "二级代理分佣比例最小值", "agent"),
("agent_profit_share_max", str(settings.DEFAULT_AGENT_PROFIT_SHARE_MAX), "二级代理分佣比例最大值", "agent"),
("company_name", "火山引擎渠道合作伙伴", "公司名称", "company"),
]
for key, value, desc, group in default_settings:
existing = db.query(Setting).filter(Setting.setting_key == key).first()
if not existing:
setting = Setting(
setting_key=key,
setting_value=value,
description=desc,
group_name=group
)
db.add(setting)
db.commit()
print("✅ 默认系统配置已初始化")
# 3. 初始化默认产品分类
default_categories = [
("大模型类产品", "ai_model", 0.03, 0.30, 0),
("云基础类产品", "cloud_base", 0.10, 0.25, 0),
("主推产品-直播大师", "main_live_master", 0.08, 0.35, 1),
("主推产品-创作Agent", "main_create_agent", 0.08, 0.35, 1),
]
for name, code, commission, rebate, is_main in default_categories:
existing = db.query(ProductCategory).filter(ProductCategory.code == code).first()
if not existing:
category = ProductCategory(
name=name,
code=code,
commission_rate=commission,
monthly_rebate=rebate,
is_main_product=is_main,
status=1
)
db.add(category)
db.commit()
print("✅ 默认产品分类已初始化")