正在显示
4 个修改的文件
包含
168 行增加
和
18 行删除
@@ -21,7 +21,7 @@ type CreateDividendsIncentivesRulesCommand struct { | @@ -21,7 +21,7 @@ type CreateDividendsIncentivesRulesCommand struct { | ||
21 | } | 21 | } |
22 | 22 | ||
23 | type CreateMoneyIncentivesRulesCommand struct { | 23 | type CreateMoneyIncentivesRulesCommand struct { |
24 | - MoneyIncentivesRuleIdString string `cname:"" json:"moneyIncentivesRuleId,string"` | 24 | + MoneyIncentivesRuleId string `cname:"" json:"moneyIncentivesRuleId,string"` |
25 | CooperationContractNumber string `cname:"" json:"cooperationContractNumber"` | 25 | CooperationContractNumber string `cname:"" json:"cooperationContractNumber"` |
26 | MoneyIncentivesAmount int `cname:"" json:"moneyIncentivesAmount"` | 26 | MoneyIncentivesAmount int `cname:"" json:"moneyIncentivesAmount"` |
27 | MoneyIncentivesStage int `cname:"" json:"moneyIncentivesStage"` | 27 | MoneyIncentivesStage int `cname:"" json:"moneyIncentivesStage"` |
@@ -33,19 +33,20 @@ type CreateMoneyIncentivesRulesCommand struct { | @@ -33,19 +33,20 @@ type CreateMoneyIncentivesRulesCommand struct { | ||
33 | } | 33 | } |
34 | 34 | ||
35 | type CreateUndertakersCommand struct { | 35 | type CreateUndertakersCommand struct { |
36 | + UndertakerId int64 `cname:"承接人ID" json:"relevantId"` | ||
36 | UserId string `cname:"承接人UID" json:"userId"` | 37 | UserId string `cname:"承接人UID" json:"userId"` |
37 | ContractAttachment []struct { | 38 | ContractAttachment []struct { |
38 | - FileType string `json:"fileType"` | ||
39 | - Name string `json:"name"` | ||
40 | - Url string `json:"url"` | ||
41 | - FileSize int64 `json:"fileSize"` | ||
42 | - } `json:"contractAttachment"` | ||
43 | - ReferrerId string `json:"referrerId"` | ||
44 | - SalesmanId string `json:"salesmanId"` | 39 | + FileType string `cname:"文件类型" json:"fileType"` |
40 | + Name string `cname:"文件名称" json:"name"` | ||
41 | + Url string `cname:"文件路径" json:"url"` | ||
42 | + FileSize int64 `cname:"文件大小" json:"fileSize"` | ||
43 | + } `cname:"附件" json:"contractAttachment"` | ||
44 | + ReferrerId string `cname:"推荐UID" json:"referrerId"` | ||
45 | + SalesmanId string `cname:"业务员UID" json:"salesmanId"` | ||
45 | } | 46 | } |
46 | 47 | ||
47 | type CreateRelevantPeopleCommand struct { | 48 | type CreateRelevantPeopleCommand struct { |
48 | - UserId string `json:"userId"` | 49 | + UserId string `cname:"相关人UID" json:"userId"` |
49 | } | 50 | } |
50 | 51 | ||
51 | type CreateCooperationContractCommand struct { | 52 | type CreateCooperationContractCommand struct { |
@@ -330,7 +330,7 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont | @@ -330,7 +330,7 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont | ||
330 | } else { | 330 | } else { |
331 | cooperationContractDao = value | 331 | cooperationContractDao = value |
332 | } | 332 | } |
333 | - //TODO 获取可删除的承接对象类型 | 333 | + // 获取可删除的承接对象类型 |
334 | undertakerTypesUncheckedAvailable, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{ | 334 | undertakerTypesUncheckedAvailable, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{ |
335 | "cooperationContractNumber": cooperationContract.CooperationContractNumber, | 335 | "cooperationContractNumber": cooperationContract.CooperationContractNumber, |
336 | "cooperationContractUndertakerTypes": cooperationContract.CooperationContractUndertakerTypes, | 336 | "cooperationContractUndertakerTypes": cooperationContract.CooperationContractUndertakerTypes, |
@@ -502,6 +502,38 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | @@ -502,6 +502,38 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | ||
502 | _ = transactionContext.RollbackTransaction() | 502 | _ = transactionContext.RollbackTransaction() |
503 | }() | 503 | }() |
504 | 504 | ||
505 | + // 公司REST服务初始化 | ||
506 | + var companyService service.CompanyService | ||
507 | + if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil { | ||
508 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
509 | + } else { | ||
510 | + companyService = value | ||
511 | + } | ||
512 | + | ||
513 | + // 获取公司信息 | ||
514 | + var company *domain.Company | ||
515 | + if data, err := companyService.CompanyFrom(updateCooperationContractCommand.CompanyId); err != nil { | ||
516 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
517 | + } else { | ||
518 | + company = data | ||
519 | + } | ||
520 | + | ||
521 | + // 组织机构REST服务初始化 | ||
522 | + var organizationService service.OrgService | ||
523 | + if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil { | ||
524 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
525 | + } else { | ||
526 | + organizationService = value | ||
527 | + } | ||
528 | + | ||
529 | + // 获取组织机构信息 | ||
530 | + var organization *domain.Org | ||
531 | + if data, err := organizationService.OrgFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId); err != nil { | ||
532 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
533 | + } else { | ||
534 | + organization = data | ||
535 | + } | ||
536 | + | ||
505 | var cooperationContractRepository domain.CooperationContractRepository | 537 | var cooperationContractRepository domain.CooperationContractRepository |
506 | if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ | 538 | if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ |
507 | "transactionContext": transactionContext, | 539 | "transactionContext": transactionContext, |
@@ -517,6 +549,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | @@ -517,6 +549,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | ||
517 | if cooperationContract == nil { | 549 | if cooperationContract == nil { |
518 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId))) | 550 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId))) |
519 | } | 551 | } |
552 | + // 更新合约基础信息 | ||
553 | + if err := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err != nil { | ||
554 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
555 | + } | ||
520 | // 用户REST服务初始化 | 556 | // 用户REST服务初始化 |
521 | var userService service.UserService | 557 | var userService service.UserService |
522 | if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil { | 558 | if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil { |
@@ -549,9 +585,106 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | @@ -549,9 +585,106 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | ||
549 | Company: relevantDomain.Company, | 585 | Company: relevantDomain.Company, |
550 | }) | 586 | }) |
551 | } | 587 | } |
552 | - if err := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err != nil { | ||
553 | - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 588 | + // 更新合约相关人 |
589 | + cooperationContract.RelevantPeople = relevantPeople | ||
590 | + | ||
591 | + //TODO 获取承接人 | ||
592 | + var undertakers []*domain.Undertaker | ||
593 | + for _, undertaker := range updateCooperationContractCommand.Undertakers { | ||
594 | + var undertakerDomain *domain.Undertaker | ||
595 | + undertakerUid, _ := strconv.ParseInt(undertaker.UserId, 10, 64) | ||
596 | + if data, err := userService.UndertakerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, undertakerUid); err != nil { | ||
597 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
598 | + } else { | ||
599 | + undertakerDomain = data | ||
600 | + } | ||
601 | + | ||
602 | + // 获取推荐人 | ||
603 | + var referrerDomain *domain.Referrer | ||
604 | + referrerUid, _ := strconv.ParseInt(undertaker.ReferrerId, 10, 64) | ||
605 | + if data, err := userService.ReferrerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, referrerUid); err != nil { | ||
606 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
607 | + } else { | ||
608 | + referrerDomain = data | ||
609 | + } | ||
610 | + | ||
611 | + // 获取业务员 | ||
612 | + var salesmanDomain *domain.Salesman | ||
613 | + salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64) | ||
614 | + if data, err := userService.SalesmanFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, salesmanUid); err != nil { | ||
615 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
616 | + } else { | ||
617 | + salesmanDomain = data | ||
618 | + } | ||
619 | + | ||
620 | + undertakers = append(undertakers, &domain.Undertaker{ | ||
621 | + UndertakerId: undertaker.UndertakerId, | ||
622 | + UserId: undertakerDomain.UserId, | ||
623 | + CooperationContractNumber: cooperationContract.CooperationContractNumber, | ||
624 | + UserBaseId: undertakerDomain.UserBaseId, | ||
625 | + Org: undertakerDomain.Org, | ||
626 | + Orgs: undertakerDomain.Orgs, | ||
627 | + Department: undertakerDomain.Department, | ||
628 | + Roles: undertakerDomain.Roles, | ||
629 | + UserInfo: undertakerDomain.UserInfo, | ||
630 | + UserType: undertakerDomain.UserType, | ||
631 | + Referrer: referrerDomain, | ||
632 | + Salesman: salesmanDomain, | ||
633 | + Status: undertakerDomain.Status, | ||
634 | + Company: undertakerDomain.Company, | ||
635 | + ContractAttachment: nil, | ||
636 | + }) | ||
554 | } | 637 | } |
638 | + //TODO 更新承接人 | ||
639 | + cooperationContract.Undertakers = undertakers | ||
640 | + | ||
641 | + //TODO 获取分红规则列表 | ||
642 | + var dividendsIncentivesRules []*domain.DividendsIncentivesRule | ||
643 | + for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules { | ||
644 | + dividendsIncentivesRuleId, _ := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64) | ||
645 | + dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{ | ||
646 | + DividendsIncentivesRuleId: dividendsIncentivesRuleId, | ||
647 | + CooperationContractNumber: cooperationContract.CooperationContractNumber, | ||
648 | + ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage, | ||
649 | + SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage, | ||
650 | + DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage, | ||
651 | + DividendsIncentivesStage: int64(dividendsIncentivesRule.DividendsIncentivesStage), | ||
652 | + DividendsIncentivesStageEnd: dividendsIncentivesRule.DividendsIncentivesStageEnd, | ||
653 | + DividendsIncentivesStageStart: dividendsIncentivesRule.DividendsIncentivesStageStart, | ||
654 | + Org: organization, | ||
655 | + Company: company, | ||
656 | + UpdatedAt: time.Time{}, | ||
657 | + DeletedAt: time.Time{}, | ||
658 | + CreatedAt: time.Now(), | ||
659 | + }) | ||
660 | + } | ||
661 | + //TODO 更新分红规则列表 | ||
662 | + cooperationContract.DividendsIncentivesRules = dividendsIncentivesRules | ||
663 | + | ||
664 | + //TODO 获取金额激励规则列表 | ||
665 | + var moneyIncentivesRules []*domain.MoneyIncentivesRule | ||
666 | + for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules { | ||
667 | + moneyIncentivesRuleId, _ := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64) | ||
668 | + moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{ | ||
669 | + MoneyIncentivesRuleId: moneyIncentivesRuleId, | ||
670 | + CooperationContractNumber: cooperationContract.CooperationContractNumber, | ||
671 | + MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount), | ||
672 | + MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage), | ||
673 | + MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd, | ||
674 | + MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart, | ||
675 | + MoneyIncentivesTime: time.Now(), | ||
676 | + ReferrerPercentage: moneyIncentivesRule.ReferrerPercentage, | ||
677 | + SalesmanPercentage: moneyIncentivesRule.SalesmanPercentage, | ||
678 | + Org: organization, | ||
679 | + Company: company, | ||
680 | + UpdatedAt: time.Time{}, | ||
681 | + DeletedAt: time.Time{}, | ||
682 | + CreatedAt: time.Now(), | ||
683 | + }) | ||
684 | + } | ||
685 | + //TODO 更新金额激励规则列表 | ||
686 | + cooperationContract.MoneyIncentivesRules = moneyIncentivesRules | ||
687 | + | ||
555 | if cooperationContract, err := cooperationContractRepository.Save(cooperationContract); err != nil { | 688 | if cooperationContract, err := cooperationContractRepository.Save(cooperationContract); err != nil { |
556 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 689 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
557 | } else { | 690 | } else { |
@@ -22,7 +22,7 @@ type CooperationContract struct { | @@ -22,7 +22,7 @@ type CooperationContract struct { | ||
22 | CooperationContractSponsor *User `json:"cooperationContractSponsor"` | 22 | CooperationContractSponsor *User `json:"cooperationContractSponsor"` |
23 | // 共创模式或者合伙模式 | 23 | // 共创模式或者合伙模式 |
24 | CooperationMode *CooperationMode `json:"cooperationMode"` | 24 | CooperationMode *CooperationMode `json:"cooperationMode"` |
25 | - // 合约状态,1启用,2禁用 | 25 | + // 合约状态,1恢复,2暂停 |
26 | Status int32 `json:"status"` | 26 | Status int32 `json:"status"` |
27 | // 数据所属组织机构 | 27 | // 数据所属组织机构 |
28 | Org *Org `json:"org"` | 28 | Org *Org `json:"org"` |
@@ -282,9 +282,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -282,9 +282,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
282 | }) | 282 | }) |
283 | } | 283 | } |
284 | // 添加相关人 | 284 | // 添加相关人 |
285 | + if len(cooperationContractRelevantPeopleToAddModels) > 0 { | ||
285 | if _, err := tx.Model(&cooperationContractRelevantPeopleToAddModels).Insert(); err != nil { | 286 | if _, err := tx.Model(&cooperationContractRelevantPeopleToAddModels).Insert(); err != nil { |
286 | return nil, err | 287 | return nil, err |
287 | } | 288 | } |
289 | + } | ||
288 | 290 | ||
289 | // 待更新或者删除的ids | 291 | // 待更新或者删除的ids |
290 | var cooperationContractRelevantPeopleToUpdateOrDeleteIds []int64 | 292 | var cooperationContractRelevantPeopleToUpdateOrDeleteIds []int64 |
@@ -302,9 +304,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -302,9 +304,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
302 | } | 304 | } |
303 | } | 305 | } |
304 | } | 306 | } |
307 | + if len(relevantModelsToUpdate) > 0 { | ||
305 | if _, err := tx.Model(&relevantModelsToUpdate).WherePK().Update(); err != nil { | 308 | if _, err := tx.Model(&relevantModelsToUpdate).WherePK().Update(); err != nil { |
306 | return nil, err | 309 | return nil, err |
307 | } | 310 | } |
311 | + } | ||
308 | 312 | ||
309 | // 待删除的相关人id | 313 | // 待删除的相关人id |
310 | relevantIdsToDelete := utils.Difference(cooperationContractRelevantIdsFetched, cooperationContractRelevantPeopleToUpdateOrDeleteIds) | 314 | relevantIdsToDelete := utils.Difference(cooperationContractRelevantIdsFetched, cooperationContractRelevantPeopleToUpdateOrDeleteIds) |
@@ -316,7 +320,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -316,7 +320,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
316 | } | 320 | } |
317 | } | 321 | } |
318 | } | 322 | } |
319 | - if _, err := tx.Model(&relevantModelsToDelete).WherePK().Delete(); err != nil { | 323 | + if _, err := tx.Model(&relevantModelsToDelete).Delete(); err != nil { |
320 | return nil, err | 324 | return nil, err |
321 | } | 325 | } |
322 | 326 | ||
@@ -367,9 +371,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -367,9 +371,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
367 | }) | 371 | }) |
368 | } | 372 | } |
369 | // 添加承接人 | 373 | // 添加承接人 |
374 | + if len(cooperationContractUndertakersToAddModels) > 0 { | ||
370 | if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil { | 375 | if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil { |
371 | return nil, err | 376 | return nil, err |
372 | } | 377 | } |
378 | + } | ||
373 | 379 | ||
374 | // 待更新或者删除的ids | 380 | // 待更新或者删除的ids |
375 | var cooperationContractUndertakersToUpdateOrDeleteIds []int64 | 381 | var cooperationContractUndertakersToUpdateOrDeleteIds []int64 |
@@ -387,11 +393,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -387,11 +393,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
387 | } | 393 | } |
388 | } | 394 | } |
389 | } | 395 | } |
396 | + if len(undertakerModelsToUpdate) > 0 { | ||
390 | if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil { | 397 | if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil { |
391 | return nil, err | 398 | return nil, err |
392 | } | 399 | } |
400 | + } | ||
393 | 401 | ||
394 | - // 待删除的相关人id | 402 | + // 待删除的承接人id |
395 | undertakerIdsToDelete := utils.Difference(cooperationContractUndertakersIdsFetched, cooperationContractUndertakersToUpdateOrDeleteIds) | 403 | undertakerIdsToDelete := utils.Difference(cooperationContractUndertakersIdsFetched, cooperationContractUndertakersToUpdateOrDeleteIds) |
396 | var undertakerModelsToDelete []*models.CooperationContractUndertaker | 404 | var undertakerModelsToDelete []*models.CooperationContractUndertaker |
397 | for _, id := range undertakerIdsToDelete { | 405 | for _, id := range undertakerIdsToDelete { |
@@ -401,7 +409,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -401,7 +409,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
401 | } | 409 | } |
402 | } | 410 | } |
403 | } | 411 | } |
404 | - if _, err := tx.Model(&relevantModelsToDelete).WherePK().Delete(); err != nil { | 412 | + if _, err := tx.Model(&undertakerModelsToDelete).Delete(); err != nil { |
405 | return nil, err | 413 | return nil, err |
406 | } | 414 | } |
407 | 415 | ||
@@ -450,9 +458,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -450,9 +458,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
450 | }) | 458 | }) |
451 | } | 459 | } |
452 | // 添加分红激励规则 | 460 | // 添加分红激励规则 |
461 | + if len(dividendsIncentivesRulesToAddModels) > 0 { | ||
453 | if _, err := tx.Model(÷ndsIncentivesRulesToAddModels).Insert(); err != nil { | 462 | if _, err := tx.Model(÷ndsIncentivesRulesToAddModels).Insert(); err != nil { |
454 | return nil, err | 463 | return nil, err |
455 | } | 464 | } |
465 | + } | ||
456 | 466 | ||
457 | // 待更新或者删除的ids | 467 | // 待更新或者删除的ids |
458 | var dividendsIncentivesRulesToUpdateOrDeleteIds []int64 | 468 | var dividendsIncentivesRulesToUpdateOrDeleteIds []int64 |
@@ -470,9 +480,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -470,9 +480,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
470 | } | 480 | } |
471 | } | 481 | } |
472 | } | 482 | } |
483 | + if len(dividendsRuleModelsToUpdate) > 0 { | ||
473 | if _, err := tx.Model(÷ndsRuleModelsToUpdate).WherePK().Update(); err != nil { | 484 | if _, err := tx.Model(÷ndsRuleModelsToUpdate).WherePK().Update(); err != nil { |
474 | return nil, err | 485 | return nil, err |
475 | } | 486 | } |
487 | + } | ||
476 | 488 | ||
477 | // 待删除的分红激励规则id | 489 | // 待删除的分红激励规则id |
478 | dividendsIncentivesRuleIdsToDelete := utils.Difference(dividendsIncentivesRuleIdsFetched, dividendsIncentivesRulesToUpdateOrDeleteIds) | 490 | dividendsIncentivesRuleIdsToDelete := utils.Difference(dividendsIncentivesRuleIdsFetched, dividendsIncentivesRulesToUpdateOrDeleteIds) |
@@ -484,7 +496,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -484,7 +496,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
484 | } | 496 | } |
485 | } | 497 | } |
486 | } | 498 | } |
487 | - if _, err := tx.Model(÷ndsIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil { | 499 | + if _, err := tx.Model(÷ndsIncentivesRuleModelsToDelete).Delete(); err != nil { |
488 | return nil, err | 500 | return nil, err |
489 | } | 501 | } |
490 | 502 | ||
@@ -533,9 +545,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -533,9 +545,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
533 | }) | 545 | }) |
534 | } | 546 | } |
535 | // 添加金额激励规则 | 547 | // 添加金额激励规则 |
548 | + if len(moneyIncentivesRulesToAddModels) > 0 { | ||
536 | if _, err := tx.Model(&moneyIncentivesRulesToAddModels).Insert(); err != nil { | 549 | if _, err := tx.Model(&moneyIncentivesRulesToAddModels).Insert(); err != nil { |
537 | return nil, err | 550 | return nil, err |
538 | } | 551 | } |
552 | + } | ||
539 | 553 | ||
540 | // 待更新或者删除的ids | 554 | // 待更新或者删除的ids |
541 | var moneyIncentivesRulesToUpdateOrDeleteIds []int64 | 555 | var moneyIncentivesRulesToUpdateOrDeleteIds []int64 |
@@ -553,9 +567,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -553,9 +567,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
553 | } | 567 | } |
554 | } | 568 | } |
555 | } | 569 | } |
570 | + if len(moneyRuleModelsToUpdate) > 0 { | ||
556 | if _, err := tx.Model(&moneyRuleModelsToUpdate).WherePK().Update(); err != nil { | 571 | if _, err := tx.Model(&moneyRuleModelsToUpdate).WherePK().Update(); err != nil { |
557 | return nil, err | 572 | return nil, err |
558 | } | 573 | } |
574 | + } | ||
559 | 575 | ||
560 | // 待删除的金额激励规则id | 576 | // 待删除的金额激励规则id |
561 | moneyIncentivesRuleIdsToDelete := utils.Difference(moneyIncentivesRuleIdsFetched, moneyIncentivesRulesToUpdateOrDeleteIds) | 577 | moneyIncentivesRuleIdsToDelete := utils.Difference(moneyIncentivesRuleIdsFetched, moneyIncentivesRulesToUpdateOrDeleteIds) |
@@ -567,7 +583,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | @@ -567,7 +583,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai | ||
567 | } | 583 | } |
568 | } | 584 | } |
569 | } | 585 | } |
570 | - if _, err := tx.Model(&moneyIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil { | 586 | + if _, err := tx.Model(&moneyIncentivesRuleModelsToDelete).Delete(); err != nil { |
571 | return nil, err | 587 | return nil, err |
572 | } | 588 | } |
573 | 589 |
-
请 注册 或 登录 后发表评论