作者 陈志颖

fix:根据合约名称查询金额激励分红

@@ -355,11 +355,43 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs @@ -355,11 +355,43 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
355 355
356 // 校验是否能够取消 356 // 校验是否能够取消
357 if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红/退货冲销 357 if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红/退货冲销
358 - if countRelativeDividendsEstimates, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{  
359 - "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
360 - "companyId": dividendsEstimate.Company.CompanyId,  
361 - "orgId": dividendsEstimate.Org.OrgId,  
362 - }); err2 != nil { 358 + // 自定义查询
  359 + queryOptions := make(map[string]interface{})
  360 +
  361 + //参与分红类型,1承接人,2推荐人,3关联业务员
  362 + if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
  363 + queryOptions = map[string]interface{}{
  364 + "companyId": dividendsEstimate.Company.CompanyId,
  365 + "orgId": dividendsEstimate.Org.OrgId,
  366 + "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  367 + "dividendsParticipateTypes": []int32{2, 3},
  368 + "offsetLimit": false,
  369 + "dividendsStage": dividendsEstimate.DividendsStage,
  370 + "dividendsTypes": []int32{1, 2},
  371 + }
  372 + } else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单
  373 + queryOptions = map[string]interface{}{
  374 + "companyId": dividendsEstimate.Company.CompanyId,
  375 + "orgId": dividendsEstimate.Org.OrgId,
  376 + "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  377 + "dividendsParticipateTypes": []int32{1, 3},
  378 + "offsetLimit": false,
  379 + "dividendsStage": dividendsEstimate.DividendsStage,
  380 + "dividendsTypes": []int32{1, 2},
  381 + }
  382 + } else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单
  383 + queryOptions = map[string]interface{}{
  384 + "companyId": dividendsEstimate.Company.CompanyId,
  385 + "orgId": dividendsEstimate.Org.OrgId,
  386 + "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  387 + "dividendsParticipateTypes": []int32{1, 2},
  388 + "offsetLimit": false,
  389 + "dividendsStage": dividendsEstimate.DividendsStage,
  390 + "dividendsTypes": []int32{1, 2},
  391 + }
  392 + }
  393 +
  394 + if countRelativeDividendsEstimates, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil {
363 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) 395 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
364 } else { 396 } else {
365 if countRelativeDividendsEstimates > 0 { 397 if countRelativeDividendsEstimates > 0 {
@@ -371,11 +403,43 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs @@ -371,11 +403,43 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
371 } 403 }
372 } 404 }
373 } else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红 405 } else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红
374 - if countRelativeDividendsEstimates, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(map[string]interface{}{  
375 - "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
376 - "companyId": dividendsEstimate.Company.CompanyId,  
377 - "orgId": dividendsEstimate.Org.OrgId,  
378 - }); err3 != nil { 406 + // 自定义查询
  407 + queryOptions := make(map[string]interface{})
  408 +
  409 + //参与分红类型,1承接人,2推荐人,3关联业务员
  410 + if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
  411 + queryOptions = map[string]interface{}{
  412 + "companyId": dividendsEstimate.Company.CompanyId,
  413 + "orgId": dividendsEstimate.Org.OrgId,
  414 + "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  415 + "dividendsParticipateTypes": []int32{2, 3},
  416 + "offsetLimit": false,
  417 + "dividendsStage": dividendsEstimate.DividendsStage,
  418 + "dividendsType": int32(3),
  419 + }
  420 + } else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单
  421 + queryOptions = map[string]interface{}{
  422 + "companyId": dividendsEstimate.Company.CompanyId,
  423 + "orgId": dividendsEstimate.Org.OrgId,
  424 + "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  425 + "dividendsParticipateTypes": []int32{1, 3},
  426 + "offsetLimit": false,
  427 + "dividendsStage": dividendsEstimate.DividendsStage,
  428 + "dividendsType": int32(3),
  429 + }
  430 + } else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单
  431 + queryOptions = map[string]interface{}{
  432 + "companyId": dividendsEstimate.Company.CompanyId,
  433 + "orgId": dividendsEstimate.Org.OrgId,
  434 + "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  435 + "dividendsParticipateTypes": []int32{1, 2},
  436 + "offsetLimit": false,
  437 + "dividendsStage": dividendsEstimate.DividendsStage,
  438 + "dividendsType": int32(3),
  439 + }
  440 + }
  441 +
  442 + if countRelativeDividendsEstimates, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(queryOptions); err3 != nil {
379 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error()) 443 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
380 } else { 444 } else {
381 if countRelativeDividendsEstimates > 0 { 445 if countRelativeDividendsEstimates > 0 {
@@ -388,6 +452,7 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs @@ -388,6 +452,7 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
388 } 452 }
389 } 453 }
390 } 454 }
  455 +
391 // 批量取消分红预算单 456 // 批量取消分红预算单
392 if dividendsEstimatesCanceled, errCancel := cancelDividendsEstimateService.CancelEstimate(dividendsEstimateIds, operator); errCancel != nil { 457 if dividendsEstimatesCanceled, errCancel := cancelDividendsEstimateService.CancelEstimate(dividendsEstimateIds, operator); errCancel != nil {
393 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errCancel.Error()) 458 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errCancel.Error())
@@ -651,6 +716,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -651,6 +716,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
651 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 716 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
652 } else { 717 } else {
653 dividendsEstimates := make([]*domain.DividendsEstimate, 0) 718 dividendsEstimates := make([]*domain.DividendsEstimate, 0)
  719 +
654 // 统计当前企业分红预算单数 720 // 统计当前企业分红预算单数
655 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{ 721 count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
656 "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId, 722 "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
@@ -658,6 +724,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -658,6 +724,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
658 if err != nil { 724 if err != nil {
659 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 725 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
660 } 726 }
  727 +
661 var countDividendsEstimate int64 728 var countDividendsEstimate int64
662 for _, orderGood := range orderGoods { 729 for _, orderGood := range orderGoods {
663 dividendsEstimate := &domain.DividendsEstimate{} 730 dividendsEstimate := &domain.DividendsEstimate{}
@@ -150,6 +150,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -150,6 +150,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
150 "dividendsType": int32(3), 150 "dividendsType": int32(3),
151 } 151 }
152 } 152 }
  153 +
153 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单 154 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
154 if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil { 155 if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil {
155 return nil, err2 156 return nil, err2
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
11 ) 12 )
12 13
13 type ConfirmDividendsIncentivesEstimateService struct { 14 type ConfirmDividendsIncentivesEstimateService struct {
@@ -53,6 +54,10 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -53,6 +54,10 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
53 // 确认业绩分红预算 54 // 确认业绩分红预算
54 var dividendsEstimateDetails []*service.DividendsEstimateDetail 55 var dividendsEstimateDetails []*service.DividendsEstimateDetail
55 for _, orderGood := range orderGoods { 56 for _, orderGood := range orderGoods {
  57 + log.Logger.Info("业绩分红预算产品", map[string]interface{}{
  58 + "orderGood": orderGood,
  59 + })
  60 +
56 // 获取合约 61 // 获取合约
57 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{ 62 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
58 "cooperationContractNumber": orderGood.CooperationContractNumber, 63 "cooperationContractNumber": orderGood.CooperationContractNumber,
@@ -95,6 +100,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -95,6 +100,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
95 }) 100 })
96 continue 101 continue
97 } else { 102 } else {
  103 + log.Logger.Info("产品相关的合约", map[string]interface{}{
  104 + "cooperationContract": cooperationContract,
  105 + })
98 if cooperationContract.Status == 2 { 106 if cooperationContract.Status == 2 {
99 var orderNumber string 107 var orderNumber string
100 if orderGood.DividendsOrderNumber != "" { 108 if orderGood.DividendsOrderNumber != "" {
@@ -30,7 +30,7 @@ type CooperationContractChangeLog struct { @@ -30,7 +30,7 @@ type CooperationContractChangeLog struct {
30 // 更新时间 30 // 更新时间
31 UpdatedAt time.Time `comment:"更新时间"` 31 UpdatedAt time.Time `comment:"更新时间"`
32 // 删除时间 32 // 删除时间
33 - DeletedAt time.Time `comment:"删除时间"` 33 + DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"`
34 // 创建时间 34 // 创建时间
35 CreatedAt time.Time `comment:"创建时间"` 35 CreatedAt time.Time `comment:"创建时间"`
36 } 36 }
@@ -1146,7 +1146,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in @@ -1146,7 +1146,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
1146 if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" { 1146 if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
1147 query.Where("cooperation_contract_number ilike ?", fmt.Sprintf("%%%s%%", cooperationContractNumber)) 1147 query.Where("cooperation_contract_number ilike ?", fmt.Sprintf("%%%s%%", cooperationContractNumber))
1148 } 1148 }
1149 - if cooperationContractName, ok := queryOptions["cooperationContactName"]; ok && cooperationContractName != "" { 1149 + if cooperationContractName, ok := queryOptions["cooperationContractName"]; ok && cooperationContractName != "" {
1150 query.Where("cooperation_contract_name like ?", fmt.Sprintf("%%%s%%", cooperationContractName)) 1150 query.Where("cooperation_contract_name like ?", fmt.Sprintf("%%%s%%", cooperationContractName))
1151 } 1151 }
1152 if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" { 1152 if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" {