refactor: add system config key 'user_init_calls' to init the new register user's api calls

This commit is contained in:
RockYang
2023-06-15 10:06:21 +08:00
parent 567cdc6f8d
commit 197714a57a
5 changed files with 23 additions and 9 deletions

View File

@@ -85,6 +85,16 @@ func (h *UserHandler) Register(c *gin.Context) {
ApiKey: "",
}),
}
// 初始化调用次数
var cfg model.Config
h.db.Where("marker = ?", "system").First(&cfg)
var config types.SystemConfig
err := utils.JsonDecode(cfg.Config, &config)
if err != nil || config.UserInitCalls <= 0 {
user.Calls = types.UserInitCalls
} else {
user.Calls = config.UserInitCalls
}
res := h.db.Create(&user)
if res.Error != nil {
resp.ERROR(c, "保存数据失败")