完善配送端账户头像管理
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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ func RegisterDelivery(serviceKey string, engine *gin.Engine) {
|
||||
staff.GET("", deliverylogic.ListStaff)
|
||||
staff.POST("", deliverylogic.CreateStaff)
|
||||
staff.GET("/:identity", deliverylogic.GetStaff)
|
||||
staff.GET("/:identity/avatar", deliverylogic.GetStaffAvatar)
|
||||
staff.PUT("/:identity", deliverylogic.UpdateStaff)
|
||||
staff.PUT("/:identity/password", deliverylogic.ResetStaffPassword)
|
||||
staff.PATCH("/:identity/status", deliverylogic.UpdateStaffStatus)
|
||||
@@ -44,6 +45,7 @@ func RegisterDelivery(serviceKey string, engine *gin.Engine) {
|
||||
user.GET("", deliverylogic.ListUser)
|
||||
user.POST("", deliverylogic.CreateUser)
|
||||
user.GET("/:identity", deliverylogic.GetUser)
|
||||
user.GET("/:identity/avatar", deliverylogic.GetUserAvatar)
|
||||
user.PUT("/:identity", deliverylogic.UpdateUser)
|
||||
user.PUT("/:identity/password", deliverylogic.ResetUserPassword)
|
||||
user.PATCH("/:identity/status", deliverylogic.UpdateUserStatus)
|
||||
|
||||
@@ -45,6 +45,8 @@ func TestDeliveryOrderActionBoundary(t *testing.T) {
|
||||
"POST /heqi/delivery/v1/gasorder_basic/:identity/adjust-amount",
|
||||
"GET /heqi/delivery/v1/wallet_recharge",
|
||||
"GET /heqi/delivery/v1/wallet_recharge/:identity",
|
||||
"GET /heqi/delivery/v1/staff_account/:identity/avatar",
|
||||
"GET /heqi/delivery/v1/user_account/:identity/avatar",
|
||||
} {
|
||||
if !routes[required] {
|
||||
t.Fatalf("missing confirmed delivery action %s", required)
|
||||
|
||||
Reference in New Issue
Block a user