2026-07-28 13:55:40 +08:00
|
|
|
package user
|
2026-07-27 01:32:44 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/errcode"
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/infra"
|
|
|
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
2026-07-28 10:42:26 +08:00
|
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
|
2026-07-27 01:32:44 +08:00
|
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ListUser 查询业主客户分页列表。
|
2026-07-28 10:42:26 +08:00
|
|
|
func ListUser(ctx *gin.Context) { common.ListPage[models.UserAccount](ctx) }
|
2026-07-27 01:32:44 +08:00
|
|
|
|
|
|
|
|
// GetUser 查询一个业主客户档案。
|
2026-07-28 10:42:26 +08:00
|
|
|
func GetUser(ctx *gin.Context) { common.GetByIdentity[models.UserAccount](ctx) }
|
2026-07-27 01:32:44 +08:00
|
|
|
|
|
|
|
|
// CreateUser 创建业主客户档案。
|
|
|
|
|
func CreateUser(ctx *gin.Context) {
|
2026-07-27 02:03:26 +08:00
|
|
|
var request struct {
|
|
|
|
|
Username string `json:"username" binding:"required,max=64"`
|
|
|
|
|
Password string `json:"password" binding:"required,min=8,max=128"`
|
|
|
|
|
Name string `json:"name" binding:"required,max=64"`
|
|
|
|
|
Phone string `json:"phone" binding:"max=32"`
|
|
|
|
|
Avatar string `json:"avatar" binding:"max=512"`
|
|
|
|
|
RealName string `json:"real_name" binding:"max=64"`
|
|
|
|
|
}
|
|
|
|
|
if err := ctx.ShouldBindJSON(&request); err != nil {
|
2026-07-27 01:32:44 +08:00
|
|
|
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-07-28 13:55:40 +08:00
|
|
|
hash, err := common.PasswordHash(request.Password)
|
2026-07-27 02:03:26 +08:00
|
|
|
if err != nil {
|
|
|
|
|
infra.Response.Error(ctx, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-07-28 10:42:26 +08:00
|
|
|
user := models.UserAccount{Entity: common.NewEntity("enabled"), Username: request.Username, PasswordHash: hash, Name: request.Name, Phone: request.Phone, Avatar: request.Avatar, RealName: request.RealName}
|
2026-07-27 02:03:26 +08:00
|
|
|
if err := impl.DBService.Create(&user).Error; err != nil {
|
2026-07-27 01:32:44 +08:00
|
|
|
infra.Response.Error(ctx, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-07-28 10:42:26 +08:00
|
|
|
common.RespondCreatedResource(ctx, user)
|
2026-07-27 01:32:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateUser 更新业主客户档案。
|
|
|
|
|
func UpdateUser(ctx *gin.Context) {
|
|
|
|
|
var request struct {
|
|
|
|
|
Name string `json:"name" binding:"required,max=64"`
|
|
|
|
|
Phone string `json:"phone" binding:"max=32"`
|
|
|
|
|
Avatar string `json:"avatar" binding:"max=512"`
|
|
|
|
|
RealName string `json:"real_name" binding:"max=64"`
|
|
|
|
|
}
|
|
|
|
|
if err := ctx.ShouldBindJSON(&request); err != nil {
|
|
|
|
|
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-07-28 10:42:26 +08:00
|
|
|
common.UpdateAllowedByIdentity(ctx, &models.UserAccount{}, gin.H{"name": request.Name, "phone": request.Phone, "avatar": request.Avatar, "real_name": request.RealName}, []string{"name", "phone", "avatar", "real_name"})
|
2026-07-27 01:32:44 +08:00
|
|
|
}
|