更新结构

This commit is contained in:
2026-04-01 16:41:41 +08:00
parent e830896d47
commit 106abeeff6
14 changed files with 357 additions and 194 deletions
+8 -7
View File
@@ -7,6 +7,7 @@ import (
"strings"
"server/models"
"server/services"
beego "github.com/beego/beego/v2/server/web"
)
@@ -60,7 +61,7 @@ func toAdminUserDTO(u models.AdminUser) adminUserDTO {
// GetAllUsers 获取全部平台管理员用户
// GET /platform/getAllUsers
func (c *PlatformAdminUserController) GetAllUsers() {
rows, total, err := models.ListAdminUsers()
rows, total, err := services.ListAdminUsers()
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "查询失败"}
_ = c.ServeJSON()
@@ -88,7 +89,7 @@ func (c *PlatformAdminUserController) GetUserInfo() {
_ = c.ServeJSON()
return
}
u, err := models.GetAdminUserByID(id)
u, err := services.GetAdminUserByID(id)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 404, "msg": "用户不存在"}
_ = c.ServeJSON()
@@ -151,7 +152,7 @@ func (c *PlatformAdminUserController) AddUser() {
roleID = *p.Rid
}
id, err := models.CreateAdminUser(p.Account, p.Password, p.Name, p.Phone, p.Email, p.Qq, p.Avatar, sex, roleID, status)
id, err := services.CreateAdminUser(p.Account, p.Password, p.Name, p.Phone, p.Email, p.Qq, p.Avatar, sex, roleID, status)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "添加失败"}
_ = c.ServeJSON()
@@ -230,14 +231,14 @@ func (c *PlatformAdminUserController) EditUser() {
}
if len(fields) > 0 {
if err := models.UpdateAdminUser(id, fields); err != nil {
if err := services.UpdateAdminUser(id, fields); err != nil {
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "编辑失败"}
_ = c.ServeJSON()
return
}
}
if p.Password != nil && strings.TrimSpace(*p.Password) != "" {
if err := models.ChangeAdminUserPassword(id, *p.Password); err != nil {
if err := services.ChangeAdminUserPassword(id, *p.Password); err != nil {
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "密码修改失败"}
_ = c.ServeJSON()
return
@@ -258,7 +259,7 @@ func (c *PlatformAdminUserController) DeleteUser() {
_ = c.ServeJSON()
return
}
if err := models.DeleteAdminUser(id); err != nil {
if err := services.DeleteAdminUser(id); err != nil {
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "删除失败"}
_ = c.ServeJSON()
return
@@ -292,7 +293,7 @@ func (c *PlatformAdminUserController) ChangePassword() {
_ = c.ServeJSON()
return
}
if err := models.ChangeAdminUserPassword(p.ID, p.Password); err != nil {
if err := services.ChangeAdminUserPassword(p.ID, p.Password); err != nil {
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "修改失败"}
_ = c.ServeJSON()
return
+25 -5
View File
@@ -12,8 +12,9 @@ import (
)
type platformLoginRequest struct {
Account string `json:"account"`
Password string `json:"password"`
TenantName string `json:"tenant_name"`
Account string `json:"account"`
Password string `json:"password"`
}
// PlatformAuthController 平台端认证控制器
@@ -45,17 +46,17 @@ func (c *PlatformAuthController) Login() {
return
}
if req.Account == "" || req.Password == "" {
if req.TenantName == "" || req.Account == "" || req.Password == "" {
c.Data["json"] = map[string]interface{}{
"code": 400,
"msg": "用户名或密码不能为空",
"msg": "租户名称、用户名或密码不能为空",
}
_ = c.ServeJSON()
return
}
// 控制器只做 HTTP 解析与响应编排,业务逻辑放 services 层
token, loginUser, err := services.PlatformLogin(req.Account, req.Password)
token, loginUser, err := services.PlatformLogin(req.TenantName, req.Account, req.Password)
if err != nil {
c.Data["json"] = map[string]interface{}{
"code": 401,
@@ -74,6 +75,7 @@ func (c *PlatformAuthController) Login() {
"id": loginUser.ID,
"account": loginUser.Account,
"name": loginUser.Name,
"tid": loginUser.Tid,
"rid": loginUser.Rid,
"avatar": loginUser.Avatar,
"role_name": loginUser.RoleName,
@@ -190,6 +192,24 @@ func (c *PlatformAuthController) GetOpenVerify() {
_ = c.ServeJSON()
}
// Register 注册(占位实现)
func (c *PlatformAuthController) Register() {
c.Data["json"] = map[string]interface{}{
"code": 501,
"msg": "注册暂未实现",
}
_ = c.ServeJSON()
}
// SendRegisterCode 发送注册验证码(占位实现)
func (c *PlatformAuthController) SendRegisterCode() {
c.Data["json"] = map[string]interface{}{
"code": 501,
"msg": "发送注册验证码暂未实现",
}
_ = c.ServeJSON()
}
// ResetPassword 忘记密码重置(占位实现)
func (c *PlatformAuthController) ResetPassword() {
c.Data["json"] = map[string]interface{}{
+20 -5
View File
@@ -10,6 +10,8 @@ import (
"time"
"server/models"
"server/pkg/passwordutil"
"server/services"
"github.com/beego/beego/v2/client/orm"
beego "github.com/beego/beego/v2/server/web"
@@ -166,6 +168,13 @@ func (c *PlatformTenantUserController) CreateTenantUser() {
_ = c.ServeJSON()
return
}
hashed, err := passwordutil.Hash(*p.Password)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 400, "msg": err.Error()}
_ = c.ServeJSON()
return
}
p.Password = &hashed
if p.Uid == 0 {
uid, err := generateTenantUID(p.Tid)
if err != nil {
@@ -185,14 +194,14 @@ func (c *PlatformTenantUserController) CreateTenantUser() {
status = *p.Status
}
id, err := models.BindTenantUser(p.Tid, p.Uid, p.Account, p.Name, p.Phone, p.Email, p.Password, isDefault, status, p.Remark)
id, err := services.BindTenantUser(p.Tid, p.Uid, p.Account, p.Name, p.Phone, p.Email, p.Password, isDefault, status, p.Remark)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "创建失败: " + err.Error()}
_ = c.ServeJSON()
return
}
if isDefault == 1 {
_ = models.SetDefaultTenant(p.Uid, p.Tid)
_ = services.SetDefaultTenant(p.Uid, p.Tid)
}
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": map[string]interface{}{"id": id}}
@@ -234,7 +243,13 @@ func (c *PlatformTenantUserController) EditTenantUser() {
update["email"] = p.Email
}
if p.Password != nil {
update["password"] = p.Password
hashed, err := passwordutil.Hash(*p.Password)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 400, "msg": err.Error()}
_ = c.ServeJSON()
return
}
update["password"] = hashed
}
if p.IsDefault != nil {
update["is_default"] = *p.IsDefault
@@ -260,7 +275,7 @@ func (c *PlatformTenantUserController) EditTenantUser() {
}
if p.IsDefault != nil && *p.IsDefault == 1 && p.Uid > 0 && p.Tid > 0 {
_ = models.SetDefaultTenant(p.Uid, p.Tid)
_ = services.SetDefaultTenant(p.Uid, p.Tid)
}
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success"}
@@ -277,7 +292,7 @@ func (c *PlatformTenantUserController) DeleteTenantUser() {
return
}
if err := models.UnbindTenantUser(id); err != nil {
if err := services.UnbindTenantUser(id); err != nil {
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "删除失败: " + err.Error()}
_ = c.ServeJSON()
return
+11 -3
View File
@@ -7,7 +7,8 @@ import (
"strings"
"time"
"server/models"
"server/pkg/passwordutil"
"server/services"
beego "github.com/beego/beego/v2/server/web"
)
@@ -62,6 +63,12 @@ func (c *PlatformUserController) AddUser() {
_ = c.ServeJSON()
return
}
hashed, err := passwordutil.Hash(p.Password)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 400, "msg": err.Error()}
_ = c.ServeJSON()
return
}
status := int8(1)
if p.Status != nil {
@@ -78,9 +85,10 @@ func (c *PlatformUserController) AddUser() {
name := &p.Name
phone := &p.Phone
email := &p.Email
password := &p.Password
hashedPwd := hashed
password := &hashedPwd
_, err := models.BindTenantUser(p.Tid, uid, account, name, phone, email, password, 0, status, p.Remark)
_, err := services.BindTenantUser(p.Tid, uid, account, name, phone, email, password, 0, status, p.Remark)
if err == nil {
c.Data["json"] = map[string]interface{}{
"code": 200,