...
|
...
|
@@ -546,25 +546,25 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
operator = data
|
|
|
}
|
|
|
|
|
|
// 分红订单仓储初始化
|
|
|
var dividendsOrderRepository domain.DividendsOrderRepository
|
|
|
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsOrderRepository = value
|
|
|
}
|
|
|
//// 分红订单仓储初始化
|
|
|
//var dividendsOrderRepository domain.DividendsOrderRepository
|
|
|
//if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
//}); err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//} else {
|
|
|
// dividendsOrderRepository = value
|
|
|
//}
|
|
|
|
|
|
// 分红退货单仓储初始化
|
|
|
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
|
|
|
if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsReturnedOrderRepository = value
|
|
|
}
|
|
|
//var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
|
|
|
//if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
//}); err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//} else {
|
|
|
// dividendsReturnedOrderRepository = value
|
|
|
//}
|
|
|
|
|
|
// 订单产品仓储初始化
|
|
|
var orderGoodRepository domain.OrderGoodRepository
|
...
|
...
|
@@ -610,10 +610,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
|
|
|
// 统计成功预算的分红订单
|
|
|
var estimateSuccessfullyDividendsOrders map[string]int
|
|
|
estimateSuccessfullyDividendsOrders := make(map[string]string)
|
|
|
|
|
|
// 统计预算失败的分红订单
|
|
|
var estimateFailedDividendsOrders map[string]int
|
|
|
estimateFailedDividendsOrders := make(map[string]string)
|
|
|
|
|
|
// 获取订单产品
|
|
|
if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
|
...
|
...
|
@@ -621,7 +621,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
var dividendsEstimates []*domain.DividendsEstimate
|
|
|
dividendsEstimates := make([]*domain.DividendsEstimate, 0)
|
|
|
// 统计当前分红预算单数
|
|
|
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
|
|
|
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
|
...
|
...
|
@@ -633,102 +633,116 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
for _, orderGood := range orderGoods {
|
|
|
dividendsEstimate := &domain.DividendsEstimate{}
|
|
|
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
|
|
|
dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
|
|
|
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
|
|
|
"companyId": orderGood.CompanyId,
|
|
|
"orgId": orderGood.OrgId,
|
|
|
})
|
|
|
if err3 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
|
|
|
}
|
|
|
if dividendsOrder == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
|
|
|
}
|
|
|
//dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
|
|
|
// "dividendsOrderNumber": orderGood.DividendsOrderNumber,
|
|
|
// "companyId": orderGood.CompanyId,
|
|
|
// "orgId": orderGood.OrgId,
|
|
|
//})
|
|
|
//if err3 != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
|
|
|
//}
|
|
|
//if dividendsOrder == nil {
|
|
|
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
|
|
|
//}
|
|
|
// 分红订单产品预算
|
|
|
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
|
|
|
// 生成分红预算单号
|
|
|
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
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,
|
|
|
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,
|
|
|
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,
|
|
|
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,
|
|
|
}
|
|
|
|
|
|
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
} else {
|
|
|
// 记录失败的订单号和原因s
|
|
|
estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
|
|
|
}
|
|
|
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
}
|
|
|
}
|
|
|
} else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
|
|
|
dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsReturnedOrder == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红退货单%s不存在", orderGood.DividendsReturnedOrderNumber))
|
|
|
}
|
|
|
// 分红退货单产品预算
|
|
|
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
|
|
|
// 生成分红预算单号
|
|
|
dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
countDividendsEstimate = countDividendsEstimate + 1
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
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,
|
|
|
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,
|
|
|
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,
|
|
|
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,
|
|
|
}
|
|
|
|
|
|
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
} else {
|
|
|
// 记录失败的退货单号和原因
|
|
|
estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
|
|
|
}
|
|
|
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -744,8 +758,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
// 分析成功和失败原因
|
|
|
successfullyCount := len(dividendsEstimatesSaved)
|
|
|
// 错误原因收集,返回第一个可能的原因
|
|
|
var failedReason []string
|
|
|
for _, v := range estimateFailedDividendsOrders {
|
|
|
failedReason = append(failedReason, v)
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"report": fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), ""),
|
|
|
"report": fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReason[0]),
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -842,11 +861,20 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives |
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
|
|
|
cooperationContractId, _ := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)
|
|
|
undertakerUIDs, _ := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids)
|
|
|
cooperationContractId, err := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "合约编号类型错误:"+err.Error())
|
|
|
}
|
|
|
|
|
|
undertakerUIDs, err := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "承接人UID类型错误:"+err.Error())
|
|
|
}
|
|
|
|
|
|
// 获取共创合约
|
|
|
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": cooperationContractId})
|
|
|
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
|
|
|
"cooperationContractId": cooperationContractId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -860,7 +888,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives |
|
|
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
|
|
|
"companyId": confirmMoneyIncentivesEstimateCommand.CompanyId,
|
|
|
})
|
|
|
|
|
|
// 分红预算单统计
|
|
|
var countDividendsEstimate int64
|
|
|
|
|
|
// 共创合约预算
|
|
|
if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
|
...
|
...
|
@@ -871,7 +902,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 统计生成的预算单数目
|
|
|
countDividendsEstimate = countDividendsEstimate + 1
|
|
|
|
|
|
dividendsEstimate := &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
...
|
...
|
@@ -894,6 +928,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives |
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
|
|
|
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
}
|
|
|
dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates)
|
...
|
...
|
|