作者 陈志颖

fix:取消预算,订单分红状态错误

... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
)
type CancelDividendsEstimateService struct {
... ... @@ -21,6 +22,12 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
var orderGoodRepository domain.OrderGoodRepository // 订单产品仓储
type orderGoodInfo struct {
OrderGoodId int64
CompanyId int64
OrgId int64
}
// 分红预算单仓储初始化
if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
return nil, err
... ... @@ -60,6 +67,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
var dividendsEstimatesCanceled []*domain.DividendsEstimate
var orderOrReturnOrderNums []string
var orderGoodIds []int64
orderGoodMaps := make(map[string][]int64, 0)
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
// 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
... ... @@ -83,6 +91,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
// 获取相关订单/退货单号
orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId)
orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum] = append(orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum], dividendsEstimatesRelative[i].OrderGoodId)
}
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
if err3 != nil {
... ... @@ -151,18 +160,20 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
}); err4 != nil {
return nil, err4
} else {
// orderGoodIds去重
newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)
if countDividendsOrder > 0 {
for i, order := range orders {
// 取消分红的订单产品
newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodMaps[order.DividendsOrderNumber])
var goodIds []int64
for _, good := range order.Goods {
if good.OrderGoodDividendsStatus == 2 {
goodIds = append(goodIds, good.OrderGoodId)
}
}
// goodIds去重
// goodIds去重
newGoodIds := utils.RemoveDuplicationInt64(goodIds)
log.Logger.Info("")
if len(newGoodIds) == len(newOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,订单分红状态变更为未分红
orders[i].DividendStatus = 1
} else if len(newGoodIds) > len(newOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,订单分红状态变更为部分分红
... ... @@ -216,21 +227,21 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
}); err5 != nil {
return nil, err5
} else {
// orderGoodIds去重
newReturnedOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)
if countDividendsReturnedOrder > 0 {
for i, returnedOrder := range returnedOrders {
goods := make([]*domain.OrderGood, 0)
// 已取消的退货单产品
newReturnedOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodMaps[returnedOrder.DividendsOrderNumber])
var goodIds []int64
for _, good := range returnedOrder.Goods {
if good.OrderGoodDividendsStatus == 2 {
goods = append(goods, good)
goodIds = append(goodIds, good.OrderGoodId)
}
}
if len(goods) == len(newReturnedOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,退货单分红状态变更为未分红
// goodIds去重
newGoodIds := utils.RemoveDuplicationInt64(goodIds)
if len(newGoodIds) == len(newReturnedOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,退货单分红状态变更为未分红
returnedOrders[i].DividendStatus = 1
} else if len(goods) > len(newReturnedOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,退货单分红状态变更为部分分红
} else if len(newGoodIds) > len(newReturnedOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,退货单分红状态变更为部分分红
returnedOrders[i].DividendStatus = 3
}
returnedOrders[i].DividendStatus = returnedOrder.DividendStatus
... ...