|
@@ -177,6 +177,17 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat |
|
@@ -177,6 +177,17 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat |
177
|
defer func() {
|
177
|
defer func() {
|
178
|
_ = transactionContext.RollbackTransaction()
|
178
|
_ = transactionContext.RollbackTransaction()
|
179
|
}()
|
179
|
}()
|
|
|
180
|
+
|
|
|
181
|
+ // 取消分红预算领域服务初始化
|
|
|
182
|
+ var cancelDividendsEstimateService service.CancelDividendsEstimate
|
|
|
183
|
+ if value, err := factory.CreateCancelDividendsEstimateService(map[string]interface{}{
|
|
|
184
|
+ "transactionContext": transactionContext,
|
|
|
185
|
+ }); err != nil {
|
|
|
186
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
187
|
+ } else {
|
|
|
188
|
+ cancelDividendsEstimateService = value
|
|
|
189
|
+ }
|
|
|
190
|
+
|
180
|
// 分红预算仓储初始化
|
191
|
// 分红预算仓储初始化
|
181
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
192
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
182
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
193
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
@@ -186,6 +197,8 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat |
|
@@ -186,6 +197,8 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat |
186
|
} else {
|
197
|
} else {
|
187
|
dividendsEstimateRepository = value
|
198
|
dividendsEstimateRepository = value
|
188
|
}
|
199
|
}
|
|
|
200
|
+
|
|
|
201
|
+ // 获取当前被取消的分红预算单
|
189
|
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": cancelDividendsEstimateCommand.DividendsEstimateId})
|
202
|
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": cancelDividendsEstimateCommand.DividendsEstimateId})
|
190
|
if err != nil {
|
203
|
if err != nil {
|
191
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
204
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -193,20 +206,42 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat |
|
@@ -193,20 +206,42 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat |
193
|
if dividendsEstimate == nil {
|
206
|
if dividendsEstimate == nil {
|
194
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cancelDividendsEstimateCommand.DividendsEstimateId, 10)))
|
207
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cancelDividendsEstimateCommand.DividendsEstimateId, 10)))
|
195
|
}
|
208
|
}
|
196
|
- // TODO 校验是否能够取消
|
|
|
197
|
|
209
|
|
198
|
- // 设置取消状态
|
|
|
199
|
- cancelDividendsEstimateCommand.IsCanceled = true
|
|
|
200
|
- if err := dividendsEstimate.Update(tool_funs.SimpleStructToMap(cancelDividendsEstimateCommand)); err != nil {
|
|
|
201
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
210
|
+ // 校验是否能够取消
|
|
|
211
|
+ if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红、退货冲销
|
|
|
212
|
+ if count, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum}); err2 != nil {
|
|
|
213
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
|
|
|
214
|
+ } else {
|
|
|
215
|
+ if count > 0 {
|
|
|
216
|
+ for _, dividendsEstimateRelative := range dividendsEstimatesRelative {
|
|
|
217
|
+ if dividendsEstimateRelative.DividendsAccountStatus == domain.ACCOUNTED {
|
|
|
218
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有相关分红预算单已结算,无法取消")
|
202
|
}
|
219
|
}
|
203
|
- if dividendsEstimate, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
|
220
|
+ }
|
|
|
221
|
+ }
|
|
|
222
|
+ }
|
|
|
223
|
+ } else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红
|
|
|
224
|
+ if count, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(map[string]interface{}{"cooperationContractNumber": dividendsEstimate.CooperationContractNumber}); err3 != nil {
|
|
|
225
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
|
|
|
226
|
+ } else {
|
|
|
227
|
+ if count > 0 {
|
|
|
228
|
+ for _, dividendsEstimateRelative := range dividendsEstimatesRelative {
|
|
|
229
|
+ if dividendsEstimateRelative.DividendsAccountStatus == domain.ACCOUNTED {
|
|
|
230
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有相关分红预算单已结算,无法取消")
|
|
|
231
|
+ }
|
|
|
232
|
+ }
|
|
|
233
|
+ }
|
|
|
234
|
+ }
|
|
|
235
|
+ }
|
|
|
236
|
+
|
|
|
237
|
+ // 取消分红预算
|
|
|
238
|
+ if dividendsEstimatesCanceled, err := cancelDividendsEstimateService.CancelEstimate([]int64{cancelDividendsEstimateCommand.DividendsEstimateId}, cancelDividendsEstimateCommand.UserId); err != nil {
|
204
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
239
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
205
|
} else {
|
240
|
} else {
|
206
|
if err := transactionContext.CommitTransaction(); err != nil {
|
241
|
if err := transactionContext.CommitTransaction(); err != nil {
|
207
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
242
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
208
|
}
|
243
|
}
|
209
|
- return dividendsEstimate, nil
|
244
|
+ return dividendsEstimatesCanceled[1], nil
|
210
|
}
|
245
|
}
|
211
|
}
|
246
|
}
|
212
|
|
247
|
|
|
@@ -225,6 +260,17 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs |
|
@@ -225,6 +260,17 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs |
225
|
defer func() {
|
260
|
defer func() {
|
226
|
_ = transactionContext.RollbackTransaction()
|
261
|
_ = transactionContext.RollbackTransaction()
|
227
|
}()
|
262
|
}()
|
|
|
263
|
+
|
|
|
264
|
+ // 取消分红预算领域服务初始化
|
|
|
265
|
+ var cancelDividendsEstimateService service.CancelDividendsEstimate
|
|
|
266
|
+ if value, err := factory.CreateCancelDividendsEstimateService(map[string]interface{}{
|
|
|
267
|
+ "transactionContext": transactionContext,
|
|
|
268
|
+ }); err != nil {
|
|
|
269
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
270
|
+ } else {
|
|
|
271
|
+ cancelDividendsEstimateService = value
|
|
|
272
|
+ }
|
|
|
273
|
+
|
228
|
// 分红预算仓储初始化
|
274
|
// 分红预算仓储初始化
|
229
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
275
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
230
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
276
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
@@ -234,24 +280,58 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs |
|
@@ -234,24 +280,58 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs |
234
|
} else {
|
280
|
} else {
|
235
|
dividendsEstimateRepository = value
|
281
|
dividendsEstimateRepository = value
|
236
|
}
|
282
|
}
|
237
|
- dividendsEstimateIds, _ := utils.SliceAtoi(batchCancelEstimateCommand.DividendsEstimateIds)
|
283
|
+
|
|
|
284
|
+ // 分红预算ID类型转换
|
|
|
285
|
+ dividendsEstimateIds, err := utils.SliceAtoi(batchCancelEstimateCommand.DividendsEstimateIds)
|
|
|
286
|
+ if err != nil {
|
|
|
287
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红预算单参数转换错误")
|
|
|
288
|
+ }
|
|
|
289
|
+
|
|
|
290
|
+ // 获取分红预算
|
238
|
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
|
291
|
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
|
239
|
"dividendsEstimateIds": dividendsEstimateIds,
|
292
|
"dividendsEstimateIds": dividendsEstimateIds,
|
240
|
}); err != nil {
|
293
|
}); err != nil {
|
241
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
294
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
242
|
} else {
|
295
|
} else {
|
243
|
if count > 0 {
|
296
|
if count > 0 {
|
244
|
- for i, _ := range dividendsEstimates {
|
|
|
245
|
- dividendsEstimates[i].IsCanceled = true
|
297
|
+ // 校验分红预算是否可以取消,已有相关分红预算单已结算,无法取消
|
|
|
298
|
+ for _, dividendsEstimate := range dividendsEstimates {
|
|
|
299
|
+ // 校验是否能够取消
|
|
|
300
|
+ if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红、退货冲销
|
|
|
301
|
+ if count, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum}); err2 != nil {
|
|
|
302
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
|
|
|
303
|
+ } else {
|
|
|
304
|
+ if count > 0 {
|
|
|
305
|
+ for _, dividendsEstimateRelative := range dividendsEstimatesRelative {
|
|
|
306
|
+ if dividendsEstimateRelative.DividendsAccountStatus == domain.ACCOUNTED {
|
|
|
307
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有相关分红预算单已结算,无法取消")
|
246
|
}
|
308
|
}
|
247
|
- dividendsEstimatesCanceled, err := dividendsEstimateRepository.UpdateMany(dividendsEstimates)
|
|
|
248
|
- if err != nil {
|
|
|
249
|
- return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
250
|
}
|
309
|
}
|
|
|
310
|
+ }
|
|
|
311
|
+ }
|
|
|
312
|
+ } else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红
|
|
|
313
|
+ if count, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(map[string]interface{}{"cooperationContractNumber": dividendsEstimate.CooperationContractNumber}); err3 != nil {
|
|
|
314
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
|
|
|
315
|
+ } else {
|
|
|
316
|
+ if count > 0 {
|
|
|
317
|
+ for _, dividendsEstimateRelative := range dividendsEstimatesRelative {
|
|
|
318
|
+ if dividendsEstimateRelative.DividendsAccountStatus == domain.ACCOUNTED {
|
|
|
319
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有相关分红预算单已结算,无法取消")
|
|
|
320
|
+ }
|
|
|
321
|
+ }
|
|
|
322
|
+ }
|
|
|
323
|
+ }
|
|
|
324
|
+ }
|
|
|
325
|
+ }
|
|
|
326
|
+ // 批量取消分红预算单
|
|
|
327
|
+ if dividendsEstimatesCanceled, err := cancelDividendsEstimateService.CancelEstimate(dividendsEstimateIds, batchCancelEstimateCommand.UserId); err != nil {
|
|
|
328
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
329
|
+ } else {
|
251
|
if err := transactionContext.CommitTransaction(); err != nil {
|
330
|
if err := transactionContext.CommitTransaction(); err != nil {
|
252
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
331
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
253
|
}
|
332
|
}
|
254
|
return dividendsEstimatesCanceled, nil
|
333
|
return dividendsEstimatesCanceled, nil
|
|
|
334
|
+ }
|
255
|
} else {
|
335
|
} else {
|
256
|
return map[string]interface{}{}, nil
|
336
|
return map[string]interface{}{}, nil
|
257
|
}
|
337
|
}
|