|
@@ -8,6 +8,7 @@ import ( |
|
@@ -8,6 +8,7 @@ import ( |
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
|
11
|
)
|
12
|
)
|
12
|
|
13
|
|
13
|
type CancelDividendsEstimateService struct {
|
14
|
type CancelDividendsEstimateService struct {
|
|
@@ -21,6 +22,12 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
|
@@ -21,6 +22,12 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
21
|
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
|
22
|
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
|
22
|
var orderGoodRepository domain.OrderGoodRepository // 订单产品仓储
|
23
|
var orderGoodRepository domain.OrderGoodRepository // 订单产品仓储
|
23
|
|
24
|
|
|
|
25
|
+ type orderGoodInfo struct {
|
|
|
26
|
+ OrderGoodId int64
|
|
|
27
|
+ CompanyId int64
|
|
|
28
|
+ OrgId int64
|
|
|
29
|
+ }
|
|
|
30
|
+
|
24
|
// 分红预算单仓储初始化
|
31
|
// 分红预算单仓储初始化
|
25
|
if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
|
32
|
if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
|
26
|
return nil, err
|
33
|
return nil, err
|
|
@@ -60,6 +67,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
|
@@ -60,6 +67,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
60
|
var dividendsEstimatesCanceled []*domain.DividendsEstimate
|
67
|
var dividendsEstimatesCanceled []*domain.DividendsEstimate
|
61
|
var orderOrReturnOrderNums []string
|
68
|
var orderOrReturnOrderNums []string
|
62
|
var orderGoodIds []int64
|
69
|
var orderGoodIds []int64
|
|
|
70
|
+ orderGoodMaps := make(map[string][]int64, 0)
|
63
|
for _, dividendsEstimate := range dividendsEstimates {
|
71
|
for _, dividendsEstimate := range dividendsEstimates {
|
64
|
if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
|
72
|
if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
|
65
|
// 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
|
73
|
// 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
|
|
@@ -83,6 +91,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
|
@@ -83,6 +91,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
83
|
// 获取相关订单/退货单号
|
91
|
// 获取相关订单/退货单号
|
84
|
orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
|
92
|
orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
|
85
|
orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId)
|
93
|
orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId)
|
|
|
94
|
+ orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum] = append(orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum], dividendsEstimatesRelative[i].OrderGoodId)
|
86
|
}
|
95
|
}
|
87
|
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
|
96
|
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
|
88
|
if err3 != nil {
|
97
|
if err3 != nil {
|
|
@@ -151,18 +160,19 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
|
@@ -151,18 +160,19 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
151
|
}); err4 != nil {
|
160
|
}); err4 != nil {
|
152
|
return nil, err4
|
161
|
return nil, err4
|
153
|
} else {
|
162
|
} else {
|
154
|
- // orderGoodIds去重
|
|
|
155
|
- newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)
|
|
|
156
|
if countDividendsOrder > 0 {
|
163
|
if countDividendsOrder > 0 {
|
157
|
for i, order := range orders {
|
164
|
for i, order := range orders {
|
|
|
165
|
+ // 取消分红的订单产品
|
|
|
166
|
+ newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodMaps[order.DividendsOrderNumber])
|
158
|
var goodIds []int64
|
167
|
var goodIds []int64
|
159
|
for _, good := range order.Goods {
|
168
|
for _, good := range order.Goods {
|
160
|
if good.OrderGoodDividendsStatus == 2 {
|
169
|
if good.OrderGoodDividendsStatus == 2 {
|
161
|
goodIds = append(goodIds, good.OrderGoodId)
|
170
|
goodIds = append(goodIds, good.OrderGoodId)
|
162
|
}
|
171
|
}
|
163
|
}
|
172
|
}
|
164
|
- // goodIds去重
|
173
|
+ // goodIds去重
|
165
|
newGoodIds := utils.RemoveDuplicationInt64(goodIds)
|
174
|
newGoodIds := utils.RemoveDuplicationInt64(goodIds)
|
|
|
175
|
+ log.Logger.Info("")
|
166
|
if len(newGoodIds) == len(newOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,订单分红状态变更为未分红
|
176
|
if len(newGoodIds) == len(newOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,订单分红状态变更为未分红
|
167
|
orders[i].DividendStatus = 1
|
177
|
orders[i].DividendStatus = 1
|
168
|
} else if len(newGoodIds) > len(newOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,订单分红状态变更为部分分红
|
178
|
} else if len(newGoodIds) > len(newOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,订单分红状态变更为部分分红
|
|
@@ -216,21 +226,21 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
|
@@ -216,21 +226,21 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
216
|
}); err5 != nil {
|
226
|
}); err5 != nil {
|
217
|
return nil, err5
|
227
|
return nil, err5
|
218
|
} else {
|
228
|
} else {
|
219
|
- // orderGoodIds去重
|
|
|
220
|
- newReturnedOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)
|
|
|
221
|
-
|
|
|
222
|
if countDividendsReturnedOrder > 0 {
|
229
|
if countDividendsReturnedOrder > 0 {
|
223
|
for i, returnedOrder := range returnedOrders {
|
230
|
for i, returnedOrder := range returnedOrders {
|
224
|
- goods := make([]*domain.OrderGood, 0)
|
231
|
+ // 已取消的退货单产品
|
|
|
232
|
+ newReturnedOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodMaps[returnedOrder.DividendsReturnedOrderNumber])
|
|
|
233
|
+ var goodIds []int64
|
225
|
for _, good := range returnedOrder.Goods {
|
234
|
for _, good := range returnedOrder.Goods {
|
226
|
if good.OrderGoodDividendsStatus == 2 {
|
235
|
if good.OrderGoodDividendsStatus == 2 {
|
227
|
- goods = append(goods, good)
|
236
|
+ goodIds = append(goodIds, good.OrderGoodId)
|
228
|
}
|
237
|
}
|
229
|
}
|
238
|
}
|
230
|
-
|
|
|
231
|
- if len(goods) == len(newReturnedOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,退货单分红状态变更为未分红
|
239
|
+ // goodIds去重
|
|
|
240
|
+ newGoodIds := utils.RemoveDuplicationInt64(goodIds)
|
|
|
241
|
+ if len(newGoodIds) == len(newReturnedOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,退货单分红状态变更为未分红
|
232
|
returnedOrders[i].DividendStatus = 1
|
242
|
returnedOrders[i].DividendStatus = 1
|
233
|
- } else if len(goods) > len(newReturnedOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,退货单分红状态变更为部分分红
|
243
|
+ } else if len(newGoodIds) > len(newReturnedOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,退货单分红状态变更为部分分红
|
234
|
returnedOrders[i].DividendStatus = 3
|
244
|
returnedOrders[i].DividendStatus = 3
|
235
|
}
|
245
|
}
|
236
|
returnedOrders[i].DividendStatus = returnedOrder.DividendStatus
|
246
|
returnedOrders[i].DividendStatus = returnedOrder.DividendStatus
|