作者 yangfu

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

…ion-cooperation into dev
正在显示 32 个修改的文件 包含 460 行增加207 行删除
@@ -14,11 +14,11 @@ type ApplyForCooperationCommand struct { @@ -14,11 +14,11 @@ type ApplyForCooperationCommand struct {
14 // 共创申请描述 14 // 共创申请描述
15 CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription,omitempty"` 15 CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription,omitempty"`
16 // 申请人ID 16 // 申请人ID
17 - UserId int64 `cname:"申请人ID" json:"userId" valid:"Required"` 17 + UserId int64 `cname:"申请人ID" json:"userId"`
18 // 用户基本id 18 // 用户基本id
19 - UserBaseId int64 `cname:"用户基本数据ID" json:"userBaseId" valid:"Required"` 19 + UserBaseId int64 `cname:"用户基本数据ID" json:"userBaseId"`
20 // 组织机构ID 20 // 组织机构ID
21 - OrgId int64 `cname:"组织机构ID" json:"orgId" valid:"Required"` 21 + OrgId int64 `cname:"组织机构ID" json:"orgId"`
22 // 公司ID,通过集成REST上下文获取 22 // 公司ID,通过集成REST上下文获取
23 CompanyId int64 `cname:"公司ID" json:"companyId"` 23 CompanyId int64 `cname:"公司ID" json:"companyId"`
24 // 共创项目ID 24 // 共创项目ID
@@ -10,6 +10,7 @@ import ( @@ -10,6 +10,7 @@ import (
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
14 "strconv" 15 "strconv"
15 "time" 16 "time"
@@ -53,14 +54,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop @@ -53,14 +54,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
53 userService = value 54 userService = value
54 } 55 }
55 56
56 - // 获取申请人  
57 - var applicant *domain.User  
58 - if data, err := userService.UserFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId, applyForCooperationCommand.UserId); err != nil {  
59 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")  
60 - } else {  
61 - applicant = data  
62 - }  
63 -  
64 // 公司REST服务初始化 57 // 公司REST服务初始化
65 var companyService service.CompanyService 58 var companyService service.CompanyService
66 if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil { 59 if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
@@ -69,14 +62,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop @@ -69,14 +62,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
69 companyService = value 62 companyService = value
70 } 63 }
71 64
72 - // 获取公司信息  
73 - var company *domain.Company  
74 - if data, err := companyService.CompanyFrom(applyForCooperationCommand.CompanyId); err != nil {  
75 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司信息失败")  
76 - } else {  
77 - company = data  
78 - }  
79 -  
80 // 组织机构REST服务初始化 65 // 组织机构REST服务初始化
81 var organizationService service.OrgService 66 var organizationService service.OrgService
82 if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil { 67 if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
@@ -85,12 +70,24 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop @@ -85,12 +70,24 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
85 organizationService = value 70 organizationService = value
86 } 71 }
87 72
88 - // 获取组织机构信息  
89 - var organization *domain.Org  
90 - if data, err := organizationService.OrgFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId); err != nil {  
91 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取组织机构数据失败") 73 + // 共创申请仓储初始化
  74 + var cooperationApplicationRepository domain.CooperationApplicationRepository
  75 + if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
  76 + "transactionContext": transactionContext,
  77 + }); err != nil {
  78 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
92 } else { 79 } else {
93 - organization = data 80 + cooperationApplicationRepository = value
  81 + }
  82 +
  83 + // 共创申请DAO初始化
  84 + var cooperationApplicationDao *dao.CooperationApplicationDao
  85 + if value, err := factory.CreateCooperationApplicationDao(map[string]interface{}{
  86 + "transactionContext": transactionContext,
  87 + }); err != nil {
  88 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  89 + } else {
  90 + cooperationApplicationDao = value
94 } 91 }
95 92
96 // 获取共创项目 93 // 获取共创项目
@@ -102,36 +99,95 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop @@ -102,36 +99,95 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
102 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(applyForCooperationCommand.CooperationProjectId, 10))) 99 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(applyForCooperationCommand.CooperationProjectId, 10)))
103 } 100 }
104 101
105 - // TODO 校验:同一个用户,不能多次申请同一个项目 102 + var newCooperationApplication *domain.CooperationApplication
  103 +
  104 + if applyForCooperationCommand.CompanyId == 0 && applyForCooperationCommand.OrgId == 0 && applyForCooperationCommand.UserId == 0 { // 游客操作
  105 + // TODO 获取申请人信息
  106 +
  107 + // TODO 校验:同一个用户,不能多次申请同一个项目
  108 +
  109 + // TODO 校验:判断用户类型是否属于承接对象
  110 + //if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
  111 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
  112 + //}
  113 +
  114 + newCooperationApplication = &domain.CooperationApplication{
  115 + CooperationApplicationApplicant: nil, // TODO 获取游客(申请人)信息
  116 + CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
  117 + CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
  118 + CooperationApplicationStatus: 1,
  119 + CooperationApplicationVerifier: nil,
  120 + CooperationApplicationVerifyDescription: "",
  121 + CooperationApplicationVerifyTime: time.Time{},
  122 + CooperationApplyTime: time.Now(),
  123 + CooperationProject: cooperationProject,
  124 + Org: cooperationProject.Org,
  125 + IsCanceled: 1,
  126 + Company: cooperationProject.Company,
  127 + CreatedAt: time.Now(),
  128 + DeletedAt: time.Time{},
  129 + UpdatedAt: time.Time{},
  130 + }
  131 + } else {
  132 + // 获取申请人
  133 + var applicant *domain.User
  134 + if data, err := userService.UserFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId, applyForCooperationCommand.UserId); err != nil {
  135 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
  136 + } else {
  137 + applicant = data
  138 + }
106 139
107 - // TODO 校验:判断用户类型是否属于承接对象 140 + // 获取公司信息
  141 + var company *domain.Company
  142 + if data, err := companyService.CompanyFrom(applyForCooperationCommand.CompanyId); err != nil {
  143 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司信息失败")
  144 + } else {
  145 + company = data
  146 + }
108 147
109 - newCooperationApplication := &domain.CooperationApplication{  
110 - CooperationApplicationApplicant: applicant,  
111 - CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,  
112 - CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,  
113 - CooperationApplicationStatus: 1,  
114 - CooperationApplicationVerifier: nil,  
115 - CooperationApplicationVerifyDescription: "",  
116 - CooperationApplicationVerifyTime: time.Time{},  
117 - CooperationApplyTime: time.Now(),  
118 - CooperationProject: cooperationProject,  
119 - Org: organization,  
120 - IsCanceled: 1,  
121 - Company: company,  
122 - CreatedAt: time.Now(),  
123 - DeletedAt: time.Time{},  
124 - UpdatedAt: time.Time{},  
125 - } 148 + // 获取组织机构信息
  149 + var organization *domain.Org
  150 + if data, err := organizationService.OrgFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId); err != nil {
  151 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取组织机构数据失败")
  152 + } else {
  153 + organization = data
  154 + }
126 155
127 - var cooperationApplicationRepository domain.CooperationApplicationRepository  
128 - if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{  
129 - "transactionContext": transactionContext,  
130 - }); err != nil {  
131 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
132 - } else {  
133 - cooperationApplicationRepository = value 156 + // 校验:同一个用户,不能多次申请同一个项目
  157 + applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{
  158 + "companyId": applyForCooperationCommand.CompanyId,
  159 + "orgId": applyForCooperationCommand.OrgId,
  160 + "cooperationApplicationId": cooperationProject.CooperationProjectId,
  161 + })
  162 + if applicationExist {
  163 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "抱歉,您已经申请过该项目")
  164 + }
  165 +
  166 + // 校验:判断用户类型是否属于承接对象
  167 + if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
  168 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
  169 + }
  170 +
  171 + newCooperationApplication = &domain.CooperationApplication{
  172 + CooperationApplicationApplicant: applicant,
  173 + CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
  174 + CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
  175 + CooperationApplicationStatus: 1,
  176 + CooperationApplicationVerifier: nil,
  177 + CooperationApplicationVerifyDescription: "",
  178 + CooperationApplicationVerifyTime: time.Time{},
  179 + CooperationApplyTime: time.Now(),
  180 + CooperationProject: cooperationProject,
  181 + Org: organization,
  182 + IsCanceled: 1,
  183 + Company: company,
  184 + CreatedAt: time.Now(),
  185 + DeletedAt: time.Time{},
  186 + UpdatedAt: time.Time{},
  187 + }
134 } 188 }
  189 +
  190 + // 保存共创申请
135 if cooperationApplication, err := cooperationApplicationRepository.Save(newCooperationApplication); err != nil { 191 if cooperationApplication, err := cooperationApplicationRepository.Save(newCooperationApplication); err != nil {
136 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 192 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
137 } else { 193 } else {
@@ -2,6 +2,9 @@ package service @@ -2,6 +2,9 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "strconv"
  6 + "time"
  7 +
5 "github.com/linmadan/egglib-go/core/application" 8 "github.com/linmadan/egglib-go/core/application"
6 "github.com/linmadan/egglib-go/utils/tool_funs" 9 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/command" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/command"
@@ -13,8 +16,6 @@ import ( @@ -13,8 +16,6 @@ import (
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" 16 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 17 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
15 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" 18 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
16 - "strconv"  
17 - "time"  
18 ) 19 )
19 20
20 // CooperationContractService 共创合约服务 21 // CooperationContractService 共创合约服务
@@ -269,7 +270,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -269,7 +270,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
269 MoneyIncentivesStage: moneyIncentivesRule.MoneyIncentivesStage, 270 MoneyIncentivesStage: moneyIncentivesRule.MoneyIncentivesStage,
270 MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd, 271 MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
271 MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart, 272 MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart,
272 - MoneyIncentivesTime: time.Now(), 273 + MoneyIncentivesTime: moneyIncentivesRule.MoneyIncentivesTime,
273 ReferrerPercentage: moneyIncentivesRule.ReferrerPercentage, 274 ReferrerPercentage: moneyIncentivesRule.ReferrerPercentage,
274 SalesmanPercentage: moneyIncentivesRule.SalesmanPercentage, 275 SalesmanPercentage: moneyIncentivesRule.SalesmanPercentage,
275 Org: organization, 276 Org: organization,
@@ -828,7 +829,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC @@ -828,7 +829,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
828 if count, cooperationContractByUndertakers, err := cooperationContractDao.SearchCooperationContractByUndertaker(tool_funs.SimpleStructToMap(searchCooperationContractByUndertakerQuery)); err != nil { 829 if count, cooperationContractByUndertakers, err := cooperationContractDao.SearchCooperationContractByUndertaker(tool_funs.SimpleStructToMap(searchCooperationContractByUndertakerQuery)); err != nil {
829 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 830 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
830 } else { 831 } else {
831 - var cooperationContractByUndertakerDtos []*dto.CooperationContractByUndertakerDto 832 + cooperationContractByUndertakerDtos := []*dto.CooperationContractByUndertakerDto{}
832 for _, cooperationContractByUndertaker := range cooperationContractByUndertakers { 833 for _, cooperationContractByUndertaker := range cooperationContractByUndertakers {
833 cooperationContractByUndertakerDto := &dto.CooperationContractByUndertakerDto{} 834 cooperationContractByUndertakerDto := &dto.CooperationContractByUndertakerDto{}
834 if err := cooperationContractByUndertakerDto.LoadDto(cooperationContractByUndertaker); err != nil { 835 if err := cooperationContractByUndertakerDto.LoadDto(cooperationContractByUndertaker); err != nil {
@@ -75,12 +75,16 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive @@ -75,12 +75,16 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
75 for _, orderGood := range orderGoods { 75 for _, orderGood := range orderGoods {
76 dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{} 76 dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{}
77 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 77 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
78 - dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber}) 78 + dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
  79 + "dividendsOrderNumber": orderGood.DividendsOrderNumber,
  80 + "companyId": orderGood.CompanyId,
  81 + "orgId": orderGood.OrgId,
  82 + })
79 if err != nil { 83 if err != nil {
80 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 84 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
81 } 85 }
82 if dividendsOrder == nil { 86 if dividendsOrder == nil {
83 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber)) 87 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
84 } 88 }
85 if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsOrder.DividendsOrderNumber, dividendsOrder.DividendsOriginalOrderNum, dividendsOrder.CustomerName, dividendsOrder.Region.RegionName, dividendsOrder.OrderTime); err != nil { 89 if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsOrder.DividendsOrderNumber, dividendsOrder.DividendsOriginalOrderNum, dividendsOrder.CustomerName, dividendsOrder.Region.RegionName, dividendsOrder.OrderTime); err != nil {
86 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 90 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -92,7 +96,7 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive @@ -92,7 +96,7 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
92 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 96 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
93 } 97 }
94 if dividendsReturnedOrder == nil { 98 if dividendsReturnedOrder == nil {
95 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber)) 99 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红退货单%s不存在", orderGood.DividendsReturnedOrderNumber))
96 } 100 }
97 if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsReturnedOrder.DividendsReturnedOrderNumber, dividendsReturnedOrder.OriginalOrderNum, dividendsReturnedOrder.DividendsReturnedCustomerName, dividendsReturnedOrder.Region.RegionName, dividendsReturnedOrder.OrderTime); err != nil { 101 if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsReturnedOrder.DividendsReturnedOrderNumber, dividendsReturnedOrder.OriginalOrderNum, dividendsReturnedOrder.DividendsReturnedCustomerName, dividendsReturnedOrder.Region.RegionName, dividendsReturnedOrder.OrderTime); err != nil {
98 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 102 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -615,12 +619,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -615,12 +619,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
615 for _, orderGood := range orderGoods { 619 for _, orderGood := range orderGoods {
616 dividendsEstimate := &domain.DividendsEstimate{} 620 dividendsEstimate := &domain.DividendsEstimate{}
617 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 621 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
618 - dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber}) 622 + dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
  623 + "dividendsOrderNumber": orderGood.DividendsOrderNumber,
  624 + "companyId": orderGood.CompanyId,
  625 + "orgId": orderGood.OrgId,
  626 + })
619 if err3 != nil { 627 if err3 != nil {
620 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在") 628 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
621 } 629 }
622 if dividendsOrder == nil { 630 if dividendsOrder == nil {
623 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber)) 631 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
624 } 632 }
625 // 分红订单产品预算 633 // 分红订单产品预算
626 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { 634 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
@@ -665,7 +673,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -665,7 +673,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
665 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 673 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
666 } 674 }
667 if dividendsReturnedOrder == nil { 675 if dividendsReturnedOrder == nil {
668 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber)) 676 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红退货单%s不存在", orderGood.DividendsReturnedOrderNumber))
669 } 677 }
670 // 分红退货单产品预算 678 // 分红退货单产品预算
671 if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { 679 if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
@@ -1098,7 +1106,11 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti @@ -1098,7 +1106,11 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
1098 for _, orderGood := range orderGoods { 1106 for _, orderGood := range orderGoods {
1099 dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{} 1107 dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{}
1100 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 1108 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
1101 - dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber}) 1109 + dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
  1110 + "dividendsOrderNumber": orderGood.DividendsOrderNumber,
  1111 + "companyId": orderGood.CompanyId,
  1112 + "orgId": orderGood.OrgId,
  1113 + })
1102 if err != nil { 1114 if err != nil {
1103 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1115 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1104 } 1116 }
@@ -18,7 +18,7 @@ type OrderGoods struct { @@ -18,7 +18,7 @@ type OrderGoods struct {
18 // 订单产品单价 18 // 订单产品单价
19 OrderGoodPrice float64 `json:"orderGoodPrice"` 19 OrderGoodPrice float64 `json:"orderGoodPrice"`
20 // 订单产品数量 20 // 订单产品数量
21 - OrderGoodQuantity int64 `json:"orderGoodQuantity"` 21 + OrderGoodQuantity float64 `json:"orderGoodQuantity"`
22 // 关联分红订单号 22 // 关联分红订单号
23 DividendsOrderNumber string `json:"dividendsOrderNumber"` 23 DividendsOrderNumber string `json:"dividendsOrderNumber"`
24 // 关联的共创合约编号 24 // 关联的共创合约编号
@@ -141,7 +141,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD @@ -141,7 +141,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
141 UpdatedAt: time.Time{}, 141 UpdatedAt: time.Time{},
142 }) 142 })
143 // 计算分红订单金额 143 // 计算分红订单金额
144 - dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)))).Float64() 144 + dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64()
145 } 145 }
146 146
147 // 订单时间转换 147 // 订单时间转换
@@ -488,7 +488,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -488,7 +488,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
488 } 488 }
489 489
490 // 产品相关:产品名称,产品数量、产品价格、费用 490 // 产品相关:产品名称,产品数量、产品价格、费用
491 - quantity, err := strconv.ParseInt(dividendsOrder.OrderGoodQuantity, 10, 64) 491 + quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64)
492 if err != nil { 492 if err != nil {
493 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 493 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
494 } 494 }
@@ -533,7 +533,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -533,7 +533,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
533 } 533 }
534 } else { // 聚合同一笔订单产品 534 } else { // 聚合同一笔订单产品
535 // 产品相关:产品名称,产品数量、产品价格、费用 535 // 产品相关:产品名称,产品数量、产品价格、费用
536 - quantity, err := strconv.ParseInt(dividendsOrder.OrderGoodQuantity, 10, 64) 536 + quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64)
537 if err != nil { 537 if err != nil {
538 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 538 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
539 } 539 }
@@ -1096,6 +1096,7 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD @@ -1096,6 +1096,7 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD
1096 DividendsReturnedOrderNumber: "", 1096 DividendsReturnedOrderNumber: "",
1097 CooperationContractNumber: orderGood.CooperationContractNumber, 1097 CooperationContractNumber: orderGood.CooperationContractNumber,
1098 OrderGoodExpense: orderGood.OrderGoodExpense, 1098 OrderGoodExpense: orderGood.OrderGoodExpense,
  1099 + OrderGoodDividendsStatus: 0,
1099 OrgId: updateDividendsOrderCommand.OrgId, 1100 OrgId: updateDividendsOrderCommand.OrgId,
1100 CompanyId: updateDividendsOrderCommand.CompanyId, 1101 CompanyId: updateDividendsOrderCommand.CompanyId,
1101 CreatedAt: time.Time{}, 1102 CreatedAt: time.Time{},
@@ -17,7 +17,7 @@ type OrderGoods struct { @@ -17,7 +17,7 @@ type OrderGoods struct {
17 // 订单产品单价 17 // 订单产品单价
18 OrderGoodPrice float64 `cname:"订单产品单价" json:"orderGoodPrice"` 18 OrderGoodPrice float64 `cname:"订单产品单价" json:"orderGoodPrice"`
19 // 订单产品数量 19 // 订单产品数量
20 - OrderGoodQuantity int64 `cname:"订单产品数量" json:"orderGoodQuantity"` 20 + OrderGoodQuantity float64 `cname:"订单产品数量" json:"orderGoodQuantity"`
21 // 关联分红订单号 21 // 关联分红订单号
22 DividendsOrderNumber string `cname:"关联分红订单号" json:"dividendsOrderNumber"` 22 DividendsOrderNumber string `cname:"关联分红订单号" json:"dividendsOrderNumber"`
23 // 关联的共创合约编号 23 // 关联的共创合约编号
@@ -10,14 +10,14 @@ import ( @@ -10,14 +10,14 @@ import (
10 type UpdateDividendsReturnedOrderCommand struct { 10 type UpdateDividendsReturnedOrderCommand struct {
11 // 分红退货单记录ID 11 // 分红退货单记录ID
12 DividendsReturnedOrderId string `cname:"分红退货单记录ID" json:"dividendsReturnedOrderId" valid:"Required"` 12 DividendsReturnedOrderId string `cname:"分红退货单记录ID" json:"dividendsReturnedOrderId" valid:"Required"`
13 - // 退货金额  
14 - DividendsReturnedOrderRefund float64 `cname:"退货金额" json:"dividendsReturnedOrderRefund" valid:"Required"`  
15 // 退货客户名称 13 // 退货客户名称
16 DividendsReturnedCustomerName string `cname:"退货客户名称" json:"dividendsReturnedCustomerName" valid:"Required"` 14 DividendsReturnedCustomerName string `cname:"退货客户名称" json:"dividendsReturnedCustomerName" valid:"Required"`
17 // 来源单号,源单号,订单号 15 // 来源单号,源单号,订单号
18 OriginalOrderNum string `cname:"来源单号" json:"originalOrderNum" valid:"Required"` 16 OriginalOrderNum string `cname:"来源单号" json:"originalOrderNum" valid:"Required"`
  17 + // 分红单号
  18 + DividendsOrderNumber string `cname:"订单号" json:"dividendsOrderNumber"`
19 // 备注 19 // 备注
20 - Remarks string `cname:"备注" json:"remarks" valid:"Required"` 20 + Remarks string `cname:"备注" json:"remarks"`
21 // 退货日期 21 // 退货日期
22 DividendsReturnedDate string `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"` 22 DividendsReturnedDate string `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
23 // 退货区域 23 // 退货区域
@@ -524,7 +524,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -524,7 +524,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
524 } 524 }
525 525
526 // 产品相关:产品名称,退货数量、退货价格 526 // 产品相关:产品名称,退货数量、退货价格
527 - quantity, err := strconv.ParseInt(dividendsReturnedOrder.OrderGoodQuantity, 10, 64) 527 + quantity, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodQuantity, 64)
528 if err != nil { 528 if err != nil {
529 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 529 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
530 } 530 }
@@ -562,7 +562,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -562,7 +562,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
562 } 562 }
563 } else { // 聚合同一笔订单产品 563 } else { // 聚合同一笔订单产品
564 // 产品相关:产品名称,退货数量、退货价格 564 // 产品相关:产品名称,退货数量、退货价格
565 - quantity, err := strconv.ParseInt(dividendsReturnedOrder.OrderGoodQuantity, 10, 64) 565 + quantity, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodQuantity, 64)
566 if err != nil { 566 if err != nil {
567 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 567 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
568 } 568 }
@@ -60,3 +60,11 @@ func CreateDividendsEstimateDao(options map[string]interface{}) (*dao.DividendsE @@ -60,3 +60,11 @@ func CreateDividendsEstimateDao(options map[string]interface{}) (*dao.DividendsE
60 } 60 }
61 return dao.NewDividendsEstimateDao(transactionContext) 61 return dao.NewDividendsEstimateDao(transactionContext)
62 } 62 }
  63 +
  64 +func CreateCooperationApplicationDao(options map[string]interface{}) (*dao.CooperationApplicationDao, error) {
  65 + var transactionContext *pg.TransactionContext
  66 + if value, ok := options["transactionContext"]; ok {
  67 + transactionContext = value.(*pg.TransactionContext)
  68 + }
  69 + return dao.NewCooperationApplicationDao(transactionContext)
  70 +}
@@ -18,7 +18,7 @@ type OrderGood struct { @@ -18,7 +18,7 @@ type OrderGood struct {
18 // 订单产品单价 18 // 订单产品单价
19 OrderGoodPrice float64 `json:"orderGoodPrice"` 19 OrderGoodPrice float64 `json:"orderGoodPrice"`
20 // 订单产品数量 20 // 订单产品数量
21 - OrderGoodQuantity int64 `json:"orderGoodQuantity,string"` 21 + OrderGoodQuantity float64 `json:"orderGoodQuantity,string"`
22 // 关联分红订单号 22 // 关联分红订单号
23 DividendsOrderNumber string `json:"dividendsOrderNumber"` 23 DividendsOrderNumber string `json:"dividendsOrderNumber"`
24 // 关联的分红退货单号 24 // 关联的分红退货单号
@@ -66,7 +66,7 @@ func (orderGood *OrderGood) Update(data map[string]interface{}) error { @@ -66,7 +66,7 @@ func (orderGood *OrderGood) Update(data map[string]interface{}) error {
66 orderGood.OrderGoodPrice = orderGoodPrice.(float64) 66 orderGood.OrderGoodPrice = orderGoodPrice.(float64)
67 } 67 }
68 if orderGoodQuantity, ok := data["orderGoodQuantity"]; ok { 68 if orderGoodQuantity, ok := data["orderGoodQuantity"]; ok {
69 - orderGood.OrderGoodQuantity = orderGoodQuantity.(int64) 69 + orderGood.OrderGoodQuantity = orderGoodQuantity.(float64)
70 } 70 }
71 if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok { 71 if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
72 orderGood.CooperationContractNumber = cooperationContractNumber.(string) 72 orderGood.CooperationContractNumber = cooperationContractNumber.(string)
@@ -31,3 +31,10 @@ type Relevant struct { @@ -31,3 +31,10 @@ type Relevant struct {
31 // 公司 31 // 公司
32 Company *Company `json:"company"` 32 Company *Company `json:"company"`
33 } 33 }
  34 +
  35 +func (relevant *Relevant) Identify() interface{} {
  36 + if relevant.RelevantId == 0 {
  37 + return nil
  38 + }
  39 + return relevant.RelevantId
  40 +}
@@ -37,3 +37,10 @@ type Undertaker struct { @@ -37,3 +37,10 @@ type Undertaker struct {
37 // 合同附件 37 // 合同附件
38 ContractAttachment []*Attachment `json:"contractAttachment"` 38 ContractAttachment []*Attachment `json:"contractAttachment"`
39 } 39 }
  40 +
  41 +func (undertaker *Undertaker) Identify() interface{} {
  42 + if undertaker.UndertakerId == 0 {
  43 + return nil
  44 + }
  45 + return undertaker.UndertakerId
  46 +}
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
  7 +)
  8 +
  9 +type CooperationApplicationDao struct {
  10 + transactionContext *pgTransaction.TransactionContext
  11 +}
  12 +
  13 +// CheckApplicationExist 判断该申请人是否提交过申请
  14 +func (dao *CooperationApplicationDao) CheckApplicationExist(queryOptions map[string]interface{}) (bool, error) {
  15 + tx := dao.transactionContext.PgTx
  16 + var cooperationApplicationModels []*models.CooperationApplication
  17 + query := tx.Model(&cooperationApplicationModels)
  18 + if cooperationApplicationId, ok := queryOptions["cooperationApplicationId"]; ok && cooperationApplicationId != "" {
  19 + query = query.Where("cooperation_application_id = ?", cooperationApplicationId)
  20 + }
  21 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  22 + query = query.Where(`cooperation_application.company @> '{"companyId":"?"}'`, companyId)
  23 + }
  24 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  25 + query = query.Where(`cooperation_application.org @> '{"orgId":"?"}'`, orgId)
  26 + }
  27 + if applicantId, ok := queryOptions["applicantId"]; ok && applicantId.(int64) != 0 {
  28 + query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userId":"?"}'`, applicantId)
  29 + }
  30 + if applicantBaseId, ok := queryOptions["applicantBaseId"]; ok && applicantBaseId.(int64) != 0 {
  31 + query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, applicantBaseId)
  32 + }
  33 + ok, err := query.Exists()
  34 + return ok, err
  35 +}
  36 +
  37 +func NewCooperationApplicationDao(transactionContext *pgTransaction.TransactionContext) (*CooperationApplicationDao, error) {
  38 + if transactionContext == nil {
  39 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  40 + } else {
  41 + return &CooperationApplicationDao{
  42 + transactionContext: transactionContext,
  43 + }, nil
  44 + }
  45 +}
@@ -47,18 +47,20 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -47,18 +47,20 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
47 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创合约不存在") 47 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创合约不存在")
48 } 48 }
49 if cooperationContract == nil { 49 if cooperationContract == nil {
50 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.CooperationContractNumber)) 50 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
51 } 51 }
52 if orderGood.DividendsOrderNumber != "" { 52 if orderGood.DividendsOrderNumber != "" {
53 // 获取分红订单 53 // 获取分红订单
54 dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{ 54 dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
55 "dividendsOrderNumber": orderGood.DividendsOrderNumber, 55 "dividendsOrderNumber": orderGood.DividendsOrderNumber,
  56 + "companyId": orderGood.CompanyId,
  57 + "orgId": orderGood.OrgId,
56 }) 58 })
57 if err2 != nil { 59 if err2 != nil {
58 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在") 60 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
59 } 61 }
60 if dividendsOrder == nil { 62 if dividendsOrder == nil {
61 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber)) 63 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
62 } 64 }
63 // 匹配分红规则 65 // 匹配分红规则
64 var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule 66 var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
@@ -77,7 +79,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -77,7 +79,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
77 for _, undertaker := range cooperationContract.Undertakers { 79 for _, undertaker := range cooperationContract.Undertakers {
78 // 添加承接人分红预算信息详情 80 // 添加承接人分红预算信息详情
79 // TODO 使用decimal提高精度 81 // TODO 使用decimal提高精度
80 - undertakerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100 82 + undertakerDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100
81 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 83 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
82 DividendsUser: &domain.User{ 84 DividendsUser: &domain.User{
83 UserId: undertaker.UserId, 85 UserId: undertaker.UserId,
@@ -88,7 +90,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -88,7 +90,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
88 Roles: undertaker.Roles, 90 Roles: undertaker.Roles,
89 UserInfo: undertaker.UserInfo, 91 UserInfo: undertaker.UserInfo,
90 UserType: undertaker.UserType, 92 UserType: undertaker.UserType,
91 - UserName: undertaker.UserName, 93 + UserName: undertaker.UserInfo.UserName,
92 UserPhone: undertaker.UserPhone, 94 UserPhone: undertaker.UserPhone,
93 Status: undertaker.Status, 95 Status: undertaker.Status,
94 Company: undertaker.Company, 96 Company: undertaker.Company,
@@ -99,7 +101,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -99,7 +101,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
99 }) 101 })
100 // 添加推荐人分红预算信息详情 102 // 添加推荐人分红预算信息详情
101 if undertaker.Referrer != nil { 103 if undertaker.Referrer != nil {
102 - referrerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.ReferrerPercentage / 100 104 + referrerDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage / 100
103 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 105 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
104 DividendsUser: &domain.User{ 106 DividendsUser: &domain.User{
105 UserId: undertaker.Referrer.UserId, 107 UserId: undertaker.Referrer.UserId,
@@ -110,7 +112,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -110,7 +112,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
110 Roles: undertaker.Referrer.Roles, 112 Roles: undertaker.Referrer.Roles,
111 UserInfo: undertaker.Referrer.UserInfo, 113 UserInfo: undertaker.Referrer.UserInfo,
112 UserType: undertaker.Referrer.UserType, 114 UserType: undertaker.Referrer.UserType,
113 - UserName: undertaker.Referrer.UserName, 115 + UserName: undertaker.Referrer.UserInfo.UserName,
114 UserPhone: undertaker.Referrer.UserPhone, 116 UserPhone: undertaker.Referrer.UserPhone,
115 Company: undertaker.Referrer.Company, 117 Company: undertaker.Referrer.Company,
116 }, 118 },
@@ -121,7 +123,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -121,7 +123,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
121 } 123 }
122 // 添加关联业务员分红预算信息详情 124 // 添加关联业务员分红预算信息详情
123 if undertaker.Salesman != nil { 125 if undertaker.Salesman != nil {
124 - salesmanDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.SalesmanPercentage / 100 126 + salesmanDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage / 100
125 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 127 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
126 DividendsUser: &domain.User{ 128 DividendsUser: &domain.User{
127 UserId: undertaker.Salesman.UserId, 129 UserId: undertaker.Salesman.UserId,
@@ -132,7 +134,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -132,7 +134,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
132 Roles: undertaker.Salesman.Roles, 134 Roles: undertaker.Salesman.Roles,
133 UserInfo: undertaker.Salesman.UserInfo, 135 UserInfo: undertaker.Salesman.UserInfo,
134 UserType: undertaker.Salesman.UserType, 136 UserType: undertaker.Salesman.UserType,
135 - UserName: undertaker.Salesman.UserName, 137 + UserName: undertaker.Salesman.UserInfo.UserName,
136 UserPhone: undertaker.Salesman.UserPhone, 138 UserPhone: undertaker.Salesman.UserPhone,
137 Company: undertaker.Salesman.Company, 139 Company: undertaker.Salesman.Company,
138 }, 140 },
@@ -175,7 +177,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -175,7 +177,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
175 Roles: undertaker.Roles, 177 Roles: undertaker.Roles,
176 UserInfo: undertaker.UserInfo, 178 UserInfo: undertaker.UserInfo,
177 UserType: undertaker.UserType, 179 UserType: undertaker.UserType,
178 - UserName: undertaker.UserName, 180 + UserName: undertaker.UserInfo.UserName,
179 UserPhone: undertaker.UserPhone, 181 UserPhone: undertaker.UserPhone,
180 Status: undertaker.Status, 182 Status: undertaker.Status,
181 Company: undertaker.Company, 183 Company: undertaker.Company,
@@ -197,7 +199,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -197,7 +199,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
197 Roles: undertaker.Referrer.Roles, 199 Roles: undertaker.Referrer.Roles,
198 UserInfo: undertaker.Referrer.UserInfo, 200 UserInfo: undertaker.Referrer.UserInfo,
199 UserType: undertaker.Referrer.UserType, 201 UserType: undertaker.Referrer.UserType,
200 - UserName: undertaker.Referrer.UserName, 202 + UserName: undertaker.Referrer.UserInfo.UserName,
201 UserPhone: undertaker.Referrer.UserPhone, 203 UserPhone: undertaker.Referrer.UserPhone,
202 Company: undertaker.Referrer.Company, 204 Company: undertaker.Referrer.Company,
203 }, 205 },
@@ -219,7 +221,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -219,7 +221,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
219 Roles: undertaker.Salesman.Roles, 221 Roles: undertaker.Salesman.Roles,
220 UserInfo: undertaker.Salesman.UserInfo, 222 UserInfo: undertaker.Salesman.UserInfo,
221 UserType: undertaker.Salesman.UserType, 223 UserType: undertaker.Salesman.UserType,
222 - UserName: undertaker.Salesman.UserName, 224 + UserName: undertaker.Salesman.UserInfo.UserName,
223 UserPhone: undertaker.Salesman.UserPhone, 225 UserPhone: undertaker.Salesman.UserPhone,
224 Company: undertaker.Salesman.Company, 226 Company: undertaker.Salesman.Company,
225 }, 227 },
@@ -440,7 +440,11 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m @@ -440,7 +440,11 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
440 DividendsUser: item.DividendsUser, 440 DividendsUser: item.DividendsUser,
441 } 441 }
442 if item.DividendsType == 1 { 442 if item.DividendsType == 1 {
443 - order, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": item.OrderOrReturnedOrderNum}) 443 + order, err := dividendsOrderRepository.FindOne(map[string]interface{}{
  444 + "dividendsOrderNumber": item.OrderOrReturnedOrderNum,
  445 + "companyId": item.Company.CompanyId,
  446 + "orgId": item.Org.OrgId,
  447 + })
444 if err != nil { 448 if err != nil {
445 return nil, err 449 return nil, err
446 } 450 }
@@ -13,7 +13,7 @@ type OrderGood struct { @@ -13,7 +13,7 @@ type OrderGood struct {
13 // 订单产品单价 13 // 订单产品单价
14 OrderGoodPrice float64 `comment:"订单产品单价"` 14 OrderGoodPrice float64 `comment:"订单产品单价"`
15 // 订单产品数量 15 // 订单产品数量
16 - OrderGoodQuantity int64 `comment:"订单产品数量"` 16 + OrderGoodQuantity float64 `comment:"订单产品数量"`
17 // 关联分红订单号 17 // 关联分红订单号
18 DividendsOrderNumber string `comment:"关联分红订单号"` 18 DividendsOrderNumber string `comment:"关联分红订单号"`
19 // 关联的分红退货单号 19 // 关联的分红退货单号
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type ContractUndertakerFeedbackRepository struct { 16 type ContractUndertakerFeedbackRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *ContractUndertakerFeedbackRepository) nextIdentify() (int64, error) { 21 func (repository *ContractUndertakerFeedbackRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -202,8 +199,13 @@ func NewContractUndertakerFeedbackRepository(transactionContext *pgTransaction.T @@ -202,8 +199,13 @@ func NewContractUndertakerFeedbackRepository(transactionContext *pgTransaction.T
202 if transactionContext == nil { 199 if transactionContext == nil {
203 return nil, fmt.Errorf("transactionContext参数不能为nil") 200 return nil, fmt.Errorf("transactionContext参数不能为nil")
204 } else { 201 } else {
  202 + idWorker, err := snowflake.NewIdWorker(1)
  203 + if err != nil {
  204 + return nil, err
  205 + }
205 return &ContractUndertakerFeedbackRepository{ 206 return &ContractUndertakerFeedbackRepository{
206 transactionContext: transactionContext, 207 transactionContext: transactionContext,
  208 + IdWorker: idWorker,
207 }, nil 209 }, nil
208 } 210 }
209 } 211 }
@@ -17,14 +17,11 @@ import ( @@ -17,14 +17,11 @@ import (
17 17
18 type CooperationApplicationRepository struct { 18 type CooperationApplicationRepository struct {
19 transactionContext *pgTransaction.TransactionContext 19 transactionContext *pgTransaction.TransactionContext
  20 + IdWorker *snowflake.IdWorker
20 } 21 }
21 22
22 func (repository *CooperationApplicationRepository) nextIdentify() (int64, error) { 23 func (repository *CooperationApplicationRepository) nextIdentify() (int64, error) {
23 - IdWorker, err := snowflake.NewIdWorker(1)  
24 - if err != nil {  
25 - return 0, err  
26 - }  
27 - id, err := IdWorker.NextId() 24 + id, err := repository.IdWorker.NextId()
28 return id, err 25 return id, err
29 } 26 }
30 27
@@ -322,8 +319,13 @@ func NewCooperationApplicationRepository(transactionContext *pgTransaction.Trans @@ -322,8 +319,13 @@ func NewCooperationApplicationRepository(transactionContext *pgTransaction.Trans
322 if transactionContext == nil { 319 if transactionContext == nil {
323 return nil, fmt.Errorf("transactionContext参数不能为nil") 320 return nil, fmt.Errorf("transactionContext参数不能为nil")
324 } else { 321 } else {
  322 + idWorker, err := snowflake.NewIdWorker(1)
  323 + if err != nil {
  324 + return nil, err
  325 + }
325 return &CooperationApplicationRepository{ 326 return &CooperationApplicationRepository{
326 transactionContext: transactionContext, 327 transactionContext: transactionContext,
  328 + IdWorker: idWorker,
327 }, nil 329 }, nil
328 } 330 }
329 } 331 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type CooperationContractChangeLogRepository struct { 16 type CooperationContractChangeLogRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *CooperationContractChangeLogRepository) nextIdentify() (int64, error) { 21 func (repository *CooperationContractChangeLogRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -198,8 +195,13 @@ func NewCooperationContractChangeLogRepository(transactionContext *pgTransaction @@ -198,8 +195,13 @@ func NewCooperationContractChangeLogRepository(transactionContext *pgTransaction
198 if transactionContext == nil { 195 if transactionContext == nil {
199 return nil, fmt.Errorf("transactionContext参数不能为nil") 196 return nil, fmt.Errorf("transactionContext参数不能为nil")
200 } else { 197 } else {
  198 + idWorker, err := snowflake.NewIdWorker(1)
  199 + if err != nil {
  200 + return nil, err
  201 + }
201 return &CooperationContractChangeLogRepository{ 202 return &CooperationContractChangeLogRepository{
202 transactionContext: transactionContext, 203 transactionContext: transactionContext,
  204 + IdWorker: idWorker,
203 }, nil 205 }, nil
204 } 206 }
205 } 207 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type CooperationContractRelevantRepository struct { 16 type CooperationContractRelevantRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *CooperationContractRelevantRepository) nextIdentify() (int64, error) { 21 func (repository *CooperationContractRelevantRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -210,8 +207,13 @@ func NewCooperationContractRelevantRepository(transactionContext *pgTransaction. @@ -210,8 +207,13 @@ func NewCooperationContractRelevantRepository(transactionContext *pgTransaction.
210 if transactionContext == nil { 207 if transactionContext == nil {
211 return nil, fmt.Errorf("transactionContext参数不能为nil") 208 return nil, fmt.Errorf("transactionContext参数不能为nil")
212 } else { 209 } else {
  210 + idWorker, err := snowflake.NewIdWorker(1)
  211 + if err != nil {
  212 + return nil, err
  213 + }
213 return &CooperationContractRelevantRepository{ 214 return &CooperationContractRelevantRepository{
214 transactionContext: transactionContext, 215 transactionContext: transactionContext,
  216 + IdWorker: idWorker,
215 }, nil 217 }, nil
216 } 218 }
217 } 219 }
@@ -16,14 +16,11 @@ import ( @@ -16,14 +16,11 @@ import (
16 16
17 type CooperationContractRepository struct { 17 type CooperationContractRepository struct {
18 transactionContext *pgTransaction.TransactionContext 18 transactionContext *pgTransaction.TransactionContext
  19 + IdWorker *snowflake.IdWorker
19 } 20 }
20 21
21 func (repository *CooperationContractRepository) nextIdentify() (int64, error) { 22 func (repository *CooperationContractRepository) nextIdentify() (int64, error) {
22 - IdWorker, err := snowflake.NewIdWorker(1)  
23 - if err != nil {  
24 - return 0, err  
25 - }  
26 - id, err := IdWorker.NextId() 23 + id, err := repository.IdWorker.NextId()
27 return id, err 24 return id, err
28 } 25 }
29 26
@@ -108,21 +105,30 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -108,21 +105,30 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
108 // 新增相关人 105 // 新增相关人
109 var relevantPeopleModel []*models.CooperationContractRelevant 106 var relevantPeopleModel []*models.CooperationContractRelevant
110 for _, relevant := range cooperationContract.RelevantPeople { 107 for _, relevant := range cooperationContract.RelevantPeople {
  108 + if relevant.Identify() == nil {
  109 + orderGoodId, err := repository.nextIdentify()
  110 + if err != nil {
  111 + return nil, err
  112 + } else {
  113 + relevant.RelevantId = orderGoodId
  114 + }
  115 + }
111 relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{ 116 relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
112 - CooperationContractNumber: cooperationContract.CooperationContractNumber,  
113 - UserId: relevant.UserId,  
114 - UserBaseId: relevant.UserBaseId,  
115 - Org: relevant.Org,  
116 - Orgs: relevant.Orgs,  
117 - Department: relevant.Department,  
118 - Roles: relevant.Roles,  
119 - UserInfo: relevant.UserInfo,  
120 - UserType: relevant.UserType,  
121 - Status: relevant.Status,  
122 - Company: relevant.Company,  
123 - UpdatedAt: time.Time{},  
124 - DeletedAt: time.Time{},  
125 - CreatedAt: time.Now(), 117 + CooperationContractRelevantId: relevant.RelevantId,
  118 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  119 + UserId: relevant.UserId,
  120 + UserBaseId: relevant.UserBaseId,
  121 + Org: relevant.Org,
  122 + Orgs: relevant.Orgs,
  123 + Department: relevant.Department,
  124 + Roles: relevant.Roles,
  125 + UserInfo: relevant.UserInfo,
  126 + UserType: relevant.UserType,
  127 + Status: relevant.Status,
  128 + Company: relevant.Company,
  129 + UpdatedAt: time.Time{},
  130 + DeletedAt: time.Time{},
  131 + CreatedAt: time.Now(),
126 }) 132 })
127 } 133 }
128 if len(relevantPeopleModel) > 0 { 134 if len(relevantPeopleModel) > 0 {
@@ -169,7 +175,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -169,7 +175,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
169 // 新增分红激励规则 175 // 新增分红激励规则
170 var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule 176 var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
171 for _, rule := range cooperationContract.DividendsIncentivesRules { 177 for _, rule := range cooperationContract.DividendsIncentivesRules {
  178 + if rule.Identify() == nil {
  179 + ruleId, err := repository.nextIdentify()
  180 + if err != nil {
  181 + return nil, err
  182 + } else {
  183 + rule.DividendsIncentivesRuleId = ruleId
  184 + }
  185 + }
172 dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{ 186 dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
  187 + DividendsIncentivesRuleId: rule.DividendsIncentivesRuleId,
173 CooperationContractNumber: cooperationContract.CooperationContractNumber, 188 CooperationContractNumber: cooperationContract.CooperationContractNumber,
174 ReferrerPercentage: rule.ReferrerPercentage, 189 ReferrerPercentage: rule.ReferrerPercentage,
175 SalesmanPercentage: rule.SalesmanPercentage, 190 SalesmanPercentage: rule.SalesmanPercentage,
@@ -197,7 +212,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -197,7 +212,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
197 // 新增金额激励规则 212 // 新增金额激励规则
198 var moneyIncentivesRulesModel []*models.MoneyIncentivesRule 213 var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
199 for _, rule := range cooperationContract.MoneyIncentivesRules { 214 for _, rule := range cooperationContract.MoneyIncentivesRules {
  215 + if rule.Identify() == nil {
  216 + ruleId, err := repository.nextIdentify()
  217 + if err != nil {
  218 + return nil, err
  219 + } else {
  220 + rule.MoneyIncentivesRuleId = ruleId
  221 + }
  222 + }
200 moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{ 223 moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
  224 + MoneyIncentivesRuleId: rule.MoneyIncentivesRuleId,
201 CooperationContractNumber: cooperationContract.CooperationContractNumber, 225 CooperationContractNumber: cooperationContract.CooperationContractNumber,
202 MoneyIncentivesAmount: rule.MoneyIncentivesAmount, 226 MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
203 MoneyIncentivesStage: rule.MoneyIncentivesStage, 227 MoneyIncentivesStage: rule.MoneyIncentivesStage,
@@ -302,21 +326,30 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -302,21 +326,30 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
302 // 将待添加的相关人领域模型转换为数据模型 326 // 将待添加的相关人领域模型转换为数据模型
303 var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant 327 var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant
304 for _, relevantDomain := range cooperationContractRelevantPeopleToAdd { 328 for _, relevantDomain := range cooperationContractRelevantPeopleToAdd {
  329 + if relevantDomain.Identify() == nil {
  330 + relevantId, err := repository.nextIdentify()
  331 + if err != nil {
  332 + return nil, err
  333 + } else {
  334 + relevantDomain.RelevantId = relevantId
  335 + }
  336 + }
305 cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{ 337 cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{
306 - CooperationContractNumber: relevantDomain.CooperationContractNumber,  
307 - UserId: relevantDomain.UserId,  
308 - UserBaseId: relevantDomain.UserBaseId,  
309 - Org: relevantDomain.Org,  
310 - Orgs: relevantDomain.Orgs,  
311 - Department: relevantDomain.Department,  
312 - Roles: relevantDomain.Roles,  
313 - UserInfo: relevantDomain.UserInfo,  
314 - UserType: relevantDomain.UserType,  
315 - Status: relevantDomain.Status,  
316 - Company: relevantDomain.Company,  
317 - UpdatedAt: time.Time{},  
318 - DeletedAt: time.Time{},  
319 - CreatedAt: time.Now(), 338 + CooperationContractRelevantId: relevantDomain.RelevantId,
  339 + CooperationContractNumber: relevantDomain.CooperationContractNumber,
  340 + UserId: relevantDomain.UserId,
  341 + UserBaseId: relevantDomain.UserBaseId,
  342 + Org: relevantDomain.Org,
  343 + Orgs: relevantDomain.Orgs,
  344 + Department: relevantDomain.Department,
  345 + Roles: relevantDomain.Roles,
  346 + UserInfo: relevantDomain.UserInfo,
  347 + UserType: relevantDomain.UserType,
  348 + Status: relevantDomain.Status,
  349 + Company: relevantDomain.Company,
  350 + UpdatedAt: time.Time{},
  351 + DeletedAt: time.Time{},
  352 + CreatedAt: time.Now(),
320 }) 353 })
321 } 354 }
322 355
@@ -401,24 +434,33 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -401,24 +434,33 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
401 // 将待添加的相关人领域模型转换为数据模型 434 // 将待添加的相关人领域模型转换为数据模型
402 var cooperationContractUndertakersToAddModels []*models.CooperationContractUndertaker 435 var cooperationContractUndertakersToAddModels []*models.CooperationContractUndertaker
403 for _, undertakerDomain := range cooperationContractUndertakersToAdd { 436 for _, undertakerDomain := range cooperationContractUndertakersToAdd {
  437 + if undertakerDomain.Identify() == nil {
  438 + undertakerId, err := repository.nextIdentify()
  439 + if err != nil {
  440 + return nil, err
  441 + } else {
  442 + undertakerDomain.UndertakerId = undertakerId
  443 + }
  444 + }
404 cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{ 445 cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{
405 - CooperationContractNumber: undertakerDomain.CooperationContractNumber,  
406 - UserId: undertakerDomain.UserId,  
407 - UserBaseId: undertakerDomain.UserBaseId,  
408 - Org: undertakerDomain.Org,  
409 - Orgs: undertakerDomain.Orgs,  
410 - Department: undertakerDomain.Department,  
411 - Roles: undertakerDomain.Roles,  
412 - UserInfo: undertakerDomain.UserInfo,  
413 - UserType: undertakerDomain.UserType,  
414 - Referrer: undertakerDomain.Referrer,  
415 - Salesman: undertakerDomain.Salesman,  
416 - Status: undertakerDomain.Status,  
417 - Company: undertakerDomain.Company,  
418 - ContractAttachment: undertakerDomain.ContractAttachment,  
419 - UpdatedAt: time.Time{},  
420 - DeletedAt: time.Time{},  
421 - CreatedAt: time.Now(), 446 + CooperationContractUndertakerId: undertakerDomain.UndertakerId,
  447 + CooperationContractNumber: undertakerDomain.CooperationContractNumber,
  448 + UserId: undertakerDomain.UserId,
  449 + UserBaseId: undertakerDomain.UserBaseId,
  450 + Org: undertakerDomain.Org,
  451 + Orgs: undertakerDomain.Orgs,
  452 + Department: undertakerDomain.Department,
  453 + Roles: undertakerDomain.Roles,
  454 + UserInfo: undertakerDomain.UserInfo,
  455 + UserType: undertakerDomain.UserType,
  456 + Referrer: undertakerDomain.Referrer,
  457 + Salesman: undertakerDomain.Salesman,
  458 + Status: undertakerDomain.Status,
  459 + Company: undertakerDomain.Company,
  460 + ContractAttachment: undertakerDomain.ContractAttachment,
  461 + UpdatedAt: time.Time{},
  462 + DeletedAt: time.Time{},
  463 + CreatedAt: time.Now(),
422 }) 464 })
423 } 465 }
424 log.Logger.Info("待添加的承接人", map[string]interface{}{ 466 log.Logger.Info("待添加的承接人", map[string]interface{}{
@@ -534,7 +576,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -534,7 +576,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
534 // 将待添加的分红激励规则领域模型转换为数据模型 576 // 将待添加的分红激励规则领域模型转换为数据模型
535 var dividendsIncentivesRulesToAddModels []*models.DividendsIncentivesRule 577 var dividendsIncentivesRulesToAddModels []*models.DividendsIncentivesRule
536 for _, dividendsIncentivesRuleDomain := range dividendsIncentivesRulesToAdd { 578 for _, dividendsIncentivesRuleDomain := range dividendsIncentivesRulesToAdd {
  579 + if dividendsIncentivesRuleDomain.Identify() == nil {
  580 + ruleId, err := repository.nextIdentify()
  581 + if err != nil {
  582 + return nil, err
  583 + } else {
  584 + dividendsIncentivesRuleDomain.DividendsIncentivesRuleId = ruleId
  585 + }
  586 + }
537 dividendsIncentivesRulesToAddModels = append(dividendsIncentivesRulesToAddModels, &models.DividendsIncentivesRule{ 587 dividendsIncentivesRulesToAddModels = append(dividendsIncentivesRulesToAddModels, &models.DividendsIncentivesRule{
  588 + DividendsIncentivesRuleId: dividendsIncentivesRuleDomain.DividendsIncentivesRuleId,
538 CooperationContractNumber: dividendsIncentivesRuleDomain.CooperationContractNumber, 589 CooperationContractNumber: dividendsIncentivesRuleDomain.CooperationContractNumber,
539 ReferrerPercentage: dividendsIncentivesRuleDomain.ReferrerPercentage, 590 ReferrerPercentage: dividendsIncentivesRuleDomain.ReferrerPercentage,
540 SalesmanPercentage: dividendsIncentivesRuleDomain.SalesmanPercentage, 591 SalesmanPercentage: dividendsIncentivesRuleDomain.SalesmanPercentage,
@@ -657,7 +708,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -657,7 +708,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
657 // 将待添加的金额激励规则领域模型转换为数据模型 708 // 将待添加的金额激励规则领域模型转换为数据模型
658 var moneyIncentivesRulesToAddModels []*models.MoneyIncentivesRule 709 var moneyIncentivesRulesToAddModels []*models.MoneyIncentivesRule
659 for _, moneyIncentivesRuleDomain := range moneyIncentivesRulesToAdd { 710 for _, moneyIncentivesRuleDomain := range moneyIncentivesRulesToAdd {
  711 + if moneyIncentivesRuleDomain.Identify() == nil {
  712 + ruleId, err := repository.nextIdentify()
  713 + if err != nil {
  714 + return nil, err
  715 + } else {
  716 + moneyIncentivesRuleDomain.MoneyIncentivesRuleId = ruleId
  717 + }
  718 + }
660 moneyIncentivesRulesToAddModels = append(moneyIncentivesRulesToAddModels, &models.MoneyIncentivesRule{ 719 moneyIncentivesRulesToAddModels = append(moneyIncentivesRulesToAddModels, &models.MoneyIncentivesRule{
  720 + MoneyIncentivesRuleId: moneyIncentivesRuleDomain.MoneyIncentivesRuleId,
661 CooperationContractNumber: moneyIncentivesRuleDomain.CooperationContractNumber, 721 CooperationContractNumber: moneyIncentivesRuleDomain.CooperationContractNumber,
662 MoneyIncentivesAmount: moneyIncentivesRuleDomain.MoneyIncentivesAmount, 722 MoneyIncentivesAmount: moneyIncentivesRuleDomain.MoneyIncentivesAmount,
663 MoneyIncentivesStage: moneyIncentivesRuleDomain.MoneyIncentivesStage, 723 MoneyIncentivesStage: moneyIncentivesRuleDomain.MoneyIncentivesStage,
@@ -1175,8 +1235,13 @@ func NewCooperationContractRepository(transactionContext *pgTransaction.Transact @@ -1175,8 +1235,13 @@ func NewCooperationContractRepository(transactionContext *pgTransaction.Transact
1175 if transactionContext == nil { 1235 if transactionContext == nil {
1176 return nil, fmt.Errorf("transactionContext参数不能为nil") 1236 return nil, fmt.Errorf("transactionContext参数不能为nil")
1177 } else { 1237 } else {
  1238 + idWorker, err := snowflake.NewIdWorker(1)
  1239 + if err != nil {
  1240 + return nil, err
  1241 + }
1178 return &CooperationContractRepository{ 1242 return &CooperationContractRepository{
1179 transactionContext: transactionContext, 1243 transactionContext: transactionContext,
  1244 + IdWorker: idWorker,
1180 }, nil 1245 }, nil
1181 } 1246 }
1182 } 1247 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type CooperationContractUndertakerRepository struct { 16 type CooperationContractUndertakerRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *CooperationContractUndertakerRepository) nextIdentify() (int64, error) { 21 func (repository *CooperationContractUndertakerRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -225,8 +222,13 @@ func NewCooperationContractUndertakerRepository(transactionContext *pgTransactio @@ -225,8 +222,13 @@ func NewCooperationContractUndertakerRepository(transactionContext *pgTransactio
225 if transactionContext == nil { 222 if transactionContext == nil {
226 return nil, fmt.Errorf("transactionContext参数不能为nil") 223 return nil, fmt.Errorf("transactionContext参数不能为nil")
227 } else { 224 } else {
  225 + idWorker, err := snowflake.NewIdWorker(1)
  226 + if err != nil {
  227 + return nil, err
  228 + }
228 return &CooperationContractUndertakerRepository{ 229 return &CooperationContractUndertakerRepository{
229 transactionContext: transactionContext, 230 transactionContext: transactionContext,
  231 + IdWorker: idWorker,
230 }, nil 232 }, nil
231 } 233 }
232 } 234 }
@@ -14,14 +14,11 @@ import ( @@ -14,14 +14,11 @@ import (
14 14
15 type CooperationModeRepository struct { 15 type CooperationModeRepository struct {
16 transactionContext *pgTransaction.TransactionContext 16 transactionContext *pgTransaction.TransactionContext
  17 + IdWorker *snowflake.IdWorker
17 } 18 }
18 19
19 func (repository *CooperationModeRepository) nextIdentify() (int64, error) { 20 func (repository *CooperationModeRepository) nextIdentify() (int64, error) {
20 - IdWorker, err := snowflake.NewIdWorker(1)  
21 - if err != nil {  
22 - return 0, err  
23 - }  
24 - id, err := IdWorker.NextId() 21 + id, err := repository.IdWorker.NextId()
25 return id, err 22 return id, err
26 } 23 }
27 24
@@ -221,8 +218,13 @@ func NewCooperationModeRepository(transactionContext *pgTransaction.TransactionC @@ -221,8 +218,13 @@ func NewCooperationModeRepository(transactionContext *pgTransaction.TransactionC
221 if transactionContext == nil { 218 if transactionContext == nil {
222 return nil, fmt.Errorf("transactionContext参数不能为nil") 219 return nil, fmt.Errorf("transactionContext参数不能为nil")
223 } else { 220 } else {
  221 + idWorker, err := snowflake.NewIdWorker(1)
  222 + if err != nil {
  223 + return nil, err
  224 + }
224 return &CooperationModeRepository{ 225 return &CooperationModeRepository{
225 transactionContext: transactionContext, 226 transactionContext: transactionContext,
  227 + IdWorker: idWorker,
226 }, nil 228 }, nil
227 } 229 }
228 } 230 }
@@ -17,14 +17,11 @@ import ( @@ -17,14 +17,11 @@ import (
17 17
18 type CooperationProjectRepository struct { 18 type CooperationProjectRepository struct {
19 transactionContext *pgTransaction.TransactionContext 19 transactionContext *pgTransaction.TransactionContext
  20 + IdWorker *snowflake.IdWorker
20 } 21 }
21 22
22 func (repository *CooperationProjectRepository) nextIdentify() (int64, error) { 23 func (repository *CooperationProjectRepository) nextIdentify() (int64, error) {
23 - IdWorker, err := snowflake.NewIdWorker(1)  
24 - if err != nil {  
25 - return 0, err  
26 - }  
27 - id, err := IdWorker.NextId() 24 + id, err := repository.IdWorker.NextId()
28 return id, err 25 return id, err
29 } 26 }
30 27
@@ -317,8 +314,13 @@ func NewCooperationProjectRepository(transactionContext *pgTransaction.Transacti @@ -317,8 +314,13 @@ func NewCooperationProjectRepository(transactionContext *pgTransaction.Transacti
317 if transactionContext == nil { 314 if transactionContext == nil {
318 return nil, fmt.Errorf("transactionContext参数不能为nil") 315 return nil, fmt.Errorf("transactionContext参数不能为nil")
319 } else { 316 } else {
  317 + idWorker, err := snowflake.NewIdWorker(1)
  318 + if err != nil {
  319 + return nil, err
  320 + }
320 return &CooperationProjectRepository{ 321 return &CooperationProjectRepository{
321 transactionContext: transactionContext, 322 transactionContext: transactionContext,
  323 + IdWorker: idWorker,
322 }, nil 324 }, nil
323 } 325 }
324 } 326 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type CreditAccountRepository struct { 16 type CreditAccountRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *CreditAccountRepository) nextIdentify() (int64, error) { 21 func (repository *CreditAccountRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -249,8 +246,13 @@ func NewCreditAccountRepository(transactionContext *pgTransaction.TransactionCon @@ -249,8 +246,13 @@ func NewCreditAccountRepository(transactionContext *pgTransaction.TransactionCon
249 if transactionContext == nil { 246 if transactionContext == nil {
250 return nil, fmt.Errorf("transactionContext参数不能为nil") 247 return nil, fmt.Errorf("transactionContext参数不能为nil")
251 } else { 248 } else {
  249 + idWorker, err := snowflake.NewIdWorker(1)
  250 + if err != nil {
  251 + return nil, err
  252 + }
252 return &CreditAccountRepository{ 253 return &CreditAccountRepository{
253 transactionContext: transactionContext, 254 transactionContext: transactionContext,
  255 + IdWorker: idWorker,
254 }, nil 256 }, nil
255 } 257 }
256 } 258 }
@@ -16,14 +16,11 @@ import ( @@ -16,14 +16,11 @@ import (
16 16
17 type DividendsEstimateRepository struct { 17 type DividendsEstimateRepository struct {
18 transactionContext *pgTransaction.TransactionContext 18 transactionContext *pgTransaction.TransactionContext
  19 + IdWorker *snowflake.IdWorker
19 } 20 }
20 21
21 func (repository *DividendsEstimateRepository) nextIdentify() (int64, error) { 22 func (repository *DividendsEstimateRepository) nextIdentify() (int64, error) {
22 - IdWorker, err := snowflake.NewIdWorker(1)  
23 - if err != nil {  
24 - return 0, err  
25 - }  
26 - id, err := IdWorker.NextId() 23 + id, err := repository.IdWorker.NextId()
27 return id, err 24 return id, err
28 } 25 }
29 26
@@ -332,8 +329,13 @@ func NewDividendsEstimateRepository(transactionContext *pgTransaction.Transactio @@ -332,8 +329,13 @@ func NewDividendsEstimateRepository(transactionContext *pgTransaction.Transactio
332 if transactionContext == nil { 329 if transactionContext == nil {
333 return nil, fmt.Errorf("transactionContext参数不能为nil") 330 return nil, fmt.Errorf("transactionContext参数不能为nil")
334 } else { 331 } else {
  332 + idWorker, err := snowflake.NewIdWorker(1)
  333 + if err != nil {
  334 + return nil, err
  335 + }
335 return &DividendsEstimateRepository{ 336 return &DividendsEstimateRepository{
336 transactionContext: transactionContext, 337 transactionContext: transactionContext,
  338 + IdWorker: idWorker,
337 }, nil 339 }, nil
338 } 340 }
339 } 341 }
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type DividendsIncentivesRuleRepository struct { 16 type DividendsIncentivesRuleRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *DividendsIncentivesRuleRepository) nextIdentify() (int64, error) { 21 func (repository *DividendsIncentivesRuleRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -202,8 +199,13 @@ func NewDividendsIncentivesRuleRepository(transactionContext *pgTransaction.Tran @@ -202,8 +199,13 @@ func NewDividendsIncentivesRuleRepository(transactionContext *pgTransaction.Tran
202 if transactionContext == nil { 199 if transactionContext == nil {
203 return nil, fmt.Errorf("transactionContext参数不能为nil") 200 return nil, fmt.Errorf("transactionContext参数不能为nil")
204 } else { 201 } else {
  202 + idWorker, err := snowflake.NewIdWorker(1)
  203 + if err != nil {
  204 + return nil, err
  205 + }
205 return &DividendsIncentivesRuleRepository{ 206 return &DividendsIncentivesRuleRepository{
206 transactionContext: transactionContext, 207 transactionContext: transactionContext,
  208 + IdWorker: idWorker,
207 }, nil 209 }, nil
208 } 210 }
209 } 211 }
@@ -122,7 +122,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -122,7 +122,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
122 CompanyId: good.CompanyId, 122 CompanyId: good.CompanyId,
123 OrgId: good.OrgId, 123 OrgId: good.OrgId,
124 OrderGoodExpense: good.OrderGoodExpense, 124 OrderGoodExpense: good.OrderGoodExpense,
125 - OrderGoodDividendsStatus: good.OrderGoodDividendsStatus, 125 + OrderGoodDividendsStatus: 1,
126 CreatedAt: time.Now(), 126 CreatedAt: time.Now(),
127 DeletedAt: time.Time{}, 127 DeletedAt: time.Time{},
128 UpdatedAt: time.Time{}, 128 UpdatedAt: time.Time{},
@@ -178,7 +178,11 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -178,7 +178,11 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
178 // 更新分红订单产品 178 // 更新分红订单产品
179 var orderGoodsFetched []*models.OrderGood 179 var orderGoodsFetched []*models.OrderGood
180 orderGoodsQuery := tx.Model(&orderGoodsFetched) 180 orderGoodsQuery := tx.Model(&orderGoodsFetched)
181 - if err := orderGoodsQuery.Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Select(); err != nil { 181 + if err := orderGoodsQuery.
  182 + Where("company_id = ?", dividendsOrder.Company.CompanyId).
  183 + Where("org_id = ?", dividendsOrder.Org.OrgId).
  184 + Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).
  185 + Select(); err != nil {
182 return nil, err 186 return nil, err
183 } 187 }
184 188
@@ -190,6 +194,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -190,6 +194,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
190 194
191 // 待更新分红产品 195 // 待更新分红产品
192 var orderGoodsToUpdate []*domain.OrderGood 196 var orderGoodsToUpdate []*domain.OrderGood
  197 +
193 // 待添加分红产品 198 // 待添加分红产品
194 var orderGoodsToAdd []*domain.OrderGood 199 var orderGoodsToAdd []*domain.OrderGood
195 for _, good := range dividendsOrder.Goods { 200 for _, good := range dividendsOrder.Goods {
@@ -223,17 +228,17 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -223,17 +228,17 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
223 OrderGoodExpense: goodDomain.OrderGoodExpense, 228 OrderGoodExpense: goodDomain.OrderGoodExpense,
224 OrgId: goodDomain.OrgId, 229 OrgId: goodDomain.OrgId,
225 CompanyId: goodDomain.CompanyId, 230 CompanyId: goodDomain.CompanyId,
226 - OrderGoodDividendsStatus: goodDomain.OrderGoodDividendsStatus, 231 + OrderGoodDividendsStatus: 1,
227 CreatedAt: time.Now(), 232 CreatedAt: time.Now(),
228 DeletedAt: time.Time{}, 233 DeletedAt: time.Time{},
229 UpdatedAt: time.Time{}, 234 UpdatedAt: time.Time{},
230 }) 235 })
231 } 236 }
232 // 添加分红订单产品 237 // 添加分红订单产品
233 - log.Logger.Info("待添加的分红订单产品", map[string]interface{}{  
234 - "orderGoodsToAddModels": orderGoodsToAddModels,  
235 - })  
236 if len(orderGoodsToAddModels) > 0 { 238 if len(orderGoodsToAddModels) > 0 {
  239 + log.Logger.Info("待添加的分红订单产品", map[string]interface{}{
  240 + "orderGoodsToAddModels": orderGoodsToAddModels,
  241 + })
237 if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil { 242 if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil {
238 return nil, err 243 return nil, err
239 } 244 }
@@ -262,16 +267,16 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -262,16 +267,16 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
262 if orderGood.OrderGoodId == orderGoodModelToUpdate.OrderGoodId { 267 if orderGood.OrderGoodId == orderGoodModelToUpdate.OrderGoodId {
263 orderGoodModelsToUpdate[i] = &models.OrderGood{ 268 orderGoodModelsToUpdate[i] = &models.OrderGood{
264 OrderGoodId: orderGoodModelToUpdate.OrderGoodId, 269 OrderGoodId: orderGoodModelToUpdate.OrderGoodId,
265 - OrderGoodAmount: orderGoodModelToUpdate.OrderGoodAmount,  
266 - OrderGoodName: orderGoodModelToUpdate.OrderGoodName,  
267 - OrderGoodPrice: orderGoodModelToUpdate.OrderGoodPrice,  
268 - OrderGoodQuantity: orderGoodModelToUpdate.OrderGoodQuantity,  
269 - DividendsOrderNumber: orderGoodModelToUpdate.DividendsOrderNumber,  
270 - DividendsReturnedOrderNumber: orderGoodModelToUpdate.DividendsReturnedOrderNumber,  
271 - CooperationContractNumber: orderGoodModelToUpdate.CooperationContractNumber, 270 + OrderGoodAmount: orderGood.OrderGoodAmount,
  271 + OrderGoodName: orderGood.OrderGoodName,
  272 + OrderGoodPrice: orderGood.OrderGoodPrice,
  273 + OrderGoodQuantity: orderGood.OrderGoodQuantity,
  274 + DividendsOrderNumber: orderGood.DividendsOrderNumber,
  275 + DividendsReturnedOrderNumber: "",
  276 + CooperationContractNumber: orderGood.CooperationContractNumber,
272 OrgId: orderGoodModelToUpdate.OrgId, 277 OrgId: orderGoodModelToUpdate.OrgId,
273 CompanyId: orderGoodModelToUpdate.CompanyId, 278 CompanyId: orderGoodModelToUpdate.CompanyId,
274 - OrderGoodExpense: orderGoodModelToUpdate.OrderGoodExpense, 279 + OrderGoodExpense: orderGood.OrderGoodExpense,
275 OrderGoodDividendsStatus: orderGoodModelToUpdate.OrderGoodDividendsStatus, 280 OrderGoodDividendsStatus: orderGoodModelToUpdate.OrderGoodDividendsStatus,
276 CreatedAt: orderGoodModelToUpdate.CreatedAt, 281 CreatedAt: orderGoodModelToUpdate.CreatedAt,
277 DeletedAt: orderGoodModelToUpdate.DeletedAt, 282 DeletedAt: orderGoodModelToUpdate.DeletedAt,
@@ -491,6 +496,12 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte @@ -491,6 +496,12 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
491 if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" { 496 if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
492 query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber) 497 query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber)
493 } 498 }
  499 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  500 + query.Where("company->>'companyId' = '?'", companyId)
  501 + }
  502 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  503 + query.Where("org->>'orgId' = '?'", orgId)
  504 + }
494 if err := query.First(); err != nil { 505 if err := query.First(); err != nil {
495 if err.Error() == "pg: no rows in result set" { 506 if err.Error() == "pg: no rows in result set" {
496 return nil, fmt.Errorf("分红订单不存在") 507 return nil, fmt.Errorf("分红订单不存在")
@@ -475,7 +475,8 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne @@ -475,7 +475,8 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne
475 if _, err := tx.Model(&orderGoodModels). 475 if _, err := tx.Model(&orderGoodModels).
476 Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId). 476 Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
477 Where("org_id = ?", dividendsReturnedOrder.Org.OrgId). 477 Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
478 - Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil { 478 + Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).
  479 + Delete(); err != nil {
479 return nil, err 480 return nil, err
480 } 481 }
481 } 482 }
@@ -505,7 +506,8 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str @@ -505,7 +506,8 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
505 if err := orderGoodModelQuery. 506 if err := orderGoodModelQuery.
506 Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId). 507 Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId).
507 Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId). 508 Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
508 - Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil { 509 + Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).
  510 + Select(); err != nil {
509 return nil, fmt.Errorf("分红退货单关联的产品不存在") 511 return nil, fmt.Errorf("分红退货单关联的产品不存在")
510 } 512 }
511 // 聚合分红退货单 513 // 聚合分红退货单
@@ -15,14 +15,11 @@ import ( @@ -15,14 +15,11 @@ import (
15 15
16 type MoneyIncentivesRuleRepository struct { 16 type MoneyIncentivesRuleRepository struct {
17 transactionContext *pgTransaction.TransactionContext 17 transactionContext *pgTransaction.TransactionContext
  18 + IdWorker *snowflake.IdWorker
18 } 19 }
19 20
20 func (repository *MoneyIncentivesRuleRepository) nextIdentify() (int64, error) { 21 func (repository *MoneyIncentivesRuleRepository) nextIdentify() (int64, error) {
21 - IdWorker, err := snowflake.NewIdWorker(1)  
22 - if err != nil {  
23 - return 0, err  
24 - }  
25 - id, err := IdWorker.NextId() 22 + id, err := repository.IdWorker.NextId()
26 return id, err 23 return id, err
27 } 24 }
28 25
@@ -202,8 +199,13 @@ func NewMoneyIncentivesRuleRepository(transactionContext *pgTransaction.Transact @@ -202,8 +199,13 @@ func NewMoneyIncentivesRuleRepository(transactionContext *pgTransaction.Transact
202 if transactionContext == nil { 199 if transactionContext == nil {
203 return nil, fmt.Errorf("transactionContext参数不能为nil") 200 return nil, fmt.Errorf("transactionContext参数不能为nil")
204 } else { 201 } else {
  202 + idWorker, err := snowflake.NewIdWorker(1)
  203 + if err != nil {
  204 + return nil, err
  205 + }
205 return &MoneyIncentivesRuleRepository{ 206 return &MoneyIncentivesRuleRepository{
206 transactionContext: transactionContext, 207 transactionContext: transactionContext,
  208 + IdWorker: idWorker,
207 }, nil 209 }, nil
208 } 210 }
209 } 211 }
@@ -125,3 +125,13 @@ func RemoveDuplication(arr []string) []string { @@ -125,3 +125,13 @@ func RemoveDuplication(arr []string) []string {
125 } 125 }
126 return arr[:j] 126 return arr[:j]
127 } 127 }
  128 +
  129 +// IsContain 判断int32数组是否包含
  130 +func IsContain(items []int32, item int32) bool {
  131 + for _, eachItem := range items {
  132 + if eachItem == item {
  133 + return true
  134 + }
  135 + }
  136 + return false
  137 +}