作者 陈志颖

fix:修复金额激励预算承接人检索错误

@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
11 "time" 12 "time"
12 ) 13 )
13 14
@@ -49,67 +50,34 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -49,67 +50,34 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
49 50
50 // 金额激励预算 51 // 金额激励预算
51 for _, undertaker := range contract.Undertakers { 52 for _, undertaker := range contract.Undertakers {
52 - // 判断承接人在当前阶段是否已经分红  
53 - undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{  
54 - "undertakerUid": undertaker.UserId,  
55 - "companyId": contract.Company.CompanyId,  
56 - "orgId": contract.Org.OrgId,  
57 - })  
58 - if err != nil {  
59 - return nil, err  
60 - }  
61 - if undertakerEstimated {  
62 - return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")  
63 - } else {  
64 - undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage))).Div(decimal.NewFromFloat(100))).Float64()  
65 - dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{  
66 - DividendsUser: &domain.User{  
67 - UserId: undertaker.UserId,  
68 - UserBaseId: undertaker.UserBaseId,  
69 - Org: undertaker.Org,  
70 - Orgs: undertaker.Orgs,  
71 - Department: undertaker.Department,  
72 - Roles: undertaker.Roles,  
73 - UserInfo: undertaker.UserInfo,  
74 - UserType: undertaker.UserType,  
75 - UserName: undertaker.UserName,  
76 - UserPhone: undertaker.UserPhone,  
77 - Status: undertaker.Status,  
78 - Company: undertaker.Company,  
79 - },  
80 - DividendsParticipateType: domain.MONEY_INCENTIVES,  
81 - DividendsStage: stage,  
82 - DividendsAmount: undertakerDividendsAmount,  
83 - })  
84 - }  
85 -  
86 - // 判断业务员在当前阶段是否已经分红  
87 - if undertaker.Salesman != nil {  
88 - salesmanEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{  
89 - "undertakerUid": undertaker.Salesman.UserId, 53 + if utils.IsContain64(undertakerUIDs, undertaker.UndertakerId) {
  54 + // 判断承接人在当前阶段是否已经分红
  55 + undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
  56 + "undertakerUid": undertaker.UserId,
90 "companyId": contract.Company.CompanyId, 57 "companyId": contract.Company.CompanyId,
91 "orgId": contract.Org.OrgId, 58 "orgId": contract.Org.OrgId,
92 }) 59 })
93 if err != nil { 60 if err != nil {
94 return nil, err 61 return nil, err
95 } 62 }
96 - if salesmanEstimated {  
97 - return nil, fmt.Errorf("业务员 " + undertaker.Salesman.UserName + " 已分红") 63 + if undertakerEstimated {
  64 + return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")
98 } else { 65 } else {
99 - undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64() 66 + undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage))).Div(decimal.NewFromFloat(100))).Float64()
100 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 67 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
101 DividendsUser: &domain.User{ 68 DividendsUser: &domain.User{
102 - UserId: undertaker.Salesman.UserId,  
103 - UserBaseId: undertaker.Salesman.UserBaseId,  
104 - Org: undertaker.Salesman.Org,  
105 - Orgs: undertaker.Salesman.Orgs,  
106 - Department: undertaker.Salesman.Department,  
107 - Roles: undertaker.Salesman.Roles,  
108 - UserInfo: undertaker.Salesman.UserInfo,  
109 - UserType: undertaker.Salesman.UserType,  
110 - UserName: undertaker.Salesman.UserName,  
111 - UserPhone: undertaker.Salesman.UserPhone,  
112 - Company: undertaker.Salesman.Company, 69 + UserId: undertaker.UserId,
  70 + UserBaseId: undertaker.UserBaseId,
  71 + Org: undertaker.Org,
  72 + Orgs: undertaker.Orgs,
  73 + Department: undertaker.Department,
  74 + Roles: undertaker.Roles,
  75 + UserInfo: undertaker.UserInfo,
  76 + UserType: undertaker.UserType,
  77 + UserName: undertaker.UserName,
  78 + UserPhone: undertaker.UserPhone,
  79 + Status: undertaker.Status,
  80 + Company: undertaker.Company,
113 }, 81 },
114 DividendsParticipateType: domain.MONEY_INCENTIVES, 82 DividendsParticipateType: domain.MONEY_INCENTIVES,
115 DividendsStage: stage, 83 DividendsStage: stage,
@@ -117,40 +85,75 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -117,40 +85,75 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
117 }) 85 })
118 } 86 }
119 87
120 - } 88 + // 判断业务员在当前阶段是否已经分红
  89 + if undertaker.Salesman != nil {
  90 + salesmanEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
  91 + "undertakerUid": undertaker.Salesman.UserId,
  92 + "companyId": contract.Company.CompanyId,
  93 + "orgId": contract.Org.OrgId,
  94 + })
  95 + if err != nil {
  96 + return nil, err
  97 + }
  98 + if salesmanEstimated {
  99 + return nil, fmt.Errorf("业务员 " + undertaker.Salesman.UserName + " 已分红")
  100 + } else {
  101 + undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64()
  102 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  103 + DividendsUser: &domain.User{
  104 + UserId: undertaker.Salesman.UserId,
  105 + UserBaseId: undertaker.Salesman.UserBaseId,
  106 + Org: undertaker.Salesman.Org,
  107 + Orgs: undertaker.Salesman.Orgs,
  108 + Department: undertaker.Salesman.Department,
  109 + Roles: undertaker.Salesman.Roles,
  110 + UserInfo: undertaker.Salesman.UserInfo,
  111 + UserType: undertaker.Salesman.UserType,
  112 + UserName: undertaker.Salesman.UserName,
  113 + UserPhone: undertaker.Salesman.UserPhone,
  114 + Company: undertaker.Salesman.Company,
  115 + },
  116 + DividendsParticipateType: domain.MONEY_INCENTIVES,
  117 + DividendsStage: stage,
  118 + DividendsAmount: undertakerDividendsAmount,
  119 + })
  120 + }
121 121
122 - // 判断关联业务员在当前阶段是否已经分红  
123 - if undertaker.Referrer != nil {  
124 - referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{  
125 - "undertakerUid": undertaker.Referrer.UserId,  
126 - "companyId": contract.Company.CompanyId,  
127 - "orgId": contract.Org.OrgId,  
128 - })  
129 - if err != nil {  
130 - return nil, err  
131 } 122 }
132 - if referrerEstimated {  
133 - return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红")  
134 - } else {  
135 - undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64()  
136 - dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{  
137 - DividendsUser: &domain.User{  
138 - UserId: undertaker.Referrer.UserId,  
139 - UserBaseId: undertaker.Referrer.UserBaseId,  
140 - Org: undertaker.Referrer.Org,  
141 - Orgs: undertaker.Referrer.Orgs,  
142 - Department: undertaker.Referrer.Department,  
143 - Roles: undertaker.Referrer.Roles,  
144 - UserInfo: undertaker.Referrer.UserInfo,  
145 - UserType: undertaker.Referrer.UserType,  
146 - UserName: undertaker.Referrer.UserName,  
147 - UserPhone: undertaker.Referrer.UserPhone,  
148 - Company: undertaker.Referrer.Company,  
149 - },  
150 - DividendsParticipateType: domain.MONEY_INCENTIVES,  
151 - DividendsStage: stage,  
152 - DividendsAmount: undertakerDividendsAmount, 123 +
  124 + // 判断关联业务员在当前阶段是否已经分红
  125 + if undertaker.Referrer != nil {
  126 + referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
  127 + "undertakerUid": undertaker.Referrer.UserId,
  128 + "companyId": contract.Company.CompanyId,
  129 + "orgId": contract.Org.OrgId,
153 }) 130 })
  131 + if err != nil {
  132 + return nil, err
  133 + }
  134 + if referrerEstimated {
  135 + return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红")
  136 + } else {
  137 + undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64()
  138 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  139 + DividendsUser: &domain.User{
  140 + UserId: undertaker.Referrer.UserId,
  141 + UserBaseId: undertaker.Referrer.UserBaseId,
  142 + Org: undertaker.Referrer.Org,
  143 + Orgs: undertaker.Referrer.Orgs,
  144 + Department: undertaker.Referrer.Department,
  145 + Roles: undertaker.Referrer.Roles,
  146 + UserInfo: undertaker.Referrer.UserInfo,
  147 + UserType: undertaker.Referrer.UserType,
  148 + UserName: undertaker.Referrer.UserName,
  149 + UserPhone: undertaker.Referrer.UserPhone,
  150 + Company: undertaker.Referrer.Company,
  151 + },
  152 + DividendsParticipateType: domain.MONEY_INCENTIVES,
  153 + DividendsStage: stage,
  154 + DividendsAmount: undertakerDividendsAmount,
  155 + })
  156 + }
154 } 157 }
155 } 158 }
156 } 159 }
@@ -135,3 +135,13 @@ func IsContain(items []int32, item int32) bool { @@ -135,3 +135,13 @@ func IsContain(items []int32, item int32) bool {
135 } 135 }
136 return false 136 return false
137 } 137 }
  138 +
  139 +// IsContain64 判断int64数组是否包含
  140 +func IsContain64(items []int64, item int64) bool {
  141 + for _, eachItem := range items {
  142 + if eachItem == item {
  143 + return true
  144 + }
  145 + }
  146 + return false
  147 +}