作者 陈志颖

fix:增加金额激励预算校验

... ... @@ -379,14 +379,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 用户REST服务初始化
//var userService service.UserService
//if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// userService = value
//}
// 公司REST服务初始化
var companyService service.CompanyService
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
... ...
... ... @@ -89,69 +89,76 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
DividendsAmount: undertakerDividendsAmount,
})
}
// 判断业务员在当前阶段是否已经分红
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 := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (moneyIncentivesRuleMatched.SalesmanPercentage / 100)
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.Salesman.UserId != 0 {
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 := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (moneyIncentivesRuleMatched.SalesmanPercentage / 100)
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,
})
}
}
// 判断关联业务员在当前阶段是否已经分红
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 := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (moneyIncentivesRuleMatched.ReferrerPercentage / 100)
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.UserId != 0 {
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 := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (moneyIncentivesRuleMatched.ReferrerPercentage / 100)
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,
})
}
}
}
return dividendsEstimateDetails, nil
... ...