作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-cooperation into dev
@@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
10 type OperateCooperationContractCommand struct { 10 type OperateCooperationContractCommand struct {
11 // 共创合约id 11 // 共创合约id
12 CooperationContractId string `cname:"共创合约id" json:"cooperationContractId" valid:"Required"` 12 CooperationContractId string `cname:"共创合约id" json:"cooperationContractId" valid:"Required"`
13 - // 操作 13 + // 操作,1暂停,2恢复
14 Action int32 `cname:"操作" json:"action" valid:"Required"` 14 Action int32 `cname:"操作" json:"action" valid:"Required"`
15 // 公司ID,通过集成REST上下文获取 15 // 公司ID,通过集成REST上下文获取
16 CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"` 16 CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
@@ -563,6 +563,24 @@ func (cooperationContractService *CooperationContractService) OperateCooperation @@ -563,6 +563,24 @@ func (cooperationContractService *CooperationContractService) OperateCooperation
563 defer func() { 563 defer func() {
564 _ = transactionContext.RollbackTransaction() 564 _ = transactionContext.RollbackTransaction()
565 }() 565 }()
  566 +
  567 + // 用户REST服务初始化
  568 + var userService service.UserService
  569 + if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
  570 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  571 + } else {
  572 + userService = value
  573 + }
  574 +
  575 + // 获取操作人
  576 + var operator *domain.User
  577 + if data, err := userService.OperatorFrom(operateCooperationContractCommand.CompanyId, operateCooperationContractCommand.OrgId, operateCooperationContractCommand.UserId); err != nil {
  578 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  579 + } else {
  580 + operator = data
  581 + }
  582 +
  583 + // 共创合约仓储初始化
566 var cooperationContractRepository domain.CooperationContractRepository 584 var cooperationContractRepository domain.CooperationContractRepository
567 if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ 585 if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
568 "transactionContext": transactionContext, 586 "transactionContext": transactionContext,
@@ -571,6 +589,18 @@ func (cooperationContractService *CooperationContractService) OperateCooperation @@ -571,6 +589,18 @@ func (cooperationContractService *CooperationContractService) OperateCooperation
571 } else { 589 } else {
572 cooperationContractRepository = value 590 cooperationContractRepository = value
573 } 591 }
  592 +
  593 + // 共创合约变更记录仓储初始化
  594 + var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
  595 + if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
  596 + "transactionContext": transactionContext,
  597 + }); err != nil {
  598 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  599 + } else {
  600 + cooperationContractChangeLogRepository = value
  601 + }
  602 +
  603 + // 获取共创合约
574 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": operateCooperationContractCommand.CooperationContractId}) 604 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": operateCooperationContractCommand.CooperationContractId})
575 if err != nil { 605 if err != nil {
576 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 606 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -578,18 +608,42 @@ func (cooperationContractService *CooperationContractService) OperateCooperation @@ -578,18 +608,42 @@ func (cooperationContractService *CooperationContractService) OperateCooperation
578 if cooperationContract == nil { 608 if cooperationContract == nil {
579 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operateCooperationContractCommand.CooperationContractId))) 609 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operateCooperationContractCommand.CooperationContractId)))
580 } 610 }
  611 +
  612 + // 更新共创合约
581 if err := cooperationContract.Update(map[string]interface{}{ 613 if err := cooperationContract.Update(map[string]interface{}{
582 "action": operateCooperationContractCommand.Action, 614 "action": operateCooperationContractCommand.Action,
583 }); err != nil { 615 }); err != nil {
584 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 616 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
585 } 617 }
586 - if cooperationContract, err := cooperationContractRepository.UpdateOne(cooperationContract); err != nil { 618 + if cooperationContractUpdated, err := cooperationContractRepository.UpdateOne(cooperationContract); err != nil {
587 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 619 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
588 } else { 620 } else {
  621 + // 新增共创合约变更记录
  622 + var operationType int32
  623 + if operateCooperationContractCommand.Action == 1 {
  624 + operationType = domain.PAUSE
  625 + } else if operateCooperationContractCommand.Action == 2 {
  626 + operationType = domain.RECOVER
  627 + }
  628 + newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
  629 + IncentivesRule: "",
  630 + IncentivesRuleDetail: "",
  631 + OperationType: operationType,
  632 + Undertakers: "",
  633 + CooperationContractNumber: cooperationContractUpdated.CooperationContractNumber,
  634 + Company: cooperationContractUpdated.Company,
  635 + Operator: operator,
  636 + CreatedAt: time.Now(),
  637 + }
  638 +
  639 + // 保存共创合约变更记录
  640 + if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
  641 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
  642 + }
589 if err := transactionContext.CommitTransaction(); err != nil { 643 if err := transactionContext.CommitTransaction(); err != nil {
590 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 644 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
591 } 645 }
592 - return cooperationContract, nil 646 + return cooperationContractUpdated, nil
593 } 647 }
594 } 648 }
595 649
@@ -608,6 +662,7 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper @@ -608,6 +662,7 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
608 defer func() { 662 defer func() {
609 _ = transactionContext.RollbackTransaction() 663 _ = transactionContext.RollbackTransaction()
610 }() 664 }()
  665 +
611 // 共创合约仓储初始化 666 // 共创合约仓储初始化
612 var cooperationContractRepository domain.CooperationContractRepository 667 var cooperationContractRepository domain.CooperationContractRepository
613 if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ 668 if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
@@ -617,7 +672,37 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper @@ -617,7 +672,37 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
617 } else { 672 } else {
618 cooperationContractRepository = value 673 cooperationContractRepository = value
619 } 674 }
620 - cooperationContractIds, _ := utils.SliceAtoi(batchOperateCooperationContractCommand.CooperationContractIds) 675 +
  676 + // 共创合约变更记录仓储初始化
  677 + var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
  678 + if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
  679 + "transactionContext": transactionContext,
  680 + }); err != nil {
  681 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  682 + } else {
  683 + cooperationContractChangeLogRepository = value
  684 + }
  685 +
  686 + // 用户REST服务初始化
  687 + var userService service.UserService
  688 + if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
  689 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  690 + } else {
  691 + userService = value
  692 + }
  693 +
  694 + // 获取操作人
  695 + var operator *domain.User
  696 + if data, err := userService.OperatorFrom(batchOperateCooperationContractCommand.CompanyId, batchOperateCooperationContractCommand.OrgId, batchOperateCooperationContractCommand.UserId); err != nil {
  697 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  698 + } else {
  699 + operator = data
  700 + }
  701 +
  702 + cooperationContractIds, err := utils.SliceAtoi(batchOperateCooperationContractCommand.CooperationContractIds)
  703 + if err != nil {
  704 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "转换共创合约ID列表错误")
  705 + }
621 if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ 706 if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
622 "cooperationContractIds": cooperationContractIds, 707 "cooperationContractIds": cooperationContractIds,
623 }); err != nil { 708 }); err != nil {
@@ -631,6 +716,31 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper @@ -631,6 +716,31 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
631 if err != nil { 716 if err != nil {
632 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 717 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
633 } 718 }
  719 + for _, cooperationContractOperated := range cooperationContractsOperated {
  720 + // 新增共创合约变更记录
  721 + var operationType int32
  722 + if batchOperateCooperationContractCommand.Action == 1 {
  723 + operationType = domain.PAUSE
  724 + } else if batchOperateCooperationContractCommand.Action == 2 {
  725 + operationType = domain.RECOVER
  726 + }
  727 + newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
  728 + IncentivesRule: "",
  729 + IncentivesRuleDetail: "",
  730 + OperationType: operationType,
  731 + Undertakers: "",
  732 + CooperationContractNumber: cooperationContractOperated.CooperationContractNumber,
  733 + Company: cooperationContractOperated.Company,
  734 + Operator: operator,
  735 + CreatedAt: time.Now(),
  736 + }
  737 +
  738 + // 保存共创合约变更记录
  739 + if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
  740 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
  741 + }
  742 + }
  743 +
634 if err := transactionContext.CommitTransaction(); err != nil { 744 if err := transactionContext.CommitTransaction(); err != nil {
635 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 745 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
636 } 746 }
@@ -705,12 +815,12 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -705,12 +815,12 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
705 if err := updateCooperationContractCommand.ValidateCommand(); err != nil { 815 if err := updateCooperationContractCommand.ValidateCommand(); err != nil {
706 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 816 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
707 } 817 }
708 - transactionContext, err := factory.CreateTransactionContext(nil)  
709 - if err != nil {  
710 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 818 + transactionContext, err1 := factory.CreateTransactionContext(nil)
  819 + if err1 != nil {
  820 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err1.Error())
711 } 821 }
712 - if err := transactionContext.StartTransaction(); err != nil {  
713 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 822 + if err2 := transactionContext.StartTransaction(); err2 != nil {
  823 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
714 } 824 }
715 defer func() { 825 defer func() {
716 _ = transactionContext.RollbackTransaction() 826 _ = transactionContext.RollbackTransaction()
@@ -718,59 +828,76 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -718,59 +828,76 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
718 828
719 // 公司REST服务初始化 829 // 公司REST服务初始化
720 var companyService service.CompanyService 830 var companyService service.CompanyService
721 - if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {  
722 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 831 + if value, err3 := factory.CreateCompanyService(map[string]interface{}{}); err3 != nil {
  832 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
723 } else { 833 } else {
724 companyService = value 834 companyService = value
725 } 835 }
726 836
727 // 获取公司信息 837 // 获取公司信息
728 var company *domain.Company 838 var company *domain.Company
729 - if data, err := companyService.CompanyFrom(updateCooperationContractCommand.CompanyId); err != nil {  
730 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 839 + if data, err4 := companyService.CompanyFrom(updateCooperationContractCommand.CompanyId); err4 != nil {
  840 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
731 } else { 841 } else {
732 company = data 842 company = data
733 } 843 }
734 844
735 // 组织机构REST服务初始化 845 // 组织机构REST服务初始化
736 var organizationService service.OrgService 846 var organizationService service.OrgService
737 - if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {  
738 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 847 + if value, err5 := factory.CreateOrganizationService(map[string]interface{}{}); err5 != nil {
  848 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err5.Error())
739 } else { 849 } else {
740 organizationService = value 850 organizationService = value
741 } 851 }
742 852
743 // 获取组织机构信息 853 // 获取组织机构信息
744 var organization *domain.Org 854 var organization *domain.Org
745 - if data, err := organizationService.OrgFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId); err != nil {  
746 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 855 + if data, err6 := organizationService.OrgFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId); err6 != nil {
  856 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
747 } else { 857 } else {
748 organization = data 858 organization = data
749 } 859 }
750 860
751 - var cooperationContractRepository domain.CooperationContractRepository  
752 - if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ 861 + // 共创合约变更记录仓储初始化
  862 + var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
  863 + if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
753 "transactionContext": transactionContext, 864 "transactionContext": transactionContext,
754 }); err != nil { 865 }); err != nil {
755 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 866 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
756 } else { 867 } else {
  868 + cooperationContractChangeLogRepository = value
  869 + }
  870 +
  871 + // 共创合约仓储初始化
  872 + var cooperationContractRepository domain.CooperationContractRepository
  873 + if value, err7 := factory.CreateCooperationContractRepository(map[string]interface{}{
  874 + "transactionContext": transactionContext,
  875 + }); err7 != nil {
  876 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err7.Error())
  877 + } else {
757 cooperationContractRepository = value 878 cooperationContractRepository = value
758 } 879 }
759 - cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": updateCooperationContractCommand.CooperationContractId})  
760 - if err != nil {  
761 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 880 +
  881 + // 获取待更新的共创合约
  882 + cooperationContract, err8 := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": updateCooperationContractCommand.CooperationContractId})
  883 + if err8 != nil {
  884 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err8.Error())
762 } 885 }
763 if cooperationContract == nil { 886 if cooperationContract == nil {
764 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId))) 887 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId)))
765 } 888 }
  889 +
  890 + cooperationContractFound := cooperationContract
  891 +
766 // 更新合约基础信息 892 // 更新合约基础信息
767 - if err := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err != nil {  
768 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 893 + if err9 := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err9 != nil {
  894 + return nil, application.ThrowError(application.BUSINESS_ERROR, err9.Error())
769 } 895 }
  896 +
770 // 用户REST服务初始化 897 // 用户REST服务初始化
771 var userService service.UserService 898 var userService service.UserService
772 - if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {  
773 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 899 + if value, err10 := factory.CreateUserService(map[string]interface{}{}); err10 != nil {
  900 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err10.Error())
774 } else { 901 } else {
775 userService = value 902 userService = value
776 } 903 }
@@ -778,12 +905,20 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -778,12 +905,20 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
778 // 获取发起人 905 // 获取发起人
779 var sponsor *domain.User 906 var sponsor *domain.User
780 sponsorUid, _ := strconv.ParseInt(updateCooperationContractCommand.SponsorUid, 10, 64) 907 sponsorUid, _ := strconv.ParseInt(updateCooperationContractCommand.SponsorUid, 10, 64)
781 - if data, err := userService.OperatorFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, sponsorUid); err != nil {  
782 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 908 + if data, err11 := userService.OperatorFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, sponsorUid); err11 != nil {
  909 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err11.Error())
783 } else { 910 } else {
784 sponsor = data 911 sponsor = data
785 } 912 }
786 913
  914 + // 获取操作人
  915 + var operator *domain.User
  916 + if data, err := userService.OperatorFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, updateCooperationContractCommand.UserId); err != nil {
  917 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  918 + } else {
  919 + operator = data
  920 + }
  921 +
787 // 更新发起人 922 // 更新发起人
788 cooperationContract.CooperationContractSponsor = sponsor 923 cooperationContract.CooperationContractSponsor = sponsor
789 924
@@ -792,8 +927,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -792,8 +927,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
792 for _, relevantPersonUid := range updateCooperationContractCommand.RelevantPeople { 927 for _, relevantPersonUid := range updateCooperationContractCommand.RelevantPeople {
793 var relevantDomain *domain.Relevant 928 var relevantDomain *domain.Relevant
794 relevantUid, _ := strconv.ParseInt(relevantPersonUid, 10, 64) 929 relevantUid, _ := strconv.ParseInt(relevantPersonUid, 10, 64)
795 - if data, err := userService.RelevantFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, relevantUid); err != nil {  
796 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 930 + if data, err12 := userService.RelevantFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, relevantUid); err12 != nil {
  931 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err12.Error())
797 } else { 932 } else {
798 relevantDomain = data 933 relevantDomain = data
799 } 934 }
@@ -821,8 +956,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -821,8 +956,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
821 for _, undertaker := range updateCooperationContractCommand.Undertakers { 956 for _, undertaker := range updateCooperationContractCommand.Undertakers {
822 var undertakerDomain *domain.Undertaker 957 var undertakerDomain *domain.Undertaker
823 undertakerUid, _ := strconv.ParseInt(undertaker.UserId, 10, 64) 958 undertakerUid, _ := strconv.ParseInt(undertaker.UserId, 10, 64)
824 - if data, err := userService.UndertakerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, undertakerUid); err != nil {  
825 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 959 + if data, err13 := userService.UndertakerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, undertakerUid); err13 != nil {
  960 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err13.Error())
826 } else { 961 } else {
827 undertakerDomain = data 962 undertakerDomain = data
828 } 963 }
@@ -831,8 +966,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -831,8 +966,8 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
831 var referrerDomain *domain.Referrer 966 var referrerDomain *domain.Referrer
832 referrerUid, _ := strconv.ParseInt(undertaker.ReferrerId, 10, 64) 967 referrerUid, _ := strconv.ParseInt(undertaker.ReferrerId, 10, 64)
833 if referrerUid > 0 { 968 if referrerUid > 0 {
834 - if data, err := userService.ReferrerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, referrerUid); err != nil {  
835 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 969 + if data, err14 := userService.ReferrerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, referrerUid); err14 != nil {
  970 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err14.Error())
836 } else { 971 } else {
837 referrerDomain = data 972 referrerDomain = data
838 } 973 }
@@ -840,18 +975,21 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -840,18 +975,21 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
840 975
841 // 获取业务员 976 // 获取业务员
842 var salesmanDomain *domain.Salesman 977 var salesmanDomain *domain.Salesman
843 - salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64) 978 + salesmanUid, err22 := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
  979 + if err22 != nil {
  980 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err22.Error())
  981 + }
844 if salesmanUid > 0 { 982 if salesmanUid > 0 {
845 - if data, err := userService.SalesmanFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, salesmanUid); err != nil {  
846 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 983 + if data, err15 := userService.SalesmanFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, salesmanUid); err15 != nil {
  984 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err15.Error())
847 } else { 985 } else {
848 salesmanDomain = data 986 salesmanDomain = data
849 } 987 }
850 } 988 }
851 989
852 - undertakerId, err3 := strconv.ParseInt(undertaker.UndertakerId, 10, 64)  
853 - if err3 != nil {  
854 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error()) 990 + undertakerId, err16 := strconv.ParseInt(undertaker.UndertakerId, 10, 64)
  991 + if err16 != nil {
  992 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err16.Error())
855 } 993 }
856 undertakers = append(undertakers, &domain.Undertaker{ 994 undertakers = append(undertakers, &domain.Undertaker{
857 UndertakerId: undertakerId, 995 UndertakerId: undertakerId,
@@ -877,9 +1015,9 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -877,9 +1015,9 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
877 // 获取分红规则列表 1015 // 获取分红规则列表
878 var dividendsIncentivesRules []*domain.DividendsIncentivesRule 1016 var dividendsIncentivesRules []*domain.DividendsIncentivesRule
879 for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules { 1017 for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules {
880 - dividendsIncentivesRuleId, err2 := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)  
881 - if err2 != nil {  
882 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) 1018 + dividendsIncentivesRuleId, err17 := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
  1019 + if err17 != nil {
  1020 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err17.Error())
883 } 1021 }
884 dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{ 1022 dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
885 DividendsIncentivesRuleId: dividendsIncentivesRuleId, 1023 DividendsIncentivesRuleId: dividendsIncentivesRuleId,
@@ -903,9 +1041,9 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -903,9 +1041,9 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
903 // 获取金额激励规则列表 1041 // 获取金额激励规则列表
904 var moneyIncentivesRules []*domain.MoneyIncentivesRule 1042 var moneyIncentivesRules []*domain.MoneyIncentivesRule
905 for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules { 1043 for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules {
906 - moneyIncentivesRuleId, err4 := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)  
907 - if err4 != nil {  
908 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error()) 1044 + moneyIncentivesRuleId, err18 := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
  1045 + if err18 != nil {
  1046 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err18.Error())
909 } 1047 }
910 moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{ 1048 moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
911 MoneyIncentivesRuleId: moneyIncentivesRuleId, 1049 MoneyIncentivesRuleId: moneyIncentivesRuleId,
@@ -927,13 +1065,220 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -927,13 +1065,220 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
927 // 更新金额激励规则列表 1065 // 更新金额激励规则列表
928 cooperationContract.MoneyIncentivesRules = moneyIncentivesRules 1066 cooperationContract.MoneyIncentivesRules = moneyIncentivesRules
929 1067
930 - if cooperationContract, err := cooperationContractRepository.Save(cooperationContract); err != nil {  
931 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1068 + // 判断激励规则变更
  1069 + incentivesType := 0
  1070 + if len(dividendsIncentivesRules) > 0 {
  1071 + incentivesType = domain.TYPE_DIVIDNEDS_INCENTIVES
  1072 + } else if len(moneyIncentivesRules) > 0 {
  1073 + incentivesType = domain.TYPE_MONEY_INCENTIVES
  1074 + }
  1075 + cooperationContract.IncentivesType = int32(incentivesType)
  1076 +
  1077 + // 保存共创合约变更
  1078 + if cooperationContractSaved, err19 := cooperationContractRepository.Save(cooperationContract); err19 != nil {
  1079 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err19.Error())
932 } else { 1080 } else {
933 - if err := transactionContext.CommitTransaction(); err != nil {  
934 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1081 + // 保存共创合约变更记录
  1082 + // 原【(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点),(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点)】-->更新后【(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点)】
  1083 + var incentivesRuleChange string
  1084 + var incentivesRuleChangeDetail string
  1085 + if cooperationContractFound.IncentivesType != cooperationContractSaved.IncentivesType && cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES && cooperationContractSaved.IncentivesType == domain.TYPE_MONEY_INCENTIVES { // 1.激励类型变更
  1086 + // 业绩分红-->金额激励
  1087 + incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
  1088 +
  1089 + //【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
  1090 + // 原业绩分红激励规则
  1091 + var dividendsIncentivesRuleOriginal string
  1092 + for _, dividendsIncentivesRule := range cooperationContractFound.DividendsIncentivesRules {
  1093 + dividendsIncentivesRuleOriginal = dividendsIncentivesRuleOriginal + dividendsIncentivesRule.DividendsIncentivesStageCN +
  1094 + ":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
  1095 + "," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
  1096 + "~" + dividendsIncentivesRule.DividendsIncentivesStageEnd.Format("2006-01-02") +
  1097 + "," + fmt.Sprint(dividendsIncentivesRule.ReferrerPercentage) +
  1098 + "," + fmt.Sprint(dividendsIncentivesRule.SalesmanPercentage) + ";"
  1099 + }
  1100 + dividendsIncentivesRuleOriginalTmp := "【" + dividendsIncentivesRuleOriginal + "】"
  1101 +
  1102 + // 变更后的金额激励规则
  1103 + var moneyIncentivesRuleChanged string
  1104 + for _, moneyIncentivesRule := range cooperationContractSaved.MoneyIncentivesRules {
  1105 + moneyIncentivesRuleChanged = moneyIncentivesRuleChanged + moneyIncentivesRule.MoneyIncentivesStageCN +
  1106 + ":" +
  1107 + "," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
  1108 + "," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
  1109 + "," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
  1110 + }
  1111 + moneyIncentivesRuleOriginalTmp := "【" + moneyIncentivesRuleChanged + "】"
  1112 +
  1113 + // 拼接规则变更
  1114 + incentivesRuleChangeDetail = dividendsIncentivesRuleOriginalTmp + " 变更为 " + moneyIncentivesRuleOriginalTmp
  1115 + } else if cooperationContractFound.IncentivesType != cooperationContractSaved.IncentivesType && cooperationContractFound.IncentivesType == domain.TYPE_MONEY_INCENTIVES && cooperationContractSaved.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES {
  1116 + // 金额激励-->业绩分红
  1117 + incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
  1118 + //【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
  1119 +
  1120 + // 原金额激励规则
  1121 + var moneyIncentivesRuleOriginal string
  1122 + for _, moneyIncentivesRule := range cooperationContractFound.MoneyIncentivesRules {
  1123 + moneyIncentivesRuleOriginal = moneyIncentivesRuleOriginal + moneyIncentivesRule.MoneyIncentivesStageCN +
  1124 + ":" +
  1125 + "," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
  1126 + "," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
  1127 + "," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
  1128 + }
  1129 + moneyIncentivesRuleOriginalTmp := "【" + moneyIncentivesRuleOriginal + "】"
  1130 +
  1131 + // 变更后的业绩分红激励规则
  1132 + var dividendsIncentivesRuleChanged string
  1133 + for _, dividendsIncentivesRule := range cooperationContractSaved.DividendsIncentivesRules {
  1134 + dividendsIncentivesRuleChanged = dividendsIncentivesRuleChanged + dividendsIncentivesRule.DividendsIncentivesStageCN +
  1135 + ":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
  1136 + "," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
  1137 + "~" + dividendsIncentivesRule.DividendsIncentivesStageEnd.Format("2006-01-02") +
  1138 + "," + fmt.Sprint(dividendsIncentivesRule.ReferrerPercentage) +
  1139 + "," + fmt.Sprint(dividendsIncentivesRule.SalesmanPercentage) + ";"
  1140 + }
  1141 + dividendsIncentivesRuleOriginalTmp := "【" + dividendsIncentivesRuleChanged + "】"
  1142 +
  1143 + // 拼接规则变更
  1144 + incentivesRuleChangeDetail = moneyIncentivesRuleOriginalTmp + " 变更为 " + dividendsIncentivesRuleOriginalTmp
  1145 + } else { // 2.激励规则变更
  1146 + if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 业绩分红激励规则变更
  1147 + if !cooperationContract.DividendsIncentivesRuleSliceEqualBCE(cooperationContractFound.DividendsIncentivesRules, cooperationContractSaved.DividendsIncentivesRules) {
  1148 + // 业绩分红-->业绩分红
  1149 + incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
  1150 + //【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
  1151 +
  1152 + // 原业绩分红激励规则
  1153 + var dividendsIncentivesRuleOriginal string
  1154 + for _, dividendsIncentivesRule := range cooperationContractFound.DividendsIncentivesRules {
  1155 + dividendsIncentivesRuleOriginal = dividendsIncentivesRuleOriginal + dividendsIncentivesRule.DividendsIncentivesStageCN +
  1156 + ":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
  1157 + "," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
  1158 + "~" + dividendsIncentivesRule.DividendsIncentivesStageEnd.Format("2006-01-02") +
  1159 + "," + fmt.Sprint(dividendsIncentivesRule.ReferrerPercentage) +
  1160 + "," + fmt.Sprint(dividendsIncentivesRule.SalesmanPercentage) + ";"
  1161 + }
  1162 + dividendsIncentivesRuleOriginalTmp := "【" + dividendsIncentivesRuleOriginal + "】"
  1163 +
  1164 + // 变更后的业绩分红激励规则
  1165 + var dividendsIncentivesRuleChanged string
  1166 + for _, dividendsIncentivesRule := range cooperationContractSaved.DividendsIncentivesRules {
  1167 + dividendsIncentivesRuleChanged = dividendsIncentivesRuleChanged + dividendsIncentivesRule.DividendsIncentivesStageCN +
  1168 + ":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
  1169 + "," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
  1170 + "~" + dividendsIncentivesRule.DividendsIncentivesStageEnd.Format("2006-01-02") +
  1171 + "," + fmt.Sprint(dividendsIncentivesRule.ReferrerPercentage) +
  1172 + "," + fmt.Sprint(dividendsIncentivesRule.SalesmanPercentage) + ";"
  1173 + }
  1174 + dividendsIncentivesRuleChangedTmp := "【" + dividendsIncentivesRuleChanged + "】"
  1175 +
  1176 + // 拼接规则变更
  1177 + incentivesRuleChangeDetail = dividendsIncentivesRuleOriginalTmp + " 变更为 " + dividendsIncentivesRuleChangedTmp
  1178 + }
  1179 + } else if cooperationContractFound.IncentivesType == domain.MONEY_INCENTIVES { // 金额激励规则变更
  1180 + if !cooperationContract.MoneyIncentivesRuleSliceEqualBCE(cooperationContractFound.MoneyIncentivesRules, cooperationContractSaved.MoneyIncentivesRules) {
  1181 + incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
  1182 + //【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
  1183 +
  1184 + // 原金额激励规则
  1185 + var moneyIncentivesRuleOriginal string
  1186 + for _, moneyIncentivesRule := range cooperationContractFound.MoneyIncentivesRules {
  1187 + moneyIncentivesRuleOriginal = moneyIncentivesRuleOriginal + moneyIncentivesRule.MoneyIncentivesStageCN +
  1188 + ":" +
  1189 + "," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
  1190 + "," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
  1191 + "," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
  1192 + }
  1193 + moneyIncentivesRuleOriginalTmp := "【" + moneyIncentivesRuleOriginal + "】"
  1194 +
  1195 + // 变更后的激励规则
  1196 + var moneyIncentivesRuleChanged string
  1197 + for _, moneyIncentivesRule := range cooperationContractSaved.MoneyIncentivesRules {
  1198 + moneyIncentivesRuleChanged = moneyIncentivesRuleChanged + moneyIncentivesRule.MoneyIncentivesStageCN +
  1199 + ":" +
  1200 + "," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
  1201 + "," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
  1202 + "," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
  1203 + }
  1204 + moneyIncentivesRuleChangedTmp := "【" + moneyIncentivesRuleChanged + "】"
  1205 +
  1206 + // 拼接规则变更
  1207 + incentivesRuleChangeDetail = moneyIncentivesRuleOriginalTmp + " 变更为 " + moneyIncentivesRuleChangedTmp
  1208 + }
  1209 + }
935 } 1210 }
936 - return cooperationContract, nil 1211 +
  1212 + // 【1(张三,李四,王五)2(买买买,,)】变更为【1(张三,,)】
  1213 + var undertakerChange string
  1214 + if !cooperationContract.UndertakerSliceEqualBCE(cooperationContractFound.Undertakers, cooperationContractSaved.Undertakers) { // 3.承接人变更
  1215 + // 原承接人
  1216 + var undertakersOriginal string
  1217 + for i, undertaker := range cooperationContractFound.Undertakers {
  1218 + undertakersOriginal = undertakersOriginal + strconv.FormatInt(int64(i), 10) + "(" + undertaker.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
  1219 + }
  1220 + undertakerChangeTmp1 := "【" + undertakersOriginal + "】"
  1221 + // 变更承接人
  1222 + var undertakersChanged string
  1223 + for i, undertaker := range cooperationContractSaved.Undertakers {
  1224 + if undertaker.Referrer == nil {
  1225 + undertaker.Referrer = &domain.Referrer{
  1226 + UserId: 0,
  1227 + UserBaseId: 0,
  1228 + Roles: nil,
  1229 + Orgs: nil,
  1230 + Org: nil,
  1231 + Department: nil,
  1232 + Company: nil,
  1233 + UserInfo: nil,
  1234 + UserType: 0,
  1235 + UserName: "",
  1236 + UserPhone: "",
  1237 + }
  1238 + }
  1239 + if undertaker.Salesman == nil {
  1240 + undertaker.Salesman = &domain.Salesman{
  1241 + UserId: 0,
  1242 + UserBaseId: 0,
  1243 + Roles: nil,
  1244 + Orgs: nil,
  1245 + Org: nil,
  1246 + Department: nil,
  1247 + Company: nil,
  1248 + UserInfo: nil,
  1249 + UserType: 0,
  1250 + UserName: "",
  1251 + UserPhone: "",
  1252 + }
  1253 + }
  1254 + undertakersChanged = undertakersChanged + strconv.FormatInt(int64(i), 10) + "(" + undertaker.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
  1255 + }
  1256 + undertakerChangeTemp2 := "【" + undertakersChanged + "】"
  1257 + // 拼接承接人变更记录
  1258 + undertakerChange = undertakerChangeTmp1 + " 变更为 " + undertakerChangeTemp2
  1259 + }
  1260 +
  1261 + // 新增共创合约变更记录
  1262 + newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
  1263 + IncentivesRule: incentivesRuleChange,
  1264 + IncentivesRuleDetail: incentivesRuleChangeDetail,
  1265 + OperationType: domain.EDIT,
  1266 + Undertakers: undertakerChange,
  1267 + CooperationContractNumber: cooperationContractSaved.CooperationContractNumber,
  1268 + Company: company,
  1269 + Operator: operator,
  1270 + UpdatedAt: time.Time{},
  1271 + CreatedAt: time.Now(),
  1272 + }
  1273 +
  1274 + // 保存共创合约变更记录
  1275 + if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
  1276 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
  1277 + }
  1278 + if err21 := transactionContext.CommitTransaction(); err21 != nil {
  1279 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err21.Error())
  1280 + }
  1281 + return cooperationContractSaved, nil
937 } 1282 }
938 } 1283 }
939 1284
@@ -65,6 +65,16 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService) @@ -65,6 +65,16 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService)
65 operator = data 65 operator = data
66 } 66 }
67 67
  68 + // 共创合约变更记录仓储初始化
  69 + var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
  70 + if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
  71 + "transactionContext": transactionContext,
  72 + }); err != nil {
  73 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  74 + } else {
  75 + cooperationContractChangeLogRepository = value
  76 + }
  77 +
68 newCooperationContractChangeLog := &domain.CooperationContractChangeLog{ 78 newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
69 IncentivesRule: createCooperationContractChangeLogCommand.IncentivesRule, 79 IncentivesRule: createCooperationContractChangeLogCommand.IncentivesRule,
70 IncentivesRuleDetail: createCooperationContractChangeLogCommand.IncentivesRuleDetail, 80 IncentivesRuleDetail: createCooperationContractChangeLogCommand.IncentivesRuleDetail,
@@ -77,14 +87,7 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService) @@ -77,14 +87,7 @@ func (cooperationContractChangeLogService *CooperationContractChangeLogService)
77 DeletedAt: time.Time{}, 87 DeletedAt: time.Time{},
78 CreatedAt: time.Now(), 88 CreatedAt: time.Now(),
79 } 89 }
80 - var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository  
81 - if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{  
82 - "transactionContext": transactionContext,  
83 - }); err != nil {  
84 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
85 - } else {  
86 - cooperationContractChangeLogRepository = value  
87 - } 90 +
88 if cooperationContractChangeLog, err := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err != nil { 91 if cooperationContractChangeLog, err := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err != nil {
89 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 92 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
90 } else { 93 } else {
@@ -125,9 +125,11 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred @@ -125,9 +125,11 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
125 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 125 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
126 } else { 126 } else {
127 // 校验共创用户是否一致 127 // 校验共创用户是否一致
128 - for i, _ := range dividendsEstimates {  
129 - if dividendsEstimates[i].DividendsUser.UserId != dividendsEstimates[i+1].DividendsUser.UserId {  
130 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "请勾选同一个共创用户进行结算") 128 + if len(dividendsEstimates) > 0 {
  129 + for i, _ := range dividendsEstimates {
  130 + if dividendsEstimates[i].DividendsUser.UserId != dividendsEstimates[0].DividendsUser.UserId {
  131 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "请勾选同一个共创用户进行结算")
  132 + }
131 } 133 }
132 } 134 }
133 135
@@ -126,8 +126,8 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD @@ -126,8 +126,8 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
126 DividendsReturnedOrderNumber: "", 126 DividendsReturnedOrderNumber: "",
127 CooperationContractNumber: orderGood.CooperationContractNumber, 127 CooperationContractNumber: orderGood.CooperationContractNumber,
128 OrderGoodExpense: orderGood.OrderGoodExpense, 128 OrderGoodExpense: orderGood.OrderGoodExpense,
129 - OrgId: organization.OrgId,  
130 - CompanyId: company.CompanyId, 129 + OrgId: createDividendsOrderCommand.OrgId,
  130 + CompanyId: createDividendsOrderCommand.CompanyId,
131 CreatedAt: time.Time{}, 131 CreatedAt: time.Time{},
132 DeletedAt: time.Time{}, 132 DeletedAt: time.Time{},
133 UpdatedAt: time.Time{}, 133 UpdatedAt: time.Time{},
@@ -148,7 +148,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD @@ -148,7 +148,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
148 DividendsOrderAmount: dividendsOrderAmount, 148 DividendsOrderAmount: dividendsOrderAmount,
149 OrderTime: orderTime, 149 OrderTime: orderTime,
150 DividendTime: time.Time{}, 150 DividendTime: time.Time{},
151 - DividendStatus: 0, 151 + DividendStatus: domain.TO_BE_DIVIDEND,
152 Region: &domain.RegionInfo{ 152 Region: &domain.RegionInfo{
153 RegionNumber: "", 153 RegionNumber: "",
154 RegionName: createDividendsOrderCommand.RegionName, 154 RegionName: createDividendsOrderCommand.RegionName,
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "github.com/beego/beego/v2/core/validation" 5 "github.com/beego/beego/v2/core/validation"
6 "reflect" 6 "reflect"
7 "strings" 7 "strings"
  8 + "time"
8 ) 9 )
9 10
10 type OrderGoods struct { 11 type OrderGoods struct {
@@ -36,7 +37,7 @@ type CreateDividendsReturnedOrderCommand struct { @@ -36,7 +37,7 @@ type CreateDividendsReturnedOrderCommand struct {
36 // 备注 37 // 备注
37 Remarks string `cname:"备注" json:"remarks" valid:"Required"` 38 Remarks string `cname:"备注" json:"remarks" valid:"Required"`
38 // 退货日期 39 // 退货日期
39 - DividendsReturnedDate string `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"` 40 + DividendsReturnedDate time.Time `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
40 // 退货区域名称 41 // 退货区域名称
41 RegionName string `cname:"退货区域名称" json:"regionName,omitempty"` 42 RegionName string `cname:"退货区域名称" json:"regionName,omitempty"`
42 // 订单产品列表 43 // 订单产品列表
@@ -121,8 +121,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide @@ -121,8 +121,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
121 DividendsReturnedOrderNumber: dividendsReturnedOrderNumber, 121 DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
122 CooperationContractNumber: orderGood.CooperationContractNumber, 122 CooperationContractNumber: orderGood.CooperationContractNumber,
123 OrderGoodExpense: 0, 123 OrderGoodExpense: 0,
124 - OrgId: organization.OrgId,  
125 - CompanyId: company.CompanyId, 124 + OrgId: createDividendsReturnedOrderCommand.OrgId,
  125 + CompanyId: createDividendsReturnedOrderCommand.CompanyId,
126 CreatedAt: time.Now(), 126 CreatedAt: time.Now(),
127 DeletedAt: time.Time{}, 127 DeletedAt: time.Time{},
128 UpdatedAt: time.Time{}, 128 UpdatedAt: time.Time{},
@@ -135,19 +135,18 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide @@ -135,19 +135,18 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
135 OriginalOrderNum: createDividendsReturnedOrderCommand.OriginalOrderNum, 135 OriginalOrderNum: createDividendsReturnedOrderCommand.OriginalOrderNum,
136 DividendsOrderNumber: createDividendsReturnedOrderCommand.DividendsOrderNumber, 136 DividendsOrderNumber: createDividendsReturnedOrderCommand.DividendsOrderNumber,
137 DividendsReturnedCustomerName: createDividendsReturnedOrderCommand.DividendsReturnedCustomerName, 137 DividendsReturnedCustomerName: createDividendsReturnedOrderCommand.DividendsReturnedCustomerName,
138 - DividendsReturnedDate: time.Time{}, 138 + DividendsReturnedDate: createDividendsReturnedOrderCommand.DividendsReturnedDate,
139 Region: &domain.RegionInfo{ 139 Region: &domain.RegionInfo{
140 RegionNumber: "", 140 RegionNumber: "",
141 RegionName: createDividendsReturnedOrderCommand.RegionName, 141 RegionName: createDividendsReturnedOrderCommand.RegionName,
142 }, 142 },
143 Goods: orderGoods, 143 Goods: orderGoods,
144 Remarks: createDividendsReturnedOrderCommand.Remarks, 144 Remarks: createDividendsReturnedOrderCommand.Remarks,
145 - DividendStatus: 1, 145 + DividendStatus: domain.TO_BE_DIVIDENDED,
146 DividendTime: time.Time{}, 146 DividendTime: time.Time{},
147 Org: organization, 147 Org: organization,
148 Company: company, 148 Company: company,
149 CreatedAt: time.Now(), 149 CreatedAt: time.Now(),
150 - DeletedAt: time.Time{},  
151 UpdatedAt: time.Time{}, 150 UpdatedAt: time.Time{},
152 Operator: operator, 151 Operator: operator,
153 OperateTime: time.Now(), 152 OperateTime: time.Now(),
@@ -9,6 +9,28 @@ const ( @@ -9,6 +9,28 @@ const (
9 TYPE_MONEY_INCENTIVES 9 TYPE_MONEY_INCENTIVES
10 ) 10 )
11 11
  12 +type IncentivesType int32
  13 +
  14 +const (
  15 + DividendsIncentives IncentivesType = 1
  16 + MoneyIncentives IncentivesType = 2
  17 +)
  18 +
  19 +func (p IncentivesType) String() string {
  20 + switch p {
  21 + case DividendsIncentives:
  22 + return "业绩分红"
  23 + case MoneyIncentives:
  24 + return "金额激励"
  25 + default:
  26 + return "未知类型"
  27 + }
  28 +}
  29 +
  30 +func (cooperationContract *CooperationContract) ReturnIncentivesName(p IncentivesType) string {
  31 + return p.String()
  32 +}
  33 +
12 // CooperationContract 共创项目合约实体 34 // CooperationContract 共创项目合约实体
13 type CooperationContract struct { 35 type CooperationContract struct {
14 // 共创合约ID 36 // 共创合约ID
@@ -101,3 +123,54 @@ func (cooperationContract *CooperationContract) Update(data map[string]interface @@ -101,3 +123,54 @@ func (cooperationContract *CooperationContract) Update(data map[string]interface
101 } 123 }
102 return nil 124 return nil
103 } 125 }
  126 +
  127 +// UndertakerSliceEqualBCE 判断承接人Slice是否一样
  128 +func (cooperationContract *CooperationContract) UndertakerSliceEqualBCE(a, b []*Undertaker) bool {
  129 + if len(a) != len(b) {
  130 + return false
  131 + }
  132 + if (a == nil) != (b == nil) {
  133 + return false
  134 + }
  135 + b = b[:len(a)]
  136 + for i, v := range a {
  137 + if v != b[i] {
  138 + return false
  139 + }
  140 + }
  141 + return true
  142 +}
  143 +
  144 +// DividendsIncentivesRuleSliceEqualBCE 判断业绩分红激励规则Slice是否一样
  145 +func (cooperationContract *CooperationContract) DividendsIncentivesRuleSliceEqualBCE(a, b []*DividendsIncentivesRule) bool {
  146 + if len(a) != len(b) {
  147 + return false
  148 + }
  149 + if (a == nil) != (b == nil) {
  150 + return false
  151 + }
  152 + b = b[:len(a)]
  153 + for i, v := range a {
  154 + if v != b[i] {
  155 + return false
  156 + }
  157 + }
  158 + return true
  159 +}
  160 +
  161 +// MoneyIncentivesRuleSliceEqualBCE 判断金额激励规则Slice是否一样
  162 +func (cooperationContract *CooperationContract) MoneyIncentivesRuleSliceEqualBCE(a, b []*MoneyIncentivesRule) bool {
  163 + if len(a) != len(b) {
  164 + return false
  165 + }
  166 + if (a == nil) != (b == nil) {
  167 + return false
  168 + }
  169 + b = b[:len(a)]
  170 + for i, v := range a {
  171 + if v != b[i] {
  172 + return false
  173 + }
  174 + }
  175 + return true
  176 +}
@@ -2,6 +2,12 @@ package domain @@ -2,6 +2,12 @@ package domain
2 2
3 import "time" 3 import "time"
4 4
  5 +const (
  6 + EDIT = iota + 1 // 编辑
  7 + PAUSE // 暂停
  8 + RECOVER // 恢复
  9 +)
  10 +
5 // CooperationContractChangeLog 共创合约变更日志 11 // CooperationContractChangeLog 共创合约变更日志
6 type CooperationContractChangeLog struct { 12 type CooperationContractChangeLog struct {
7 // 共创合约变更日志 13 // 共创合约变更日志
@@ -18,8 +24,12 @@ type CooperationContractChangeLog struct { @@ -18,8 +24,12 @@ type CooperationContractChangeLog struct {
18 Undertakers string `json:"undertakers"` 24 Undertakers string `json:"undertakers"`
19 // 公司 25 // 公司
20 Company *Company `json:"company"` 26 Company *Company `json:"company"`
  27 + // 组织机构
  28 + Org *Org `json:"org"`
21 // 操作人 29 // 操作人
22 Operator *User `json:"operator"` 30 Operator *User `json:"operator"`
  31 + // 操作时间
  32 + OperatorTime time.Time `json:"operatorTime"`
23 // 更新时间 33 // 更新时间
24 UpdatedAt time.Time `json:"updatedAt"` 34 UpdatedAt time.Time `json:"updatedAt"`
25 // 删除时间 35 // 删除时间
@@ -58,56 +68,5 @@ func (cooperationContractChangeLog *CooperationContractChangeLog) Update(data ma @@ -58,56 +68,5 @@ func (cooperationContractChangeLog *CooperationContractChangeLog) Update(data ma
58 if undertakers, ok := data["undertakers"]; ok { 68 if undertakers, ok := data["undertakers"]; ok {
59 cooperationContractChangeLog.Undertakers = undertakers.(string) 69 cooperationContractChangeLog.Undertakers = undertakers.(string)
60 } 70 }
61 - if companyId, ok := data["companyId"]; ok {  
62 - cooperationContractChangeLog.Company.CompanyId = companyId.(int64)  
63 - }  
64 - if companyLogo, ok := data["companyLogo"]; ok {  
65 - cooperationContractChangeLog.Company.CompanyLogo = companyLogo.(string)  
66 - }  
67 - if companyName, ok := data["companyName"]; ok {  
68 - cooperationContractChangeLog.Company.CompanyName = companyName.(string)  
69 - }  
70 - if userId, ok := data["userId"]; ok {  
71 - cooperationContractChangeLog.Operator.UserId = userId.(int64)  
72 - }  
73 - if userBaseId, ok := data["userBaseId"]; ok {  
74 - cooperationContractChangeLog.Operator.UserBaseId = userBaseId.(int64)  
75 - }  
76 - if orgId, ok := data["orgId"]; ok {  
77 - cooperationContractChangeLog.Operator.Org.OrgId = orgId.(int64)  
78 - }  
79 - if orgName, ok := data["orgName"]; ok {  
80 - cooperationContractChangeLog.Operator.Org.OrgName = orgName.(string)  
81 - }  
82 - if departmentId, ok := data["departmentId"]; ok {  
83 - cooperationContractChangeLog.Operator.Department.DepartmentId = departmentId.(int64)  
84 - }  
85 - if departmentName, ok := data["departmentName"]; ok {  
86 - cooperationContractChangeLog.Operator.Department.DepartmentName = departmentName.(string)  
87 - }  
88 - if departmentNumber, ok := data["departmentNumber"]; ok {  
89 - cooperationContractChangeLog.Operator.Department.DepartmentNumber = departmentNumber.(string)  
90 - }  
91 - if userAvatar, ok := data["userAvatar"]; ok {  
92 - cooperationContractChangeLog.Operator.UserInfo.UserAvatar = userAvatar.(string)  
93 - }  
94 - if userEmail, ok := data["userEmail"]; ok {  
95 - cooperationContractChangeLog.Operator.UserInfo.UserEmail = userEmail.(string)  
96 - }  
97 - if userName, ok := data["userName"]; ok {  
98 - cooperationContractChangeLog.Operator.UserInfo.UserName = userName.(string)  
99 - }  
100 - if userPhone, ok := data["userPhone"]; ok {  
101 - cooperationContractChangeLog.Operator.UserInfo.UserPhone = userPhone.(string)  
102 - }  
103 - if userAccount, ok := data["userAccount"]; ok {  
104 - cooperationContractChangeLog.Operator.UserInfo.UserAccount = userAccount.(string)  
105 - }  
106 - if userType, ok := data["userType"]; ok {  
107 - cooperationContractChangeLog.Operator.UserType = userType.(int32)  
108 - }  
109 - if status, ok := data["status"]; ok {  
110 - cooperationContractChangeLog.Operator.Status = status.(int32)  
111 - }  
112 return nil 71 return nil
113 } 72 }
@@ -2,6 +2,12 @@ package domain @@ -2,6 +2,12 @@ package domain
2 2
3 import "time" 3 import "time"
4 4
  5 +const (
  6 + TO_BE_DIVIDEND = iota + 1
  7 + ALL_DIVIDENDED
  8 + PART_DIVIDENDED
  9 +)
  10 +
5 // DividendsOrder 分红订单实体 11 // DividendsOrder 分红订单实体
6 type DividendsOrder struct { 12 type DividendsOrder struct {
7 // 分红订单ID 13 // 分红订单ID
@@ -21,8 +21,12 @@ type CooperationContractChangeLog struct { @@ -21,8 +21,12 @@ type CooperationContractChangeLog struct {
21 Undertakers string `comment:"承接人"` 21 Undertakers string `comment:"承接人"`
22 // 公司 22 // 公司
23 Company *domain.Company `comment:"公司"` 23 Company *domain.Company `comment:"公司"`
  24 + // 组织机构
  25 + Org *domain.Org `comment:"组织"`
24 // 操作人 26 // 操作人
25 Operator *domain.User `comment:"操作人"` 27 Operator *domain.User `comment:"操作人"`
  28 + // 操作时间
  29 + OperatorTime time.Time `comment:"操作时间"`
26 // 更新时间 30 // 更新时间
27 UpdatedAt time.Time `comment:"更新时间"` 31 UpdatedAt time.Time `comment:"更新时间"`
28 // 删除时间 32 // 删除时间
@@ -13,7 +13,9 @@ func TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationC @@ -13,7 +13,9 @@ func TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationC
13 CooperationContractNumber: cooperationContractChangeLogModel.CooperationContractNumber, 13 CooperationContractNumber: cooperationContractChangeLogModel.CooperationContractNumber,
14 Undertakers: cooperationContractChangeLogModel.Undertakers, 14 Undertakers: cooperationContractChangeLogModel.Undertakers,
15 Company: cooperationContractChangeLogModel.Company, 15 Company: cooperationContractChangeLogModel.Company,
  16 + Org: cooperationContractChangeLogModel.Org,
16 Operator: cooperationContractChangeLogModel.Operator, 17 Operator: cooperationContractChangeLogModel.Operator,
  18 + OperatorTime: cooperationContractChangeLogModel.OperatorTime,
17 UpdatedAt: cooperationContractChangeLogModel.UpdatedAt, 19 UpdatedAt: cooperationContractChangeLogModel.UpdatedAt,
18 DeletedAt: cooperationContractChangeLogModel.DeletedAt, 20 DeletedAt: cooperationContractChangeLogModel.DeletedAt,
19 CreatedAt: cooperationContractChangeLogModel.CreatedAt, 21 CreatedAt: cooperationContractChangeLogModel.CreatedAt,
@@ -33,7 +33,9 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -33,7 +33,9 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
33 "cooperation_contract_number", 33 "cooperation_contract_number",
34 "undertakers", 34 "undertakers",
35 "company", 35 "company",
  36 + "org",
36 "operator", 37 "operator",
  38 + "operator_time",
37 "updated_at", 39 "updated_at",
38 "deleted_at", 40 "deleted_at",
39 "created_at", 41 "created_at",
@@ -59,7 +61,9 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -59,7 +61,9 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
59 &cooperationContractChangeLog.CooperationContractNumber, 61 &cooperationContractChangeLog.CooperationContractNumber,
60 &cooperationContractChangeLog.Undertakers, 62 &cooperationContractChangeLog.Undertakers,
61 &cooperationContractChangeLog.Company, 63 &cooperationContractChangeLog.Company,
  64 + &cooperationContractChangeLog.Org,
62 &cooperationContractChangeLog.Operator, 65 &cooperationContractChangeLog.Operator,
  66 + &cooperationContractChangeLog.OperatorTime,
63 &cooperationContractChangeLog.UpdatedAt, 67 &cooperationContractChangeLog.UpdatedAt,
64 &cooperationContractChangeLog.DeletedAt, 68 &cooperationContractChangeLog.DeletedAt,
65 &cooperationContractChangeLog.CreatedAt, 69 &cooperationContractChangeLog.CreatedAt,
@@ -71,7 +75,9 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -71,7 +75,9 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
71 cooperationContractChangeLog.CooperationContractNumber, 75 cooperationContractChangeLog.CooperationContractNumber,
72 cooperationContractChangeLog.Undertakers, 76 cooperationContractChangeLog.Undertakers,
73 cooperationContractChangeLog.Company, 77 cooperationContractChangeLog.Company,
  78 + cooperationContractChangeLog.Org,
74 cooperationContractChangeLog.Operator, 79 cooperationContractChangeLog.Operator,
  80 + cooperationContractChangeLog.OperatorTime,
75 cooperationContractChangeLog.UpdatedAt, 81 cooperationContractChangeLog.UpdatedAt,
76 nil, 82 nil,
77 cooperationContractChangeLog.CreatedAt, 83 cooperationContractChangeLog.CreatedAt,
@@ -87,7 +93,9 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -87,7 +93,9 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
87 &cooperationContractChangeLog.CooperationContractNumber, 93 &cooperationContractChangeLog.CooperationContractNumber,
88 &cooperationContractChangeLog.Undertakers, 94 &cooperationContractChangeLog.Undertakers,
89 &cooperationContractChangeLog.Company, 95 &cooperationContractChangeLog.Company,
  96 + &cooperationContractChangeLog.Org,
90 &cooperationContractChangeLog.Operator, 97 &cooperationContractChangeLog.Operator,
  98 + &cooperationContractChangeLog.OperatorTime,
91 &cooperationContractChangeLog.UpdatedAt, 99 &cooperationContractChangeLog.UpdatedAt,
92 &cooperationContractChangeLog.DeletedAt, 100 &cooperationContractChangeLog.DeletedAt,
93 &cooperationContractChangeLog.CreatedAt, 101 &cooperationContractChangeLog.CreatedAt,
@@ -99,7 +107,9 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -99,7 +107,9 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
99 cooperationContractChangeLog.CooperationContractNumber, 107 cooperationContractChangeLog.CooperationContractNumber,
100 cooperationContractChangeLog.Undertakers, 108 cooperationContractChangeLog.Undertakers,
101 cooperationContractChangeLog.Company, 109 cooperationContractChangeLog.Company,
  110 + cooperationContractChangeLog.Org,
102 cooperationContractChangeLog.Operator, 111 cooperationContractChangeLog.Operator,
  112 + cooperationContractChangeLog.OperatorTime,
103 cooperationContractChangeLog.UpdatedAt, 113 cooperationContractChangeLog.UpdatedAt,
104 nil, 114 nil,
105 cooperationContractChangeLog.CreatedAt, 115 cooperationContractChangeLog.CreatedAt,