作者 陈志颖

fix:修复退货单产品新增错误

@@ -356,43 +356,6 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs @@ -356,43 +356,6 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
356 356
357 // 校验是否能够取消 357 // 校验是否能够取消
358 if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红/退货冲销 358 if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红/退货冲销
359 -  
360 - //// 自定义查询  
361 - //queryOptions := make(map[string]interface{})  
362 - //  
363 - ////参与分红类型,1承接人,2推荐人,3关联业务员  
364 - //if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单  
365 - // queryOptions = map[string]interface{}{  
366 - // "companyId": dividendsEstimate.Company.CompanyId,  
367 - // "orgId": dividendsEstimate.Org.OrgId,  
368 - // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
369 - // "dividendsParticipateTypes": []int32{2, 3},  
370 - // "offsetLimit": false,  
371 - // "dividendsStage": dividendsEstimate.DividendsStage,  
372 - // "dividendsTypes": []int32{1, 2},  
373 - // }  
374 - //} else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单  
375 - // queryOptions = map[string]interface{}{  
376 - // "companyId": dividendsEstimate.Company.CompanyId,  
377 - // "orgId": dividendsEstimate.Org.OrgId,  
378 - // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
379 - // "dividendsParticipateTypes": []int32{1, 3},  
380 - // "offsetLimit": false,  
381 - // "dividendsStage": dividendsEstimate.DividendsStage,  
382 - // "dividendsTypes": []int32{1, 2},  
383 - // }  
384 - //} else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单  
385 - // queryOptions = map[string]interface{}{  
386 - // "companyId": dividendsEstimate.Company.CompanyId,  
387 - // "orgId": dividendsEstimate.Org.OrgId,  
388 - // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
389 - // "dividendsParticipateTypes": []int32{1, 2},  
390 - // "offsetLimit": false,  
391 - // "dividendsStage": dividendsEstimate.DividendsStage,  
392 - // "dividendsTypes": []int32{1, 2},  
393 - // }  
394 - //}  
395 -  
396 if countRelativeDividendsEstimates, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{ 359 if countRelativeDividendsEstimates, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
397 "companyId": dividendsEstimate.Company.CompanyId, 360 "companyId": dividendsEstimate.Company.CompanyId,
398 "orgId": dividendsEstimate.Org.OrgId, 361 "orgId": dividendsEstimate.Org.OrgId,
@@ -415,43 +378,6 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs @@ -415,43 +378,6 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
415 } 378 }
416 } 379 }
417 } else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红 380 } else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红
418 -  
419 - //// 自定义查询  
420 - //queryOptions := make(map[string]interface{})  
421 - //  
422 - ////参与分红类型,1承接人,2推荐人,3关联业务员  
423 - //if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单  
424 - // queryOptions = map[string]interface{}{  
425 - // "companyId": dividendsEstimate.Company.CompanyId,  
426 - // "orgId": dividendsEstimate.Org.OrgId,  
427 - // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
428 - // "dividendsParticipateTypes": []int32{2, 3},  
429 - // "offsetLimit": false,  
430 - // "dividendsStage": dividendsEstimate.DividendsStage,  
431 - // "dividendsType": int32(3),  
432 - // }  
433 - //} else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单  
434 - // queryOptions = map[string]interface{}{  
435 - // "companyId": dividendsEstimate.Company.CompanyId,  
436 - // "orgId": dividendsEstimate.Org.OrgId,  
437 - // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
438 - // "dividendsParticipateTypes": []int32{1, 3},  
439 - // "offsetLimit": false,  
440 - // "dividendsStage": dividendsEstimate.DividendsStage,  
441 - // "dividendsType": int32(3),  
442 - // }  
443 - //} else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单  
444 - // queryOptions = map[string]interface{}{  
445 - // "companyId": dividendsEstimate.Company.CompanyId,  
446 - // "orgId": dividendsEstimate.Org.OrgId,  
447 - // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
448 - // "dividendsParticipateTypes": []int32{1, 2},  
449 - // "offsetLimit": false,  
450 - // "dividendsStage": dividendsEstimate.DividendsStage,  
451 - // "dividendsType": int32(3),  
452 - // }  
453 - //}  
454 -  
455 if countRelativeDividendsEstimates, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(map[string]interface{}{ 381 if countRelativeDividendsEstimates, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(map[string]interface{}{
456 "companyId": dividendsEstimate.Company.CompanyId, 382 "companyId": dividendsEstimate.Company.CompanyId,
457 "orgId": dividendsEstimate.Org.OrgId, 383 "orgId": dividendsEstimate.Org.OrgId,
@@ -1281,7 +1281,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide @@ -1281,7 +1281,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
1281 orderGoodFound := &domain.OrderGood{} 1281 orderGoodFound := &domain.OrderGood{}
1282 1282
1283 // 获取产品 1283 // 获取产品
1284 - if orderGood.OrderGoodId != "" { 1284 + if orderGoodId != 0 {
1285 orderGoodFetched, err4 := orderGoodRepository.FindOne(map[string]interface{}{ 1285 orderGoodFetched, err4 := orderGoodRepository.FindOne(map[string]interface{}{
1286 "orderGoodId": orderGoodId, 1286 "orderGoodId": orderGoodId,
1287 }) 1287 })
@@ -69,50 +69,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -69,50 +69,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
69 var orderGoodIds []int64 69 var orderGoodIds []int64
70 for _, dividendsEstimate := range dividendsEstimates { 70 for _, dividendsEstimate := range dividendsEstimates {
71 if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销 71 if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
72 - // 自定义查询  
73 -  
74 - //queryOptions := map[string]interface{}{  
75 - // "companyId": dividendsEstimate.Company.CompanyId,  
76 - // "orgId": dividendsEstimate.Org.OrgId,  
77 - // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
78 - // "dividendsParticipateTypes": []int32{1, 2, 3},  
79 - // "offsetLimit": false,  
80 - // "dividendsStage": dividendsEstimate.DividendsStage,  
81 - // "dividendsTypes": []int32{1, 2},  
82 - //}  
83 - //参与分红类型,1承接人,2推荐人,3关联业务员  
84 - //if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单  
85 - // queryOptions = map[string]interface{}{  
86 - // "companyId": dividendsEstimate.Company.CompanyId,  
87 - // "orgId": dividendsEstimate.Org.OrgId,  
88 - // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
89 - // "dividendsParticipateTypes": []int32{1, 2, 3},  
90 - // "offsetLimit": false,  
91 - // "dividendsStage": dividendsEstimate.DividendsStage,  
92 - // "dividendsTypes": []int32{1, 2},  
93 - // }  
94 - //} else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单  
95 - // queryOptions = map[string]interface{}{  
96 - // "companyId": dividendsEstimate.Company.CompanyId,  
97 - // "orgId": dividendsEstimate.Org.OrgId,  
98 - // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
99 - // "dividendsParticipateTypes": []int32{1, 3},  
100 - // "offsetLimit": false,  
101 - // "dividendsStage": dividendsEstimate.DividendsStage,  
102 - // "dividendsTypes": []int32{1, 2},  
103 - // }  
104 - //} else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单  
105 - // queryOptions = map[string]interface{}{  
106 - // "companyId": dividendsEstimate.Company.CompanyId,  
107 - // "orgId": dividendsEstimate.Org.OrgId,  
108 - // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
109 - // "dividendsParticipateTypes": []int32{1, 2},  
110 - // "offsetLimit": false,  
111 - // "dividendsStage": dividendsEstimate.DividendsStage,  
112 - // "dividendsTypes": []int32{1, 2},  
113 - // }  
114 - //}  
115 -  
116 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单 72 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
117 if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{ 73 if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
118 "companyId": dividendsEstimate.Company.CompanyId, 74 "companyId": dividendsEstimate.Company.CompanyId,
@@ -143,60 +99,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -143,60 +99,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
143 } 99 }
144 } 100 }
145 } else if dividendsEstimate.DividendsType == 3 { // 3.金额激励 101 } else if dividendsEstimate.DividendsType == 3 { // 3.金额激励
146 -  
147 - // 查询合约  
148 - //cooperationContract, err3 := cooperationContactRepository.FindOne(map[string]interface{}{  
149 - // "companyId": dividendsEstimate.Company.CompanyId,  
150 - // "orgId": dividendsEstimate.Org.OrgId,  
151 - // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
152 - //})  
153 - //if err3 != nil {  
154 - // return nil, err3  
155 - //}  
156 -  
157 - // 自定义查询  
158 - //queryOptions := map[string]interface{}{  
159 - // "companyId": dividendsEstimate.Company.CompanyId,  
160 - // "orgId": dividendsEstimate.Org.OrgId,  
161 - // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
162 - // "dividendsParticipateTypes": []int32{1, 2, 3},  
163 - // "offsetLimit": false,  
164 - // "dividendsStage": dividendsEstimate.DividendsStage,  
165 - // "dividendsType": int32(3),  
166 - //}  
167 - //参与分红类型,1承接人,2推荐人,3关联业务员  
168 - //if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单  
169 - // queryOptions = map[string]interface{}{  
170 - // "companyId": dividendsEstimate.Company.CompanyId,  
171 - // "orgId": dividendsEstimate.Org.OrgId,  
172 - // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
173 - // "dividendsParticipateTypes": []int32{2, 3},  
174 - // "offsetLimit": false,  
175 - // "dividendsStage": dividendsEstimate.DividendsStage,  
176 - // "dividendsType": int32(3),  
177 - // }  
178 - //} else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单  
179 - // queryOptions = map[string]interface{}{  
180 - // "companyId": dividendsEstimate.Company.CompanyId,  
181 - // "orgId": dividendsEstimate.Org.OrgId,  
182 - // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
183 - // "dividendsParticipateTypes": []int32{1, 3},  
184 - // "offsetLimit": false,  
185 - // "dividendsStage": dividendsEstimate.DividendsStage,  
186 - // "dividendsType": int32(3),  
187 - // }  
188 - //} else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单  
189 - // queryOptions = map[string]interface{}{  
190 - // "companyId": dividendsEstimate.Company.CompanyId,  
191 - // "orgId": dividendsEstimate.Org.OrgId,  
192 - // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
193 - // "dividendsParticipateTypes": []int32{1, 2},  
194 - // "offsetLimit": false,  
195 - // "dividendsStage": dividendsEstimate.DividendsStage,  
196 - // "dividendsType": int32(3),  
197 - // }  
198 - //}  
199 -  
200 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单 102 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
201 if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{ 103 if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
202 "companyId": dividendsEstimate.Company.CompanyId, 104 "companyId": dividendsEstimate.Company.CompanyId,
@@ -288,7 +190,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -288,7 +190,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
288 // 获取分红订单产品并更新产品状态 190 // 获取分红订单产品并更新产品状态
289 if len(ordersNumbers) > 0 { 191 if len(ordersNumbers) > 0 {
290 if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{ 192 if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
291 - //"orderNumbers": ordersNumbers,  
292 "orderGoodIds": orderGoodIds, 193 "orderGoodIds": orderGoodIds,
293 "companyId": dividendsEstimates[0].Company.CompanyId, 194 "companyId": dividendsEstimates[0].Company.CompanyId,
294 "orgId": dividendsEstimates[0].Org.OrgId, 195 "orgId": dividendsEstimates[0].Org.OrgId,
@@ -318,11 +219,21 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -318,11 +219,21 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
318 }); err5 != nil { 219 }); err5 != nil {
319 return nil, err5 220 return nil, err5
320 } else { 221 } else {
  222 + // orderGoodIds去重
  223 + newReturnedOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)
  224 +
321 if countDividendsReturnedOrder > 0 { 225 if countDividendsReturnedOrder > 0 {
322 for i, returnedOrder := range returnedOrders { 226 for i, returnedOrder := range returnedOrders {
323 - if len(returnedOrder.Goods) == len(orderGoodIds) { // 1.全部产品取消分红预算 227 + goods := make([]*domain.OrderGood, 0)
  228 + for _, good := range returnedOrder.Goods {
  229 + if good.OrderGoodDividendsStatus == 2 {
  230 + goods = append(goods, good)
  231 + }
  232 + }
  233 +
  234 + if len(goods) == len(newReturnedOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,退货单分红状态变更为未分红
324 returnedOrders[i].DividendStatus = 1 235 returnedOrders[i].DividendStatus = 1
325 - } else if len(returnedOrder.Goods) > len(orderGoodIds) { // 3.部分产品被取消分红预算 236 + } else if len(goods) > len(newReturnedOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,退货单分红状态变更为部分分红
326 returnedOrders[i].DividendStatus = 3 237 returnedOrders[i].DividendStatus = 3
327 } 238 }
328 returnedOrders[i].DividendStatus = returnedOrder.DividendStatus 239 returnedOrders[i].DividendStatus = returnedOrder.DividendStatus
@@ -342,7 +253,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -342,7 +253,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
342 // 获取退货单产品并更新产品状态 253 // 获取退货单产品并更新产品状态
343 if len(returnedOrdersNumbers) > 0 { 254 if len(returnedOrdersNumbers) > 0 {
344 if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{ 255 if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
345 - //"returnedOrderNumbers": returnedOrdersNumbers,  
346 "orderGoodIds": orderGoodIds, 256 "orderGoodIds": orderGoodIds,
347 "companyId": dividendsEstimates[0].Company.CompanyId, 257 "companyId": dividendsEstimates[0].Company.CompanyId,
348 "orgId": dividendsEstimates[0].Org.OrgId, 258 "orgId": dividendsEstimates[0].Org.OrgId,