作者 陈志颖

refactor:共创合约优化

@@ -1056,6 +1056,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1056,6 +1056,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1056 UpdatedAt: time.Time{}, 1056 UpdatedAt: time.Time{},
1057 DeletedAt: time.Time{}, 1057 DeletedAt: time.Time{},
1058 CreatedAt: time.Now(), 1058 CreatedAt: time.Now(),
  1059 + Remarks: dividendsIncentivesRule.Remarks,
1059 }) 1060 })
1060 } 1061 }
1061 1062
@@ -1084,6 +1085,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1084,6 +1085,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1084 UpdatedAt: time.Time{}, 1085 UpdatedAt: time.Time{},
1085 DeletedAt: time.Time{}, 1086 DeletedAt: time.Time{},
1086 CreatedAt: time.Now(), 1087 CreatedAt: time.Now(),
  1088 + Remarks: moneyIncentivesRule.Remarks,
1087 }) 1089 })
1088 } 1090 }
1089 1091
@@ -434,27 +434,27 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -434,27 +434,27 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
434 "待更新的承接人": undertakerModelsToUpdate, 434 "待更新的承接人": undertakerModelsToUpdate,
435 }) 435 })
436 for i, undertakerModelToUpdate := range undertakerModelsToUpdate { 436 for i, undertakerModelToUpdate := range undertakerModelsToUpdate {
437 - for j, undertaker := range cooperationContract.Undertakers { 437 + for _, undertaker := range cooperationContract.Undertakers {
438 if undertaker.UndertakerId == undertakerModelToUpdate.CooperationContractUndertakerId { 438 if undertaker.UndertakerId == undertakerModelToUpdate.CooperationContractUndertakerId {
439 undertakerModelsToUpdate[i] = &models.CooperationContractUndertaker{ 439 undertakerModelsToUpdate[i] = &models.CooperationContractUndertaker{
440 - CooperationContractUndertakerId: cooperationContract.Undertakers[j].UndertakerId,  
441 - CooperationContractNumber: cooperationContract.Undertakers[j].CooperationContractNumber,  
442 - UserId: cooperationContract.Undertakers[j].UserId,  
443 - UserBaseId: cooperationContract.Undertakers[j].UserBaseId,  
444 - Org: cooperationContract.Undertakers[j].Org,  
445 - Orgs: cooperationContract.Undertakers[j].Orgs,  
446 - Department: cooperationContract.Undertakers[j].Department,  
447 - Roles: cooperationContract.Undertakers[j].Roles,  
448 - UserInfo: cooperationContract.Undertakers[j].UserInfo,  
449 - UserType: cooperationContract.Undertakers[j].UserType,  
450 - Referrer: cooperationContract.Undertakers[j].Referrer,  
451 - Salesman: cooperationContract.Undertakers[j].Salesman,  
452 - Status: cooperationContract.Undertakers[j].Status,  
453 - Company: cooperationContract.Undertakers[j].Company,  
454 - ContractAttachment: cooperationContract.Undertakers[j].ContractAttachment,  
455 - CreatedAt: undertakerModelsToUpdate[i].CreatedAt, 440 + CooperationContractUndertakerId: undertaker.UndertakerId,
  441 + CooperationContractNumber: undertaker.CooperationContractNumber,
  442 + UserId: undertaker.UserId,
  443 + UserBaseId: undertaker.UserBaseId,
  444 + Org: undertaker.Org,
  445 + Orgs: undertaker.Orgs,
  446 + Department: undertaker.Department,
  447 + Roles: undertaker.Roles,
  448 + UserInfo: undertaker.UserInfo,
  449 + UserType: undertaker.UserType,
  450 + Referrer: undertaker.Referrer,
  451 + Salesman: undertaker.Salesman,
  452 + Status: undertaker.Status,
  453 + Company: undertaker.Company,
  454 + ContractAttachment: undertaker.ContractAttachment,
  455 + CreatedAt: undertakerModelToUpdate.CreatedAt,
456 UpdatedAt: time.Now(), 456 UpdatedAt: time.Now(),
457 - DeletedAt: undertakerModelsToUpdate[i].DeletedAt, 457 + DeletedAt: undertakerModelToUpdate.DeletedAt,
458 } 458 }
459 } 459 }
460 } 460 }
@@ -558,7 +558,30 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -558,7 +558,30 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
558 log.Logger.Info("待更新的分红激励规则", map[string]interface{}{ 558 log.Logger.Info("待更新的分红激励规则", map[string]interface{}{
559 "dividendsRuleModelsToUpdate": dividendsRuleModelsToUpdate, 559 "dividendsRuleModelsToUpdate": dividendsRuleModelsToUpdate,
560 }) 560 })
  561 +
561 if len(dividendsRuleModelsToUpdate) > 0 { 562 if len(dividendsRuleModelsToUpdate) > 0 {
  563 + for i, dividendsRuleModelToUpdate := range dividendsRuleModelsToUpdate {
  564 + for _, dividendsRule := range cooperationContract.DividendsIncentivesRules {
  565 + if dividendsRule.DividendsIncentivesRuleId == dividendsRuleModelToUpdate.DividendsIncentivesRuleId {
  566 + dividendsRuleModelsToUpdate[i] = &models.DividendsIncentivesRule{
  567 + DividendsIncentivesRuleId: dividendsRuleModelToUpdate.DividendsIncentivesRuleId,
  568 + CooperationContractNumber: dividendsRuleModelToUpdate.CooperationContractNumber,
  569 + ReferrerPercentage: dividendsRuleModelToUpdate.ReferrerPercentage,
  570 + SalesmanPercentage: dividendsRuleModelToUpdate.SalesmanPercentage,
  571 + DividendsIncentivesPercentage: dividendsRuleModelToUpdate.DividendsIncentivesPercentage,
  572 + DividendsIncentivesStage: dividendsRuleModelToUpdate.DividendsIncentivesStage,
  573 + DividendsIncentivesStageEnd: dividendsRuleModelToUpdate.DividendsIncentivesStageEnd,
  574 + DividendsIncentivesStageStart: dividendsRuleModelToUpdate.DividendsIncentivesStageStart,
  575 + Remarks: dividendsRuleModelToUpdate.Remarks,
  576 + Org: dividendsRuleModelToUpdate.Org,
  577 + Company: dividendsRuleModelToUpdate.Company,
  578 + UpdatedAt: time.Now(),
  579 + DeletedAt: dividendsRuleModelToUpdate.DeletedAt,
  580 + CreatedAt: dividendsRuleModelToUpdate.CreatedAt,
  581 + }
  582 + }
  583 + }
  584 + }
562 if _, err := tx.Model(&dividendsRuleModelsToUpdate).WherePK().Update(); err != nil { 585 if _, err := tx.Model(&dividendsRuleModelsToUpdate).WherePK().Update(); err != nil {
563 return nil, err 586 return nil, err
564 } 587 }
@@ -656,6 +679,29 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -656,6 +679,29 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
656 "moneyRuleModelsToUpdate": moneyRuleModelsToUpdate, 679 "moneyRuleModelsToUpdate": moneyRuleModelsToUpdate,
657 }) 680 })
658 if len(moneyRuleModelsToUpdate) > 0 { 681 if len(moneyRuleModelsToUpdate) > 0 {
  682 + for i, moneyRuleModelToUpdate := range moneyRuleModelsToUpdate {
  683 + for _, moneyRule := range cooperationContract.MoneyIncentivesRules {
  684 + if moneyRule.MoneyIncentivesRuleId == moneyRuleModelToUpdate.MoneyIncentivesRuleId {
  685 + moneyRuleModelsToUpdate[i] = &models.MoneyIncentivesRule{
  686 + MoneyIncentivesRuleId: moneyRule.MoneyIncentivesRuleId,
  687 + CooperationContractNumber: moneyRule.CooperationContractNumber,
  688 + MoneyIncentivesAmount: moneyRule.MoneyIncentivesAmount,
  689 + MoneyIncentivesStage: moneyRule.MoneyIncentivesStage,
  690 + MoneyIncentivesStageEnd: moneyRule.MoneyIncentivesStageEnd,
  691 + MoneyIncentivesStageStart: moneyRule.MoneyIncentivesStageStart,
  692 + MoneyIncentivesTime: moneyRule.MoneyIncentivesTime,
  693 + ReferrerPercentage: moneyRule.MoneyIncentivesAmount,
  694 + SalesmanPercentage: moneyRule.MoneyIncentivesAmount,
  695 + Remarks: moneyRule.Remarks,
  696 + Org: moneyRule.Org,
  697 + Company: moneyRule.Company,
  698 + UpdatedAt: time.Now(),
  699 + DeletedAt: moneyRuleModelToUpdate.DeletedAt,
  700 + CreatedAt: moneyRuleModelToUpdate.CreatedAt,
  701 + }
  702 + }
  703 + }
  704 + }
659 if _, err := tx.Model(&moneyRuleModelsToUpdate).WherePK().Update(); err != nil { 705 if _, err := tx.Model(&moneyRuleModelsToUpdate).WherePK().Update(); err != nil {
660 return nil, err 706 return nil, err
661 } 707 }
@@ -243,30 +243,31 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend @@ -243,30 +243,31 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
243 log.Logger.Info("待更新的分红订单产品", map[string]interface{}{ 243 log.Logger.Info("待更新的分红订单产品", map[string]interface{}{
244 "orderGoodModelsToUpdate": orderGoodModelsToUpdate, 244 "orderGoodModelsToUpdate": orderGoodModelsToUpdate,
245 }) 245 })
246 - for i, orderGoodModelToUpdate := range orderGoodModelsToUpdate {  
247 - for j, orderGood := range dividendsOrder.Goods {  
248 - if orderGood.OrderGoodId == orderGoodModelToUpdate.OrderGoodId {  
249 - orderGoodModelsToUpdate[i] = &models.OrderGood{  
250 - OrderGoodId: dividendsOrder.Goods[j].OrderGoodId,  
251 - OrderGoodAmount: dividendsOrder.Goods[j].OrderGoodAmount,  
252 - OrderGoodName: dividendsOrder.Goods[j].OrderGoodName,  
253 - OrderGoodPrice: dividendsOrder.Goods[j].OrderGoodPrice,  
254 - OrderGoodQuantity: dividendsOrder.Goods[j].OrderGoodQuantity,  
255 - DividendsOrderNumber: dividendsOrder.Goods[j].DividendsOrderNumber,  
256 - DividendsReturnedOrderNumber: dividendsOrder.Goods[j].DividendsReturnedOrderNumber,  
257 - CooperationContractNumber: dividendsOrder.Goods[j].CooperationContractNumber,  
258 - OrgId: dividendsOrder.Goods[j].OrgId,  
259 - CompanyId: dividendsOrder.Goods[j].CompanyId,  
260 - OrderGoodExpense: dividendsOrder.Goods[j].OrderGoodExpense,  
261 - OrderGoodDividendsStatus: dividendsOrder.Goods[j].OrderGoodDividendsStatus,  
262 - CreatedAt: orderGoodModelsToUpdate[i].CreatedAt,  
263 - DeletedAt: orderGoodModelsToUpdate[i].DeletedAt,  
264 - UpdatedAt: time.Now(), 246 +
  247 + if len(orderGoodModelsToUpdate) > 0 {
  248 + for i, orderGoodModelToUpdate := range orderGoodModelsToUpdate {
  249 + for _, orderGood := range dividendsOrder.Goods {
  250 + if orderGood.OrderGoodId == orderGoodModelToUpdate.OrderGoodId {
  251 + orderGoodModelsToUpdate[i] = &models.OrderGood{
  252 + OrderGoodId: orderGoodModelToUpdate.OrderGoodId,
  253 + OrderGoodAmount: orderGoodModelToUpdate.OrderGoodAmount,
  254 + OrderGoodName: orderGoodModelToUpdate.OrderGoodName,
  255 + OrderGoodPrice: orderGoodModelToUpdate.OrderGoodPrice,
  256 + OrderGoodQuantity: orderGoodModelToUpdate.OrderGoodQuantity,
  257 + DividendsOrderNumber: orderGoodModelToUpdate.DividendsOrderNumber,
  258 + DividendsReturnedOrderNumber: orderGoodModelToUpdate.DividendsReturnedOrderNumber,
  259 + CooperationContractNumber: orderGoodModelToUpdate.CooperationContractNumber,
  260 + OrgId: orderGoodModelToUpdate.OrgId,
  261 + CompanyId: orderGoodModelToUpdate.CompanyId,
  262 + OrderGoodExpense: orderGoodModelToUpdate.OrderGoodExpense,
  263 + OrderGoodDividendsStatus: orderGoodModelToUpdate.OrderGoodDividendsStatus,
  264 + CreatedAt: orderGoodModelToUpdate.CreatedAt,
  265 + DeletedAt: orderGoodModelToUpdate.DeletedAt,
  266 + UpdatedAt: time.Now(),
  267 + }
265 } 268 }
266 } 269 }
267 } 270 }
268 - }  
269 - if len(orderGoodModelsToUpdate) > 0 {  
270 if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil { 271 if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil {
271 return nil, err 272 return nil, err
272 } 273 }