...
|
...
|
@@ -8,6 +8,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -49,67 +50,34 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do |
|
|
|
|
|
// 金额激励预算
|
|
|
for _, undertaker := range contract.Undertakers {
|
|
|
// 判断承接人在当前阶段是否已经分红
|
|
|
undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
|
|
|
"undertakerUid": undertaker.UserId,
|
|
|
"companyId": contract.Company.CompanyId,
|
|
|
"orgId": contract.Org.OrgId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if undertakerEstimated {
|
|
|
return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")
|
|
|
} else {
|
|
|
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage))).Div(decimal.NewFromFloat(100))).Float64()
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: &domain.User{
|
|
|
UserId: undertaker.UserId,
|
|
|
UserBaseId: undertaker.UserBaseId,
|
|
|
Org: undertaker.Org,
|
|
|
Orgs: undertaker.Orgs,
|
|
|
Department: undertaker.Department,
|
|
|
Roles: undertaker.Roles,
|
|
|
UserInfo: undertaker.UserInfo,
|
|
|
UserType: undertaker.UserType,
|
|
|
UserName: undertaker.UserName,
|
|
|
UserPhone: undertaker.UserPhone,
|
|
|
Status: undertaker.Status,
|
|
|
Company: undertaker.Company,
|
|
|
},
|
|
|
DividendsParticipateType: domain.MONEY_INCENTIVES,
|
|
|
DividendsStage: stage,
|
|
|
DividendsAmount: undertakerDividendsAmount,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 判断业务员在当前阶段是否已经分红
|
|
|
if undertaker.Salesman != nil {
|
|
|
salesmanEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
|
|
|
"undertakerUid": undertaker.Salesman.UserId,
|
|
|
if utils.IsContain64(undertakerUIDs, undertaker.UndertakerId) {
|
|
|
// 判断承接人在当前阶段是否已经分红
|
|
|
undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
|
|
|
"undertakerUid": undertaker.UserId,
|
|
|
"companyId": contract.Company.CompanyId,
|
|
|
"orgId": contract.Org.OrgId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if salesmanEstimated {
|
|
|
return nil, fmt.Errorf("业务员 " + undertaker.Salesman.UserName + " 已分红")
|
|
|
if undertakerEstimated {
|
|
|
return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")
|
|
|
} else {
|
|
|
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64()
|
|
|
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage))).Div(decimal.NewFromFloat(100))).Float64()
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: &domain.User{
|
|
|
UserId: undertaker.Salesman.UserId,
|
|
|
UserBaseId: undertaker.Salesman.UserBaseId,
|
|
|
Org: undertaker.Salesman.Org,
|
|
|
Orgs: undertaker.Salesman.Orgs,
|
|
|
Department: undertaker.Salesman.Department,
|
|
|
Roles: undertaker.Salesman.Roles,
|
|
|
UserInfo: undertaker.Salesman.UserInfo,
|
|
|
UserType: undertaker.Salesman.UserType,
|
|
|
UserName: undertaker.Salesman.UserName,
|
|
|
UserPhone: undertaker.Salesman.UserPhone,
|
|
|
Company: undertaker.Salesman.Company,
|
|
|
UserId: undertaker.UserId,
|
|
|
UserBaseId: undertaker.UserBaseId,
|
|
|
Org: undertaker.Org,
|
|
|
Orgs: undertaker.Orgs,
|
|
|
Department: undertaker.Department,
|
|
|
Roles: undertaker.Roles,
|
|
|
UserInfo: undertaker.UserInfo,
|
|
|
UserType: undertaker.UserType,
|
|
|
UserName: undertaker.UserName,
|
|
|
UserPhone: undertaker.UserPhone,
|
|
|
Status: undertaker.Status,
|
|
|
Company: undertaker.Company,
|
|
|
},
|
|
|
DividendsParticipateType: domain.MONEY_INCENTIVES,
|
|
|
DividendsStage: stage,
|
...
|
...
|
@@ -117,40 +85,75 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do |
|
|
})
|
|
|
}
|
|
|
|
|
|
}
|
|
|
// 判断业务员在当前阶段是否已经分红
|
|
|
if undertaker.Salesman != nil {
|
|
|
salesmanEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
|
|
|
"undertakerUid": undertaker.Salesman.UserId,
|
|
|
"companyId": contract.Company.CompanyId,
|
|
|
"orgId": contract.Org.OrgId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if salesmanEstimated {
|
|
|
return nil, fmt.Errorf("业务员 " + undertaker.Salesman.UserName + " 已分红")
|
|
|
} else {
|
|
|
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64()
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: &domain.User{
|
|
|
UserId: undertaker.Salesman.UserId,
|
|
|
UserBaseId: undertaker.Salesman.UserBaseId,
|
|
|
Org: undertaker.Salesman.Org,
|
|
|
Orgs: undertaker.Salesman.Orgs,
|
|
|
Department: undertaker.Salesman.Department,
|
|
|
Roles: undertaker.Salesman.Roles,
|
|
|
UserInfo: undertaker.Salesman.UserInfo,
|
|
|
UserType: undertaker.Salesman.UserType,
|
|
|
UserName: undertaker.Salesman.UserName,
|
|
|
UserPhone: undertaker.Salesman.UserPhone,
|
|
|
Company: undertaker.Salesman.Company,
|
|
|
},
|
|
|
DividendsParticipateType: domain.MONEY_INCENTIVES,
|
|
|
DividendsStage: stage,
|
|
|
DividendsAmount: undertakerDividendsAmount,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 判断关联业务员在当前阶段是否已经分红
|
|
|
if undertaker.Referrer != nil {
|
|
|
referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
|
|
|
"undertakerUid": undertaker.Referrer.UserId,
|
|
|
"companyId": contract.Company.CompanyId,
|
|
|
"orgId": contract.Org.OrgId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if referrerEstimated {
|
|
|
return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红")
|
|
|
} else {
|
|
|
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64()
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: &domain.User{
|
|
|
UserId: undertaker.Referrer.UserId,
|
|
|
UserBaseId: undertaker.Referrer.UserBaseId,
|
|
|
Org: undertaker.Referrer.Org,
|
|
|
Orgs: undertaker.Referrer.Orgs,
|
|
|
Department: undertaker.Referrer.Department,
|
|
|
Roles: undertaker.Referrer.Roles,
|
|
|
UserInfo: undertaker.Referrer.UserInfo,
|
|
|
UserType: undertaker.Referrer.UserType,
|
|
|
UserName: undertaker.Referrer.UserName,
|
|
|
UserPhone: undertaker.Referrer.UserPhone,
|
|
|
Company: undertaker.Referrer.Company,
|
|
|
},
|
|
|
DividendsParticipateType: domain.MONEY_INCENTIVES,
|
|
|
DividendsStage: stage,
|
|
|
DividendsAmount: undertakerDividendsAmount,
|
|
|
|
|
|
// 判断关联业务员在当前阶段是否已经分红
|
|
|
if undertaker.Referrer != nil {
|
|
|
referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
|
|
|
"undertakerUid": undertaker.Referrer.UserId,
|
|
|
"companyId": contract.Company.CompanyId,
|
|
|
"orgId": contract.Org.OrgId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if referrerEstimated {
|
|
|
return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红")
|
|
|
} else {
|
|
|
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64()
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: &domain.User{
|
|
|
UserId: undertaker.Referrer.UserId,
|
|
|
UserBaseId: undertaker.Referrer.UserBaseId,
|
|
|
Org: undertaker.Referrer.Org,
|
|
|
Orgs: undertaker.Referrer.Orgs,
|
|
|
Department: undertaker.Referrer.Department,
|
|
|
Roles: undertaker.Referrer.Roles,
|
|
|
UserInfo: undertaker.Referrer.UserInfo,
|
|
|
UserType: undertaker.Referrer.UserType,
|
|
|
UserName: undertaker.Referrer.UserName,
|
|
|
UserPhone: undertaker.Referrer.UserPhone,
|
|
|
Company: undertaker.Referrer.Company,
|
|
|
},
|
|
|
DividendsParticipateType: domain.MONEY_INCENTIVES,
|
|
|
DividendsStage: stage,
|
|
|
DividendsAmount: undertakerDividendsAmount,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
|