fix: 修复新建店铺未初始化代理钱包导致充值订单报错
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m6s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m6s
新建店铺时在 shop.Service.Create() 中自动初始化主钱包(main)和分佣钱包(commission),修复充值订单创建时「目标店铺主钱包不存在」错误 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user