|
@@ -3,10 +3,12 @@ package service |
|
@@ -3,10 +3,12 @@ package service |
3
|
import (
|
3
|
import (
|
4
|
"fmt"
|
4
|
"fmt"
|
5
|
"github.com/linmadan/egglib-go/core/application"
|
5
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
6
|
+ pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
6
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
7
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/command"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/command"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/dto"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/dto"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/query"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/query"
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/event/subscriber"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
|
12
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
|
11
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
13
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
12
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
|
14
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
|
|
@@ -368,10 +370,151 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
@@ -368,10 +370,151 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
368
|
defer func() {
|
370
|
defer func() {
|
369
|
_ = transactionContext.RollbackTransaction()
|
371
|
_ = transactionContext.RollbackTransaction()
|
370
|
}()
|
372
|
}()
|
371
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
372
|
- return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
373
|
+ // 分红订单仓储初始化
|
|
|
374
|
+ var dividendsOrderRepository domain.DividendsOrderRepository
|
|
|
375
|
+ if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
|
|
|
376
|
+ "transactionContext": transactionContext,
|
|
|
377
|
+ }); err != nil {
|
|
|
378
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
379
|
+ } else {
|
|
|
380
|
+ dividendsOrderRepository = value
|
|
|
381
|
+ }
|
|
|
382
|
+
|
|
|
383
|
+ // 分红退货单仓储初始化
|
|
|
384
|
+ var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
|
|
|
385
|
+ if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
|
|
|
386
|
+ "transactionContext": transactionContext,
|
|
|
387
|
+ }); err != nil {
|
|
|
388
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
389
|
+ } else {
|
|
|
390
|
+ dividendsReturnedOrderRepository = value
|
|
|
391
|
+ }
|
|
|
392
|
+
|
|
|
393
|
+ // 订单产品仓储初始化
|
|
|
394
|
+ var orderGoodRepository domain.OrderGoodRepository
|
|
|
395
|
+ if value, err := factory.CreateOrderGoodRepository(map[string]interface{}{
|
|
|
396
|
+ "transactionContext": transactionContext,
|
|
|
397
|
+ }); err != nil {
|
|
|
398
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
399
|
+ } else {
|
|
|
400
|
+ orderGoodRepository = value
|
|
|
401
|
+ }
|
|
|
402
|
+
|
|
|
403
|
+ // 分红预算仓储初始化
|
|
|
404
|
+ var dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
405
|
+ if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
406
|
+ "transactionContext": transactionContext,
|
|
|
407
|
+ }); err != nil {
|
|
|
408
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
409
|
+ } else {
|
|
|
410
|
+ dividendsEstimateRepository = value
|
|
|
411
|
+ }
|
|
|
412
|
+
|
|
|
413
|
+ // 初始化确认业绩激励分红预算领域服务
|
|
|
414
|
+ var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
|
|
|
415
|
+ if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
|
|
|
416
|
+ "transactionContext": transactionContext,
|
|
|
417
|
+ }); err != nil {
|
|
|
418
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
419
|
+ } else {
|
|
|
420
|
+ confirmDividendsIncentivesEstimateService = value
|
|
|
421
|
+ _ = confirmDividendsIncentivesEstimateService.Subscribe(&subscriber.DividendsEstimateSubscriber{
|
|
|
422
|
+ TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
423
|
+ })
|
|
|
424
|
+ }
|
|
|
425
|
+
|
|
|
426
|
+ // 获取订单产品
|
|
|
427
|
+ if _, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(confirmDividendsIncentivesEstimateCommand)); err != nil {
|
|
|
428
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
429
|
+ } else {
|
|
|
430
|
+ var dividendsEstimates []*domain.DividendsEstimate
|
|
|
431
|
+ for _, orderGood := range orderGoods {
|
|
|
432
|
+ dividendsEstimate := &domain.DividendsEstimate{}
|
|
|
433
|
+ if orderGood.DividendsOrderNumber != "" { // 查询分红订单
|
|
|
434
|
+ dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
|
|
|
435
|
+ if err != nil {
|
|
|
436
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
437
|
+ }
|
|
|
438
|
+ if dividendsOrder == nil {
|
|
|
439
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
|
|
|
440
|
+ }
|
|
|
441
|
+ // 分红订单产品预算
|
|
|
442
|
+ if dividendsAmount, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
|
|
|
443
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
444
|
+ } else {
|
|
|
445
|
+ dividendsEstimate = &domain.DividendsEstimate{
|
|
|
446
|
+ DividendsEstimateId: 0,
|
|
|
447
|
+ DividendsAccountStatus: 0,
|
|
|
448
|
+ DividendsAmount: dividendsAmount,
|
|
|
449
|
+ DividendsEstimateOrderNumber: "",
|
|
|
450
|
+ DividendsEstimateTime: time.Time{},
|
|
|
451
|
+ DividendsParticipateType: 0,
|
|
|
452
|
+ DividendsType: 0,
|
|
|
453
|
+ OrderOrReturnedOrderNum: "",
|
|
|
454
|
+ CooperationContractNumber: "",
|
|
|
455
|
+ DividendsUser: nil,
|
|
|
456
|
+ DividendsStage: 0,
|
|
|
457
|
+ Org: nil,
|
|
|
458
|
+ Company: nil,
|
|
|
459
|
+ Operator: nil,
|
|
|
460
|
+ OperateTime: time.Time{},
|
|
|
461
|
+ IsCanceled: false,
|
|
|
462
|
+ CreatedAt: time.Time{},
|
|
|
463
|
+ DeletedAt: time.Time{},
|
|
|
464
|
+ UpdatedAt: time.Time{},
|
|
|
465
|
+ }
|
|
|
466
|
+ }
|
|
|
467
|
+ } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
|
|
|
468
|
+ dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber})
|
|
|
469
|
+ if err != nil {
|
|
|
470
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
471
|
+ }
|
|
|
472
|
+ if dividendsReturnedOrder == nil {
|
|
|
473
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
|
|
|
474
|
+ }
|
|
|
475
|
+ // 分红退货单产品预算
|
|
|
476
|
+ if dividendsAmount, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
|
|
|
477
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
478
|
+ } else {
|
|
|
479
|
+ dividendsEstimate = &domain.DividendsEstimate{
|
|
|
480
|
+ DividendsEstimateId: 0,
|
|
|
481
|
+ DividendsAccountStatus: 0,
|
|
|
482
|
+ DividendsAmount: dividendsAmount,
|
|
|
483
|
+ DividendsEstimateOrderNumber: "",
|
|
|
484
|
+ DividendsEstimateTime: time.Time{},
|
|
|
485
|
+ DividendsParticipateType: 0,
|
|
|
486
|
+ DividendsType: 0,
|
|
|
487
|
+ OrderOrReturnedOrderNum: "",
|
|
|
488
|
+ CooperationContractNumber: "",
|
|
|
489
|
+ DividendsUser: nil,
|
|
|
490
|
+ DividendsStage: 0,
|
|
|
491
|
+ Org: nil,
|
|
|
492
|
+ Company: nil,
|
|
|
493
|
+ Operator: nil,
|
|
|
494
|
+ OperateTime: time.Time{},
|
|
|
495
|
+ IsCanceled: false,
|
|
|
496
|
+ CreatedAt: time.Time{},
|
|
|
497
|
+ DeletedAt: time.Time{},
|
|
|
498
|
+ UpdatedAt: time.Time{},
|
|
|
499
|
+ }
|
|
|
500
|
+ }
|
|
|
501
|
+ }
|
|
|
502
|
+ dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
503
|
+ }
|
|
|
504
|
+ var dividendsEstimatesSaved []*domain.DividendsEstimate
|
|
|
505
|
+ for _, dividendsEstimate := range dividendsEstimates {
|
|
|
506
|
+ if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
|
|
|
507
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
508
|
+ } else {
|
|
|
509
|
+ dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved)
|
|
|
510
|
+ }
|
|
|
511
|
+ }
|
|
|
512
|
+
|
|
|
513
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
514
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
515
|
+ }
|
|
|
516
|
+ return dividendsEstimatesSaved, nil
|
373
|
}
|
517
|
}
|
374
|
- return nil, nil
|
|
|
375
|
}
|
518
|
}
|
376
|
|
519
|
|
377
|
// ConfirmMoneyIncentivesEstimate TODO 确定金额激励分红预算
|
520
|
// ConfirmMoneyIncentivesEstimate TODO 确定金额激励分红预算
|
|
@@ -410,6 +553,7 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g |
|
@@ -410,6 +553,7 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g |
410
|
defer func() {
|
553
|
defer func() {
|
411
|
_ = transactionContext.RollbackTransaction()
|
554
|
_ = transactionContext.RollbackTransaction()
|
412
|
}()
|
555
|
}()
|
|
|
556
|
+ // 分红预算单仓储初始化
|
413
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
557
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
414
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
558
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
415
|
"transactionContext": transactionContext,
|
559
|
"transactionContext": transactionContext,
|