适配气站工作人员与用户受保护头像
This commit is contained in:
@@ -7,6 +7,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"
|
||||
)
|
||||
@@ -52,15 +53,31 @@ func GetStaff(ctx *gin.Context) {
|
||||
Where("identity = ? AND gas_basic_id = ?", ctx.Param("identity"), station.ID), &models.StaffAccount{})
|
||||
}
|
||||
|
||||
// GetStaffAvatar 返回当前气站范围内工作人员的受保护头像。
|
||||
func GetStaffAvatar(ctx *gin.Context) {
|
||||
station, ok := currentGas(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var account models.StaffAccount
|
||||
if err := common.ActiveRecords(impl.DBService).Select("avatar").
|
||||
Where("identity = ? AND gas_basic_id = ?", ctx.Param("identity"), station.ID).
|
||||
First(&account).Error; err != nil {
|
||||
common.RespondRecordError(ctx, err)
|
||||
return
|
||||
}
|
||||
upload.ServeAvatar(ctx, account.Avatar)
|
||||
}
|
||||
|
||||
type staffRequest 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"`
|
||||
RoleCode string `json:"role_code" binding:"required"`
|
||||
DeliveryBasicIdentity string `json:"delivery_basic_identity"`
|
||||
WorkStatus string `json:"work_status" 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"`
|
||||
RoleCode string `json:"role_code" binding:"required"`
|
||||
DeliveryBasicIdentity string `json:"delivery_basic_identity"`
|
||||
WorkStatus string `json:"work_status" binding:"required"`
|
||||
}
|
||||
|
||||
func CreateStaff(ctx *gin.Context) {
|
||||
@@ -87,9 +104,13 @@ func CreateStaff(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
avatar := ""
|
||||
if request.Avatar != nil {
|
||||
avatar = *request.Avatar
|
||||
}
|
||||
staff := models.StaffAccount{
|
||||
Entity: common.NewEntity(common.StatusEnable), Username: request.Username, PasswordHash: hash,
|
||||
Name: request.Name, Phone: request.Phone, Avatar: request.Avatar, RoleCode: request.RoleCode,
|
||||
Name: request.Name, Phone: request.Phone, Avatar: avatar, RoleCode: request.RoleCode,
|
||||
GasBasicID: station.ID, DeliveryBasicID: deliveryID, WorkStatus: request.WorkStatus,
|
||||
}
|
||||
if err := common.CreateStaffRecord(&staff); err != nil {
|
||||
@@ -120,10 +141,15 @@ func UpdateStaff(ctx *gin.Context) {
|
||||
}
|
||||
deliveryID = delivery.ID
|
||||
}
|
||||
common.UpdateAllowedByIdentityWithError(ctx, &models.StaffAccount{}, gin.H{
|
||||
"name": request.Name, "phone": request.Phone, "avatar": request.Avatar, "role_code": request.RoleCode,
|
||||
values := gin.H{
|
||||
"name": request.Name, "phone": request.Phone, "role_code": request.RoleCode,
|
||||
"delivery_basic_id": deliveryID, "work_status": request.WorkStatus,
|
||||
}, []string{"name", "phone", "avatar", "role_code", "delivery_basic_id", "work_status"}, common.StaffWriteError)
|
||||
}
|
||||
// 未选择新头像时不提交 avatar,避免编辑基础资料误清空现有头像。
|
||||
if request.Avatar != nil {
|
||||
values["avatar"] = *request.Avatar
|
||||
}
|
||||
common.UpdateAllowedByIdentityWithError(ctx, &models.StaffAccount{}, values, []string{"name", "phone", "avatar", "role_code", "delivery_basic_id", "work_status"}, common.StaffWriteError)
|
||||
}
|
||||
|
||||
func UpdateStaffStatus(ctx *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user