...
|
...
|
@@ -649,16 +649,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
cooperationContractRepository = value
|
|
|
}
|
|
|
|
|
|
// 共创项目仓储初始化
|
|
|
//var cooperationProjectRepository domain.CooperationProjectRepository
|
|
|
//if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
//}); err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//} else {
|
|
|
// cooperationProjectRepository = value
|
|
|
//}
|
|
|
|
|
|
// 初始化确认业绩激励分红预算领域服务
|
|
|
var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
|
|
|
if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
|
...
|
...
|
@@ -672,26 +662,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
})
|
|
|
}
|
|
|
|
|
|
// 查询共创项目
|
|
|
//cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)
|
|
|
//if count, cooperationProjectsFound, err := cooperationProjectRepository.Find(map[string]interface{}{
|
|
|
// "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
|
|
|
// "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
|
|
|
// "offsetLimit": false,
|
|
|
//}); err != nil {
|
|
|
// return nil, err
|
|
|
//} else {
|
|
|
// if count > 0 {
|
|
|
// for _, cooperationProjectFound := range cooperationProjectsFound {
|
|
|
// cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
//
|
|
|
//log.Logger.Info("查询共创项目", map[string]interface{}{
|
|
|
// "cooperationProjectsMap": cooperationProjectsMap,
|
|
|
//})
|
|
|
|
|
|
// 统计成功预算的分红订单
|
|
|
estimateSuccessfullyDividendsOrders := make(map[string]string)
|
|
|
|
...
|
...
|
@@ -716,8 +686,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
|
|
|
newCooperationContractNumbers := utils.RemoveDuplicationString(cooperationContractNumbers)
|
|
|
|
|
|
// 查询共创合约
|
|
|
cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
|
|
|
|
|
|
// 查询共创合约
|
|
|
if len(newCooperationContractNumbers) > 0 {
|
|
|
if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
"cooperationContractNumbers": newCooperationContractNumbers,
|
|
|
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
|
...
|
...
|
@@ -732,10 +704,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
log.Logger.Info("查询共创合约", map[string]interface{}{
|
|
|
"cooperationContractsMap": cooperationContractsMap,
|
|
|
})
|
|
|
} else {
|
|
|
return map[string]interface{}{
|
|
|
"report": fmt.Sprintf("已完成0单订单分红预算,生成0单分红预算,失败原因:产品未关联合约"),
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 统计当前企业分红预算单数
|
|
|
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
|
...
|
...
|
@@ -747,18 +720,22 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
|
|
|
var countDividendsEstimate int64
|
|
|
|
|
|
for _, orderGood := range orderGoods {
|
|
|
log.Logger.Info("hello 1")
|
|
|
dividendsEstimate := &domain.DividendsEstimate{}
|
|
|
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
|
|
|
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
returnedOrderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
|
|
|
for _, orderGood := range orderGoods {
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
|
|
// 分红订单产品预算
|
|
|
} else if orderGood.DividendsReturnedOrderNumber != "" {
|
|
|
returnedOrderGoodsToConfirm = append(returnedOrderGoodsToConfirm, orderGood)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if len(orderGoodsToConfirm) > 0 { // 分红订单产品预算
|
|
|
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
|
|
|
log.Logger.Info("hello 2")
|
|
|
if dividendsEstimateDetail.IsSuccessfully {
|
|
|
// 生成分红预算单号
|
|
|
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
...
|
...
|
@@ -772,7 +749,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
// 统计分红预算单数目
|
|
|
countDividendsEstimate = countDividendsEstimate + 1
|
|
|
|
|
|
dividendsEstimate = &domain.DividendsEstimate{
|
|
|
dividendsEstimate := &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
DividendsAmount: dividendsEstimateDetail.DividendsAmount,
|
...
|
...
|
@@ -781,8 +758,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
|
|
|
DividendsType: domain.ORDER_DIVIDENDS,
|
|
|
DividendsTypeName: "订单分红",
|
|
|
OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
|
|
|
CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
OrderOrReturnedOrderNum: dividendsEstimateDetail.OrderOrReturnedOrderNumber,
|
|
|
CooperationContractNumber: dividendsEstimateDetail.CooperationContractNumber,
|
|
|
DividendsUser: dividendsEstimateDetail.DividendsUser,
|
|
|
DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
|
|
|
DividendsStage: dividendsEstimateDetail.DividendsStage,
|
...
|
...
|
@@ -794,8 +771,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
OrderGoodId: orderGood.OrderGoodId,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
OrderGoodId: dividendsEstimateDetail.OrderGoodId,
|
|
|
OrderGoodAmount: dividendsEstimateDetail.OrderGoodAmount,
|
|
|
PaymentStatus: int32(1),
|
|
|
CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
|
|
|
}
|
...
|
...
|
@@ -807,12 +784,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
|
|
|
log.Logger.Info("hello 3")
|
|
|
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
|
|
// 分红退货单产品预算
|
|
|
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
} else if len(returnedOrderGoodsToConfirm) > 0 { // 退货单产品预算
|
|
|
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(returnedOrderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
|
...
|
...
|
@@ -829,7 +802,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
// 统计生成的预算单数量
|
|
|
countDividendsEstimate = countDividendsEstimate + 1
|
|
|
|
|
|
dividendsEstimate = &domain.DividendsEstimate{
|
|
|
dividendsEstimate := &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
|
...
|
...
|
@@ -838,8 +811,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
|
|
|
DividendsType: domain.RETURN_WRITE_OFF,
|
|
|
DividendsTypeName: "退货冲销",
|
|
|
OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
|
|
|
CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
OrderOrReturnedOrderNum: dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber,
|
|
|
CooperationContractNumber: dividendsReturnedEstimateDetail.CooperationContractNumber,
|
|
|
DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
|
|
|
DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
|
|
|
DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
|
...
|
...
|
@@ -851,8 +824,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
OrderGoodId: orderGood.OrderGoodId,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
OrderGoodId: dividendsReturnedEstimateDetail.OrderGoodId,
|
|
|
OrderGoodAmount: dividendsReturnedEstimateDetail.OrderGoodAmount,
|
|
|
PaymentStatus: int32(1),
|
|
|
CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
|
|
|
}
|
...
|
...
|
@@ -865,11 +838,123 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
log.Logger.Info("新增的分红预算单", map[string]interface{}{
|
|
|
"dividendsEstimates": dividendsEstimates,
|
|
|
})
|
|
|
//for _, orderGood := range orderGoods {
|
|
|
// dividendsEstimate := &domain.DividendsEstimate{}
|
|
|
// if orderGood.DividendsOrderNumber != "" { // 查询分红订单
|
|
|
// orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
// orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
|
|
// // 分红订单产品预算
|
|
|
// if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// } else {
|
|
|
// for _, dividendsEstimateDetail := range dividendsEstimateDetails {
|
|
|
// if dividendsEstimateDetail.IsSuccessfully {
|
|
|
// // 生成分红预算单号
|
|
|
// dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
// if err != nil {
|
|
|
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
// }
|
|
|
//
|
|
|
// // 记录成功的订单号
|
|
|
// estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber
|
|
|
//
|
|
|
// // 统计分红预算单数目
|
|
|
// countDividendsEstimate = countDividendsEstimate + 1
|
|
|
//
|
|
|
// dividendsEstimate = &domain.DividendsEstimate{
|
|
|
// DividendsEstimateId: 0,
|
|
|
// DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
// DividendsAmount: dividendsEstimateDetail.DividendsAmount,
|
|
|
// DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
|
|
|
// DividendsEstimateTime: time.Now(),
|
|
|
// DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
|
|
|
// DividendsType: domain.ORDER_DIVIDENDS,
|
|
|
// DividendsTypeName: "订单分红",
|
|
|
// OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
|
|
|
// CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
// DividendsUser: dividendsEstimateDetail.DividendsUser,
|
|
|
// DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
|
|
|
// DividendsStage: dividendsEstimateDetail.DividendsStage,
|
|
|
// Org: organization,
|
|
|
// Company: company,
|
|
|
// Operator: operator,
|
|
|
// OperateTime: time.Time{},
|
|
|
// IsCanceled: false,
|
|
|
// CreatedAt: time.Now(),
|
|
|
// DeletedAt: time.Time{},
|
|
|
// UpdatedAt: time.Time{},
|
|
|
// OrderGoodId: orderGood.OrderGoodId,
|
|
|
// OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
// PaymentStatus: int32(1),
|
|
|
// CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
|
|
|
// }
|
|
|
//
|
|
|
// dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
// } else {
|
|
|
// // 记录失败的订单号和原因
|
|
|
// estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
|
|
|
// orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
// orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
|
|
// // 分红退货单产品预算
|
|
|
// if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// } else {
|
|
|
// for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
|
|
|
// if dividendsReturnedEstimateDetail.IsSuccessfully {
|
|
|
// // 生成分红预算单号
|
|
|
// dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
// if err != nil {
|
|
|
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
// }
|
|
|
//
|
|
|
// // 记录成功的退货单号
|
|
|
// estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber
|
|
|
//
|
|
|
// // 统计生成的预算单数量
|
|
|
// countDividendsEstimate = countDividendsEstimate + 1
|
|
|
//
|
|
|
// dividendsEstimate = &domain.DividendsEstimate{
|
|
|
// DividendsEstimateId: 0,
|
|
|
// DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
// DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
|
|
|
// DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
|
|
|
// DividendsEstimateTime: time.Now(),
|
|
|
// DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
|
|
|
// DividendsType: domain.RETURN_WRITE_OFF,
|
|
|
// DividendsTypeName: "退货冲销",
|
|
|
// OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
|
|
|
// CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
// DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
|
|
|
// DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
|
|
|
// DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
|
|
|
// Org: organization,
|
|
|
// Company: company,
|
|
|
// Operator: operator,
|
|
|
// OperateTime: time.Time{},
|
|
|
// IsCanceled: false,
|
|
|
// CreatedAt: time.Now(),
|
|
|
// DeletedAt: time.Time{},
|
|
|
// UpdatedAt: time.Time{},
|
|
|
// OrderGoodId: orderGood.OrderGoodId,
|
|
|
// OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
// PaymentStatus: int32(1),
|
|
|
// CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
|
|
|
// }
|
|
|
//
|
|
|
// dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
// } else {
|
|
|
// // 记录失败的退货单号和原因
|
|
|
// estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -918,14 +1003,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
|
|
|
log.Logger.Info("分红订单", map[string]interface{}{
|
|
|
"dividendsOrderNumbers": dividendsOrderNumbers,
|
|
|
})
|
|
|
|
|
|
log.Logger.Info("分红退货单", map[string]interface{}{
|
|
|
"dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
|
|
|
})
|
|
|
|
|
|
// 查找分红订单
|
|
|
if len(dividendsOrderNumbers) > 0 {
|
|
|
if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{
|
...
|
...
|
|