diff --git a/internal/bootstrap/services.go b/internal/bootstrap/services.go index 65c8f60..06763b2 100644 --- a/internal/bootstrap/services.go +++ b/internal/bootstrap/services.go @@ -106,7 +106,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, s.AccountRole), + Shop: shopSvc.New(s.Shop, s.Account, s.ShopRole, s.Role, s.AccountRole, s.AgentWallet), 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 1c31a7c..356a799 100644 --- a/internal/service/shop/service.go +++ b/internal/service/shop/service.go @@ -20,6 +20,7 @@ type Service struct { shopRoleStore *postgres.ShopRoleStore roleStore *postgres.RoleStore accountRoleStore *postgres.AccountRoleStore + agentWalletStore *postgres.AgentWalletStore } func New( @@ -28,6 +29,7 @@ func New( shopRoleStore *postgres.ShopRoleStore, roleStore *postgres.RoleStore, accountRoleStore *postgres.AccountRoleStore, + agentWalletStore *postgres.AgentWalletStore, ) *Service { return &Service{ shopStore: shopStore, @@ -35,6 +37,7 @@ func New( shopRoleStore: shopRoleStore, roleStore: roleStore, accountRoleStore: accountRoleStore, + agentWalletStore: agentWalletStore, } } @@ -147,6 +150,32 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateShopRequest) (*dto. return nil, errors.Wrap(errors.CodeInternalError, err, "设置店铺默认角色失败") } + // 初始化店铺代理钱包:主钱包 + 分佣钱包 + // 新店铺必须有两个钱包才能参与充值和分佣体系 + wallets := []*model.AgentWallet{ + { + ShopID: shop.ID, + WalletType: constants.AgentWalletTypeMain, + Balance: 0, + Currency: "CNY", + Status: constants.AgentWalletStatusNormal, + ShopIDTag: shop.ID, + }, + { + ShopID: shop.ID, + WalletType: constants.AgentWalletTypeCommission, + Balance: 0, + Currency: "CNY", + Status: constants.AgentWalletStatusNormal, + ShopIDTag: shop.ID, + }, + } + for _, wallet := range wallets { + if err := s.agentWalletStore.Create(ctx, wallet); err != nil { + return nil, errors.Wrap(errors.CodeInternalError, err, "初始化店铺钱包失败") + } + } + return &dto.ShopResponse{ ID: shop.ID, ShopName: shop.ShopName,