邀请 N天配置

This commit is contained in:
2026-03-08 07:31:11 -07:00
parent 7a3a53f1a9
commit 4907853667
4 changed files with 68 additions and 4 deletions
@@ -43,11 +43,26 @@ func (l *UpdateInviteConfigLogic) UpdateInviteConfig(req *types.InviteConfig) er
fieldName := t.Field(i).Name
// Get the field value to string
fieldValue := tool.ConvertValueToString(v.Field(i))
// Update the invite config
err = db.Model(&system.System{}).Where("`category` = 'invite' and `key` = ?", fieldName).Update("value", fieldValue).Error
// Update existing row; if missing (RowsAffected=0), create it to avoid silent config loss.
updateResult := db.Model(&system.System{}).
Where("`category` = 'invite' and `key` = ?", fieldName).
Update("value", fieldValue)
err = updateResult.Error
if err != nil {
break
}
if updateResult.RowsAffected == 0 {
err = db.Create(&system.System{
Category: "invite",
Key: fieldName,
Value: fieldValue,
Type: getSystemFieldType(v.Field(i)),
Desc: "invite config: " + fieldName,
}).Error
if err != nil {
break
}
}
}
if err != nil {
return err
@@ -62,3 +77,24 @@ func (l *UpdateInviteConfigLogic) UpdateInviteConfig(req *types.InviteConfig) er
initialize.Invite(l.svcCtx)
return nil
}
func getSystemFieldType(field reflect.Value) string {
kind := field.Kind()
if kind == reflect.Ptr && !field.IsNil() {
kind = field.Elem().Kind()
}
switch kind {
case reflect.Bool:
return "bool"
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return "int"
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return "uint"
case reflect.Float32, reflect.Float64:
return "float"
case reflect.String:
return "string"
default:
return "string"
}
}