...
|
...
|
@@ -8,7 +8,6 @@ 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/repository"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
|
|
|
)
|
|
|
|
|
|
type ConfirmDividendsIncentivesEstimateService struct {
|
...
|
...
|
@@ -17,26 +16,10 @@ type ConfirmDividendsIncentivesEstimateService struct { |
|
|
}
|
|
|
|
|
|
// Confirm 确认业绩分红预算
|
|
|
func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64) ([]*service.DividendsEstimateDetail, error) {
|
|
|
var cooperationContractRepository domain.CooperationContractRepository // 共创合约仓储
|
|
|
var cooperationProjectRepository domain.CooperationProjectRepository // 共创项目仓储
|
|
|
func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64, cooperationContractsMap map[string]*domain.CooperationContract, cooperationProjectsMap map[string]*domain.CooperationProject) ([]*service.DividendsEstimateDetail, error) {
|
|
|
var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储
|
|
|
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
|
|
|
|
|
|
// 共创合约仓储初始化
|
|
|
if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
cooperationContractRepository = repo
|
|
|
}
|
|
|
|
|
|
// 共创项目仓储初始化
|
|
|
if repo, err := repository.NewCooperationProjectRepository(domainService.transactionContext); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
cooperationProjectRepository = repo
|
|
|
}
|
|
|
|
|
|
// 分红订单仓储初始化
|
|
|
if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -51,29 +34,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
dividendsReturnedOrderRepository = repo
|
|
|
}
|
|
|
|
|
|
// 查询共创合约
|
|
|
cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
|
|
|
if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
"companyId": companyId,
|
|
|
"orgId": orgId,
|
|
|
"offsetLimit": false,
|
|
|
}); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
for _, cooperationContractFound := range cooperationContractsFound {
|
|
|
cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 确认业绩分红预算
|
|
|
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 != "" {
|
...
|
...
|
@@ -93,9 +56,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
continue
|
|
|
}
|
|
|
|
|
|
var cooperationContract *domain.CooperationContract
|
|
|
|
|
|
// 获取合约
|
|
|
var cooperationContract *domain.CooperationContract
|
|
|
if _, ok := cooperationContractsMap[orderGood.CooperationContractNumber]; !ok {
|
|
|
var orderNumber string
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
...
|
...
|
@@ -115,52 +77,6 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
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 {
|
|
|
var orderNumber string
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
...
|
...
|
@@ -181,32 +97,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取共创项目
|
|
|
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 {
|
|
|
// 判断共创项目是否存在
|
|
|
if _, ok := cooperationProjectsMap[cooperationContract.CooperationProjectNumber]; !ok {
|
|
|
var orderNumber string
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderNumber = orderGood.DividendsOrderNumber
|
...
|
...
|
@@ -224,7 +116,6 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
})
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if orderGood.DividendsOrderNumber != "" { // 获取分红订单
|
|
|
// 获取分红订单
|
...
|
...
|
@@ -408,6 +299,18 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
}
|
|
|
}
|
|
|
// 计算分红
|
|
|
if len(cooperationContract.Undertakers) <= 0 {
|
|
|
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
|
|
|
DividendsUser: nil,
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsStage: 0,
|
|
|
DividendsAmount: 0,
|
|
|
OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
|
|
|
IsSuccessfully: false,
|
|
|
Reason: "合约承接人不存在",
|
|
|
})
|
|
|
continue
|
|
|
} else {
|
|
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
|
// 添加承接人分红退货预算信息详情
|
|
|
if dividendsIncentivesRuleMatched.DividendsIncentivesPercentage > 0 {
|
...
|
...
|
@@ -497,6 +400,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return dividendsEstimateDetails, nil
|
|
|
}
|
|
|
|
...
|
...
|
|