Files
kefu_cloud/server/cmd/seed/main.go
T
yml2213 f88030acf5 chore(seed): 种子数据最小化,移除全部虚构演示/测试数据
- seed 仅初始化平台管理员与三个套餐,不再预置假租户/坐席/客户/知识库/公告
- 租户改由平台后台正常开通(自动创建管理员账号与默认网页渠道)
- README 与 deploy 文档、脚本中的演示账号说明同步更新
2026-09-05 15:58:00 +08:00

57 lines
1.9 KiB
Go
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.
package main
import (
"log"
"golang.org/x/crypto/bcrypt"
"kefu-cloud/server/internal/config"
"kefu-cloud/server/internal/model"
)
func main() {
cfg := config.Load()
model.InitDB(cfg.Database.DSN())
seed()
log.Println("种子数据填充完成")
}
// seed 仅初始化平台运行所需的最小数据:平台管理员账号与套餐定价。
// 租户、坐席、渠道、知识库等业务数据请通过平台管理后台正常开通创建,
// 不再预置任何虚构的演示/测试数据。
func seed() {
hash, _ := bcrypt.GenerateFromPassword([]byte("kefu_admin123"), bcrypt.DefaultCost)
pwd := string(hash)
model.EnsurePermissions()
// 平台管理员(TenantID=0)
var count int64
model.DB.Model(&model.User{}).Where("username = ?", "platform_admin").Count(&count)
if count == 0 {
model.DB.Create(&model.User{
TenantID: 0, Role: "platform_admin", Username: "platform_admin",
PasswordHash: pwd, Nickname: "平台管理员", Status: "online",
})
log.Println("平台管理员账号: platform_admin / kefu_admin123")
} else {
log.Println("平台管理员账号已存在,跳过")
}
// 套餐定价
var planCount int64
model.DB.Model(&model.Plan{}).Count(&planCount)
if planCount == 0 {
plans := []model.Plan{
{Name: "基础版", PriceMonthly: 299, Seats: 2, StorageDays: 30, KBLimit: 50, Status: "active", Features: `{"stats":"basic","api":false,"channels":["web"],"brand":false}`},
{Name: "专业版", PriceMonthly: 699, Seats: 10, StorageDays: 180, KBLimit: 500, Status: "active", Features: `{"stats":"advanced","api":true,"channels":["web","wechat","app"],"brand":true}`},
{Name: "企业版", PriceMonthly: 1999, Seats: 50, StorageDays: 0, KBLimit: 0, Status: "active", Features: `{"stats":"custom","api":true,"channels":["all"],"brand":true,"dedicated":true}`},
}
model.DB.Create(&plans)
log.Println("已初始化默认套餐:基础版 / 专业版 / 企业版")
} else {
log.Println("套餐已存在,跳过")
}
}