完善配送端账户头像管理

This commit is contained in:
czl231
2026-08-22 21:10:22 +08:00
parent 25254cb773
commit 2e2c1a35dd
14 changed files with 356 additions and 24 deletions

View File

@@ -6,6 +6,7 @@ import (
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/infra"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/upload"
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
@@ -57,13 +58,26 @@ func GetUser(ctx *gin.Context) {
infra.Response.Success(ctx, response)
}
// GetUserAvatar 返回当前配送点存在有效服务关系的用户受保护头像。
func GetUserAvatar(ctx *gin.Context) {
point, _, ok := currentScope(ctx)
if !ok {
return
}
user, _, ok := scopedUser(ctx, ctx.Param("identity"), point.ID)
if !ok {
return
}
upload.ServeAvatar(ctx, user.Avatar)
}
type userRequest struct {
Username string `json:"username"`
Password string `json:"password"`
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"`
Username string `json:"username"`
Password string `json:"password"`
Name string `json:"name" binding:"required,max=64"`
Phone string `json:"phone" binding:"max=32"`
Avatar *string `json:"avatar" binding:"omitempty,max=512"`
RealName string `json:"real_name" binding:"max=64"`
}
func CreateUser(ctx *gin.Context) {
@@ -81,9 +95,13 @@ func CreateUser(ctx *gin.Context) {
infra.Response.Error(ctx, err)
return
}
avatar := ""
if request.Avatar != nil {
avatar = *request.Avatar
}
user := models.UserAccount{
Entity: common.NewEntity(common.StatusEnable), Username: request.Username, PasswordHash: hash,
Name: request.Name, Phone: request.Phone, Avatar: request.Avatar, RealName: request.RealName,
Name: request.Name, Phone: request.Phone, Avatar: avatar, RealName: request.RealName,
}
relation := models.UserServiceRelation{
Entity: common.NewEntity(common.StatusEnable), GasBasicID: point.GasBasicID, DeliveryBasicID: point.ID,
@@ -115,9 +133,12 @@ func UpdateUser(ctx *gin.Context) {
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
return
}
if err := db().Model(&user).Updates(map[string]any{
"name": request.Name, "phone": request.Phone, "avatar": request.Avatar, "real_name": request.RealName,
}).Error; err != nil {
values := map[string]any{"name": request.Name, "phone": request.Phone, "real_name": request.RealName}
// 未选择新头像时不提交 avatar避免编辑基础资料误清空现有头像。
if request.Avatar != nil {
values["avatar"] = *request.Avatar
}
if err := db().Model(&user).Updates(values).Error; err != nil {
infra.Response.Error(ctx, err)
return
}