作者 陈志颖

fix:取消分红预算后订单状态更新错误

@@ -255,11 +255,20 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -255,11 +255,20 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
255 }); err4 != nil { 255 }); err4 != nil {
256 return nil, err4 256 return nil, err4
257 } else { 257 } else {
  258 + // orderGoodIds去重
  259 + newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)
  260 +
258 if countDividendsOrder > 0 { 261 if countDividendsOrder > 0 {
259 for i, order := range orders { 262 for i, order := range orders {
260 - if len(order.Goods) == len(orderGoodIds) { // 1.全部产品取消分红预算 263 + goods := make([]*domain.OrderGood, 0)
  264 + for _, good := range order.Goods {
  265 + if good.OrderGoodDividendsStatus == 2 {
  266 + goods = append(goods, good)
  267 + }
  268 + }
  269 + if len(goods) == len(newOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,订单分红状态变更为未分红
261 orders[i].DividendStatus = 1 270 orders[i].DividendStatus = 1
262 - } else if len(order.Goods) > len(orderGoodIds) { // 3.部分产品被取消分红预算 271 + } else if len(goods) > len(newOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,订单分红状态变更为部分分红
263 orders[i].DividendStatus = 3 272 orders[i].DividendStatus = 3
264 } 273 }
265 orders[i].DividendStatus = order.DividendStatus 274 orders[i].DividendStatus = order.DividendStatus
@@ -126,6 +126,21 @@ func RemoveDuplication(arr []string) []string { @@ -126,6 +126,21 @@ func RemoveDuplication(arr []string) []string {
126 return arr[:j] 126 return arr[:j]
127 } 127 }
128 128
  129 +func RemoveDuplicationInt64(arr []int64) []int64 {
  130 + set := make(map[int64]struct{}, len(arr))
  131 + j := 0
  132 + for _, v := range arr {
  133 + _, ok := set[v]
  134 + if ok {
  135 + continue
  136 + }
  137 + set[v] = struct{}{}
  138 + arr[j] = v
  139 + j++
  140 + }
  141 + return arr[:j]
  142 +}
  143 +
129 // IsContain 判断int32数组是否包含 144 // IsContain 判断int32数组是否包含
130 func IsContain(items []int32, item int32) bool { 145 func IsContain(items []int32, item int32) bool {
131 for _, eachItem := range items { 146 for _, eachItem := range items {