作者 陈志颖

feat:增加合约新增和更新校验

@@ -86,7 +86,7 @@ type CreateCooperationContractCommand struct { @@ -86,7 +86,7 @@ type CreateCooperationContractCommand struct {
86 // 共创合约名称 86 // 共创合约名称
87 CooperationContractName string `cname:"共创合约名称" json:"cooperationContractName" valid:"Required"` 87 CooperationContractName string `cname:"共创合约名称" json:"cooperationContractName" valid:"Required"`
88 // 共创模式编码 88 // 共创模式编码
89 - CooperationModeNumber string `cname:"共创模式编码" json:"cooperationModeNumber,omitempty"` 89 + CooperationModeNumber string `cname:"共创模式编码" json:"cooperationModeNumber" valid:"Required"`
90 // 共创合约发起人uid 90 // 共创合约发起人uid
91 SponsorUid string `cname:"共创合约发起人uid" json:"sponsorUid,omitempty"` 91 SponsorUid string `cname:"共创合约发起人uid" json:"sponsorUid,omitempty"`
92 // 业绩分红激励规则列表 92 // 业绩分红激励规则列表
@@ -108,7 +108,14 @@ type CreateCooperationContractCommand struct { @@ -108,7 +108,14 @@ type CreateCooperationContractCommand struct {
108 } 108 }
109 109
110 func (createCooperationContractCommand *CreateCooperationContractCommand) Valid(validation *validation.Validation) { 110 func (createCooperationContractCommand *CreateCooperationContractCommand) Valid(validation *validation.Validation) {
111 - //validation.SetError("CustomValid", "未实现的自定义认证") 111 + // 激励规则自定义校验
  112 + if len(createCooperationContractCommand.DividendsIncentivesRules) == 0 && len(createCooperationContractCommand.MoneyIncentivesRules) == 0 {
  113 + validation.Error("激励规则不能为空")
  114 + }
  115 + // 承接人列表校验
  116 + if len(createCooperationContractCommand.Undertakers) == 0 {
  117 + validation.Error("承接人不能为空")
  118 + }
112 } 119 }
113 120
114 func (createCooperationContractCommand *CreateCooperationContractCommand) ValidateCommand() error { 121 func (createCooperationContractCommand *CreateCooperationContractCommand) ValidateCommand() error {
@@ -42,7 +42,31 @@ type UpdateCooperationContractCommand struct { @@ -42,7 +42,31 @@ type UpdateCooperationContractCommand struct {
42 } 42 }
43 43
44 func (updateCooperationContractCommand *UpdateCooperationContractCommand) Valid(validation *validation.Validation) { 44 func (updateCooperationContractCommand *UpdateCooperationContractCommand) Valid(validation *validation.Validation) {
45 - //validation.SetError("CustomValid", "未实现的自定义认证") 45 + // 激励规则自定义校验
  46 + if len(updateCooperationContractCommand.DividendsIncentivesRules) <= 0 && len(updateCooperationContractCommand.MoneyIncentivesRules) <= 0 {
  47 + validation.Error("激励规则不能为空")
  48 + } else {
  49 + for i, _ := range updateCooperationContractCommand.DividendsIncentivesRules {
  50 + if updateCooperationContractCommand.DividendsIncentivesRules[i].DividendsIncentivesRuleId == "" {
  51 + updateCooperationContractCommand.DividendsIncentivesRules[i].DividendsIncentivesRuleId = "0"
  52 + }
  53 + }
  54 + for j, _ := range updateCooperationContractCommand.MoneyIncentivesRules {
  55 + if updateCooperationContractCommand.MoneyIncentivesRules[j].MoneyIncentivesRuleId == "" {
  56 + updateCooperationContractCommand.MoneyIncentivesRules[j].MoneyIncentivesRuleId = "0"
  57 + }
  58 + }
  59 + }
  60 + // 承接人列表校验
  61 + if len(updateCooperationContractCommand.Undertakers) <= 0 {
  62 + validation.Error("承接人不能为空")
  63 + } else {
  64 + for i, _ := range updateCooperationContractCommand.Undertakers {
  65 + if updateCooperationContractCommand.Undertakers[i].UndertakerId == "" {
  66 + updateCooperationContractCommand.Undertakers[i].UndertakerId = "0"
  67 + }
  68 + }
  69 + }
46 } 70 }
47 71
48 func (updateCooperationContractCommand *UpdateCooperationContractCommand) ValidateCommand() error { 72 func (updateCooperationContractCommand *UpdateCooperationContractCommand) ValidateCommand() error {
@@ -166,7 +166,6 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -166,7 +166,6 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
166 referrerDomain = data 166 referrerDomain = data
167 } 167 }
168 } 168 }
169 -  
170 // 获取业务员 169 // 获取业务员
171 var salesmanDomain *domain.Salesman 170 var salesmanDomain *domain.Salesman
172 salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64) 171 salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
@@ -179,6 +178,17 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -179,6 +178,17 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
179 } 178 }
180 } 179 }
181 180
  181 + // 解析附件
  182 + var attachments []*domain.Attachment
  183 + for _, attachment := range undertaker.ContractAttachment {
  184 + attachments = append(attachments, &domain.Attachment{
  185 + FileType: attachment.FileType,
  186 + Name: attachment.Name,
  187 + Url: attachment.Url,
  188 + FileSize: attachment.FileSize,
  189 + })
  190 + }
  191 +
182 undertakers = append(undertakers, &domain.Undertaker{ 192 undertakers = append(undertakers, &domain.Undertaker{
183 UndertakerId: 0, 193 UndertakerId: 0,
184 UserId: undertakerDomain.UserId, 194 UserId: undertakerDomain.UserId,
@@ -192,9 +202,9 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -192,9 +202,9 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
192 UserType: undertakerDomain.UserType, 202 UserType: undertakerDomain.UserType,
193 Referrer: referrerDomain, 203 Referrer: referrerDomain,
194 Salesman: salesmanDomain, 204 Salesman: salesmanDomain,
195 - Status: 0, 205 + Status: undertakerDomain.Status,
196 Company: company, 206 Company: company,
197 - ContractAttachment: nil, 207 + ContractAttachment: attachments,
198 }) 208 })
199 } 209 }
200 210
@@ -282,6 +292,12 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -282,6 +292,12 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
282 if cooperationMode == nil { 292 if cooperationMode == nil {
283 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationContractCommand.CooperationModeNumber)) 293 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationContractCommand.CooperationModeNumber))
284 } else { 294 } else {
  295 + incentivesType := 0
  296 + if len(dividendsIncentivesRules) > 0 {
  297 + incentivesType = domain.TYPE_DIVIDNEDS_INCENTIVES
  298 + } else if len(moneyIncentivesRules) > 0 {
  299 + incentivesType = domain.TYPE_MONEY_INCENTIVES
  300 + }
285 newCooperationContract := &domain.CooperationContract{ 301 newCooperationContract := &domain.CooperationContract{
286 CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription, 302 CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
287 CooperationContractName: createCooperationContractCommand.CooperationContractName, 303 CooperationContractName: createCooperationContractCommand.CooperationContractName,
@@ -297,6 +313,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -297,6 +313,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
297 Operator: operator, 313 Operator: operator,
298 DividendsIncentivesRules: dividendsIncentivesRules, 314 DividendsIncentivesRules: dividendsIncentivesRules,
299 MoneyIncentivesRules: moneyIncentivesRules, 315 MoneyIncentivesRules: moneyIncentivesRules,
  316 + IncentivesType: int32(incentivesType),
300 Undertakers: undertakers, 317 Undertakers: undertakers,
301 RelevantPeople: relevantPeople, 318 RelevantPeople: relevantPeople,
302 OperateTime: time.Now(), 319 OperateTime: time.Now(),
@@ -314,7 +331,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -314,7 +331,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
314 } else { 331 } else {
315 cooperationContractRepository = value 332 cooperationContractRepository = value
316 } 333 }
317 - 334 + // 保存共创合约
318 if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil { 335 if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil {
319 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 336 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
320 } else { 337 } else {
@@ -795,6 +812,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -795,6 +812,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
795 Company: relevantDomain.Company, 812 Company: relevantDomain.Company,
796 }) 813 })
797 } 814 }
  815 +
798 // 更新合约相关人 816 // 更新合约相关人
799 cooperationContract.RelevantPeople = relevantPeople 817 cooperationContract.RelevantPeople = relevantPeople
800 818
@@ -4,6 +4,11 @@ import ( @@ -4,6 +4,11 @@ import (
4 "time" 4 "time"
5 ) 5 )
6 6
  7 +const (
  8 + TYPE_DIVIDNEDS_INCENTIVES = iota + 1
  9 + TYPE_MONEY_INCENTIVES
  10 +)
  11 +
7 // CooperationContract 共创项目合约实体 12 // CooperationContract 共创项目合约实体
8 type CooperationContract struct { 13 type CooperationContract struct {
9 // 共创合约ID 14 // 共创合约ID
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 type CooperationContractRelevant struct { 8 type CooperationContractRelevant struct {
9 tableName string `comment:"共创合约相关人" pg:"cooperation_contract_relevants,alias:cooperation_contract_relevant"` 9 tableName string `comment:"共创合约相关人" pg:"cooperation_contract_relevants,alias:cooperation_contract_relevant"`
10 // 共创合约相关人id 10 // 共创合约相关人id
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 // 合约人userId 14 // 合约人userId
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 type CooperationContractUndertaker struct { 8 type CooperationContractUndertaker struct {
9 tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"` 9 tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"`
10 // 共创合约承接人id 10 // 共创合约承接人id
11 - CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:"pk:cooperation_contract_undertaker_id"` 11 + CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:",pk:cooperation_contract_undertaker_id"`
12 // 共创合约编号 12 // 共创合约编号
13 CooperationContractNumber string `comment:"共创合约编号"` 13 CooperationContractNumber string `comment:"共创合约编号"`
14 // 共创合约承接人uid 14 // 共创合约承接人uid
@@ -10,6 +10,7 @@ import ( @@ -10,6 +10,7 @@ import (
10 "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"
11 "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 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
13 "time" 14 "time"
14 ) 15 )
15 16
@@ -159,6 +160,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -159,6 +160,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
159 var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule 160 var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
160 for _, rule := range cooperationContract.DividendsIncentivesRules { 161 for _, rule := range cooperationContract.DividendsIncentivesRules {
161 dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{ 162 dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
  163 + DividendsIncentivesRuleId: 0,
162 CooperationContractNumber: cooperationContract.CooperationContractNumber, 164 CooperationContractNumber: cooperationContract.CooperationContractNumber,
163 ReferrerPercentage: rule.ReferrerPercentage, 165 ReferrerPercentage: rule.ReferrerPercentage,
164 SalesmanPercentage: rule.SalesmanPercentage, 166 SalesmanPercentage: rule.SalesmanPercentage,
@@ -183,6 +185,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -183,6 +185,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
183 var moneyIncentivesRulesModel []*models.MoneyIncentivesRule 185 var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
184 for _, rule := range cooperationContract.MoneyIncentivesRules { 186 for _, rule := range cooperationContract.MoneyIncentivesRules {
185 moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{ 187 moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
  188 + MoneyIncentivesRuleId: 0,
186 CooperationContractNumber: cooperationContract.CooperationContractNumber, 189 CooperationContractNumber: cooperationContract.CooperationContractNumber,
187 MoneyIncentivesAmount: rule.MoneyIncentivesAmount, 190 MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
188 MoneyIncentivesStage: rule.MoneyIncentivesStage, 191 MoneyIncentivesStage: rule.MoneyIncentivesStage,
@@ -278,6 +281,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -278,6 +281,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
278 var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant 281 var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant
279 for _, relevantDomain := range cooperationContractRelevantPeopleToAdd { 282 for _, relevantDomain := range cooperationContractRelevantPeopleToAdd {
280 cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{ 283 cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{
  284 + CooperationContractRelevantId: 0,
281 CooperationContractNumber: relevantDomain.CooperationContractNumber, 285 CooperationContractNumber: relevantDomain.CooperationContractNumber,
282 UserId: relevantDomain.UserId, 286 UserId: relevantDomain.UserId,
283 UserBaseId: relevantDomain.UserBaseId, 287 UserBaseId: relevantDomain.UserBaseId,
@@ -333,9 +337,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -333,9 +337,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
333 } 337 }
334 } 338 }
335 } 339 }
  340 + log.Logger.Info("待删除的相关人", map[string]interface{}{
  341 + "待删除的相关人": relevantModelsToDelete,
  342 + })
  343 + if len(relevantModelsToDelete) > 0 {
336 if _, err := tx.Model(&relevantModelsToDelete).Delete(); err != nil { 344 if _, err := tx.Model(&relevantModelsToDelete).Delete(); err != nil {
337 return nil, err 345 return nil, err
338 } 346 }
  347 + }
339 348
340 /************************* 更新承接人 ****************************/ 349 /************************* 更新承接人 ****************************/
341 // 获取承接人列表 350 // 获取承接人列表
@@ -383,6 +392,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -383,6 +392,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
383 CreatedAt: time.Now(), 392 CreatedAt: time.Now(),
384 }) 393 })
385 } 394 }
  395 + log.Logger.Info("待添加的承接人", map[string]interface{}{
  396 + "待添加的承接人": cooperationContractUndertakersToAddModels,
  397 + })
386 // 添加承接人 398 // 添加承接人
387 if len(cooperationContractUndertakersToAddModels) > 0 { 399 if len(cooperationContractUndertakersToAddModels) > 0 {
388 if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil { 400 if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil {
@@ -406,6 +418,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -406,6 +418,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
406 } 418 }
407 } 419 }
408 } 420 }
  421 + log.Logger.Info("待更新的承接人", map[string]interface{}{
  422 + "待更新的承接人": undertakerModelsToUpdate,
  423 + })
409 if len(undertakerModelsToUpdate) > 0 { 424 if len(undertakerModelsToUpdate) > 0 {
410 if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil { 425 if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil {
411 return nil, err 426 return nil, err
@@ -422,9 +437,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -422,9 +437,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
422 } 437 }
423 } 438 }
424 } 439 }
  440 + log.Logger.Info("待删除的承接人", map[string]interface{}{
  441 + "待删除的承接人": undertakerModelsToDelete,
  442 + })
  443 + if len(undertakerModelsToDelete) > 0 {
425 if _, err := tx.Model(&undertakerModelsToDelete).Delete(); err != nil { 444 if _, err := tx.Model(&undertakerModelsToDelete).Delete(); err != nil {
426 return nil, err 445 return nil, err
427 } 446 }
  447 + }
428 448
429 /************************ 更新分红激励规则 **************************/ 449 /************************ 更新分红激励规则 **************************/
430 // 获取分红激励规则列表 450 // 获取分红激励规则列表
@@ -471,6 +491,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -471,6 +491,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
471 }) 491 })
472 } 492 }
473 // 添加分红激励规则 493 // 添加分红激励规则
  494 + log.Logger.Info("待添加的分红激励规则", map[string]interface{}{
  495 + "dividendsIncentivesRulesToAddModels": dividendsIncentivesRulesToAddModels,
  496 + })
474 if len(dividendsIncentivesRulesToAddModels) > 0 { 497 if len(dividendsIncentivesRulesToAddModels) > 0 {
475 if _, err := tx.Model(&dividendsIncentivesRulesToAddModels).Insert(); err != nil { 498 if _, err := tx.Model(&dividendsIncentivesRulesToAddModels).Insert(); err != nil {
476 return nil, err 499 return nil, err
@@ -493,6 +516,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -493,6 +516,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
493 } 516 }
494 } 517 }
495 } 518 }
  519 + log.Logger.Info("待更新的分红激励规则", map[string]interface{}{
  520 + "dividendsRuleModelsToUpdate": dividendsRuleModelsToUpdate,
  521 + })
496 if len(dividendsRuleModelsToUpdate) > 0 { 522 if len(dividendsRuleModelsToUpdate) > 0 {
497 if _, err := tx.Model(&dividendsRuleModelsToUpdate).WherePK().Update(); err != nil { 523 if _, err := tx.Model(&dividendsRuleModelsToUpdate).WherePK().Update(); err != nil {
498 return nil, err 524 return nil, err
@@ -509,9 +535,12 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -509,9 +535,12 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
509 } 535 }
510 } 536 }
511 } 537 }
512 - if _, err := tx.Model(&dividendsIncentivesRuleModelsToDelete).Delete(); err != nil { 538 + log.Logger.Info("待删除的分红激励规则", map[string]interface{}{})
  539 + if len(dividendsIncentivesRuleModelsToDelete) > 0 {
  540 + if _, err := tx.Model(&dividendsIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
513 return nil, err 541 return nil, err
514 } 542 }
  543 + }
515 544
516 /********************** 更新金额激励规则 **************************/ 545 /********************** 更新金额激励规则 **************************/
517 var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule 546 var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
@@ -558,6 +587,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -558,6 +587,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
558 }) 587 })
559 } 588 }
560 // 添加金额激励规则 589 // 添加金额激励规则
  590 + log.Logger.Info("待添加的金额激励规则", map[string]interface{}{
  591 + "moneyIncentivesRulesToAddModels": moneyIncentivesRulesToAddModels,
  592 + })
561 if len(moneyIncentivesRulesToAddModels) > 0 { 593 if len(moneyIncentivesRulesToAddModels) > 0 {
562 if _, err := tx.Model(&moneyIncentivesRulesToAddModels).Insert(); err != nil { 594 if _, err := tx.Model(&moneyIncentivesRulesToAddModels).Insert(); err != nil {
563 return nil, err 595 return nil, err
@@ -580,6 +612,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -580,6 +612,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
580 } 612 }
581 } 613 }
582 } 614 }
  615 + log.Logger.Info("待更新的金额激励规则", map[string]interface{}{
  616 + "moneyRuleModelsToUpdate": moneyRuleModelsToUpdate,
  617 + })
583 if len(moneyRuleModelsToUpdate) > 0 { 618 if len(moneyRuleModelsToUpdate) > 0 {
584 if _, err := tx.Model(&moneyRuleModelsToUpdate).WherePK().Update(); err != nil { 619 if _, err := tx.Model(&moneyRuleModelsToUpdate).WherePK().Update(); err != nil {
585 return nil, err 620 return nil, err
@@ -596,10 +631,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -596,10 +631,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
596 } 631 }
597 } 632 }
598 } 633 }
599 - if _, err := tx.Model(&moneyIncentivesRuleModelsToDelete).Delete(); err != nil { 634 + log.Logger.Info("待删除的金额激励规则", map[string]interface{}{
  635 + "moneyIncentivesRuleModelsToDelete": moneyIncentivesRuleModelsToDelete,
  636 + })
  637 + if len(moneyIncentivesRuleModelsToDelete) > 0 {
  638 + if _, err := tx.Model(&moneyIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
600 return nil, err 639 return nil, err
601 } 640 }
602 - 641 + }
603 } 642 }
604 return cooperationContract, nil 643 return cooperationContract, nil
605 } 644 }
@@ -693,7 +732,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom @@ -693,7 +732,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
693 if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil { 732 if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
694 return nil, err 733 return nil, err
695 } else { 734 } else {
696 - if _, err := tx.Model(&cooperationContractUndertakerModels).Delete(); err != nil { 735 + if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
697 return nil, err 736 return nil, err
698 } 737 }
699 } 738 }
@@ -703,7 +742,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom @@ -703,7 +742,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
703 if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil { 742 if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
704 return nil, err 743 return nil, err
705 } else { 744 } else {
706 - if _, err := tx.Model(&cooperationContractRelevantModels).Delete(); err != nil { 745 + if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
707 return nil, err 746 return nil, err
708 } 747 }
709 } 748 }
@@ -730,42 +769,50 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract @@ -730,42 +769,50 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract
730 if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil { 769 if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
731 return nil, err 770 return nil, err
732 } else { 771 } else {
  772 + if len(dividendsIncentivesRuleModels) > 0 {
733 if _, err := tx.Model(&dividendsIncentivesRuleModels).WherePK().Delete(); err != nil { 773 if _, err := tx.Model(&dividendsIncentivesRuleModels).WherePK().Delete(); err != nil {
734 return nil, err 774 return nil, err
735 } 775 }
736 } 776 }
  777 + }
737 // 获取金额激励规则列表 778 // 获取金额激励规则列表
738 var moneyIncentivesRuleModels []*models.MoneyIncentivesRule 779 var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
739 moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels) 780 moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
740 if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil { 781 if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
741 return nil, err 782 return nil, err
742 } else { 783 } else {
  784 + if len(moneyIncentivesRuleModels) > 0 {
743 if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil { 785 if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil {
744 return nil, err 786 return nil, err
745 } 787 }
746 } 788 }
  789 + }
747 // 获取承接人列表 790 // 获取承接人列表
748 var cooperationContractUndertakerModels []*models.CooperationContractUndertaker 791 var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
749 cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels) 792 cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
750 if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil { 793 if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
751 return nil, err 794 return nil, err
752 } else { 795 } else {
753 - if _, err := tx.Model(&cooperationContractUndertakerModels).Delete(); err != nil { 796 + if len(cooperationContractUndertakerModels) > 0 {
  797 + if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
754 return nil, err 798 return nil, err
755 } 799 }
756 } 800 }
  801 + }
757 // 获取相关人列表 802 // 获取相关人列表
758 var cooperationContractRelevantModels []*models.CooperationContractRelevant 803 var cooperationContractRelevantModels []*models.CooperationContractRelevant
759 cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels) 804 cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
760 if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil { 805 if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
761 return nil, err 806 return nil, err
762 } else { 807 } else {
763 - if _, err := tx.Model(&cooperationContractRelevantModels).Delete(); err != nil { 808 + if len(cooperationContractRelevantModels) > 0 {
  809 + if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
764 return nil, err 810 return nil, err
765 } 811 }
766 } 812 }
767 } 813 }
768 } 814 }
  815 + }
769 return cooperationContracts, nil 816 return cooperationContracts, nil
770 } 817 }
771 818
@@ -118,94 +118,266 @@ func (translator *UserTranslator) ToRelevantFromRepresentation(user *UserDetail) @@ -118,94 +118,266 @@ func (translator *UserTranslator) ToRelevantFromRepresentation(user *UserDetail)
118 } 118 }
119 119
120 func (translator *UserTranslator) ToReferrerFromRepresentation(user *UserDetail) (*domain.Referrer, error) { 120 func (translator *UserTranslator) ToReferrerFromRepresentation(user *UserDetail) (*domain.Referrer, error) {
  121 + var orgs []*domain.Org
  122 + for _, org := range user.UserOrg {
  123 + orgs = append(orgs, &domain.Org{
  124 + OrgId: org.OrgID,
  125 + OrgName: org.OrgName,
  126 + Company: &domain.Company{
  127 + CompanyId: user.Company.CompanyId,
  128 + CompanyLogo: "",
  129 + CompanyName: user.Company.CompanyName,
  130 + },
  131 + })
  132 + }
  133 + var roles []*domain.Role
  134 + for _, role := range user.UserRole {
  135 + roles = append(roles, &domain.Role{
  136 + RoleId: int64(role.RoleID),
  137 + RoleName: role.RoleName,
  138 + })
  139 + }
121 return &domain.Referrer{ 140 return &domain.Referrer{
122 UserId: user.UserId, 141 UserId: user.UserId,
123 UserBaseId: user.UserBaseId, 142 UserBaseId: user.UserBaseId,
124 - Roles: nil,  
125 - Orgs: nil,  
126 - Org: nil,  
127 - Department: nil, 143 + Roles: roles,
  144 + Orgs: orgs,
  145 + Org: &domain.Org{
  146 + OrgId: user.Org.OrgId,
  147 + OrgName: user.Org.OrgName,
128 Company: nil, 148 Company: nil,
  149 + },
  150 + Department: &domain.Department{
  151 + DepartmentId: user.Department.DepartmentId,
  152 + DepartmentName: user.Department.DepartmentName,
  153 + DepartmentNumber: "",
  154 + IsOrganization: false,
  155 + },
  156 + Company: &domain.Company{
  157 + CompanyId: user.Company.CompanyId,
  158 + CompanyLogo: "",
  159 + CompanyName: user.Company.CompanyName,
  160 + },
129 UserInfo: nil, 161 UserInfo: nil,
130 - UserType: 0, 162 + UserType: user.UserType,
131 UserName: user.UserInfo.UserName, 163 UserName: user.UserInfo.UserName,
132 UserPhone: user.UserInfo.Phone, 164 UserPhone: user.UserInfo.Phone,
133 }, nil 165 }, nil
134 } 166 }
135 167
136 func (translator *UserTranslator) ToUndertakerFromRepresentation(user *UserDetail) (*domain.Undertaker, error) { 168 func (translator *UserTranslator) ToUndertakerFromRepresentation(user *UserDetail) (*domain.Undertaker, error) {
  169 + var orgs []*domain.Org
  170 + for _, org := range user.UserOrg {
  171 + orgs = append(orgs, &domain.Org{
  172 + OrgId: org.OrgID,
  173 + OrgName: org.OrgName,
  174 + Company: &domain.Company{
  175 + CompanyId: user.Company.CompanyId,
  176 + CompanyLogo: "",
  177 + CompanyName: user.Company.CompanyName,
  178 + },
  179 + })
  180 + }
  181 + var roles []*domain.Role
  182 + for _, role := range user.UserRole {
  183 + roles = append(roles, &domain.Role{
  184 + RoleId: int64(role.RoleID),
  185 + RoleName: role.RoleName,
  186 + })
  187 + }
137 return &domain.Undertaker{ 188 return &domain.Undertaker{
138 UserId: user.UserId, 189 UserId: user.UserId,
139 UserBaseId: user.UserBaseId, 190 UserBaseId: user.UserBaseId,
140 - Org: nil,  
141 - Orgs: nil,  
142 - Department: nil,  
143 - Roles: nil,  
144 - UserInfo: nil,  
145 - UserType: 0, 191 + Org: &domain.Org{
  192 + OrgId: user.Org.OrgId,
  193 + OrgName: user.Org.OrgName,
  194 + Company: nil,
  195 + },
  196 + Orgs: orgs,
  197 + Department: &domain.Department{
  198 + DepartmentId: user.Department.DepartmentId,
  199 + DepartmentName: user.Department.DepartmentName,
  200 + DepartmentNumber: "",
  201 + IsOrganization: false,
  202 + },
  203 + Roles: roles,
  204 + UserInfo: &domain.UserInfo{
  205 + UserAvatar: user.UserInfo.Avatar,
  206 + UserEmail: user.UserInfo.Email,
146 UserName: user.UserInfo.UserName, 207 UserName: user.UserInfo.UserName,
147 UserPhone: user.UserInfo.Phone, 208 UserPhone: user.UserInfo.Phone,
148 - Status: 0,  
149 - Company: nil, 209 + UserAccount: "",
  210 + },
  211 + UserType: user.UserType,
  212 + UserName: user.UserInfo.UserName,
  213 + UserPhone: user.UserInfo.Phone,
  214 + Status: user.EnableStatus,
  215 + Company: &domain.Company{
  216 + CompanyId: user.Company.CompanyId,
  217 + CompanyLogo: "",
  218 + CompanyName: user.Company.CompanyName,
  219 + },
150 ContractAttachment: nil, 220 ContractAttachment: nil,
151 }, nil 221 }, nil
152 } 222 }
153 223
154 func (translator *UserTranslator) ToSalesmanFromRepresentation(user *UserDetail) (*domain.Salesman, error) { 224 func (translator *UserTranslator) ToSalesmanFromRepresentation(user *UserDetail) (*domain.Salesman, error) {
  225 + var orgs []*domain.Org
  226 + for _, org := range user.UserOrg {
  227 + orgs = append(orgs, &domain.Org{
  228 + OrgId: org.OrgID,
  229 + OrgName: org.OrgName,
  230 + Company: &domain.Company{
  231 + CompanyId: user.Company.CompanyId,
  232 + CompanyLogo: "",
  233 + CompanyName: user.Company.CompanyName,
  234 + },
  235 + })
  236 + }
  237 + var roles []*domain.Role
  238 + for _, role := range user.UserRole {
  239 + roles = append(roles, &domain.Role{
  240 + RoleId: int64(role.RoleID),
  241 + RoleName: role.RoleName,
  242 + })
  243 + }
155 return &domain.Salesman{ 244 return &domain.Salesman{
156 UserId: user.UserId, 245 UserId: user.UserId,
157 UserBaseId: user.UserBaseId, 246 UserBaseId: user.UserBaseId,
158 - Roles: nil,  
159 - Orgs: nil,  
160 - Org: nil,  
161 - Department: nil, 247 + Roles: roles,
  248 + Orgs: orgs,
  249 + Org: &domain.Org{
  250 + OrgId: user.Org.OrgId,
  251 + OrgName: user.Org.OrgName,
162 Company: nil, 252 Company: nil,
163 - UserInfo: nil,  
164 - UserType: 0, 253 + },
  254 + Department: &domain.Department{
  255 + DepartmentId: user.Department.DepartmentId,
  256 + DepartmentName: user.Department.DepartmentName,
  257 + DepartmentNumber: "",
  258 + IsOrganization: false,
  259 + },
  260 + Company: &domain.Company{
  261 + CompanyId: user.Company.CompanyId,
  262 + CompanyLogo: "",
  263 + CompanyName: user.Company.CompanyName,
  264 + },
  265 + UserInfo: &domain.UserInfo{
  266 + UserAvatar: user.UserInfo.Avatar,
  267 + UserEmail: user.UserInfo.Email,
  268 + UserName: user.UserInfo.UserName,
  269 + UserPhone: user.UserInfo.Phone,
  270 + UserAccount: "",
  271 + },
  272 + UserType: user.UserType,
165 UserName: user.UserInfo.UserName, 273 UserName: user.UserInfo.UserName,
166 UserPhone: user.UserInfo.Phone, 274 UserPhone: user.UserInfo.Phone,
167 }, nil 275 }, nil
168 } 276 }
169 277
170 func (translator *UserTranslator) ToOperatorFromRepresentation(user *UserDetail) (*domain.User, error) { 278 func (translator *UserTranslator) ToOperatorFromRepresentation(user *UserDetail) (*domain.User, error) {
  279 + var orgs []*domain.Org
  280 + for _, org := range user.UserOrg {
  281 + orgs = append(orgs, &domain.Org{
  282 + OrgId: org.OrgID,
  283 + OrgName: org.OrgName,
  284 + Company: &domain.Company{
  285 + CompanyId: user.Company.CompanyId,
  286 + CompanyLogo: "",
  287 + CompanyName: user.Company.CompanyName,
  288 + },
  289 + })
  290 + }
  291 + var roles []*domain.Role
  292 + for _, role := range user.UserRole {
  293 + roles = append(roles, &domain.Role{
  294 + RoleId: int64(role.RoleID),
  295 + RoleName: role.RoleName,
  296 + })
  297 + }
171 return &domain.User{ 298 return &domain.User{
172 UserId: user.UserId, 299 UserId: user.UserId,
173 UserBaseId: user.UserBaseId, 300 UserBaseId: user.UserBaseId,
174 - Org: nil,  
175 - Orgs: nil,  
176 - Department: nil,  
177 - Roles: nil, 301 + Org: &domain.Org{
  302 + OrgId: user.Org.OrgId,
  303 + OrgName: user.Org.OrgName,
  304 + Company: nil,
  305 + },
  306 + Orgs: orgs,
  307 + Department: &domain.Department{
  308 + DepartmentId: user.Department.DepartmentId,
  309 + DepartmentName: user.Department.DepartmentName,
  310 + DepartmentNumber: "",
  311 + IsOrganization: false,
  312 + },
  313 + Roles: roles,
178 UserInfo: &domain.UserInfo{ 314 UserInfo: &domain.UserInfo{
179 UserName: user.UserInfo.UserName, 315 UserName: user.UserInfo.UserName,
180 UserPhone: user.UserInfo.Phone, 316 UserPhone: user.UserInfo.Phone,
181 UserAvatar: user.UserInfo.Avatar, 317 UserAvatar: user.UserInfo.Avatar,
182 }, 318 },
183 - UserType: 0, 319 + UserType: user.UserType,
184 UserName: user.UserInfo.UserName, 320 UserName: user.UserInfo.UserName,
185 UserPhone: user.UserInfo.Phone, 321 UserPhone: user.UserInfo.Phone,
186 - Status: 0,  
187 - Company: nil, 322 + Status: user.EnableStatus,
  323 + Company: &domain.Company{
  324 + CompanyId: user.Company.CompanyId,
  325 + CompanyLogo: "",
  326 + CompanyName: user.Company.CompanyName,
  327 + },
188 }, nil 328 }, nil
189 } 329 }
190 330
191 func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*domain.User, error) { 331 func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*domain.User, error) {
  332 + var orgs []*domain.Org
  333 + for _, org := range user.UserOrg {
  334 + orgs = append(orgs, &domain.Org{
  335 + OrgId: org.OrgID,
  336 + OrgName: org.OrgName,
  337 + Company: &domain.Company{
  338 + CompanyId: user.Company.CompanyId,
  339 + CompanyLogo: "",
  340 + CompanyName: user.Company.CompanyName,
  341 + },
  342 + })
  343 + }
  344 + var roles []*domain.Role
  345 + for _, role := range user.UserRole {
  346 + roles = append(roles, &domain.Role{
  347 + RoleId: int64(role.RoleID),
  348 + RoleName: role.RoleName,
  349 + })
  350 + }
192 return &domain.User{ 351 return &domain.User{
193 UserId: user.UserId, 352 UserId: user.UserId,
194 UserBaseId: user.UserBaseId, 353 UserBaseId: user.UserBaseId,
195 - Org: nil,  
196 - Orgs: nil,  
197 - Department: nil,  
198 - Roles: nil, 354 + Org: &domain.Org{
  355 + OrgId: user.Org.OrgId,
  356 + OrgName: user.Org.OrgName,
  357 + Company: nil,
  358 + },
  359 + Orgs: orgs,
  360 + Department: &domain.Department{
  361 + DepartmentId: user.Department.DepartmentId,
  362 + DepartmentName: user.Department.DepartmentName,
  363 + DepartmentNumber: "",
  364 + IsOrganization: false,
  365 + },
  366 + Roles: roles,
199 UserInfo: &domain.UserInfo{ 367 UserInfo: &domain.UserInfo{
200 UserName: user.UserInfo.UserName, 368 UserName: user.UserInfo.UserName,
201 UserPhone: user.UserInfo.Phone, 369 UserPhone: user.UserInfo.Phone,
202 UserAvatar: user.UserInfo.Avatar, 370 UserAvatar: user.UserInfo.Avatar,
203 }, 371 },
204 - UserType: 0, 372 + UserType: user.UserType,
205 UserName: user.UserInfo.UserName, 373 UserName: user.UserInfo.UserName,
206 UserPhone: user.UserInfo.Phone, 374 UserPhone: user.UserInfo.Phone,
207 - Status: 0,  
208 - Company: nil, 375 + Status: user.EnableStatus,
  376 + Company: &domain.Company{
  377 + CompanyId: user.Company.CompanyId,
  378 + CompanyLogo: "",
  379 + CompanyName: user.Company.CompanyName,
  380 + },
209 }, nil 381 }, nil
210 } 382 }
211 383