fix: 新增店铺时为初始账号分配默认角色
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m0s

问题:创建店铺时只创建了 shop_roles 记录(店铺可用角色),
但没有创建 account_roles 记录,导致初始账号没有任何权限。

修复:在创建初始账号后,立即为其分配默认角色到 account_roles 表。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 16:47:36 +08:00
parent efe8a362aa
commit c1eec5d4f1
2 changed files with 24 additions and 9 deletions

View File

@@ -96,7 +96,7 @@ func initServices(s *stores, deps *Dependencies) *services {
Role: roleSvc.New(s.Role, s.Permission, s.RolePermission),
Permission: permissionSvc.New(s.Permission, s.AccountRole, s.RolePermission, account, deps.Redis),
PersonalCustomer: personalCustomerSvc.NewService(s.PersonalCustomer, s.PersonalCustomerPhone, deps.VerificationService, deps.JWTManager, deps.WechatOfficialAccount, deps.Logger),
Shop: shopSvc.New(s.Shop, s.Account, s.ShopRole, s.Role),
Shop: shopSvc.New(s.Shop, s.Account, s.ShopRole, s.Role, s.AccountRole),
Auth: authSvc.New(s.Account, s.AccountRole, s.RolePermission, s.Permission, s.Shop, deps.TokenManager, deps.Logger),
ShopCommission: shopCommissionSvc.New(s.Shop, s.Account, s.AgentWallet, s.CommissionWithdrawalRequest, s.CommissionRecord),
CommissionWithdrawal: commissionWithdrawalSvc.New(deps.DB, s.Shop, s.Account, s.AgentWallet, s.AgentWalletTransaction, s.CommissionWithdrawalRequest),

View File

@@ -15,10 +15,11 @@ import (
)
type Service struct {
shopStore *postgres.ShopStore
accountStore *postgres.AccountStore
shopRoleStore *postgres.ShopRoleStore
roleStore *postgres.RoleStore
shopStore *postgres.ShopStore
accountStore *postgres.AccountStore
shopRoleStore *postgres.ShopRoleStore
roleStore *postgres.RoleStore
accountRoleStore *postgres.AccountRoleStore
}
func New(
@@ -26,12 +27,14 @@ func New(
accountStore *postgres.AccountStore,
shopRoleStore *postgres.ShopRoleStore,
roleStore *postgres.RoleStore,
accountRoleStore *postgres.AccountRoleStore,
) *Service {
return &Service{
shopStore: shopStore,
accountStore: accountStore,
shopRoleStore: shopRoleStore,
roleStore: roleStore,
shopStore: shopStore,
accountStore: accountStore,
shopRoleStore: shopRoleStore,
roleStore: roleStore,
accountRoleStore: accountRoleStore,
}
}
@@ -120,6 +123,18 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateShopRequest) (*dto.
return nil, errors.Wrap(errors.CodeInternalError, err, "创建初始账号失败")
}
// 为初始账号分配默认角色
accountRole := &model.AccountRole{
AccountID: account.ID,
RoleID: req.DefaultRoleID,
Status: constants.StatusEnabled,
Creator: currentUserID,
Updater: currentUserID,
}
if err := s.accountRoleStore.Create(ctx, accountRole); err != nil {
return nil, errors.Wrap(errors.CodeInternalError, err, "为初始账号分配角色失败")
}
// 设置店铺默认角色
shopRole := &model.ShopRole{
ShopID: shop.ID,