作者 陈志颖

refactor:优化分红预算提示信息

@@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
10 10
11 type ApplyForCooperationCommand struct { 11 type ApplyForCooperationCommand struct {
12 // 共创申请描述附件 12 // 共创申请描述附件
13 - CooperationApplicationAttachment []*domain.Attachment `cname:"共创申请描述附件" json:"cooperationApplicationAttachment" valid:"Required"` 13 + CooperationApplicationAttachment []*domain.Attachment `cname:"共创申请描述附件" json:"cooperationApplicationAttachment"`
14 // 共创申请描述 14 // 共创申请描述
15 CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription,omitempty"` 15 CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription,omitempty"`
16 // 申请人ID 16 // 申请人ID
@@ -546,25 +546,25 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -546,25 +546,25 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
546 operator = data 546 operator = data
547 } 547 }
548 548
549 - // 分红订单仓储初始化  
550 - var dividendsOrderRepository domain.DividendsOrderRepository  
551 - if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{  
552 - "transactionContext": transactionContext,  
553 - }); err != nil {  
554 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
555 - } else {  
556 - dividendsOrderRepository = value  
557 - } 549 + //// 分红订单仓储初始化
  550 + //var dividendsOrderRepository domain.DividendsOrderRepository
  551 + //if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
  552 + // "transactionContext": transactionContext,
  553 + //}); err != nil {
  554 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  555 + //} else {
  556 + // dividendsOrderRepository = value
  557 + //}
558 558
559 // 分红退货单仓储初始化 559 // 分红退货单仓储初始化
560 - var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository  
561 - if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{  
562 - "transactionContext": transactionContext,  
563 - }); err != nil {  
564 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
565 - } else {  
566 - dividendsReturnedOrderRepository = value  
567 - } 560 + //var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
  561 + //if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
  562 + // "transactionContext": transactionContext,
  563 + //}); err != nil {
  564 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  565 + //} else {
  566 + // dividendsReturnedOrderRepository = value
  567 + //}
568 568
569 // 订单产品仓储初始化 569 // 订单产品仓储初始化
570 var orderGoodRepository domain.OrderGoodRepository 570 var orderGoodRepository domain.OrderGoodRepository
@@ -610,10 +610,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -610,10 +610,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
610 } 610 }
611 611
612 // 统计成功预算的分红订单 612 // 统计成功预算的分红订单
613 - var estimateSuccessfullyDividendsOrders map[string]int 613 + estimateSuccessfullyDividendsOrders := make(map[string]string)
614 614
615 // 统计预算失败的分红订单 615 // 统计预算失败的分红订单
616 - var estimateFailedDividendsOrders map[string]int 616 + estimateFailedDividendsOrders := make(map[string]string)
617 617
618 // 获取订单产品 618 // 获取订单产品
619 if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{ 619 if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
@@ -621,7 +621,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -621,7 +621,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
621 }); err != nil { 621 }); err != nil {
622 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 622 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
623 } else { 623 } else {
624 - var dividendsEstimates []*domain.DividendsEstimate 624 + dividendsEstimates := make([]*domain.DividendsEstimate, 0)
625 // 统计当前分红预算单数 625 // 统计当前分红预算单数
626 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{ 626 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
627 "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId, 627 "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
@@ -633,28 +633,35 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -633,28 +633,35 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
633 for _, orderGood := range orderGoods { 633 for _, orderGood := range orderGoods {
634 dividendsEstimate := &domain.DividendsEstimate{} 634 dividendsEstimate := &domain.DividendsEstimate{}
635 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 635 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
636 - dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{  
637 - "dividendsOrderNumber": orderGood.DividendsOrderNumber,  
638 - "companyId": orderGood.CompanyId,  
639 - "orgId": orderGood.OrgId,  
640 - })  
641 - if err3 != nil {  
642 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")  
643 - }  
644 - if dividendsOrder == nil {  
645 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))  
646 - } 636 + //dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
  637 + // "dividendsOrderNumber": orderGood.DividendsOrderNumber,
  638 + // "companyId": orderGood.CompanyId,
  639 + // "orgId": orderGood.OrgId,
  640 + //})
  641 + //if err3 != nil {
  642 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
  643 + //}
  644 + //if dividendsOrder == nil {
  645 + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
  646 + //}
647 // 分红订单产品预算 647 // 分红订单产品预算
648 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { 648 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
649 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 649 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
650 } else { 650 } else {
651 for _, dividendsEstimateDetail := range dividendsEstimateDetails { 651 for _, dividendsEstimateDetail := range dividendsEstimateDetails {
  652 + if dividendsEstimateDetail.IsSuccessfully {
652 // 生成分红预算单号 653 // 生成分红预算单号
653 dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate) 654 dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
654 if err != nil { 655 if err != nil {
655 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 656 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
656 } 657 }
  658 +
  659 + // 记录成功的订单号
  660 + estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber
  661 +
  662 + // 统计分红预算单数目
657 countDividendsEstimate = countDividendsEstimate + 1 663 countDividendsEstimate = countDividendsEstimate + 1
  664 +
658 dividendsEstimate = &domain.DividendsEstimate{ 665 dividendsEstimate = &domain.DividendsEstimate{
659 DividendsEstimateId: 0, 666 DividendsEstimateId: 0,
660 DividendsAccountStatus: domain.TO_BE_ACCOUNT, 667 DividendsAccountStatus: domain.TO_BE_ACCOUNT,
@@ -679,31 +686,33 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -679,31 +686,33 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
679 OrderGoodId: orderGood.OrderGoodId, 686 OrderGoodId: orderGood.OrderGoodId,
680 OrderGoodAmount: orderGood.OrderGoodAmount, 687 OrderGoodAmount: orderGood.OrderGoodAmount,
681 } 688 }
  689 +
682 dividendsEstimates = append(dividendsEstimates, dividendsEstimate) 690 dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
  691 + } else {
  692 + // 记录失败的订单号和原因s
  693 + estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
683 } 694 }
684 } 695 }
685 - } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单  
686 - dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber})  
687 - if err != nil {  
688 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
689 - }  
690 - if dividendsReturnedOrder == nil {  
691 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红退货单%s不存在", orderGood.DividendsReturnedOrderNumber))  
692 } 696 }
  697 + } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
693 // 分红退货单产品预算 698 // 分红退货单产品预算
694 if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { 699 if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
695 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 700 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
696 } else { 701 } else {
697 for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails { 702 for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
  703 + if dividendsReturnedEstimateDetail.IsSuccessfully {
698 // 生成分红预算单号 704 // 生成分红预算单号
699 dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate) 705 dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
700 if err != nil { 706 if err != nil {
701 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 707 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
702 } 708 }
  709 +
  710 + // 记录成功的退货单号
  711 + estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber
  712 +
  713 + // 统计生成的预算单数量
703 countDividendsEstimate = countDividendsEstimate + 1 714 countDividendsEstimate = countDividendsEstimate + 1
704 - if err != nil {  
705 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
706 - } 715 +
707 dividendsEstimate = &domain.DividendsEstimate{ 716 dividendsEstimate = &domain.DividendsEstimate{
708 DividendsEstimateId: 0, 717 DividendsEstimateId: 0,
709 DividendsAccountStatus: domain.TO_BE_ACCOUNT, 718 DividendsAccountStatus: domain.TO_BE_ACCOUNT,
@@ -728,7 +737,12 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -728,7 +737,12 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
728 OrderGoodId: orderGood.OrderGoodId, 737 OrderGoodId: orderGood.OrderGoodId,
729 OrderGoodAmount: orderGood.OrderGoodAmount, 738 OrderGoodAmount: orderGood.OrderGoodAmount,
730 } 739 }
  740 +
731 dividendsEstimates = append(dividendsEstimates, dividendsEstimate) 741 dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
  742 + } else {
  743 + // 记录失败的退货单号和原因
  744 + estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
  745 + }
732 } 746 }
733 } 747 }
734 } 748 }
@@ -744,8 +758,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -744,8 +758,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
744 } 758 }
745 // 分析成功和失败原因 759 // 分析成功和失败原因
746 successfullyCount := len(dividendsEstimatesSaved) 760 successfullyCount := len(dividendsEstimatesSaved)
  761 + // 错误原因收集,返回第一个可能的原因
  762 + var failedReason []string
  763 + for _, v := range estimateFailedDividendsOrders {
  764 + failedReason = append(failedReason, v)
  765 + }
747 return map[string]interface{}{ 766 return map[string]interface{}{
748 - "report": fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), ""), 767 + "report": fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReason[0]),
749 }, nil 768 }, nil
750 } 769 }
751 } 770 }
@@ -842,11 +861,20 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -842,11 +861,20 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
842 dividendsEstimateRepository = value 861 dividendsEstimateRepository = value
843 } 862 }
844 863
845 - cooperationContractId, _ := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)  
846 - undertakerUIDs, _ := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids) 864 + cooperationContractId, err := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)
  865 + if err != nil {
  866 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "合约编号类型错误:"+err.Error())
  867 + }
  868 +
  869 + undertakerUIDs, err := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids)
  870 + if err != nil {
  871 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "承接人UID类型错误:"+err.Error())
  872 + }
847 873
848 // 获取共创合约 874 // 获取共创合约
849 - cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": cooperationContractId}) 875 + cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
  876 + "cooperationContractId": cooperationContractId,
  877 + })
850 if err != nil { 878 if err != nil {
851 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 879 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
852 } 880 }
@@ -860,7 +888,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -860,7 +888,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
860 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{ 888 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
861 "companyId": confirmMoneyIncentivesEstimateCommand.CompanyId, 889 "companyId": confirmMoneyIncentivesEstimateCommand.CompanyId,
862 }) 890 })
  891 +
  892 + // 分红预算单统计
863 var countDividendsEstimate int64 893 var countDividendsEstimate int64
  894 +
864 // 共创合约预算 895 // 共创合约预算
865 if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil { 896 if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil {
866 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) 897 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
@@ -871,7 +902,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -871,7 +902,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
871 if err != nil { 902 if err != nil {
872 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 903 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
873 } 904 }
  905 +
  906 + // 统计生成的预算单数目
874 countDividendsEstimate = countDividendsEstimate + 1 907 countDividendsEstimate = countDividendsEstimate + 1
  908 +
875 dividendsEstimate := &domain.DividendsEstimate{ 909 dividendsEstimate := &domain.DividendsEstimate{
876 DividendsEstimateId: 0, 910 DividendsEstimateId: 0,
877 DividendsAccountStatus: domain.TO_BE_ACCOUNT, 911 DividendsAccountStatus: domain.TO_BE_ACCOUNT,
@@ -894,6 +928,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -894,6 +928,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
894 DeletedAt: time.Time{}, 928 DeletedAt: time.Time{},
895 UpdatedAt: time.Time{}, 929 UpdatedAt: time.Time{},
896 } 930 }
  931 +
897 dividendsEstimates = append(dividendsEstimates, dividendsEstimate) 932 dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
898 } 933 }
899 dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates) 934 dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates)
@@ -12,6 +12,9 @@ type DividendsEstimateDetail struct { @@ -12,6 +12,9 @@ type DividendsEstimateDetail struct {
12 DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 12 DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型
13 DividendsStage int32 `json:"dividendsStage"` // 分红阶段 13 DividendsStage int32 `json:"dividendsStage"` // 分红阶段
14 DividendsAmount float64 `json:"dividendsAmount"` // 分红金额 14 DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
  15 + OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号
  16 + IsSuccessfully bool `json:"isSuccessfully"` // 是否预算成功
  17 + Reason string `json:"reason"` // 错误原因
15 } 18 }
16 19
17 // GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号 20 // GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
@@ -2,7 +2,6 @@ package domain_service @@ -2,7 +2,6 @@ package domain_service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "github.com/linmadan/egglib-go/core/application"  
6 coreDomain "github.com/linmadan/egglib-go/core/domain" 5 coreDomain "github.com/linmadan/egglib-go/core/domain"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
8 "github.com/shopspring/decimal" 7 "github.com/shopspring/decimal"
@@ -57,29 +56,84 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -57,29 +56,84 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
57 // 获取合约 56 // 获取合约
58 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{ 57 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
59 "cooperationContractNumber": orderGood.CooperationContractNumber, 58 "cooperationContractNumber": orderGood.CooperationContractNumber,
  59 + "companyId": orderGood.CompanyId,
  60 + "orgId": orderGood.OrgId,
60 }) 61 })
61 if err != nil { 62 if err != nil {
62 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 63 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  64 + DividendsUser: nil,
  65 + DividendsParticipateType: 0,
  66 + DividendsStage: 0,
  67 + DividendsAmount: 0,
  68 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  69 + IsSuccessfully: false,
  70 + Reason: "共创合约错误",
  71 + })
  72 + continue
  73 + //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
63 } 74 }
64 if cooperationContract == nil { 75 if cooperationContract == nil {
65 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber)) 76 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  77 + DividendsUser: nil,
  78 + DividendsParticipateType: 0,
  79 + DividendsStage: 0,
  80 + DividendsAmount: 0,
  81 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  82 + IsSuccessfully: false,
  83 + Reason: "共创合约" + orderGood.CooperationContractNumber + "不存在",
  84 + })
  85 + continue
  86 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
66 } 87 }
67 88
68 // 获取共创项目 89 // 获取共创项目
69 cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{ 90 cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
70 "cooperationProjectNumber": cooperationContract.CooperationProjectNumber, 91 "cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
  92 + "companyId": cooperationContract.Company.CompanyId,
  93 + "orgId": cooperationContract.Org.OrgId,
  94 + "notPause": true,
71 }) 95 })
72 if err != nil { 96 if err != nil {
73 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 97 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  98 + DividendsUser: nil,
  99 + DividendsParticipateType: 0,
  100 + DividendsStage: 0,
  101 + DividendsAmount: 0,
  102 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  103 + IsSuccessfully: false,
  104 + Reason: "共创项目" + orderGood.CooperationContractNumber + "查询错误",
  105 + })
  106 + continue
  107 + //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
74 } 108 }
75 if cooperationProject == nil { 109 if cooperationProject == nil {
76 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber)) 110 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  111 + DividendsUser: nil,
  112 + DividendsParticipateType: 0,
  113 + DividendsStage: 0,
  114 + DividendsAmount: 0,
  115 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  116 + IsSuccessfully: false,
  117 + Reason: "共创项目" + orderGood.CooperationContractNumber + "已结束或不存在",
  118 + })
  119 + continue
  120 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber))
77 } 121 }
78 122
79 // 校验合约关联的项目是否已结束 123 // 校验合约关联的项目是否已结束
80 - if cooperationProject.Status == 2 {  
81 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s已结束", cooperationContract.CooperationProjectNumber))  
82 - } 124 + //if cooperationProject.Status == 2 {
  125 + // dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  126 + // DividendsUser: nil,
  127 + // DividendsParticipateType: 0,
  128 + // DividendsStage: 0,
  129 + // DividendsAmount: 0,
  130 + // OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  131 + // IsSuccessfully: false,
  132 + // Reason: "共创项目" + orderGood.CooperationContractNumber + "已结束",
  133 + // })
  134 + // continue
  135 + // //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s已结束", cooperationContract.CooperationProjectNumber))
  136 + //}
83 137
84 if orderGood.DividendsOrderNumber != "" { // 获取分红订单 138 if orderGood.DividendsOrderNumber != "" { // 获取分红订单
85 // 获取分红订单 139 // 获取分红订单
@@ -89,10 +143,30 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -89,10 +143,30 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
89 "orgId": orderGood.OrgId, 143 "orgId": orderGood.OrgId,
90 }) 144 })
91 if err2 != nil { 145 if err2 != nil {
92 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在") 146 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  147 + DividendsUser: nil,
  148 + DividendsParticipateType: 0,
  149 + DividendsStage: 0,
  150 + DividendsAmount: 0,
  151 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  152 + IsSuccessfully: false,
  153 + Reason: "分红订单" + orderGood.DividendsOrderNumber + "查询错误",
  154 + })
  155 + continue
  156 + //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
93 } 157 }
94 if dividendsOrder == nil { 158 if dividendsOrder == nil {
95 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber)) 159 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  160 + DividendsUser: nil,
  161 + DividendsParticipateType: 0,
  162 + DividendsStage: 0,
  163 + DividendsAmount: 0,
  164 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  165 + IsSuccessfully: false,
  166 + Reason: "分红订单" + orderGood.DividendsOrderNumber + "不存在",
  167 + })
  168 + continue
  169 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
96 } 170 }
97 171
98 // 匹配分红规则 172 // 匹配分红规则
@@ -104,7 +178,17 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -104,7 +178,17 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
104 } 178 }
105 } 179 }
106 if dividendsIncentivesRuleMatched == nil { 180 if dividendsIncentivesRuleMatched == nil {
107 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "未匹配到分红规则") 181 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  182 + DividendsUser: nil,
  183 + DividendsParticipateType: 0,
  184 + DividendsStage: 0,
  185 + DividendsAmount: 0,
  186 + OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
  187 + IsSuccessfully: false,
  188 + Reason: "未匹配到分红规则",
  189 + })
  190 + continue
  191 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "未匹配到分红规则")
108 } 192 }
109 193
110 // 计算分红 194 // 计算分红
@@ -130,6 +214,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -130,6 +214,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
130 DividendsParticipateType: domain.UNDERTAKER, 214 DividendsParticipateType: domain.UNDERTAKER,
131 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, 215 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
132 DividendsAmount: undertakerDividendsAmount, 216 DividendsAmount: undertakerDividendsAmount,
  217 + OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
  218 + IsSuccessfully: true,
133 }) 219 })
134 // 添加推荐人分红预算信息详情 220 // 添加推荐人分红预算信息详情
135 if undertaker.Referrer != nil { 221 if undertaker.Referrer != nil {
@@ -151,6 +237,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -151,6 +237,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
151 DividendsParticipateType: domain.REFERRER, 237 DividendsParticipateType: domain.REFERRER,
152 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, 238 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
153 DividendsAmount: referrerDividendsAmount, 239 DividendsAmount: referrerDividendsAmount,
  240 + OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
  241 + IsSuccessfully: true,
154 }) 242 })
155 } 243 }
156 // 添加关联业务员分红预算信息详情 244 // 添加关联业务员分红预算信息详情
@@ -173,19 +261,43 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -173,19 +261,43 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
173 DividendsParticipateType: domain.SALESMAN, 261 DividendsParticipateType: domain.SALESMAN,
174 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, 262 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
175 DividendsAmount: salesmanDividendsAmount, 263 DividendsAmount: salesmanDividendsAmount,
  264 + OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
  265 + IsSuccessfully: true,
176 }) 266 })
177 } 267 }
178 } 268 }
179 } 269 }
180 - } else if orderGood.DividendsReturnedOrderNumber != "" { // 获取分红退货单 270 + } else if orderGood.DividendsReturnedOrderNumber != "" { // 获取退货单
181 dividendsReturnedOrder, err3 := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{ 271 dividendsReturnedOrder, err3 := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
182 "dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber, 272 "dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber,
  273 + "companyId": orderGood.CompanyId,
  274 + "orgId": orderGood.OrgId,
183 }) 275 })
184 if err3 != nil { 276 if err3 != nil {
185 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单不存在") 277 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  278 + DividendsUser: nil,
  279 + DividendsParticipateType: 0,
  280 + DividendsStage: 0,
  281 + DividendsAmount: 0,
  282 + OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
  283 + IsSuccessfully: false,
  284 + Reason: "退货单" + orderGood.DividendsReturnedOrderNumber + "不存在",
  285 + })
  286 + continue
  287 + //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单不存在")
186 } 288 }
187 if dividendsReturnedOrder == nil { 289 if dividendsReturnedOrder == nil {
188 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber)) 290 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  291 + DividendsUser: nil,
  292 + DividendsParticipateType: 0,
  293 + DividendsStage: 0,
  294 + DividendsAmount: 0,
  295 + OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
  296 + IsSuccessfully: false,
  297 + Reason: "退货单" + orderGood.DividendsReturnedOrderNumber + "不存在",
  298 + })
  299 + continue
  300 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
189 } 301 }
190 // 匹配分红规则 302 // 匹配分红规则
191 var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule 303 var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
@@ -217,6 +329,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -217,6 +329,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
217 DividendsParticipateType: domain.UNDERTAKER, 329 DividendsParticipateType: domain.UNDERTAKER,
218 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, 330 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
219 DividendsAmount: -undertakerDividendsAmount, 331 DividendsAmount: -undertakerDividendsAmount,
  332 + OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsOrderNumber,
  333 + IsSuccessfully: true,
220 }) 334 })
221 // 添加推荐人分红退货预算信息详情 335 // 添加推荐人分红退货预算信息详情
222 if undertaker.Referrer != nil { 336 if undertaker.Referrer != nil {
@@ -238,6 +352,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -238,6 +352,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
238 DividendsParticipateType: domain.REFERRER, 352 DividendsParticipateType: domain.REFERRER,
239 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, 353 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
240 DividendsAmount: -referrerDividendsAmount, 354 DividendsAmount: -referrerDividendsAmount,
  355 + OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsOrderNumber,
  356 + IsSuccessfully: true,
241 }) 357 })
242 } 358 }
243 // 添加关联业务员分红退货预算信息详情 359 // 添加关联业务员分红退货预算信息详情
@@ -260,6 +376,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -260,6 +376,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
260 DividendsParticipateType: domain.SALESMAN, 376 DividendsParticipateType: domain.SALESMAN,
261 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, 377 DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
262 DividendsAmount: -salesmanDividendsAmount, 378 DividendsAmount: -salesmanDividendsAmount,
  379 + OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsOrderNumber,
  380 + IsSuccessfully: true,
263 }) 381 })
264 } 382 }
265 } 383 }
@@ -17,16 +17,8 @@ type ConfirmMoneyIncentivesEstimateService struct { @@ -17,16 +17,8 @@ type ConfirmMoneyIncentivesEstimateService struct {
17 } 17 }
18 18
19 func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *domain.CooperationContract, stage int32, undertakerUIDs []int64) ([]*service.DividendsEstimateDetail, error) { 19 func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *domain.CooperationContract, stage int32, undertakerUIDs []int64) ([]*service.DividendsEstimateDetail, error) {
20 - //var dividendsEstimateRepository domain.DividendsEstimateRepository // 分红预算单仓储  
21 var dividendsEstimateDao *dao.DividendsEstimateDao // 分红预算DAO 20 var dividendsEstimateDao *dao.DividendsEstimateDao // 分红预算DAO
22 21
23 - // 分红预算单仓储初始化  
24 - //if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {  
25 - // return nil, err  
26 - //} else {  
27 - // dividendsEstimateRepository = repo  
28 - //}  
29 -  
30 // 分红预算DAO初始化 22 // 分红预算DAO初始化
31 if estimateDao, err := dao.NewDividendsEstimateDao(domainService.transactionContext); err != nil { 23 if estimateDao, err := dao.NewDividendsEstimateDao(domainService.transactionContext); err != nil {
32 return nil, err 24 return nil, err
@@ -220,6 +220,9 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string] @@ -220,6 +220,9 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
220 if cooperationProjectId, ok := queryOptions["cooperationProjectId"]; ok && cooperationProjectId.(int64) != 0 { 220 if cooperationProjectId, ok := queryOptions["cooperationProjectId"]; ok && cooperationProjectId.(int64) != 0 {
221 query.Where("cooperation_project.cooperation_project_id = ?", cooperationProjectId) 221 query.Where("cooperation_project.cooperation_project_id = ?", cooperationProjectId)
222 } 222 }
  223 + if notPause, ok := queryOptions["notPause"]; ok && notPause.(bool) != false {
  224 + query.Where("status <> ?", 2)
  225 + }
223 if err := query.First(); err != nil { 226 if err := query.First(); err != nil {
224 if err.Error() == "pg: no rows in result set" { 227 if err.Error() == "pg: no rows in result set" {
225 return nil, fmt.Errorf("共创项目不存在") 228 return nil, fmt.Errorf("共创项目不存在")
@@ -195,6 +195,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do @@ -195,6 +195,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
195 UpdatedAt: dividendsEstimate.UpdatedAt, 195 UpdatedAt: dividendsEstimate.UpdatedAt,
196 }) 196 })
197 } 197 }
  198 + if len(dividendsEstimateModels) > 0 {
198 if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil { 199 if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {
199 return nil, err 200 return nil, err
200 } 201 }
@@ -207,6 +208,8 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do @@ -207,6 +208,8 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
207 } 208 }
208 } 209 }
209 return dividendsEstimatesSaved, nil 210 return dividendsEstimatesSaved, nil
  211 + }
  212 + return nil, nil
210 } 213 }
211 214
212 func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) { 215 func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) {