作者 陈志颖

fix:代码错误xiugai

@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "github.com/beego/beego/v2/server/web" 5 "github.com/beego/beego/v2/server/web"
6 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" 6 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  7 + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego"
7 ) 8 )
8 9
9 func main() { 10 func main() {
@@ -111,9 +111,6 @@ func (dividendsOrder *DividendsOrder) Update(data map[string]interface{}) error @@ -111,9 +111,6 @@ func (dividendsOrder *DividendsOrder) Update(data map[string]interface{}) error
111 if userType, ok := data["userType"]; ok { 111 if userType, ok := data["userType"]; ok {
112 dividendsOrder.OrderSalesman.UserType = userType.(int32) 112 dividendsOrder.OrderSalesman.UserType = userType.(int32)
113 } 113 }
114 - if status, ok := data["status"]; ok {  
115 - dividendsOrder.OrderSalesman.Status = status.(int32)  
116 - }  
117 if orderTime, ok := data["orderTime"]; ok { 114 if orderTime, ok := data["orderTime"]; ok {
118 dividendsOrder.OrderTime = orderTime.(time.Time) 115 dividendsOrder.OrderTime = orderTime.(time.Time)
119 } 116 }
@@ -2,6 +2,10 @@ package domain @@ -2,6 +2,10 @@ package domain
2 2
3 // Relevant 共创合约相关人值对象 3 // Relevant 共创合约相关人值对象
4 type Relevant struct { 4 type Relevant struct {
  5 + // 相关人id
  6 + RelevantId int64 `json:"relevantId"`
  7 + // 共创合约编号
  8 + CooperationContractNumber string `json:"cooperationContractNumber"`
5 // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 9 // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
6 UserId int64 `json:"userId,string"` 10 UserId int64 `json:"userId,string"`
7 // 用户基本id 11 // 用户基本id
@@ -16,7 +16,7 @@ type ContractUndertakerFeedback struct { @@ -16,7 +16,7 @@ type ContractUndertakerFeedback struct {
16 // 共创合约编号 16 // 共创合约编号
17 CooperationContractNumber string `comment:"共创合约编号"` 17 CooperationContractNumber string `comment:"共创合约编号"`
18 // 共创合约承接人 18 // 共创合约承接人
19 - ContractUndertaker *domain.User `comment:"共创合约承接人"` 19 + ContractUndertaker *domain.Undertaker `comment:"共创合约承接人"`
20 // 共创模式编号 20 // 共创模式编号
21 CooperationModeNumber string `comment:"共创模式编号"` 21 CooperationModeNumber string `comment:"共创模式编号"`
22 // 数据所属组织机构 22 // 数据所属组织机构
@@ -11,8 +11,26 @@ type CooperationContractRelevant struct { @@ -11,8 +11,26 @@ type CooperationContractRelevant struct {
11 CooperationContractRelevantId int64 `comment:"共创合约相关人id" pg:"pk:cooperation_contract_relevant_id"` 11 CooperationContractRelevantId int64 `comment:"共创合约相关人id" pg:"pk:cooperation_contract_relevant_id"`
12 // 共创合约编号 12 // 共创合约编号
13 CooperationContractNumber string `comment:"共创合约编号"` 13 CooperationContractNumber string `comment:"共创合约编号"`
14 - // 相关人  
15 - Relevant *domain.Relevant `comment:"相关人"` 14 + // 合约人userId
  15 + UserId int64 `comment:"合约人userId"`
  16 + //合约人userBaseId
  17 + UserBaseId int64 `comment:"合约人userBaseId"`
  18 + //合约人所属组织机构
  19 + Org *domain.Org `comment:"合约人所属组织机构"`
  20 + //合约人关联的组织机构
  21 + Orgs []*domain.Org `comment:"合约人关联的组织机构"`
  22 + //合约人所属部门
  23 + Department *domain.Department `comment:"合约人所属部门"`
  24 + //合约人角色
  25 + Role *domain.Role `comment:"合约人角色"`
  26 + //合约人用户信息
  27 + UserInfo *domain.UserInfo `comment:"合约人用户信息"`
  28 + //合约人用户类型
  29 + UserType int32 `comment:"合约人用户类型"`
  30 + //合约人状态
  31 + Status int32 `comment:"合约人状态"`
  32 + //合约人公司
  33 + Company *domain.Company `comment:"合约人公司"`
16 // 更新时间 34 // 更新时间
17 UpdatedAt time.Time `comment:"更新时间"` 35 UpdatedAt time.Time `comment:"更新时间"`
18 // 删除时间 36 // 删除时间
@@ -16,7 +16,7 @@ type DividendsOrder struct { @@ -16,7 +16,7 @@ type DividendsOrder struct {
16 // 分红订单金额 16 // 分红订单金额
17 DividendsOrderAmount float64 `comment:"分红订单金额"` 17 DividendsOrderAmount float64 `comment:"分红订单金额"`
18 // 订单业务员 18 // 订单业务员
19 - OrderSalesman *domain.User `comment:"订单业务员"` 19 + OrderSalesman *domain.Salesman `comment:"订单业务员"`
20 // 订单产生时间 20 // 订单产生时间
21 OrderTime time.Time `comment:"订单产生时间"` 21 OrderTime time.Time `comment:"订单产生时间"`
22 // 分红订单分红时间 22 // 分红订单分红时间
@@ -55,16 +55,16 @@ func TransformToCooperationContractDomainModelFromPgModels( @@ -55,16 +55,16 @@ func TransformToCooperationContractDomainModelFromPgModels(
55 var relevantPeopleDomain []*domain.Relevant 55 var relevantPeopleDomain []*domain.Relevant
56 for _, relevant := range relevantPeople { 56 for _, relevant := range relevantPeople {
57 relevantPeopleDomain = append(relevantPeopleDomain, &domain.Relevant{ 57 relevantPeopleDomain = append(relevantPeopleDomain, &domain.Relevant{
58 - UserId: relevant.Relevant.UserId,  
59 - UserBaseId: relevant.Relevant.UserBaseId,  
60 - Org: relevant.Relevant.Org,  
61 - Orgs: relevant.Relevant.Orgs,  
62 - Department: relevant.Relevant.Department,  
63 - Role: relevant.Relevant.Role,  
64 - UserInfo: relevant.Relevant.UserInfo,  
65 - UserType: relevant.Relevant.UserType,  
66 - Status: relevant.Relevant.Status,  
67 - Company: relevant.Relevant.Company, 58 + UserId: relevant.UserId,
  59 + UserBaseId: relevant.UserBaseId,
  60 + Org: relevant.Org,
  61 + Orgs: relevant.Orgs,
  62 + Department: relevant.Department,
  63 + Role: relevant.Role,
  64 + UserInfo: relevant.UserInfo,
  65 + UserType: relevant.UserType,
  66 + Status: relevant.Status,
  67 + Company: relevant.Company,
68 }) 68 })
69 } 69 }
70 // 承接人列表 70 // 承接人列表
@@ -9,9 +9,22 @@ func TransformToCooperationContractRelevantDomainModelFromPgModels(cooperationCo @@ -9,9 +9,22 @@ func TransformToCooperationContractRelevantDomainModelFromPgModels(cooperationCo
9 return &domain.CooperationContractRelevant{ 9 return &domain.CooperationContractRelevant{
10 CooperationContractRelevantId: cooperationContractRelevantModel.CooperationContractRelevantId, 10 CooperationContractRelevantId: cooperationContractRelevantModel.CooperationContractRelevantId,
11 CooperationContractNumber: cooperationContractRelevantModel.CooperationContractNumber, 11 CooperationContractNumber: cooperationContractRelevantModel.CooperationContractNumber,
12 - Relevant: cooperationContractRelevantModel.Relevant,  
13 - UpdatedAt: cooperationContractRelevantModel.UpdatedAt,  
14 - DeletedAt: cooperationContractRelevantModel.DeletedAt,  
15 - CreatedAt: cooperationContractRelevantModel.CreatedAt, 12 + Relevant: &domain.Relevant{
  13 + RelevantId: cooperationContractRelevantModel.CooperationContractRelevantId,
  14 + CooperationContractNumber: cooperationContractRelevantModel.CooperationContractNumber,
  15 + UserId: cooperationContractRelevantModel.UserId,
  16 + UserBaseId: cooperationContractRelevantModel.UserBaseId,
  17 + Org: cooperationContractRelevantModel.Org,
  18 + Orgs: cooperationContractRelevantModel.Orgs,
  19 + Department: cooperationContractRelevantModel.Department,
  20 + Role: cooperationContractRelevantModel.Role,
  21 + UserInfo: cooperationContractRelevantModel.UserInfo,
  22 + UserType: cooperationContractRelevantModel.UserType,
  23 + Status: cooperationContractRelevantModel.Status,
  24 + Company: cooperationContractRelevantModel.Company,
  25 + },
  26 + UpdatedAt: cooperationContractRelevantModel.UpdatedAt,
  27 + DeletedAt: cooperationContractRelevantModel.DeletedAt,
  28 + CreatedAt: cooperationContractRelevantModel.CreatedAt,
16 }, nil 29 }, nil
17 } 30 }
@@ -5,10 +5,7 @@ import ( @@ -5,10 +5,7 @@ import (
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" 5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
6 ) 6 )
7 7
8 -func TransformToDividendsOrderDomainModelFromPgModels(  
9 - dividendsOrderModel *models.DividendsOrder,  
10 - goods []*models.OrderGood,  
11 -) (*domain.DividendsOrder, error) { 8 +func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *models.DividendsOrder, goods []*models.OrderGood) (*domain.DividendsOrder, error) {
12 var orderGoods []*domain.OrderGood 9 var orderGoods []*domain.OrderGood
13 for _, good := range goods { 10 for _, good := range goods {
14 orderGoods = append(orderGoods, &domain.OrderGood{ 11 orderGoods = append(orderGoods, &domain.OrderGood{
@@ -138,7 +138,13 @@ func (repository *ContractUndertakerFeedbackRepository) FindOne(queryOptions map @@ -138,7 +138,13 @@ func (repository *ContractUndertakerFeedbackRepository) FindOne(queryOptions map
138 if contractUndertakerFeedbackModel.FeedbackId == 0 { 138 if contractUndertakerFeedbackModel.FeedbackId == 0 {
139 return nil, nil 139 return nil, nil
140 } else { 140 } else {
141 - return transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel) 141 + // 获取共创模式
  142 + cooperationModeModel := new(models.CooperationMode)
  143 + cooperationModeQuery := tx.Model(cooperationModeModel)
  144 + if err := cooperationModeQuery.Where("cooperation_mode_number = ?", contractUndertakerFeedbackModel.CooperationModeNumber).First(); err != nil {
  145 + return nil, err
  146 + }
  147 + return transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel, cooperationModeModel)
142 } 148 }
143 } 149 }
144 func (repository *ContractUndertakerFeedbackRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ContractUndertakerFeedback, error) { 150 func (repository *ContractUndertakerFeedbackRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ContractUndertakerFeedback, error) {
@@ -152,7 +158,13 @@ func (repository *ContractUndertakerFeedbackRepository) Find(queryOptions map[st @@ -152,7 +158,13 @@ func (repository *ContractUndertakerFeedbackRepository) Find(queryOptions map[st
152 return 0, contractUndertakerFeedbacks, err 158 return 0, contractUndertakerFeedbacks, err
153 } else { 159 } else {
154 for _, contractUndertakerFeedbackModel := range contractUndertakerFeedbackModels { 160 for _, contractUndertakerFeedbackModel := range contractUndertakerFeedbackModels {
155 - if contractUndertakerFeedback, err := transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel); err != nil { 161 + // 获取共创模式
  162 + cooperationModeModel := new(models.CooperationMode)
  163 + cooperationModeQuery := tx.Model(cooperationModeModel)
  164 + if err := cooperationModeQuery.Where("cooperation_mode_number = ?", contractUndertakerFeedbackModel.CooperationModeNumber).First(); err != nil {
  165 + return 0, nil, err
  166 + }
  167 + if contractUndertakerFeedback, err := transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel, cooperationModeModel); err != nil {
156 return 0, contractUndertakerFeedbacks, err 168 return 0, contractUndertakerFeedbacks, err
157 } else { 169 } else {
158 contractUndertakerFeedbacks = append(contractUndertakerFeedbacks, contractUndertakerFeedback) 170 contractUndertakerFeedbacks = append(contractUndertakerFeedbacks, contractUndertakerFeedback)
@@ -2,6 +2,7 @@ package repository @@ -2,6 +2,7 @@ package repository
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/go-pg/pg/v10"
5 6
6 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 7 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -157,7 +158,13 @@ func (repository *CooperationApplicationRepository) FindOne(queryOptions map[str @@ -157,7 +158,13 @@ func (repository *CooperationApplicationRepository) FindOne(queryOptions map[str
157 if cooperationApplicationModel.CooperationApplicationId == 0 { 158 if cooperationApplicationModel.CooperationApplicationId == 0 {
158 return nil, nil 159 return nil, nil
159 } else { 160 } else {
160 - return transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel) 161 + // 获取共创项目
  162 + cooperationProjectModel := new(models.CooperationProject)
  163 + cooperationProjectQuery := tx.Model(cooperationProjectModel)
  164 + if err := cooperationProjectQuery.Where("cooperation_project_number = ?", cooperationApplicationModel.CooperationProjectNumber).First(); err != nil {
  165 + return nil, err
  166 + }
  167 + return transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel, cooperationProjectModel)
161 } 168 }
162 } 169 }
163 func (repository *CooperationApplicationRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationApplication, error) { 170 func (repository *CooperationApplicationRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationApplication, error) {
@@ -171,7 +178,13 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string @@ -171,7 +178,13 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
171 return 0, cooperationApplications, err 178 return 0, cooperationApplications, err
172 } else { 179 } else {
173 for _, cooperationApplicationModel := range cooperationApplicationModels { 180 for _, cooperationApplicationModel := range cooperationApplicationModels {
174 - if cooperationApplication, err := transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel); err != nil { 181 + // 获取共创项目
  182 + cooperationProjectModel := new(models.CooperationProject)
  183 + cooperationProjectQuery := tx.Model(cooperationProjectModel)
  184 + if err := cooperationProjectQuery.Where("cooperation_project_number = ?", cooperationApplicationModel.CooperationProjectNumber).First(); err != nil {
  185 + return 0, nil, err
  186 + }
  187 + if cooperationApplication, err := transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel, cooperationProjectModel); err != nil {
175 return 0, cooperationApplications, err 188 return 0, cooperationApplications, err
176 } else { 189 } else {
177 cooperationApplications = append(cooperationApplications, cooperationApplication) 190 cooperationApplications = append(cooperationApplications, cooperationApplication)
@@ -3,14 +3,13 @@ package repository @@ -3,14 +3,13 @@ package repository
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg/v10" 5 "github.com/go-pg/pg/v10"
6 - "time"  
7 -  
8 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 6 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
9 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
10 "github.com/linmadan/egglib-go/utils/snowflake" 8 "github.com/linmadan/egglib-go/utils/snowflake"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
  12 + "time"
14 ) 13 )
15 14
16 type CooperationContractRepository struct { 15 type CooperationContractRepository struct {
@@ -98,80 +97,88 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -98,80 +97,88 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
98 cooperationContract.UpdatedAt, 97 cooperationContract.UpdatedAt,
99 ); err != nil { 98 ); err != nil {
100 return cooperationContract, err 99 return cooperationContract, err
101 - } else {  
102 - // 新增相关人  
103 - var relevantPeopleModel []*models.CooperationContractRelevant  
104 - for _, relevant := range cooperationContract.RelevantPeople {  
105 - relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{  
106 - CooperationContractNumber: cooperationContract.CooperationContractNumber,  
107 - Relevant: relevant,  
108 - UpdatedAt: time.Time{},  
109 - DeletedAt: time.Time{},  
110 - CreatedAt: time.Now(),  
111 - })  
112 - }  
113 - if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {  
114 - return nil, err  
115 - } 100 + }
  101 + // 新增相关人
  102 + var relevantPeopleModel []*models.CooperationContractRelevant
  103 + for _, relevant := range cooperationContract.RelevantPeople {
  104 + relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
  105 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  106 + UserId: relevant.UserId,
  107 + UserBaseId: relevant.UserBaseId,
  108 + Org: relevant.Org,
  109 + Orgs: relevant.Orgs,
  110 + Department: relevant.Department,
  111 + Role: relevant.Role,
  112 + UserInfo: relevant.UserInfo,
  113 + UserType: relevant.UserType,
  114 + Status: relevant.Status,
  115 + Company: relevant.Company,
  116 + UpdatedAt: time.Now(),
  117 + DeletedAt: time.Time{},
  118 + CreatedAt: time.Time{},
  119 + })
  120 + }
  121 + if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
  122 + return nil, err
  123 + }
116 124
117 - // 新增承接人  
118 - var undertakersModel []*models.CooperationContractUndertaker  
119 - for _, undertaker := range cooperationContract.Undertakers {  
120 - undertakersModel = append(undertakersModel, &models.CooperationContractUndertaker{  
121 - CooperationContractNumber: cooperationContract.CooperationContractNumber,  
122 - Undertaker: undertaker,  
123 - CreatedAt: time.Time{},  
124 - UpdatedAt: time.Time{},  
125 - DeletedAt: time.Now(),  
126 - })  
127 - }  
128 - if _, err := tx.Model(&undertakersModel).Insert(); err != nil {  
129 - return nil, err  
130 - } 125 + // 新增承接人
  126 + var undertakersModel []*models.CooperationContractUndertaker
  127 + for _, undertaker := range cooperationContract.Undertakers {
  128 + undertakersModel = append(undertakersModel, &models.CooperationContractUndertaker{
  129 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  130 + Undertaker: undertaker,
  131 + CreatedAt: time.Time{},
  132 + UpdatedAt: time.Time{},
  133 + DeletedAt: time.Now(),
  134 + })
  135 + }
  136 + if _, err := tx.Model(&undertakersModel).Insert(); err != nil {
  137 + return nil, err
  138 + }
131 139
132 - // 新增分红激励规则  
133 - var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule  
134 - for _, rule := range cooperationContract.DividendsIncentivesRules {  
135 - dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{  
136 - CooperationContractNumber: cooperationContract.CooperationContractNumber,  
137 - ReferrerPercentage: rule.ReferrerPercentage,  
138 - SalesmanPercentage: rule.SalesmanPercentage,  
139 - DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,  
140 - DividendsIncentivesStage: rule.DividendsIncentivesStage,  
141 - DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,  
142 - DividendsIncentivesStageEnd: rule.DividendsIncentivesStageEnd,  
143 - Org: rule.Org,  
144 - Company: rule.Company,  
145 - UpdatedAt: time.Time{},  
146 - DeletedAt: time.Time{},  
147 - CreatedAt: time.Now(),  
148 - })  
149 - }  
150 - if _, err := tx.Model(&dividendsIncentivesRulesModel).Insert(); err != nil {  
151 - return nil, err  
152 - }  
153 - // 新增金额激励规则  
154 - var moneyIncentivesRulesModel []*models.MoneyIncentivesRule  
155 - for _, rule := range cooperationContract.MoneyIncentivesRules {  
156 - moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{  
157 - CooperationContractNumber: cooperationContract.CooperationContractNumber,  
158 - MoneyIncentivesAmount: rule.MoneyIncentivesAmount,  
159 - MoneyIncentivesStage: rule.MoneyIncentivesStage,  
160 - MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,  
161 - MoneyIncentivesStageEnd: rule.MoneyIncentivesStageEnd,  
162 - MoneyIncentivesTime: rule.MoneyIncentivesTime,  
163 - ReferrerPercentage: rule.ReferrerPercentage,  
164 - SalesmanPercentage: rule.SalesmanPercentage,  
165 - Org: rule.Org,  
166 - Company: rule.Company,  
167 - UpdatedAt: time.Time{},  
168 - DeletedAt: time.Time{},  
169 - CreatedAt: time.Now(),  
170 - })  
171 - }  
172 - if _, err := tx.Model(&moneyIncentivesRulesModel).Insert(); err != nil {  
173 - return nil, err  
174 - } 140 + // 新增分红激励规则
  141 + var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
  142 + for _, rule := range cooperationContract.DividendsIncentivesRules {
  143 + dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
  144 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  145 + ReferrerPercentage: rule.ReferrerPercentage,
  146 + SalesmanPercentage: rule.SalesmanPercentage,
  147 + DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,
  148 + DividendsIncentivesStage: rule.DividendsIncentivesStage,
  149 + DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,
  150 + DividendsIncentivesStageEnd: rule.DividendsIncentivesStageEnd,
  151 + Org: rule.Org,
  152 + Company: rule.Company,
  153 + UpdatedAt: time.Time{},
  154 + DeletedAt: time.Time{},
  155 + CreatedAt: time.Now(),
  156 + })
  157 + }
  158 + if _, err := tx.Model(&dividendsIncentivesRulesModel).Insert(); err != nil {
  159 + return nil, err
  160 + }
  161 + // 新增金额激励规则
  162 + var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
  163 + for _, rule := range cooperationContract.MoneyIncentivesRules {
  164 + moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
  165 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  166 + MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
  167 + MoneyIncentivesStage: rule.MoneyIncentivesStage,
  168 + MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,
  169 + MoneyIncentivesStageEnd: rule.MoneyIncentivesStageEnd,
  170 + MoneyIncentivesTime: rule.MoneyIncentivesTime,
  171 + ReferrerPercentage: rule.ReferrerPercentage,
  172 + SalesmanPercentage: rule.SalesmanPercentage,
  173 + Org: rule.Org,
  174 + Company: rule.Company,
  175 + UpdatedAt: time.Time{},
  176 + DeletedAt: time.Time{},
  177 + CreatedAt: time.Now(),
  178 + })
  179 + }
  180 + if _, err := tx.Model(&moneyIncentivesRulesModel).Insert(); err != nil {
  181 + return nil, err
175 } 182 }
176 } else { 183 } else {
177 if _, err := tx.QueryOne( 184 if _, err := tx.QueryOne(
@@ -215,53 +222,80 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -215,53 +222,80 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
215 cooperationContract.Identify(), 222 cooperationContract.Identify(),
216 ); err != nil { 223 ); err != nil {
217 return cooperationContract, err 224 return cooperationContract, err
218 - } else {  
219 - // 获取相关人列表  
220 - var cooperationContractRelevantModels []*models.CooperationContractRelevant  
221 - cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)  
222 - if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {  
223 - return nil, err  
224 - } 225 + }
  226 + // 获取相关人列表
  227 + var cooperationContractRelevantModels []*models.CooperationContractRelevant
  228 + cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
  229 + if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
  230 + return nil, err
  231 + }
225 232
226 - //var cooperationContractRelevantModelsUpdate []*models.CooperationContractRelevant // 待更新的相关人  
227 - //var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人  
228 - //var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人  
229 - //  
230 - //for _, cooperationContractRelevantModels := range cooperationContractRelevantModels {  
231 - // for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {  
232 - //  
233 - // }  
234 - //} 233 + //var cooperationContractRelevantModelsUpdate []*models.CooperationContractRelevant // 待更新的相关人
  234 + //var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人
  235 + //var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人
235 236
236 - // 更新的相关人 237 + var relevantIdsHave []int64
  238 + var relevantIdsModify []int64
  239 + //var relevantIdsUpdate []int64
237 240
238 - // 删除的相关人 241 + for _, cooperationContractRelevantModel := range cooperationContractRelevantModels {
  242 + relevantIdsHave = append(relevantIdsHave, cooperationContractRelevantModel.CooperationContractRelevantId)
  243 + }
239 244
240 - // 新增的相关人 245 + for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {
  246 + relevantIdsModify = append(relevantIdsModify, cooperationContractRelevantDomain.RelevantId)
  247 + }
241 248
242 - //TODO 更新承接人  
243 - // 获取承接人列表  
244 - var cooperationContractUndertakerModels []*models.CooperationContractUndertaker  
245 - cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)  
246 - if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {  
247 - return nil, err  
248 - } 249 + // 待更新的相关人
  250 + //relevantIdsUpdate := utils.Intersect(relevantIdsHave, relevantIdsModify)
249 251
250 - //TODO 更新分红激励规则  
251 - // 获取分红激励规则列表  
252 - var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule  
253 - dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)  
254 - if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {  
255 - return nil, err  
256 - } 252 + var relevantPeopleModelUpdate []*models.CooperationContractRelevant
  253 + for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {
  254 + relevantPeopleModelUpdate = append(relevantPeopleModelUpdate, &models.CooperationContractRelevant{
  255 + CooperationContractRelevantId: cooperationContractRelevantDomain.RelevantId,
  256 + CooperationContractNumber: cooperationContractRelevantDomain.CooperationContractNumber,
  257 + UserId: cooperationContractRelevantDomain.UserId,
  258 + UserBaseId: cooperationContractRelevantDomain.UserBaseId,
  259 + Org: cooperationContractRelevantDomain.Org,
  260 + Orgs: cooperationContractRelevantDomain.Orgs,
  261 + Department: cooperationContractRelevantDomain.Department,
  262 + Role: cooperationContractRelevantDomain.Role,
  263 + UserInfo: cooperationContractRelevantDomain.UserInfo,
  264 + UserType: cooperationContractRelevantDomain.UserType,
  265 + Status: cooperationContractRelevantDomain.Status,
  266 + Company: cooperationContractRelevantDomain.Company,
  267 + UpdatedAt: time.Now(),
  268 + DeletedAt: time.Time{},
  269 + CreatedAt: time.Time{},
  270 + })
  271 + }
257 272
258 - //TODO 更新金额激励规则  
259 - // 获取金额激励规则列表  
260 - var moneyIncentivesRuleModels []*models.MoneyIncentivesRule  
261 - moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)  
262 - if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {  
263 - return nil, err  
264 - } 273 + // 待删除的相关人
  274 +
  275 + // 待新增的相关人
  276 +
  277 + //TODO 更新承接人
  278 + // 获取承接人列表
  279 + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
  280 + cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
  281 + if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
  282 + return nil, err
  283 + }
  284 +
  285 + //TODO 更新分红激励规则
  286 + // 获取分红激励规则列表
  287 + var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
  288 + dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
  289 + if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
  290 + return nil, err
  291 + }
  292 +
  293 + //TODO 更新金额激励规则
  294 + // 获取金额激励规则列表
  295 + var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
  296 + moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
  297 + if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
  298 + return nil, err
265 } 299 }
266 } 300 }
267 return cooperationContract, nil 301 return cooperationContract, nil
@@ -343,8 +377,8 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in @@ -343,8 +377,8 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
343 } else { 377 } else {
344 for _, cooperationContractModel := range cooperationContractModels { 378 for _, cooperationContractModel := range cooperationContractModels {
345 // 获取共创模式 379 // 获取共创模式
346 - cooperationModeModels := new(models.CooperationMode)  
347 - cooperationModeQuery := tx.Model(cooperationModeModels) 380 + cooperationModeModel := new(models.CooperationMode)
  381 + cooperationModeQuery := tx.Model(cooperationModeModel)
348 if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil { 382 if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil {
349 return 0, nil, err 383 return 0, nil, err
350 } 384 }
@@ -374,7 +408,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in @@ -374,7 +408,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
374 } 408 }
375 if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels( 409 if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
376 cooperationContractModel, 410 cooperationContractModel,
377 - cooperationModeModels, 411 + cooperationModeModel,
378 dividendsIncentivesRuleModels, 412 dividendsIncentivesRuleModels,
379 moneyIncentivesRuleModels, 413 moneyIncentivesRuleModels,
380 cooperationContractRelevantModels, 414 cooperationContractRelevantModels,
@@ -3,6 +3,7 @@ package repository @@ -3,6 +3,7 @@ package repository
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg/v10" 5 "github.com/go-pg/pg/v10"
  6 + "time"
6 7
7 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 8 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 9 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -98,6 +99,26 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -98,6 +99,26 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
98 ); err != nil { 99 ); err != nil {
99 return dividendsOrder, err 100 return dividendsOrder, err
100 } 101 }
  102 + // 新增分红订单产品
  103 + var orderGoodsModel []*models.OrderGood
  104 + for _, good := range dividendsOrder.Goods {
  105 + orderGoodsModel = append(orderGoodsModel, &models.OrderGood{
  106 + OrderGoodAmount: good.OrderGoodAmount,
  107 + OrderGoodName: good.OrderGoodName,
  108 + OrderGoodPrice: good.OrderGoodPrice,
  109 + OrderGoodQuantity: good.OrderGoodQuantity,
  110 + DividendsOrderNumber: good.DividendsOrderNumber,
  111 + DividendsReturnedOrderNumber: good.DividendsReturnedOrderNumber,
  112 + CooperationContractNumber: good.CooperationContractNumber,
  113 + OrderGoodExpense: good.OrderGoodExpense,
  114 + CreatedAt: time.Now(),
  115 + DeletedAt: time.Time{},
  116 + UpdatedAt: time.Time{},
  117 + })
  118 + }
  119 + if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil {
  120 + return nil, err
  121 + }
101 } else { 122 } else {
102 if _, err := tx.QueryOne( 123 if _, err := tx.QueryOne(
103 pg.Scan( 124 pg.Scan(
@@ -141,6 +162,8 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -141,6 +162,8 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
141 ); err != nil { 162 ); err != nil {
142 return dividendsOrder, err 163 return dividendsOrder, err
143 } 164 }
  165 + //TODO 新增、更新、删除分红订单产品
  166 +
144 } 167 }
145 return dividendsOrder, nil 168 return dividendsOrder, nil
146 } 169 }
@@ -3,6 +3,7 @@ package repository @@ -3,6 +3,7 @@ package repository
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg/v10" 5 "github.com/go-pg/pg/v10"
  6 + "time"
6 7
7 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 8 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 9 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -101,6 +102,26 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -101,6 +102,26 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
101 ); err != nil { 102 ); err != nil {
102 return dividendsReturnedOrder, err 103 return dividendsReturnedOrder, err
103 } 104 }
  105 + // 新增订单产品
  106 + var orderGoodsModel []*models.OrderGood
  107 + for _, good := range dividendsReturnedOrder.Goods {
  108 + orderGoodsModel = append(orderGoodsModel, &models.OrderGood{
  109 + OrderGoodAmount: good.OrderGoodAmount,
  110 + OrderGoodName: good.OrderGoodName,
  111 + OrderGoodPrice: good.OrderGoodPrice,
  112 + OrderGoodQuantity: good.OrderGoodQuantity,
  113 + DividendsOrderNumber: good.DividendsOrderNumber,
  114 + DividendsReturnedOrderNumber: good.DividendsReturnedOrderNumber,
  115 + CooperationContractNumber: good.CooperationContractNumber,
  116 + OrderGoodExpense: good.OrderGoodExpense,
  117 + CreatedAt: time.Now(),
  118 + DeletedAt: time.Time{},
  119 + UpdatedAt: time.Time{},
  120 + })
  121 + }
  122 + if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil {
  123 + return nil, err
  124 + }
104 } else { 125 } else {
105 if _, err := tx.QueryOne( 126 if _, err := tx.QueryOne(
106 pg.Scan( 127 pg.Scan(
@@ -146,6 +167,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -146,6 +167,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
146 ); err != nil { 167 ); err != nil {
147 return dividendsReturnedOrder, err 168 return dividendsReturnedOrder, err
148 } 169 }
  170 + //TODO 新增、更新、删除分红退货单产品
149 } 171 }
150 return dividendsReturnedOrder, nil 172 return dividendsReturnedOrder, nil
151 } 173 }
@@ -2,6 +2,7 @@ package repository @@ -2,6 +2,7 @@ package repository
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/go-pg/pg/v10"
5 6
6 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 7 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -55,7 +56,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai @@ -55,7 +56,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai
55 } 56 }
56 if _, err := tx.QueryOne( 57 if _, err := tx.QueryOne(
57 pg.Scan( 58 pg.Scan(
58 - &moneyIncentivesRule.MoneyIcentivesRuleId, 59 + &moneyIncentivesRule.MoneyIncentivesRuleId,
59 &moneyIncentivesRule.CooperationContractNumber, 60 &moneyIncentivesRule.CooperationContractNumber,
60 &moneyIncentivesRule.MoneyIncentivesAmount, 61 &moneyIncentivesRule.MoneyIncentivesAmount,
61 &moneyIncentivesRule.MoneyIncentivesStage, 62 &moneyIncentivesRule.MoneyIncentivesStage,
@@ -71,7 +72,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai @@ -71,7 +72,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai
71 &moneyIncentivesRule.CreatedAt, 72 &moneyIncentivesRule.CreatedAt,
72 ), 73 ),
73 fmt.Sprintf("INSERT INTO money_incentives_rules (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), 74 fmt.Sprintf("INSERT INTO money_incentives_rules (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
74 - moneyIncentivesRule.MoneyIcentivesRuleId, 75 + moneyIncentivesRule.MoneyIncentivesRuleId,
75 moneyIncentivesRule.CooperationContractNumber, 76 moneyIncentivesRule.CooperationContractNumber,
76 moneyIncentivesRule.MoneyIncentivesAmount, 77 moneyIncentivesRule.MoneyIncentivesAmount,
77 moneyIncentivesRule.MoneyIncentivesStage, 78 moneyIncentivesRule.MoneyIncentivesStage,
@@ -91,7 +92,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai @@ -91,7 +92,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai
91 } else { 92 } else {
92 if _, err := tx.QueryOne( 93 if _, err := tx.QueryOne(
93 pg.Scan( 94 pg.Scan(
94 - &moneyIncentivesRule.MoneyIcentivesRuleId, 95 + &moneyIncentivesRule.MoneyIncentivesRuleId,
95 &moneyIncentivesRule.CooperationContractNumber, 96 &moneyIncentivesRule.CooperationContractNumber,
96 &moneyIncentivesRule.MoneyIncentivesAmount, 97 &moneyIncentivesRule.MoneyIncentivesAmount,
97 &moneyIncentivesRule.MoneyIncentivesStage, 98 &moneyIncentivesRule.MoneyIncentivesStage,
@@ -107,7 +108,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai @@ -107,7 +108,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai
107 &moneyIncentivesRule.CreatedAt, 108 &moneyIncentivesRule.CreatedAt,
108 ), 109 ),
109 fmt.Sprintf("UPDATE money_incentives_rules SET %s WHERE money_incentives_rule_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), 110 fmt.Sprintf("UPDATE money_incentives_rules SET %s WHERE money_incentives_rule_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
110 - moneyIncentivesRule.MoneyIcentivesRuleId, 111 + moneyIncentivesRule.MoneyIncentivesRuleId,
111 moneyIncentivesRule.CooperationContractNumber, 112 moneyIncentivesRule.CooperationContractNumber,
112 moneyIncentivesRule.MoneyIncentivesAmount, 113 moneyIncentivesRule.MoneyIncentivesAmount,
113 moneyIncentivesRule.MoneyIncentivesStage, 114 moneyIncentivesRule.MoneyIncentivesStage,
  1 +package utils
  2 +
  3 +func Intersect(nums1 []int64, nums2 []int64) []int64 {
  4 + if len(nums1) > len(nums2) {
  5 + return Intersect(nums2, nums1)
  6 + }
  7 + m := map[int64]int64{}
  8 + for _, num := range nums1 {
  9 + m[num]++
  10 + }
  11 +
  12 + var intersection []int64
  13 + for _, num := range nums2 {
  14 + if m[num] > 0 {
  15 + intersection = append(intersection, num)
  16 + m[num]--
  17 + }
  18 + }
  19 + return intersection
  20 +}