完善配送端账户头像管理
This commit is contained in:
@@ -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"
|
||||
@@ -41,13 +42,26 @@ func GetStaff(ctx *gin.Context) {
|
||||
ctx.Param("identity"), point.GasBasicID, point.ID, "delivery"), &staff)
|
||||
}
|
||||
|
||||
// GetStaffAvatar 返回当前配送点范围内配送人员的受保护头像。
|
||||
func GetStaffAvatar(ctx *gin.Context) {
|
||||
point, _, ok := currentScope(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
staff, ok := scopedStaff(ctx, ctx.Param("identity"), point)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
upload.ServeAvatar(ctx, staff.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"`
|
||||
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"`
|
||||
WorkStatus string `json:"work_status" binding:"required"`
|
||||
}
|
||||
|
||||
func CreateStaff(ctx *gin.Context) {
|
||||
@@ -66,9 +80,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: "delivery",
|
||||
Name: request.Name, Phone: request.Phone, Avatar: avatar, RoleCode: "delivery",
|
||||
GasBasicID: point.GasBasicID, DeliveryBasicID: point.ID, WorkStatus: request.WorkStatus,
|
||||
}
|
||||
if err := common.CreateStaffRecord(&staff); err != nil {
|
||||
@@ -92,9 +110,13 @@ func UpdateStaff(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
common.UpdateAllowedByIdentityWithError(ctx, &models.StaffAccount{}, gin.H{
|
||||
"name": request.Name, "phone": request.Phone, "avatar": request.Avatar, "work_status": request.WorkStatus,
|
||||
}, []string{"name", "phone", "avatar", "work_status"}, common.StaffWriteError)
|
||||
values := gin.H{"name": request.Name, "phone": request.Phone, "work_status": request.WorkStatus}
|
||||
// 未选择新头像时不提交 avatar,避免编辑基础资料误清空现有头像。
|
||||
if request.Avatar != nil {
|
||||
values["avatar"] = *request.Avatar
|
||||
}
|
||||
common.UpdateAllowedByIdentityWithError(ctx, &models.StaffAccount{}, values,
|
||||
[]string{"name", "phone", "avatar", "work_status"}, common.StaffWriteError)
|
||||
}
|
||||
|
||||
func ResetStaffPassword(ctx *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user