更新接口

This commit is contained in:
2026-06-01 22:35:56 +08:00
parent 6d9977cb76
commit 31fc86e878
6 changed files with 583 additions and 48 deletions
+26 -2
View File
@@ -1,9 +1,13 @@
package services
import "server/models"
import (
"strings"
"server/models"
)
// BindTenantUser 绑定用户到租户(若已存在则更新状态/默认值)
func BindTenantUser(tid, uid uint64, account, name, phone, email, password *string, isDefault, status int8, remark *string) (uint64, error) {
func BindTenantUser(tid, uid uint64, account, name, phone, email *string, sex *uint8, birth *string, password *string, isDefault, status int8, remark *string) (uint64, error) {
var existed models.SystemTenantUser
err := models.Orm.QueryTable(new(models.SystemTenantUser)).
Filter("tid", tid).
@@ -20,6 +24,17 @@ func BindTenantUser(tid, uid uint64, account, name, phone, email, password *stri
"is_default": isDefault,
"remark": remark,
}
if sex != nil {
update["sex"] = *sex
}
if birth != nil {
trimmedBirth := strings.TrimSpace(*birth)
if trimmedBirth == "" {
update["birth"] = nil
} else {
update["birth"] = trimmedBirth
}
}
_, uErr := models.Orm.QueryTable(new(models.SystemTenantUser)).Filter("id", existed.ID).Update(update)
return existed.ID, uErr
}
@@ -36,6 +51,15 @@ func BindTenantUser(tid, uid uint64, account, name, phone, email, password *stri
Status: status,
Remark: remark,
}
if sex != nil {
m.Sex = *sex
}
if birth != nil {
trimmedBirth := strings.TrimSpace(*birth)
if trimmedBirth != "" {
m.Birth = &trimmedBirth
}
}
id, iErr := models.Orm.Insert(m)
return uint64(id), iErr
}