作者 陈志颖

refactor:优化分红预算

@@ -649,16 +649,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -649,16 +649,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
649 cooperationContractRepository = value 649 cooperationContractRepository = value
650 } 650 }
651 651
652 - // 共创项目仓储初始化  
653 - //var cooperationProjectRepository domain.CooperationProjectRepository  
654 - //if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{  
655 - // "transactionContext": transactionContext,  
656 - //}); err != nil {  
657 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
658 - //} else {  
659 - // cooperationProjectRepository = value  
660 - //}  
661 -  
662 // 初始化确认业绩激励分红预算领域服务 652 // 初始化确认业绩激励分红预算领域服务
663 var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService 653 var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
664 if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{ 654 if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
@@ -672,26 +662,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -672,26 +662,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
672 }) 662 })
673 } 663 }
674 664
675 - // 查询共创项目  
676 - //cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)  
677 - //if count, cooperationProjectsFound, err := cooperationProjectRepository.Find(map[string]interface{}{  
678 - // "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,  
679 - // "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,  
680 - // "offsetLimit": false,  
681 - //}); err != nil {  
682 - // return nil, err  
683 - //} else {  
684 - // if count > 0 {  
685 - // for _, cooperationProjectFound := range cooperationProjectsFound {  
686 - // cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound  
687 - // }  
688 - // }  
689 - //}  
690 - //  
691 - //log.Logger.Info("查询共创项目", map[string]interface{}{  
692 - // "cooperationProjectsMap": cooperationProjectsMap,  
693 - //})  
694 -  
695 // 统计成功预算的分红订单 665 // 统计成功预算的分红订单
696 estimateSuccessfullyDividendsOrders := make(map[string]string) 666 estimateSuccessfullyDividendsOrders := make(map[string]string)
697 667
@@ -716,27 +686,30 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -716,27 +686,30 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
716 686
717 newCooperationContractNumbers := utils.RemoveDuplicationString(cooperationContractNumbers) 687 newCooperationContractNumbers := utils.RemoveDuplicationString(cooperationContractNumbers)
718 688
719 - // 查询共创合约  
720 cooperationContractsMap := make(map[string]*domain.CooperationContract, 0) 689 cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
721 - if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{  
722 - "cooperationContractNumbers": newCooperationContractNumbers,  
723 - "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,  
724 - "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,  
725 - "offsetLimit": false,  
726 - }); err != nil {  
727 - return nil, err  
728 - } else {  
729 - if count > 0 {  
730 - for _, cooperationContractFound := range cooperationContractsFound {  
731 - cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound 690 +
  691 + // 查询共创合约
  692 + if len(newCooperationContractNumbers) > 0 {
  693 + if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
  694 + "cooperationContractNumbers": newCooperationContractNumbers,
  695 + "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
  696 + "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
  697 + "offsetLimit": false,
  698 + }); err != nil {
  699 + return nil, err
  700 + } else {
  701 + if count > 0 {
  702 + for _, cooperationContractFound := range cooperationContractsFound {
  703 + cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
  704 + }
732 } 705 }
733 } 706 }
  707 + } else {
  708 + return map[string]interface{}{
  709 + "report": fmt.Sprintf("已完成0单订单分红预算,生成0单分红预算,失败原因:产品未关联合约"),
  710 + }, nil
734 } 711 }
735 712
736 - log.Logger.Info("查询共创合约", map[string]interface{}{  
737 - "cooperationContractsMap": cooperationContractsMap,  
738 - })  
739 -  
740 // 统计当前企业分红预算单数 713 // 统计当前企业分红预算单数
741 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{ 714 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
742 "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId, 715 "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
@@ -747,129 +720,241 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -747,129 +720,241 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
747 720
748 var countDividendsEstimate int64 721 var countDividendsEstimate int64
749 722
  723 + orderGoodsToConfirm := make([]*domain.OrderGood, 0)
  724 + returnedOrderGoodsToConfirm := make([]*domain.OrderGood, 0)
  725 +
750 for _, orderGood := range orderGoods { 726 for _, orderGood := range orderGoods {
751 - log.Logger.Info("hello 1")  
752 - dividendsEstimate := &domain.DividendsEstimate{}  
753 - if orderGood.DividendsOrderNumber != "" { // 查询分红订单  
754 - orderGoodsToConfirm := make([]*domain.OrderGood, 0) 727 + if orderGood.DividendsOrderNumber != "" {
755 orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood) 728 orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
756 - // 分红订单产品预算  
757 - if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {  
758 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
759 - } else {  
760 - for _, dividendsEstimateDetail := range dividendsEstimateDetails {  
761 - log.Logger.Info("hello 2")  
762 - if dividendsEstimateDetail.IsSuccessfully {  
763 - // 生成分红预算单号  
764 - dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)  
765 - if err != nil {  
766 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
767 - } 729 + } else if orderGood.DividendsReturnedOrderNumber != "" {
  730 + returnedOrderGoodsToConfirm = append(returnedOrderGoodsToConfirm, orderGood)
  731 + }
  732 + }
768 733
769 - // 记录成功的订单号  
770 - estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber  
771 -  
772 - // 统计分红预算单数目  
773 - countDividendsEstimate = countDividendsEstimate + 1  
774 -  
775 - dividendsEstimate = &domain.DividendsEstimate{  
776 - DividendsEstimateId: 0,  
777 - DividendsAccountStatus: domain.TO_BE_ACCOUNT,  
778 - DividendsAmount: dividendsEstimateDetail.DividendsAmount,  
779 - DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,  
780 - DividendsEstimateTime: time.Now(),  
781 - DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,  
782 - DividendsType: domain.ORDER_DIVIDENDS,  
783 - DividendsTypeName: "订单分红",  
784 - OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,  
785 - CooperationContractNumber: orderGood.CooperationContractNumber,  
786 - DividendsUser: dividendsEstimateDetail.DividendsUser,  
787 - DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,  
788 - DividendsStage: dividendsEstimateDetail.DividendsStage,  
789 - Org: organization,  
790 - Company: company,  
791 - Operator: operator,  
792 - OperateTime: time.Time{},  
793 - IsCanceled: false,  
794 - CreatedAt: time.Now(),  
795 - DeletedAt: time.Time{},  
796 - UpdatedAt: time.Time{},  
797 - OrderGoodId: orderGood.OrderGoodId,  
798 - OrderGoodAmount: orderGood.OrderGoodAmount,  
799 - PaymentStatus: int32(1),  
800 - CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,  
801 - } 734 + if len(orderGoodsToConfirm) > 0 { // 分红订单产品预算
  735 + if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
  736 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  737 + } else {
  738 + for _, dividendsEstimateDetail := range dividendsEstimateDetails {
  739 + if dividendsEstimateDetail.IsSuccessfully {
  740 + // 生成分红预算单号
  741 + dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
  742 + if err != nil {
  743 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  744 + }
802 745
803 - dividendsEstimates = append(dividendsEstimates, dividendsEstimate)  
804 - } else {  
805 - // 记录失败的订单号和原因  
806 - estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason 746 + // 记录成功的订单号
  747 + estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber
  748 +
  749 + // 统计分红预算单数目
  750 + countDividendsEstimate = countDividendsEstimate + 1
  751 +
  752 + dividendsEstimate := &domain.DividendsEstimate{
  753 + DividendsEstimateId: 0,
  754 + DividendsAccountStatus: domain.TO_BE_ACCOUNT,
  755 + DividendsAmount: dividendsEstimateDetail.DividendsAmount,
  756 + DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
  757 + DividendsEstimateTime: time.Now(),
  758 + DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
  759 + DividendsType: domain.ORDER_DIVIDENDS,
  760 + DividendsTypeName: "订单分红",
  761 + OrderOrReturnedOrderNum: dividendsEstimateDetail.OrderOrReturnedOrderNumber,
  762 + CooperationContractNumber: dividendsEstimateDetail.CooperationContractNumber,
  763 + DividendsUser: dividendsEstimateDetail.DividendsUser,
  764 + DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
  765 + DividendsStage: dividendsEstimateDetail.DividendsStage,
  766 + Org: organization,
  767 + Company: company,
  768 + Operator: operator,
  769 + OperateTime: time.Time{},
  770 + IsCanceled: false,
  771 + CreatedAt: time.Now(),
  772 + DeletedAt: time.Time{},
  773 + UpdatedAt: time.Time{},
  774 + OrderGoodId: dividendsEstimateDetail.OrderGoodId,
  775 + OrderGoodAmount: dividendsEstimateDetail.OrderGoodAmount,
  776 + PaymentStatus: int32(1),
  777 + CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
807 } 778 }
  779 +
  780 + dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
  781 + } else {
  782 + // 记录失败的订单号和原因
  783 + estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
808 } 784 }
809 } 785 }
810 - } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单  
811 - log.Logger.Info("hello 3")  
812 - orderGoodsToConfirm := make([]*domain.OrderGood, 0)  
813 - orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)  
814 - // 分红退货单产品预算  
815 - if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {  
816 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
817 - } else {  
818 - for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {  
819 - if dividendsReturnedEstimateDetail.IsSuccessfully {  
820 - // 生成分红预算单号  
821 - dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)  
822 - if err != nil {  
823 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
824 - }  
825 -  
826 - // 记录成功的退货单号  
827 - estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber  
828 -  
829 - // 统计生成的预算单数量  
830 - countDividendsEstimate = countDividendsEstimate + 1  
831 -  
832 - dividendsEstimate = &domain.DividendsEstimate{  
833 - DividendsEstimateId: 0,  
834 - DividendsAccountStatus: domain.TO_BE_ACCOUNT,  
835 - DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,  
836 - DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,  
837 - DividendsEstimateTime: time.Now(),  
838 - DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,  
839 - DividendsType: domain.RETURN_WRITE_OFF,  
840 - DividendsTypeName: "退货冲销",  
841 - OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,  
842 - CooperationContractNumber: orderGood.CooperationContractNumber,  
843 - DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,  
844 - DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,  
845 - DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,  
846 - Org: organization,  
847 - Company: company,  
848 - Operator: operator,  
849 - OperateTime: time.Time{},  
850 - IsCanceled: false,  
851 - CreatedAt: time.Now(),  
852 - DeletedAt: time.Time{},  
853 - UpdatedAt: time.Time{},  
854 - OrderGoodId: orderGood.OrderGoodId,  
855 - OrderGoodAmount: orderGood.OrderGoodAmount,  
856 - PaymentStatus: int32(1),  
857 - CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,  
858 - } 786 + }
  787 + } else if len(returnedOrderGoodsToConfirm) > 0 { // 退货单产品预算
  788 + if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(returnedOrderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
  789 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  790 + } else {
  791 + for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
  792 + if dividendsReturnedEstimateDetail.IsSuccessfully {
  793 + // 生成分红预算单号
  794 + dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
  795 + if err != nil {
  796 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  797 + }
859 798
860 - dividendsEstimates = append(dividendsEstimates, dividendsEstimate)  
861 - } else {  
862 - // 记录失败的退货单号和原因  
863 - estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason 799 + // 记录成功的退货单号
  800 + estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber
  801 +
  802 + // 统计生成的预算单数量
  803 + countDividendsEstimate = countDividendsEstimate + 1
  804 +
  805 + dividendsEstimate := &domain.DividendsEstimate{
  806 + DividendsEstimateId: 0,
  807 + DividendsAccountStatus: domain.TO_BE_ACCOUNT,
  808 + DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
  809 + DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
  810 + DividendsEstimateTime: time.Now(),
  811 + DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
  812 + DividendsType: domain.RETURN_WRITE_OFF,
  813 + DividendsTypeName: "退货冲销",
  814 + OrderOrReturnedOrderNum: dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber,
  815 + CooperationContractNumber: dividendsReturnedEstimateDetail.CooperationContractNumber,
  816 + DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
  817 + DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
  818 + DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
  819 + Org: organization,
  820 + Company: company,
  821 + Operator: operator,
  822 + OperateTime: time.Time{},
  823 + IsCanceled: false,
  824 + CreatedAt: time.Now(),
  825 + DeletedAt: time.Time{},
  826 + UpdatedAt: time.Time{},
  827 + OrderGoodId: dividendsReturnedEstimateDetail.OrderGoodId,
  828 + OrderGoodAmount: dividendsReturnedEstimateDetail.OrderGoodAmount,
  829 + PaymentStatus: int32(1),
  830 + CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
864 } 831 }
  832 +
  833 + dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
  834 + } else {
  835 + // 记录失败的退货单号和原因
  836 + estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
865 } 837 }
866 } 838 }
867 } 839 }
868 } 840 }
869 841
870 - log.Logger.Info("新增的分红预算单", map[string]interface{}{  
871 - "dividendsEstimates": dividendsEstimates,  
872 - }) 842 + //for _, orderGood := range orderGoods {
  843 + // dividendsEstimate := &domain.DividendsEstimate{}
  844 + // if orderGood.DividendsOrderNumber != "" { // 查询分红订单
  845 + // orderGoodsToConfirm := make([]*domain.OrderGood, 0)
  846 + // orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
  847 + // // 分红订单产品预算
  848 + // if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
  849 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  850 + // } else {
  851 + // for _, dividendsEstimateDetail := range dividendsEstimateDetails {
  852 + // if dividendsEstimateDetail.IsSuccessfully {
  853 + // // 生成分红预算单号
  854 + // dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
  855 + // if err != nil {
  856 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  857 + // }
  858 + //
  859 + // // 记录成功的订单号
  860 + // estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber
  861 + //
  862 + // // 统计分红预算单数目
  863 + // countDividendsEstimate = countDividendsEstimate + 1
  864 + //
  865 + // dividendsEstimate = &domain.DividendsEstimate{
  866 + // DividendsEstimateId: 0,
  867 + // DividendsAccountStatus: domain.TO_BE_ACCOUNT,
  868 + // DividendsAmount: dividendsEstimateDetail.DividendsAmount,
  869 + // DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
  870 + // DividendsEstimateTime: time.Now(),
  871 + // DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
  872 + // DividendsType: domain.ORDER_DIVIDENDS,
  873 + // DividendsTypeName: "订单分红",
  874 + // OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
  875 + // CooperationContractNumber: orderGood.CooperationContractNumber,
  876 + // DividendsUser: dividendsEstimateDetail.DividendsUser,
  877 + // DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
  878 + // DividendsStage: dividendsEstimateDetail.DividendsStage,
  879 + // Org: organization,
  880 + // Company: company,
  881 + // Operator: operator,
  882 + // OperateTime: time.Time{},
  883 + // IsCanceled: false,
  884 + // CreatedAt: time.Now(),
  885 + // DeletedAt: time.Time{},
  886 + // UpdatedAt: time.Time{},
  887 + // OrderGoodId: orderGood.OrderGoodId,
  888 + // OrderGoodAmount: orderGood.OrderGoodAmount,
  889 + // PaymentStatus: int32(1),
  890 + // CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
  891 + // }
  892 + //
  893 + // dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
  894 + // } else {
  895 + // // 记录失败的订单号和原因
  896 + // estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
  897 + // }
  898 + // }
  899 + // }
  900 + // } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
  901 + // orderGoodsToConfirm := make([]*domain.OrderGood, 0)
  902 + // orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
  903 + // // 分红退货单产品预算
  904 + // if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
  905 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  906 + // } else {
  907 + // for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
  908 + // if dividendsReturnedEstimateDetail.IsSuccessfully {
  909 + // // 生成分红预算单号
  910 + // dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
  911 + // if err != nil {
  912 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  913 + // }
  914 + //
  915 + // // 记录成功的退货单号
  916 + // estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber
  917 + //
  918 + // // 统计生成的预算单数量
  919 + // countDividendsEstimate = countDividendsEstimate + 1
  920 + //
  921 + // dividendsEstimate = &domain.DividendsEstimate{
  922 + // DividendsEstimateId: 0,
  923 + // DividendsAccountStatus: domain.TO_BE_ACCOUNT,
  924 + // DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
  925 + // DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
  926 + // DividendsEstimateTime: time.Now(),
  927 + // DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
  928 + // DividendsType: domain.RETURN_WRITE_OFF,
  929 + // DividendsTypeName: "退货冲销",
  930 + // OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
  931 + // CooperationContractNumber: orderGood.CooperationContractNumber,
  932 + // DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
  933 + // DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
  934 + // DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
  935 + // Org: organization,
  936 + // Company: company,
  937 + // Operator: operator,
  938 + // OperateTime: time.Time{},
  939 + // IsCanceled: false,
  940 + // CreatedAt: time.Now(),
  941 + // DeletedAt: time.Time{},
  942 + // UpdatedAt: time.Time{},
  943 + // OrderGoodId: orderGood.OrderGoodId,
  944 + // OrderGoodAmount: orderGood.OrderGoodAmount,
  945 + // PaymentStatus: int32(1),
  946 + // CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
  947 + // }
  948 + //
  949 + // dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
  950 + // } else {
  951 + // // 记录失败的退货单号和原因
  952 + // estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
  953 + // }
  954 + // }
  955 + // }
  956 + // }
  957 + //}
873 958
874 if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil { 959 if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
875 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 960 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -918,14 +1003,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -918,14 +1003,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
918 } 1003 }
919 } 1004 }
920 1005
921 - log.Logger.Info("分红订单", map[string]interface{}{  
922 - "dividendsOrderNumbers": dividendsOrderNumbers,  
923 - })  
924 -  
925 - log.Logger.Info("分红退货单", map[string]interface{}{  
926 - "dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,  
927 - })  
928 -  
929 // 查找分红订单 1006 // 查找分红订单
930 if len(dividendsOrderNumbers) > 0 { 1007 if len(dividendsOrderNumbers) > 0 {
931 if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{ 1008 if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{
@@ -5,8 +5,8 @@ import "os" @@ -5,8 +5,8 @@ import "os"
5 const SERVICE_NAME = "allied-creation-cooperation" 5 const SERVICE_NAME = "allied-creation-cooperation"
6 6
7 // LOG_TYPE 日志相关设置 7 // LOG_TYPE 日志相关设置
8 -var LOG_TYPE = "console" // file, console, es  
9 -var LOG_FRAMEWORK = "logrus" // beego logrus 8 +var LOG_TYPE = "console" // file, console, es
  9 +var LOG_FRAMEWORK = "beego" // beego logrus
10 var LOG_LEVEL = "debug" 10 var LOG_LEVEL = "debug"
11 var LOG_FILE = "app.log" 11 var LOG_FILE = "app.log"
12 var LOG_PREFIX = "[allied-creation-cooperation]" 12 var LOG_PREFIX = "[allied-creation-cooperation]"
@@ -17,6 +17,9 @@ type DividendsEstimateDetail struct { @@ -17,6 +17,9 @@ type DividendsEstimateDetail struct {
17 IsSuccessfully bool `json:"isSuccessfully"` // 是否预算成功 17 IsSuccessfully bool `json:"isSuccessfully"` // 是否预算成功
18 Reason string `json:"reason"` // 错误原因 18 Reason string `json:"reason"` // 错误原因
19 CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId"` // 承接人记录ID 19 CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId"` // 承接人记录ID
  20 + CooperationContractNumber string `json:"cooperationContractNumber"`
  21 + OrderGoodId int64 `json:"orderGoodId"`
  22 + OrderGoodAmount float64 `json:"orderGoodAmount"`
20 } 23 }
21 24
22 // GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号 25 // GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
@@ -97,26 +97,6 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -97,26 +97,6 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
97 } 97 }
98 } 98 }
99 99
100 - // 判断共创项目是否存在  
101 - //if _, ok := cooperationProjectsMap[cooperationContract.CooperationProjectNumber]; !ok {  
102 - // var orderNumber string  
103 - // if orderGood.DividendsOrderNumber != "" {  
104 - // orderNumber = orderGood.DividendsOrderNumber  
105 - // } else {  
106 - // orderNumber = orderGood.DividendsReturnedOrderNumber  
107 - // }  
108 - // dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{  
109 - // DividendsUser: nil,  
110 - // DividendsParticipateType: 0,  
111 - // DividendsStage: 0,  
112 - // DividendsAmount: 0,  
113 - // OrderOrReturnedOrderNumber: orderNumber,  
114 - // IsSuccessfully: false,  
115 - // Reason: "共创项目" + cooperationContract.CooperationProjectNumber + "已结束或不存在",  
116 - // })  
117 - // continue  
118 - //}  
119 -  
120 if orderGood.DividendsOrderNumber != "" { // 获取分红订单 100 if orderGood.DividendsOrderNumber != "" { // 获取分红订单
121 // 获取分红订单 101 // 获取分红订单
122 dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{ 102 dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
@@ -199,6 +179,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -199,6 +179,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
199 IsSuccessfully: true, 179 IsSuccessfully: true,
200 CooperationContractUndertakerId: undertaker.UndertakerId, 180 CooperationContractUndertakerId: undertaker.UndertakerId,
201 DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage, 181 DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage,
  182 + CooperationContractNumber: orderGood.CooperationContractNumber,
  183 + OrderGoodId: orderGood.OrderGoodId,
  184 + OrderGoodAmount: orderGood.OrderGoodAmount,
202 }) 185 })
203 } 186 }
204 // 添加推荐人分红预算信息详情 187 // 添加推荐人分红预算信息详情
@@ -226,6 +209,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -226,6 +209,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
226 IsSuccessfully: true, 209 IsSuccessfully: true,
227 CooperationContractUndertakerId: undertaker.UndertakerId, 210 CooperationContractUndertakerId: undertaker.UndertakerId,
228 DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage, 211 DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage,
  212 + CooperationContractNumber: orderGood.CooperationContractNumber,
  213 + OrderGoodId: orderGood.OrderGoodId,
  214 + OrderGoodAmount: orderGood.OrderGoodAmount,
229 }) 215 })
230 } 216 }
231 } 217 }
@@ -254,6 +240,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -254,6 +240,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
254 IsSuccessfully: true, 240 IsSuccessfully: true,
255 CooperationContractUndertakerId: undertaker.UndertakerId, 241 CooperationContractUndertakerId: undertaker.UndertakerId,
256 DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage, 242 DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage,
  243 + CooperationContractNumber: orderGood.CooperationContractNumber,
  244 + OrderGoodId: orderGood.OrderGoodId,
  245 + OrderGoodAmount: orderGood.OrderGoodAmount,
257 }) 246 })
258 } 247 }
259 } 248 }
@@ -337,6 +326,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -337,6 +326,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
337 IsSuccessfully: true, 326 IsSuccessfully: true,
338 CooperationContractUndertakerId: undertaker.UndertakerId, 327 CooperationContractUndertakerId: undertaker.UndertakerId,
339 DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage, 328 DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage,
  329 + CooperationContractNumber: orderGood.CooperationContractNumber,
  330 + OrderGoodId: orderGood.OrderGoodId,
  331 + OrderGoodAmount: orderGood.OrderGoodAmount,
340 }) 332 })
341 } 333 }
342 334
@@ -365,6 +357,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -365,6 +357,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
365 IsSuccessfully: true, 357 IsSuccessfully: true,
366 CooperationContractUndertakerId: undertaker.UndertakerId, 358 CooperationContractUndertakerId: undertaker.UndertakerId,
367 DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage, 359 DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage,
  360 + CooperationContractNumber: orderGood.CooperationContractNumber,
  361 + OrderGoodId: orderGood.OrderGoodId,
  362 + OrderGoodAmount: orderGood.OrderGoodAmount,
368 }) 363 })
369 } 364 }
370 } 365 }
@@ -394,6 +389,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -394,6 +389,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
394 IsSuccessfully: true, 389 IsSuccessfully: true,
395 CooperationContractUndertakerId: undertaker.UndertakerId, 390 CooperationContractUndertakerId: undertaker.UndertakerId,
396 DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage, 391 DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage,
  392 + CooperationContractNumber: orderGood.CooperationContractNumber,
  393 + OrderGoodId: orderGood.OrderGoodId,
  394 + OrderGoodAmount: orderGood.OrderGoodAmount,
397 }) 395 })
398 } 396 }
399 } 397 }
@@ -68,10 +68,9 @@ func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) @@ -68,10 +68,9 @@ func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent)
68 } 68 }
69 if constant.LOG_FRAMEWORK == "logrus" { 69 if constant.LOG_FRAMEWORK == "logrus" {
70 rawlog.Println(string(sqlStr)) 70 rawlog.Println(string(sqlStr))
  71 + } else {
  72 + //log.Logger.Debug(string(sqlStr))
71 } 73 }
72 - //else {  
73 - // log.Logger.Debug(string(sqlStr))  
74 - //}  
75 74
76 return nil 75 return nil
77 } 76 }
@@ -223,15 +223,16 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do @@ -223,15 +223,16 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
223 if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil { 223 if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {
224 return nil, err 224 return nil, err
225 } 225 }
226 - var dividendsEstimatesSaved []*domain.DividendsEstimate  
227 - for _, dividendsEstimateModel := range dividendsEstimateModels {  
228 - if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {  
229 - return dividendsEstimates, err  
230 - } else {  
231 - dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimate)  
232 - }  
233 - }  
234 - return dividendsEstimatesSaved, nil 226 + //var dividendsEstimatesSaved []*domain.DividendsEstimate
  227 + //for _, dividendsEstimateModel := range dividendsEstimateModels {
  228 + // if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
  229 + // return dividendsEstimates, err
  230 + // } else {
  231 + // dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimate)
  232 + // }
  233 + //}
  234 + //return dividendsEstimatesSaved, nil
  235 + return dividendsEstimates, nil
235 } 236 }
236 return nil, nil 237 return nil, nil
237 } 238 }
@@ -50,7 +50,8 @@ func (logger *BeegoLog) Debug(msg string, appends ...map[string]interface{}) { @@ -50,7 +50,8 @@ func (logger *BeegoLog) Debug(msg string, appends ...map[string]interface{}) {
50 logs.Debug(msg, make(map[string]interface{}, 0)) 50 logs.Debug(msg, make(map[string]interface{}, 0))
51 } else { 51 } else {
52 var out bytes.Buffer 52 var out bytes.Buffer
53 - err := json.Indent(&out, appendsJson, "", " ") 53 + //err := json.Indent(&out, appendsJson, "", " ")
  54 + err := json.Compact(&out, appendsJson)
54 if err != nil { 55 if err != nil {
55 fmt.Println(msg) 56 fmt.Println(msg)
56 return 57 return
@@ -65,7 +66,8 @@ func (logger *BeegoLog) Info(msg string, appends ...map[string]interface{}) { @@ -65,7 +66,8 @@ func (logger *BeegoLog) Info(msg string, appends ...map[string]interface{}) {
65 logs.Info(msg, make(map[string]interface{}, 0)) 66 logs.Info(msg, make(map[string]interface{}, 0))
66 } else { 67 } else {
67 var out bytes.Buffer 68 var out bytes.Buffer
68 - err := json.Indent(&out, appendsJson, "", " ") 69 + //err := json.Indent(&out, appendsJson, "", " ")
  70 + err := json.Compact(&out, appendsJson)
69 if err != nil { 71 if err != nil {
70 fmt.Println(msg) 72 fmt.Println(msg)
71 return 73 return