feat: 新增店铺时自动设置默认角色
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m1s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m1s
- CreateShopRequest 新增必填字段 default_role_id - 创建店铺时验证默认角色(必须存在、是客户角色、已启用) - 创建店铺后自动设置 ShopRole,初始账号立即拥有权限 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -68,6 +68,18 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateShopRequest) (*dto.
|
||||
return nil, errors.New(errors.CodePhoneExists, "初始账号手机号已存在")
|
||||
}
|
||||
|
||||
// 验证默认角色:必须存在、是客户角色且已启用
|
||||
defaultRole, err := s.roleStore.GetByID(ctx, req.DefaultRoleID)
|
||||
if err != nil {
|
||||
return nil, errors.New(errors.CodeNotFound, "默认角色不存在")
|
||||
}
|
||||
if defaultRole.RoleType != constants.RoleTypeCustomer {
|
||||
return nil, errors.New(errors.CodeInvalidParam, "店铺默认角色必须是客户角色")
|
||||
}
|
||||
if defaultRole.Status != constants.StatusEnabled {
|
||||
return nil, errors.New(errors.CodeInvalidParam, "默认角色已禁用")
|
||||
}
|
||||
|
||||
shop := &model.Shop{
|
||||
ShopName: req.ShopName,
|
||||
ShopCode: req.ShopCode,
|
||||
@@ -108,6 +120,18 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateShopRequest) (*dto.
|
||||
return nil, errors.Wrap(errors.CodeInternalError, err, "创建初始账号失败")
|
||||
}
|
||||
|
||||
// 设置店铺默认角色
|
||||
shopRole := &model.ShopRole{
|
||||
ShopID: shop.ID,
|
||||
RoleID: req.DefaultRoleID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: currentUserID,
|
||||
Updater: currentUserID,
|
||||
}
|
||||
if err := s.shopRoleStore.BatchCreate(ctx, []*model.ShopRole{shopRole}); err != nil {
|
||||
return nil, errors.Wrap(errors.CodeInternalError, err, "设置店铺默认角色失败")
|
||||
}
|
||||
|
||||
return &dto.ShopResponse{
|
||||
ID: shop.ID,
|
||||
ShopName: shop.ShopName,
|
||||
|
||||
Reference in New Issue
Block a user