From b44363b335e263ac13ebb0f1387c9ff2a653b400 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 17 Mar 2026 14:08:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E9=92=B1=E5=8C=85=E5=AF=BC=E8=87=B4=E5=85=85=E5=80=BC?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新建店铺时在 shop.Service.Create() 中自动初始化主钱包(main)和分佣钱包(commission),修复充值订单创建时「目标店铺主钱包不存在」错误 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- internal/bootstrap/services.go | 2 +- internal/service/shop/service.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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,