|
@@ -60,26 +60,29 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
|
@@ -60,26 +60,29 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
60
|
var dividendsEstimatesCanceled []*domain.DividendsEstimate
|
60
|
var dividendsEstimatesCanceled []*domain.DividendsEstimate
|
61
|
var orderOrReturnOrderNums []string
|
61
|
var orderOrReturnOrderNums []string
|
62
|
for _, dividendsEstimate := range dividendsEstimates {
|
62
|
for _, dividendsEstimate := range dividendsEstimates {
|
63
|
- // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
|
|
|
64
|
- if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
|
|
|
65
|
- "companyId": dividendsEstimate.Company.CompanyId,
|
|
|
66
|
- "orgId": dividendsEstimate.Org.OrgId,
|
|
|
67
|
- "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
|
|
|
68
|
- }); err2 != nil {
|
|
|
69
|
- return nil, err2
|
|
|
70
|
- } else {
|
|
|
71
|
- if countRelative > 0 {
|
|
|
72
|
- for i, _ := range dividendsEstimatesRelative {
|
|
|
73
|
- dividendsEstimatesRelative[i].IsCanceled = true
|
|
|
74
|
- dividendsEstimatesRelative[i].Operator = operator
|
|
|
75
|
- // 获取相关订单/退货单号
|
|
|
76
|
- orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
|
|
|
77
|
- }
|
|
|
78
|
- dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
|
|
|
79
|
- if err3 != nil {
|
|
|
80
|
- return nil, err3
|
63
|
+ if dividendsEstimate.DividendsType != 3 { // 非金额激励分红预算单处理
|
|
|
64
|
+ // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
|
|
|
65
|
+ if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
|
|
|
66
|
+ "companyId": dividendsEstimate.Company.CompanyId,
|
|
|
67
|
+ "orgId": dividendsEstimate.Org.OrgId,
|
|
|
68
|
+ "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
|
|
|
69
|
+ "offsetLimit": false,
|
|
|
70
|
+ }); err2 != nil {
|
|
|
71
|
+ return nil, err2
|
|
|
72
|
+ } else {
|
|
|
73
|
+ if countRelative > 0 {
|
|
|
74
|
+ for i, _ := range dividendsEstimatesRelative {
|
|
|
75
|
+ dividendsEstimatesRelative[i].IsCanceled = true
|
|
|
76
|
+ dividendsEstimatesRelative[i].Operator = operator
|
|
|
77
|
+ // 获取相关订单/退货单号
|
|
|
78
|
+ orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
|
|
|
79
|
+ }
|
|
|
80
|
+ dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
|
|
|
81
|
+ if err3 != nil {
|
|
|
82
|
+ return nil, err3
|
|
|
83
|
+ }
|
|
|
84
|
+ dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
|
81
|
}
|
85
|
}
|
82
|
- dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
|
|
|
83
|
}
|
86
|
}
|
84
|
}
|
87
|
}
|
85
|
}
|
88
|
}
|
|
@@ -88,98 +91,107 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
|
@@ -88,98 +91,107 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
88
|
var orderNums []string
|
91
|
var orderNums []string
|
89
|
var returnedOrderNums []string
|
92
|
var returnedOrderNums []string
|
90
|
|
93
|
|
91
|
- // 订单/退货单号数组去重
|
|
|
92
|
- orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums)
|
|
|
93
|
- for _, orderNullNum := range orderOrReturnOrderNumsWithoutDup {
|
|
|
94
|
- if orderNullNum[:2] == "RE" { // 分红退后单
|
|
|
95
|
- returnedOrderNums = append(returnedOrderNums, orderNullNum)
|
|
|
96
|
- } else if orderNullNum[:2] == "SL" { // 分红订单
|
|
|
97
|
- orderNums = append(orderNums, orderNullNum)
|
94
|
+ if len(orderOrReturnOrderNums) > 0 {
|
|
|
95
|
+ // 订单/退货单号数组去重
|
|
|
96
|
+ orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums)
|
|
|
97
|
+ for _, orderNullNum := range orderOrReturnOrderNumsWithoutDup {
|
|
|
98
|
+ if orderNullNum[:2] == "RE" { // 分红退后单
|
|
|
99
|
+ returnedOrderNums = append(returnedOrderNums, orderNullNum)
|
|
|
100
|
+ } else if orderNullNum[:2] == "SL" { // 分红订单
|
|
|
101
|
+ orderNums = append(orderNums, orderNullNum)
|
|
|
102
|
+ }
|
98
|
}
|
103
|
}
|
99
|
- }
|
|
|
100
|
|
104
|
|
101
|
- // 获取分红订单
|
|
|
102
|
- if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{
|
|
|
103
|
- "companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
104
|
- "orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
105
|
- "dividendsOrderNumbers": orderNums,
|
|
|
106
|
- }); err4 != nil {
|
|
|
107
|
- return nil, err4
|
|
|
108
|
- } else {
|
|
|
109
|
- if countDividendsOrder > 0 {
|
|
|
110
|
- for i, _ := range orders {
|
|
|
111
|
- orders[i].DividendStatus = 1
|
|
|
112
|
- }
|
|
|
113
|
- // 保存订单状态
|
|
|
114
|
- if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil {
|
|
|
115
|
- return nil, err6
|
|
|
116
|
- }
|
|
|
117
|
- // 获取订单编号
|
|
|
118
|
- ordersNumbers := make([]string, 0)
|
|
|
119
|
- for _, order := range orders {
|
|
|
120
|
- ordersNumbers = append(ordersNumbers, order.DividendsOrderNumber)
|
|
|
121
|
- }
|
|
|
122
|
- // 获取分红订单产品并更新产品状态
|
|
|
123
|
- if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
124
|
- "orderNumbers": ordersNumbers,
|
|
|
125
|
- "companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
126
|
- "orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
127
|
- }); err != nil {
|
|
|
128
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
105
|
+ // 获取分红订单
|
|
|
106
|
+ if len(orderNums) > 0 {
|
|
|
107
|
+ if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{
|
|
|
108
|
+ "companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
109
|
+ "orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
110
|
+ "dividendsOrderNumbers": orderNums,
|
|
|
111
|
+ }); err4 != nil {
|
|
|
112
|
+ return nil, err4
|
129
|
} else {
|
113
|
} else {
|
130
|
- if countOrderGood > 0 {
|
|
|
131
|
- for i, _ := range orderGoodsFound {
|
|
|
132
|
- orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红
|
114
|
+ if countDividendsOrder > 0 {
|
|
|
115
|
+ for i, _ := range orders {
|
|
|
116
|
+ orders[i].DividendStatus = 1
|
133
|
}
|
117
|
}
|
134
|
- if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
|
|
|
135
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
|
118
|
+ // 保存订单状态
|
|
|
119
|
+ if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil {
|
|
|
120
|
+ return nil, err6
|
|
|
121
|
+ }
|
|
|
122
|
+ // 获取订单编号
|
|
|
123
|
+ ordersNumbers := make([]string, 0)
|
|
|
124
|
+ for _, order := range orders {
|
|
|
125
|
+ ordersNumbers = append(ordersNumbers, order.DividendsOrderNumber)
|
|
|
126
|
+ }
|
|
|
127
|
+ // 获取分红订单产品并更新产品状态
|
|
|
128
|
+ if len(ordersNumbers) > 0 {
|
|
|
129
|
+ if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
130
|
+ "orderNumbers": ordersNumbers,
|
|
|
131
|
+ "companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
132
|
+ "orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
133
|
+ }); err != nil {
|
|
|
134
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
135
|
+ } else {
|
|
|
136
|
+ if countOrderGood > 0 {
|
|
|
137
|
+ for i, _ := range orderGoodsFound {
|
|
|
138
|
+ orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红
|
|
|
139
|
+ }
|
|
|
140
|
+ if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
|
|
|
141
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
|
|
|
142
|
+ }
|
|
|
143
|
+ }
|
|
|
144
|
+ }
|
136
|
}
|
145
|
}
|
137
|
}
|
146
|
}
|
138
|
}
|
147
|
}
|
139
|
}
|
148
|
}
|
140
|
- }
|
|
|
141
|
|
149
|
|
142
|
- // 获取分红退货单
|
|
|
143
|
- if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{
|
|
|
144
|
- "companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
145
|
- "orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
146
|
- "dividendsReturnedOrderNumbers": returnedOrderNums,
|
|
|
147
|
- }); err5 != nil {
|
|
|
148
|
- return nil, err5
|
|
|
149
|
- } else {
|
|
|
150
|
- if countDividendsReturnedOrder > 0 {
|
|
|
151
|
- for i, _ := range returnedOrders {
|
|
|
152
|
- returnedOrders[i].DividendStatus = 1
|
|
|
153
|
- }
|
|
|
154
|
- // 保存退货单状态
|
|
|
155
|
- if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil {
|
|
|
156
|
- return nil, err7
|
|
|
157
|
- }
|
|
|
158
|
- // 获取订单编号
|
|
|
159
|
- returnedOrdersNumbers := make([]string, 0)
|
|
|
160
|
- for _, returnedOrder := range returnedOrders {
|
|
|
161
|
- returnedOrdersNumbers = append(returnedOrdersNumbers, returnedOrder.DividendsReturnedOrderNumber)
|
|
|
162
|
- }
|
|
|
163
|
- // 获取退货单产品并更新产品状态
|
|
|
164
|
- if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
165
|
- "returnedOrderNumbers": returnedOrdersNumbers,
|
|
|
166
|
- "companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
167
|
- "orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
168
|
- }); err != nil {
|
|
|
169
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
150
|
+ // 获取分红退货单
|
|
|
151
|
+ if len(returnedOrderNums) > 0 {
|
|
|
152
|
+ if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{
|
|
|
153
|
+ "companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
154
|
+ "orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
155
|
+ "dividendsReturnedOrderNumbers": returnedOrderNums,
|
|
|
156
|
+ }); err5 != nil {
|
|
|
157
|
+ return nil, err5
|
170
|
} else {
|
158
|
} else {
|
171
|
- if countOrderGood > 0 {
|
|
|
172
|
- for i, _ := range orderGoodsFound {
|
|
|
173
|
- orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红
|
159
|
+ if countDividendsReturnedOrder > 0 {
|
|
|
160
|
+ for i, _ := range returnedOrders {
|
|
|
161
|
+ returnedOrders[i].DividendStatus = 1
|
|
|
162
|
+ }
|
|
|
163
|
+ // 保存退货单状态
|
|
|
164
|
+ if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil {
|
|
|
165
|
+ return nil, err7
|
174
|
}
|
166
|
}
|
175
|
- if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
|
|
|
176
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
|
167
|
+ // 获取订单编号
|
|
|
168
|
+ returnedOrdersNumbers := make([]string, 0)
|
|
|
169
|
+ for _, returnedOrder := range returnedOrders {
|
|
|
170
|
+ returnedOrdersNumbers = append(returnedOrdersNumbers, returnedOrder.DividendsReturnedOrderNumber)
|
|
|
171
|
+ }
|
|
|
172
|
+ // 获取退货单产品并更新产品状态
|
|
|
173
|
+ if len(returnedOrdersNumbers) > 0 {
|
|
|
174
|
+ if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
175
|
+ "returnedOrderNumbers": returnedOrdersNumbers,
|
|
|
176
|
+ "companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
177
|
+ "orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
178
|
+ }); err != nil {
|
|
|
179
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
180
|
+ } else {
|
|
|
181
|
+ if countOrderGood > 0 {
|
|
|
182
|
+ for i, _ := range orderGoodsFound {
|
|
|
183
|
+ orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红
|
|
|
184
|
+ }
|
|
|
185
|
+ if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
|
|
|
186
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
|
|
|
187
|
+ }
|
|
|
188
|
+ }
|
|
|
189
|
+ }
|
177
|
}
|
190
|
}
|
178
|
}
|
191
|
}
|
179
|
}
|
192
|
}
|
180
|
}
|
193
|
}
|
181
|
}
|
194
|
}
|
182
|
-
|
|
|
183
|
return dividendsEstimatesCanceled, nil
|
195
|
return dividendsEstimatesCanceled, nil
|
184
|
}
|
196
|
}
|
185
|
}
|
197
|
}
|