...
|
...
|
@@ -784,7 +784,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
orderGoodSavedIds = append(orderGoodSavedIds, dividendsEstimate.OrderGoodId)
|
|
|
}
|
|
|
|
|
|
// 获取订单产品
|
|
|
// 更新订单产品分红状态
|
|
|
var orderGoodsSaved []*domain.OrderGood
|
|
|
if len(orderGoodSavedIds) > 0 {
|
|
|
if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
"orderGoodIds": orderGoodSavedIds,
|
...
|
...
|
@@ -795,6 +796,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
for i, _ := range orderGoodsFound {
|
|
|
orderGoodsFound[i].OrderGoodDividendsStatus = int32(2) // 已分红
|
|
|
}
|
|
|
orderGoodsSaved = orderGoodsFound
|
|
|
if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
|
|
|
}
|
...
|
...
|
@@ -834,12 +836,21 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
} else {
|
|
|
if countDividendsOrdersFound > 0 {
|
|
|
for i, dividendsOrderFound := range dividendsOrdersFound {
|
|
|
for i, _ := range dividendsOrderFound.Goods {
|
|
|
for _, good := range orderGoodsSaved {
|
|
|
if dividendsOrderFound.Goods[i].OrderGoodId == good.OrderGoodId {
|
|
|
dividendsOrderFound.Goods[i].OrderGoodDividendsStatus = good.OrderGoodDividendsStatus
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var dividendsGoodCount int
|
|
|
for _, orderGood := range dividendsOrderFound.Goods {
|
|
|
if orderGood.OrderGoodDividendsStatus == 2 {
|
|
|
dividendsGoodCount = dividendsGoodCount + 1
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if dividendsGoodCount == len(dividendsOrderFound.Goods) { // 2已分红
|
|
|
dividendsOrdersFound[i].DividendStatus = 2
|
|
|
} else if dividendsGoodCount > 0 && dividendsGoodCount < len(dividendsOrderFound.Goods) { // 3部分分红
|
...
|
...
|
@@ -848,6 +859,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
dividendsOrdersFound[i].DividendStatus = 1
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 保存订单状态
|
|
|
if _, err6 := dividendsOrderRepository.UpdateMany(dividendsOrdersFound); err6 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -867,6 +879,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
} else {
|
|
|
if countDividendsReturnedOrdersFound > 0 {
|
|
|
for i, dividendsReturnedOrderFound := range dividendsReturnedOrdersFound {
|
|
|
for i, _ := range dividendsReturnedOrderFound.Goods {
|
|
|
for _, good := range orderGoodsSaved {
|
|
|
if dividendsReturnedOrderFound.Goods[i].OrderGoodId == good.OrderGoodId {
|
|
|
dividendsReturnedOrderFound.Goods[i].OrderGoodDividendsStatus = good.OrderGoodDividendsStatus
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var dividendsGoodCount int
|
|
|
for _, orderGood := range dividendsReturnedOrderFound.Goods {
|
|
|
if orderGood.OrderGoodDividendsStatus == 2 {
|
...
|
...
|
@@ -1307,10 +1327,12 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti |
|
|
"orgId": searchDividendsIncentivesEstimateQuery.OrgId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
log.Logger.Error(err.Error())
|
|
|
continue
|
|
|
//return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsOrder == nil {
|
|
|
log.Logger.Info(fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
|
|
|
continue
|
|
|
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
|
|
|
}
|
...
|
...
|
@@ -1326,10 +1348,12 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti |
|
|
"orgId": searchDividendsIncentivesEstimateQuery.OrgId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
log.Logger.Error(err.Error())
|
|
|
continue
|
|
|
//return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsReturnedOrder == nil {
|
|
|
log.Logger.Info(fmt.Sprintf("分红退货单%s不存在", orderGood.DividendsReturnedOrderNumber))
|
|
|
continue
|
|
|
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
|
|
|
}
|
...
|
...
|
@@ -1401,12 +1425,11 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE |
|
|
stageAndUndertaker := make([]*dto.StageAndUndertaker, 0)
|
|
|
|
|
|
// 初始化阶段承接人map
|
|
|
|
|
|
for _, rule := range cooperationContract.MoneyIncentivesRules {
|
|
|
stageUndertakerMap[rule.MoneyIncentivesStage] = make([]*domain.Undertaker, 0)
|
|
|
}
|
|
|
|
|
|
// TODO 校验当前时间和激励阶段是否匹配
|
|
|
|
|
|
log.Logger.Info("阶段承接人map初始化", map[string]interface{}{
|
|
|
"stageUndertakerMap": stageUndertakerMap,
|
|
|
})
|
...
|
...
|
@@ -1424,6 +1447,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE |
|
|
"orgId": cooperationContract.Org.OrgId,
|
|
|
"dividendsUserId": undertaker.UserId,
|
|
|
"offsetLimit": false,
|
|
|
"dividendsParticipateType": int32(1),
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -1445,7 +1469,20 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE |
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 去除没有承接人的阶段
|
|
|
// 校验当前时间和激励阶段是否匹配
|
|
|
currentTime := time.Now()
|
|
|
for _, rule := range cooperationContract.MoneyIncentivesRules {
|
|
|
if currentTime.Before(rule.MoneyIncentivesTime) {
|
|
|
delete(stageUndertakerMap, rule.MoneyIncentivesStage)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 去除没有承接人的阶段
|
|
|
for k, v := range stageUndertakerMap {
|
|
|
if len(v) == 0 {
|
|
|
delete(stageUndertakerMap, k)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
log.Logger.Info("阶段承接人map", map[string]interface{}{
|
|
|
"stageUndertakerMap": stageUndertakerMap,
|
...
|
...
|
|