diff --git a/internal/service/account/service.go b/internal/service/account/service.go index 9de7c96..81c0924 100644 --- a/internal/service/account/service.go +++ b/internal/service/account/service.go @@ -124,6 +124,23 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateAccountRequest) (*m return nil, errors.Wrap(errors.CodeInternalError, err, "创建账号失败") } + // 代理账号自动分配该店铺的默认角色 + if req.UserType == constants.UserTypeAgent && req.ShopID != nil { + roleIDs, err := s.shopRoleStore.GetRoleIDsByShopID(ctx, *req.ShopID) + if err == nil { + for _, roleID := range roleIDs { + ar := &model.AccountRole{ + AccountID: account.ID, + RoleID: roleID, + Status: constants.StatusEnabled, + Creator: currentUserID, + Updater: currentUserID, + } + _ = s.accountRoleStore.Create(ctx, ar) + } + } + } + currentAccount, _ := s.accountStore.GetByID(ctx, currentUserID) operatorName := "" if currentAccount != nil {