作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -30,6 +30,10 @@ type SearchMoneyIncentivesEstimateQuery struct {
PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
// 激励方式
IncentivesType int32 `cname:"激励方式" json:"incentivesType,omitempty"`
// 合约状态,1正常,2暂停
Status int32 `cname:"合约状态" json:"status,omitempty"`
// 查询限制
OffsetLimit bool `json:"offsetLimit,omitempty"`
}
func (searchMoneyIncentivesEstimateQuery *SearchMoneyIncentivesEstimateQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -1380,6 +1380,8 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
// 查找共创合约
searchMoneyIncentivesEstimateQuery.IncentivesType = 2
searchMoneyIncentivesEstimateQuery.Status = 1
searchMoneyIncentivesEstimateQuery.OffsetLimit = false
if count, cooperationContracts, err := cooperationContractRepository.Find(tool_funs.SimpleStructToMap(searchMoneyIncentivesEstimateQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -1387,15 +1389,19 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
for _, cooperationContract := range cooperationContracts {
// 阶段承接人map
stageUndertakerMap := make(map[int32][]*domain.Undertaker)
// 阶段承接人列表
stageAndUndertaker := make([]*dto.StageAndUndertaker, 0)
// 初始化阶段承接人map
for _, rule := range cooperationContract.MoneyIncentivesRules {
stageUndertakerMap[rule.MoneyIncentivesStage] = make([]*domain.Undertaker, 0)
}
log.Logger.Info("阶段承接人map初始化", map[string]interface{}{
"stageUndertakerMap": stageUndertakerMap,
})
// 获取承接人
for _, undertaker := range cooperationContract.Undertakers {
// 查询承接人分红预算单
... ... @@ -1404,6 +1410,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
"companyId": cooperationContract.Company.CompanyId,
"orgId": cooperationContract.Org.OrgId,
"dividendsUserId": undertaker.UserId,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -1413,16 +1420,20 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
stageUndertakerMap[dividendsEstimate.DividendsStage] = append(stageUndertakerMap[dividendsEstimate.DividendsStage], undertaker)
}
}
break
} else if countDividendsEstimates == 0 { // 未分红,可以加入任意阶段进行金额激励
for i, _ := range stageUndertakerMap {
stageUndertakerMap[i] = append(stageUndertakerMap[i], undertaker)
}
break
}
}
}
log.Logger.Info("阶段承接人map", map[string]interface{}{
"stageUndertakerMap": stageUndertakerMap,
})
for k, v := range stageUndertakerMap {
stageAndUndertaker = append(stageAndUndertaker, &dto.StageAndUndertaker{
Stage: k,
... ... @@ -1431,11 +1442,23 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
}
moneyIncentivesEstimateDto := &dto.MoneyIncentivesEstimateDto{}
// 判断当前合约的承接人是否全部分红
allEstimate := true
for i, _ := range stageUndertakerMap {
if len(stageUndertakerMap[i]) > 0 {
allEstimate = false
break
}
}
if !allEstimate {
if err := moneyIncentivesEstimateDto.LoadDto(cooperationContract, stageAndUndertaker); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
moneyIncentivesEstimateDtos = append(moneyIncentivesEstimateDtos, moneyIncentivesEstimateDto)
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...