diff --git a/app/main/api/internal/service/agentService.go b/app/main/api/internal/service/agentService.go index 147877a..5dcbb7d 100644 --- a/app/main/api/internal/service/agentService.go +++ b/app/main/api/internal/service/agentService.go @@ -290,26 +290,29 @@ func (l *AgentService) CommissionCost(ctx context.Context, descendantId int64, A if agentMembershipConfigModel.PriceIncreaseAmount.Valid { // 拥有则查看该上级设定的成本 agentMembershipUserConfigModel, findAgentMembershipUserConfigModelErr := l.AgentMembershipUserConfigModel.FindOneByAgentIdProductId(ctx, AncestorId, productID) - if findAgentMembershipUserConfigModelErr != nil { + if findAgentMembershipUserConfigModelErr != nil && !errors.Is(findAgentMembershipUserConfigModelErr, model.ErrNotFound) { return 0, findAgentMembershipUserConfigModelErr } + if agentMembershipUserConfigModel != nil { + deductCostAmount := agentMembershipUserConfigModel.PriceIncreaseAmount - deductCostAmount := agentMembershipUserConfigModel.PriceIncreaseAmount + agentCommissionDeductionModel := model.AgentCommissionDeduction{ + AgentId: AncestorId, + DeductedAgentId: descendantId, + Amount: deductCostAmount, + Type: model.AgentDeductionTypeCost, + ProductId: productID, + } - agentCommissionDeductionModel := model.AgentCommissionDeduction{ - AgentId: AncestorId, - DeductedAgentId: descendantId, - Amount: deductCostAmount, - Type: model.AgentDeductionTypeCost, - ProductId: productID, + _, insertAgentCommissionDeductionModelErr := l.AgentCommissionDeductionModel.Insert(ctx, session, &agentCommissionDeductionModel) + if insertAgentCommissionDeductionModelErr != nil { + return 0, insertAgentCommissionDeductionModelErr + } + + return deductCostAmount, nil + } else { + return 0, nil } - - _, insertAgentCommissionDeductionModelErr := l.AgentCommissionDeductionModel.Insert(ctx, session, &agentCommissionDeductionModel) - if insertAgentCommissionDeductionModelErr != nil { - return 0, insertAgentCommissionDeductionModelErr - } - - return deductCostAmount, nil } return 0, nil }