适配气站工作人员与用户受保护头像
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"git.apinb.com/bsm-sdk/core/infra"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
"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,14 +58,27 @@ func GetUser(ctx *gin.Context) {
|
||||
infra.Response.Success(ctx, response)
|
||||
}
|
||||
|
||||
// GetUserAvatar 返回与当前气站存在服务关系的用户受保护头像。
|
||||
func GetUserAvatar(ctx *gin.Context) {
|
||||
station, ok := currentGas(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
user, _, ok := requireUser(ctx, ctx.Param("identity"), station.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"`
|
||||
DeliveryBasicIdentity string `json:"delivery_basic_identity" binding:"required"`
|
||||
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"`
|
||||
DeliveryBasicIdentity string `json:"delivery_basic_identity" binding:"required"`
|
||||
}
|
||||
|
||||
func CreateUser(ctx *gin.Context) {
|
||||
@@ -86,9 +100,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: station.ID, DeliveryBasicID: delivery.ID}
|
||||
if err := impl.DBService.Transaction(func(tx *gorm.DB) error {
|
||||
@@ -123,9 +141,14 @@ func UpdateUser(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := impl.DBService.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.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 := tx.Model(&user).Updates(values).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Model(&relation).Update("delivery_basic_id", delivery.ID).Error
|
||||
|
||||
Reference in New Issue
Block a user