...
|
...
|
@@ -67,101 +67,31 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 确认业绩分红预算
|
|
|
var dividendsEstimateDetails []*service.DividendsEstimateDetail
|
|
|
for _, orderGood := range orderGoods {
|
|
|
log.Logger.Info("业绩分红预算产品", map[string]interface{}{
|
|
|
"orderGood": orderGood,
|
|
|
})
|
|
|
|
|
|
if orderGood.CooperationContractNumber == "" {
|
|
|
var orderNumber string
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderNumber = orderGood.DividendsOrderNumber
|
|
|
} else {
|
|
|
orderNumber = orderGood.DividendsReturnedOrderNumber
|
|
|
// 查询共创项目
|
|
|
cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)
|
|
|
if count, cooperationProjectsFound, err := cooperationProjectRepository.Find(map[string]interface{}{
|
|
|
"companyId": companyId,
|
|
|
"orgId": orgId,
|
|
|
"offsetLimit": false,
|
|
|
}); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
for _, cooperationProjectFound := range cooperationProjectsFound {
|
|
|
cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound
|
|
|
}
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "产品未关联合约,不能进行分红预算",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var cooperationContract *domain.CooperationContract
|
|
|
|
|
|
// 获取合约
|
|
|
if _, ok := cooperationContractsMap[orderGood.CooperationContractNumber]; !ok {
|
|
|
var orderNumber string
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderNumber = orderGood.DividendsOrderNumber
|
|
|
} else {
|
|
|
orderNumber = orderGood.DividendsReturnedOrderNumber
|
|
|
}
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "共创合约" + orderGood.CooperationContractNumber + "不存在",
|
|
|
// 确认业绩分红预算
|
|
|
var dividendsEstimateDetails []*service.DividendsEstimateDetail
|
|
|
go func() {
|
|
|
for _, orderGood := range orderGoods {
|
|
|
log.Logger.Info("业绩分红预算产品", map[string]interface{}{
|
|
|
"orderGood": orderGood,
|
|
|
})
|
|
|
continue
|
|
|
} else {
|
|
|
cooperationContract = cooperationContractsMap[orderGood.CooperationContractNumber]
|
|
|
}
|
|
|
|
|
|
//cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
|
|
|
// "cooperationContractNumber": orderGood.CooperationContractNumber,
|
|
|
// "companyId": orderGood.CompanyId,
|
|
|
// "orgId": orderGood.OrgId,
|
|
|
//})
|
|
|
//if err != nil {
|
|
|
// var orderNumber string
|
|
|
// if orderGood.DividendsOrderNumber != "" {
|
|
|
// orderNumber = orderGood.DividendsOrderNumber
|
|
|
// } else {
|
|
|
// orderNumber = orderGood.DividendsReturnedOrderNumber
|
|
|
// }
|
|
|
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
// DividendsUser: nil,
|
|
|
// DividendsParticipateType: 0,
|
|
|
// DividendsStage: 0,
|
|
|
// DividendsAmount: 0,
|
|
|
// OrderOrReturnedOrderNumber: orderNumber,
|
|
|
// IsSuccessfully: false,
|
|
|
// Reason: "共创合约错误",
|
|
|
// })
|
|
|
// continue
|
|
|
//}
|
|
|
if cooperationContract == nil {
|
|
|
var orderNumber string
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderNumber = orderGood.DividendsOrderNumber
|
|
|
} else {
|
|
|
orderNumber = orderGood.DividendsReturnedOrderNumber
|
|
|
}
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "共创合约" + orderGood.CooperationContractNumber + "不存在",
|
|
|
})
|
|
|
continue
|
|
|
} else {
|
|
|
log.Logger.Info("产品相关的合约", map[string]interface{}{
|
|
|
"cooperationContract": cooperationContract,
|
|
|
})
|
|
|
if cooperationContract.Status == 2 {
|
|
|
if orderGood.CooperationContractNumber == "" {
|
|
|
var orderNumber string
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderNumber = orderGood.DividendsOrderNumber
|
...
|
...
|
@@ -175,20 +105,14 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "共创合约" + orderGood.CooperationContractNumber + "已暂停",
|
|
|
Reason: "产品未关联合约,不能进行分红预算",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取共创项目
|
|
|
if cooperationContract.CooperationProjectNumber != "" {
|
|
|
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
|
|
|
"cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
|
|
|
"companyId": cooperationContract.Company.CompanyId,
|
|
|
"orgId": cooperationContract.Org.OrgId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
// 获取合约
|
|
|
var cooperationContract *domain.CooperationContract
|
|
|
if _, ok := cooperationContractsMap[orderGood.CooperationContractNumber]; !ok {
|
|
|
var orderNumber string
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderNumber = orderGood.DividendsOrderNumber
|
...
|
...
|
@@ -202,11 +126,142 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "共创项目" + cooperationContract.CooperationProjectNumber + "查询错误",
|
|
|
Reason: "共创合约" + orderGood.CooperationContractNumber + "不存在",
|
|
|
})
|
|
|
continue
|
|
|
} else {
|
|
|
cooperationContract = cooperationContractsMap[orderGood.CooperationContractNumber]
|
|
|
if cooperationContract.Status == 2 {
|
|
|
var orderNumber string
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderNumber = orderGood.DividendsOrderNumber
|
|
|
} else {
|
|
|
orderNumber = orderGood.DividendsReturnedOrderNumber
|
|
|
}
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "共创合约" + orderGood.CooperationContractNumber + "已暂停",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
if cooperationProject == nil {
|
|
|
|
|
|
//cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
|
|
|
// "cooperationContractNumber": orderGood.CooperationContractNumber,
|
|
|
// "companyId": orderGood.CompanyId,
|
|
|
// "orgId": orderGood.OrgId,
|
|
|
//})
|
|
|
//if err != nil {
|
|
|
// var orderNumber string
|
|
|
// if orderGood.DividendsOrderNumber != "" {
|
|
|
// orderNumber = orderGood.DividendsOrderNumber
|
|
|
// } else {
|
|
|
// orderNumber = orderGood.DividendsReturnedOrderNumber
|
|
|
// }
|
|
|
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
// DividendsUser: nil,
|
|
|
// DividendsParticipateType: 0,
|
|
|
// DividendsStage: 0,
|
|
|
// DividendsAmount: 0,
|
|
|
// OrderOrReturnedOrderNumber: orderNumber,
|
|
|
// IsSuccessfully: false,
|
|
|
// Reason: "共创合约错误",
|
|
|
// })
|
|
|
// continue
|
|
|
//}
|
|
|
//if cooperationContract == nil {
|
|
|
// var orderNumber string
|
|
|
// if orderGood.DividendsOrderNumber != "" {
|
|
|
// orderNumber = orderGood.DividendsOrderNumber
|
|
|
// } else {
|
|
|
// orderNumber = orderGood.DividendsReturnedOrderNumber
|
|
|
// }
|
|
|
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
// DividendsUser: nil,
|
|
|
// DividendsParticipateType: 0,
|
|
|
// DividendsStage: 0,
|
|
|
// DividendsAmount: 0,
|
|
|
// OrderOrReturnedOrderNumber: orderNumber,
|
|
|
// IsSuccessfully: false,
|
|
|
// Reason: "共创合约" + orderGood.CooperationContractNumber + "不存在",
|
|
|
// })
|
|
|
// continue
|
|
|
//} else {
|
|
|
// log.Logger.Info("产品相关的合约", map[string]interface{}{
|
|
|
// "cooperationContract": cooperationContract,
|
|
|
// })
|
|
|
// if cooperationContract.Status == 2 {
|
|
|
// var orderNumber string
|
|
|
// if orderGood.DividendsOrderNumber != "" {
|
|
|
// orderNumber = orderGood.DividendsOrderNumber
|
|
|
// } else {
|
|
|
// orderNumber = orderGood.DividendsReturnedOrderNumber
|
|
|
// }
|
|
|
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
// DividendsUser: nil,
|
|
|
// DividendsParticipateType: 0,
|
|
|
// DividendsStage: 0,
|
|
|
// DividendsAmount: 0,
|
|
|
// OrderOrReturnedOrderNumber: orderNumber,
|
|
|
// IsSuccessfully: false,
|
|
|
// Reason: "共创合约" + orderGood.CooperationContractNumber + "已暂停",
|
|
|
// })
|
|
|
// continue
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
// 获取共创项目
|
|
|
//if cooperationContract.CooperationProjectNumber != "" {
|
|
|
// cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
|
|
|
// "cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
|
|
|
// "companyId": cooperationContract.Company.CompanyId,
|
|
|
// "orgId": cooperationContract.Org.OrgId,
|
|
|
// })
|
|
|
// if err != nil {
|
|
|
// var orderNumber string
|
|
|
// if orderGood.DividendsOrderNumber != "" {
|
|
|
// orderNumber = orderGood.DividendsOrderNumber
|
|
|
// } else {
|
|
|
// orderNumber = orderGood.DividendsReturnedOrderNumber
|
|
|
// }
|
|
|
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
// DividendsUser: nil,
|
|
|
// DividendsParticipateType: 0,
|
|
|
// DividendsStage: 0,
|
|
|
// DividendsAmount: 0,
|
|
|
// OrderOrReturnedOrderNumber: orderNumber,
|
|
|
// IsSuccessfully: false,
|
|
|
// Reason: "共创项目" + cooperationContract.CooperationProjectNumber + "查询错误",
|
|
|
// })
|
|
|
// continue
|
|
|
// }
|
|
|
// if cooperationProject == nil {
|
|
|
// var orderNumber string
|
|
|
// if orderGood.DividendsOrderNumber != "" {
|
|
|
// orderNumber = orderGood.DividendsOrderNumber
|
|
|
// } else {
|
|
|
// orderNumber = orderGood.DividendsReturnedOrderNumber
|
|
|
// }
|
|
|
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
// DividendsUser: nil,
|
|
|
// DividendsParticipateType: 0,
|
|
|
// DividendsStage: 0,
|
|
|
// DividendsAmount: 0,
|
|
|
// OrderOrReturnedOrderNumber: orderNumber,
|
|
|
// IsSuccessfully: false,
|
|
|
// Reason: "共创项目" + cooperationContract.CooperationProjectNumber + "已结束或不存在",
|
|
|
// })
|
|
|
// continue
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
// 判断共创项目是否存在
|
|
|
if _, ok := cooperationProjectsMap[cooperationContract.CooperationProjectNumber]; !ok {
|
|
|
var orderNumber string
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderNumber = orderGood.DividendsOrderNumber
|
...
|
...
|
@@ -224,66 +279,191 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if orderGood.DividendsOrderNumber != "" { // 获取分红订单
|
|
|
// 获取分红订单
|
|
|
dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
|
|
|
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
|
|
|
"companyId": orderGood.CompanyId,
|
|
|
"orgId": orderGood.OrgId,
|
|
|
})
|
|
|
if err2 != nil {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "分红订单" + orderGood.DividendsOrderNumber + "查询错误",
|
|
|
if orderGood.DividendsOrderNumber != "" { // 获取分红订单
|
|
|
// 获取分红订单
|
|
|
dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
|
|
|
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
|
|
|
"companyId": orderGood.CompanyId,
|
|
|
"orgId": orderGood.OrgId,
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
if dividendsOrder == nil {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "分红订单" + orderGood.DividendsOrderNumber + "不存在",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
if err2 != nil {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "分红订单" + orderGood.DividendsOrderNumber + "查询错误",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
if dividendsOrder == nil {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "分红订单" + orderGood.DividendsOrderNumber + "不存在",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
// 匹配分红规则
|
|
|
var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
|
|
|
for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
|
|
|
if (dividendsOrder.OrderTime.After(dividendsIncentivesRule.DividendsIncentivesStageStart) || dividendsOrder.OrderTime.Equal(dividendsIncentivesRule.DividendsIncentivesStageStart)) &&
|
|
|
(dividendsOrder.OrderTime.Before(dividendsIncentivesRule.DividendsIncentivesStageEnd) || dividendsOrder.OrderTime.Equal(dividendsIncentivesRule.DividendsIncentivesStageEnd)) {
|
|
|
dividendsIncentivesRuleMatched = dividendsIncentivesRule
|
|
|
break
|
|
|
// 匹配分红规则
|
|
|
var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
|
|
|
for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
|
|
|
if (dividendsOrder.OrderTime.After(dividendsIncentivesRule.DividendsIncentivesStageStart) || dividendsOrder.OrderTime.Equal(dividendsIncentivesRule.DividendsIncentivesStageStart)) &&
|
|
|
(dividendsOrder.OrderTime.Before(dividendsIncentivesRule.DividendsIncentivesStageEnd) || dividendsOrder.OrderTime.Equal(dividendsIncentivesRule.DividendsIncentivesStageEnd)) {
|
|
|
dividendsIncentivesRuleMatched = dividendsIncentivesRule
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if dividendsIncentivesRuleMatched == nil {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "未匹配到分红规则",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
if dividendsIncentivesRuleMatched == nil {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "未匹配到分红规则",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
// 计算分红
|
|
|
if dividendsIncentivesRuleMatched != nil {
|
|
|
// 计算分红
|
|
|
if dividendsIncentivesRuleMatched != nil {
|
|
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
|
// 添加承接人分红预算信息详情
|
|
|
if dividendsIncentivesRuleMatched.DividendsIncentivesPercentage > 0 {
|
|
|
undertakerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.DividendsIncentivesPercentage).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.UserInfo.UserName,
|
|
|
UserPhone: undertaker.UserPhone,
|
|
|
Status: undertaker.Status,
|
|
|
Company: undertaker.Company,
|
|
|
},
|
|
|
DividendsParticipateType: domain.UNDERTAKER,
|
|
|
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
|
|
|
DividendsAmount: undertakerDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
IsSuccessfully: true,
|
|
|
CooperationContractUndertakerId: undertaker.UndertakerId,
|
|
|
DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage,
|
|
|
})
|
|
|
}
|
|
|
// 添加推荐人分红预算信息详情
|
|
|
if undertaker.Referrer != nil {
|
|
|
if dividendsIncentivesRuleMatched.ReferrerPercentage > 0 {
|
|
|
referrerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.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.REFERRER,
|
|
|
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
|
|
|
DividendsAmount: referrerDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
IsSuccessfully: true,
|
|
|
CooperationContractUndertakerId: undertaker.UndertakerId,
|
|
|
DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
// 添加关联业务员分红预算信息详情
|
|
|
if undertaker.Salesman != nil {
|
|
|
if dividendsIncentivesRuleMatched.SalesmanPercentage > 0 {
|
|
|
salesmanDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.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.UserInfo.UserName,
|
|
|
UserPhone: undertaker.Salesman.UserPhone,
|
|
|
Company: undertaker.Salesman.Company,
|
|
|
},
|
|
|
DividendsParticipateType: domain.SALESMAN,
|
|
|
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
|
|
|
DividendsAmount: salesmanDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
IsSuccessfully: true,
|
|
|
CooperationContractUndertakerId: undertaker.UndertakerId,
|
|
|
DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else if orderGood.DividendsReturnedOrderNumber != "" { // 获取退货单
|
|
|
dividendsReturnedOrder, err3 := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
|
|
|
"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber,
|
|
|
"companyId": orderGood.CompanyId,
|
|
|
"orgId": orderGood.OrgId,
|
|
|
})
|
|
|
if err3 != nil {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "退货单" + orderGood.DividendsReturnedOrderNumber + "不存在",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
if dividendsReturnedOrder == nil {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "退货单" + orderGood.DividendsReturnedOrderNumber + "不存在",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
// 匹配分红规则
|
|
|
var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
|
|
|
for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
|
|
|
if (dividendsReturnedOrder.OrderTime.After(dividendsIncentivesRule.DividendsIncentivesStageStart) || dividendsReturnedOrder.OrderTime.Equal(dividendsIncentivesRule.DividendsIncentivesStageStart)) &&
|
|
|
(dividendsReturnedOrder.OrderTime.Before(dividendsIncentivesRule.DividendsIncentivesStageEnd) || dividendsReturnedOrder.OrderTime.Equal(dividendsIncentivesRule.DividendsIncentivesStageEnd)) {
|
|
|
dividendsIncentivesRuleMatched = dividendsIncentivesRule
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
// 计算分红
|
|
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
|
// 添加承接人分红预算信息详情
|
|
|
// 添加承接人分红退货预算信息详情
|
|
|
if dividendsIncentivesRuleMatched.DividendsIncentivesPercentage > 0 {
|
|
|
undertakerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.DividendsIncentivesPercentage).Div(decimal.NewFromFloat(100))).Float64()
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
...
|
...
|
@@ -303,14 +483,15 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
},
|
|
|
DividendsParticipateType: domain.UNDERTAKER,
|
|
|
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
|
|
|
DividendsAmount: undertakerDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
DividendsAmount: -undertakerDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: true,
|
|
|
CooperationContractUndertakerId: undertaker.UndertakerId,
|
|
|
DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage,
|
|
|
})
|
|
|
}
|
|
|
// 添加推荐人分红预算信息详情
|
|
|
|
|
|
// 添加推荐人分红退货预算信息详情
|
|
|
if undertaker.Referrer != nil {
|
|
|
if dividendsIncentivesRuleMatched.ReferrerPercentage > 0 {
|
|
|
referrerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64()
|
...
|
...
|
@@ -330,15 +511,16 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
},
|
|
|
DividendsParticipateType: domain.REFERRER,
|
|
|
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
|
|
|
DividendsAmount: referrerDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
DividendsAmount: -referrerDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: true,
|
|
|
CooperationContractUndertakerId: undertaker.UndertakerId,
|
|
|
DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
// 添加关联业务员分红预算信息详情
|
|
|
|
|
|
// 添加关联业务员分红退货预算信息详情
|
|
|
if undertaker.Salesman != nil {
|
|
|
if dividendsIncentivesRuleMatched.SalesmanPercentage > 0 {
|
|
|
salesmanDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64()
|
...
|
...
|
@@ -358,8 +540,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
},
|
|
|
DividendsParticipateType: domain.SALESMAN,
|
|
|
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
|
|
|
DividendsAmount: salesmanDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
DividendsAmount: -salesmanDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: true,
|
|
|
CooperationContractUndertakerId: undertaker.UndertakerId,
|
|
|
DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage,
|
...
|
...
|
@@ -368,135 +550,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else if orderGood.DividendsReturnedOrderNumber != "" { // 获取退货单
|
|
|
dividendsReturnedOrder, err3 := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
|
|
|
"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber,
|
|
|
"companyId": orderGood.CompanyId,
|
|
|
"orgId": orderGood.OrgId,
|
|
|
})
|
|
|
if err3 != nil {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "退货单" + orderGood.DividendsReturnedOrderNumber + "不存在",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
if dividendsReturnedOrder == nil {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "退货单" + orderGood.DividendsReturnedOrderNumber + "不存在",
|
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
// 匹配分红规则
|
|
|
var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
|
|
|
for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
|
|
|
if (dividendsReturnedOrder.OrderTime.After(dividendsIncentivesRule.DividendsIncentivesStageStart) || dividendsReturnedOrder.OrderTime.Equal(dividendsIncentivesRule.DividendsIncentivesStageStart)) &&
|
|
|
(dividendsReturnedOrder.OrderTime.Before(dividendsIncentivesRule.DividendsIncentivesStageEnd) || dividendsReturnedOrder.OrderTime.Equal(dividendsIncentivesRule.DividendsIncentivesStageEnd)) {
|
|
|
dividendsIncentivesRuleMatched = dividendsIncentivesRule
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
// 计算分红
|
|
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
|
// 添加承接人分红退货预算信息详情
|
|
|
if dividendsIncentivesRuleMatched.DividendsIncentivesPercentage > 0 {
|
|
|
undertakerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.DividendsIncentivesPercentage).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.UserInfo.UserName,
|
|
|
UserPhone: undertaker.UserPhone,
|
|
|
Status: undertaker.Status,
|
|
|
Company: undertaker.Company,
|
|
|
},
|
|
|
DividendsParticipateType: domain.UNDERTAKER,
|
|
|
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
|
|
|
DividendsAmount: -undertakerDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: true,
|
|
|
CooperationContractUndertakerId: undertaker.UndertakerId,
|
|
|
DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 添加推荐人分红退货预算信息详情
|
|
|
if undertaker.Referrer != nil {
|
|
|
if dividendsIncentivesRuleMatched.ReferrerPercentage > 0 {
|
|
|
referrerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.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.REFERRER,
|
|
|
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
|
|
|
DividendsAmount: -referrerDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: true,
|
|
|
CooperationContractUndertakerId: undertaker.UndertakerId,
|
|
|
DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 添加关联业务员分红退货预算信息详情
|
|
|
if undertaker.Salesman != nil {
|
|
|
if dividendsIncentivesRuleMatched.SalesmanPercentage > 0 {
|
|
|
salesmanDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.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.UserInfo.UserName,
|
|
|
UserPhone: undertaker.Salesman.UserPhone,
|
|
|
Company: undertaker.Salesman.Company,
|
|
|
},
|
|
|
DividendsParticipateType: domain.SALESMAN,
|
|
|
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
|
|
|
DividendsAmount: -salesmanDividendsAmount,
|
|
|
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: true,
|
|
|
CooperationContractUndertakerId: undertaker.UndertakerId,
|
|
|
DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
return dividendsEstimateDetails, nil
|
|
|
}
|
|
|
|
...
|
...
|
|