diff --git a/internal/bootstrap/services.go b/internal/bootstrap/services.go index 6387964..59269f3 100644 --- a/internal/bootstrap/services.go +++ b/internal/bootstrap/services.go @@ -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), diff --git a/internal/service/shop/service.go b/internal/service/shop/service.go index 4e51045..1c31a7c 100644 --- a/internal/service/shop/service.go +++ b/internal/service/shop/service.go @@ -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,