作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

@@ -354,7 +354,7 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs @@ -354,7 +354,7 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
354 } 354 }
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{}{ 358 if countRelativeDividendsEstimates, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
359 "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum, 359 "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
360 "companyId": dividendsEstimate.Company.CompanyId, 360 "companyId": dividendsEstimate.Company.CompanyId,
@@ -389,11 +389,11 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs @@ -389,11 +389,11 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
389 } 389 }
390 } 390 }
391 // 批量取消分红预算单 391 // 批量取消分红预算单
392 - if dividendsEstimatesCanceled, err := cancelDividendsEstimateService.CancelEstimate(dividendsEstimateIds, operator); err != nil {  
393 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 392 + if dividendsEstimatesCanceled, errCancel := cancelDividendsEstimateService.CancelEstimate(dividendsEstimateIds, operator); errCancel != nil {
  393 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errCancel.Error())
394 } else { 394 } else {
395 - if err := transactionContext.CommitTransaction(); err != nil {  
396 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 395 + if errTx := transactionContext.CommitTransaction(); errTx != nil {
  396 + return nil, application.ThrowError(application.TRANSACTION_ERROR, errTx.Error())
397 } 397 }
398 return dividendsEstimatesCanceled, nil 398 return dividendsEstimatesCanceled, nil
399 } 399 }
@@ -40,7 +40,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -40,7 +40,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
40 return nil, err 40 return nil, err
41 } else { 41 } else {
42 dividendsReturnedOrderRepository = repo 42 dividendsReturnedOrderRepository = repo
43 -  
44 } 43 }
45 44
46 // 订单产品仓储初始化 45 // 订单产品仓储初始化
@@ -60,14 +59,45 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -60,14 +59,45 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
60 var dividendsEstimatesCanceled []*domain.DividendsEstimate 59 var dividendsEstimatesCanceled []*domain.DividendsEstimate
61 var orderOrReturnOrderNums []string 60 var orderOrReturnOrderNums []string
62 for _, dividendsEstimate := range dividendsEstimates { 61 for _, dividendsEstimate := range dividendsEstimates {
63 - if dividendsEstimate.DividendsType != 3 { // 非金额激励分红预算单处理 62 + if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
  63 + // 自定义查询
  64 + queryOptions := make(map[string]interface{})
  65 +
  66 + //参与分红类型,1承接人,2推荐人,3关联业务员
  67 + if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
  68 + queryOptions = map[string]interface{}{
  69 + "companyId": dividendsEstimate.Company.CompanyId,
  70 + "orgId": dividendsEstimate.Org.OrgId,
  71 + "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  72 + "dividendsParticipateTypes": []int32{2, 3},
  73 + "offsetLimit": false,
  74 + "dividendsStage": dividendsEstimate.DividendsStage,
  75 + "dividendsTypes": []int32{1, 2},
  76 + }
  77 + } else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单
  78 + queryOptions = map[string]interface{}{
  79 + "companyId": dividendsEstimate.Company.CompanyId,
  80 + "orgId": dividendsEstimate.Org.OrgId,
  81 + "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  82 + "dividendsParticipateTypes": []int32{1, 3},
  83 + "offsetLimit": false,
  84 + "dividendsStage": dividendsEstimate.DividendsStage,
  85 + "dividendsTypes": []int32{1, 2},
  86 + }
  87 + } else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单
  88 + queryOptions = map[string]interface{}{
  89 + "companyId": dividendsEstimate.Company.CompanyId,
  90 + "orgId": dividendsEstimate.Org.OrgId,
  91 + "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  92 + "dividendsParticipateTypes": []int32{1, 2},
  93 + "offsetLimit": false,
  94 + "dividendsStage": dividendsEstimate.DividendsStage,
  95 + "dividendsTypes": []int32{1, 2},
  96 + }
  97 + }
  98 +
64 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单 99 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
65 - if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{  
66 - "companyId": dividendsEstimate.Company.CompanyId,  
67 - "orgId": dividendsEstimate.Org.OrgId,  
68 - "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
69 - "offsetLimit": false,  
70 - }); err2 != nil { 100 + if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil {
71 return nil, err2 101 return nil, err2
72 } else { 102 } else {
73 if countRelative > 0 { 103 if countRelative > 0 {
@@ -84,15 +114,44 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -84,15 +114,44 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
84 dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...) 114 dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
85 } 115 }
86 } 116 }
87 - } else if dividendsEstimate.DividendsType == 3 { 117 + } else if dividendsEstimate.DividendsType == 3 { // 3.金额激励
  118 + // 自定义查询
  119 + queryOptions := make(map[string]interface{})
  120 +
  121 + //参与分红类型,1承接人,2推荐人,3关联业务员
  122 + if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
  123 + queryOptions = map[string]interface{}{
  124 + "companyId": dividendsEstimate.Company.CompanyId,
  125 + "orgId": dividendsEstimate.Org.OrgId,
  126 + "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  127 + "dividendsParticipateTypes": []int32{2, 3},
  128 + "offsetLimit": false,
  129 + "dividendsStage": dividendsEstimate.DividendsStage,
  130 + "dividendsType": int32(3),
  131 + }
  132 + } else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单
  133 + queryOptions = map[string]interface{}{
  134 + "companyId": dividendsEstimate.Company.CompanyId,
  135 + "orgId": dividendsEstimate.Org.OrgId,
  136 + "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  137 + "dividendsParticipateTypes": []int32{1, 3},
  138 + "offsetLimit": false,
  139 + "dividendsStage": dividendsEstimate.DividendsStage,
  140 + "dividendsType": int32(3),
  141 + }
  142 + } else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单
  143 + queryOptions = map[string]interface{}{
  144 + "companyId": dividendsEstimate.Company.CompanyId,
  145 + "orgId": dividendsEstimate.Org.OrgId,
  146 + "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  147 + "dividendsParticipateTypes": []int32{1, 2},
  148 + "offsetLimit": false,
  149 + "dividendsStage": dividendsEstimate.DividendsStage,
  150 + "dividendsType": int32(3),
  151 + }
  152 + }
88 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单 153 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
89 - if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{  
90 - "companyId": dividendsEstimate.Company.CompanyId,  
91 - "orgId": dividendsEstimate.Org.OrgId,  
92 - "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
93 - "dividendsType": int32(3),  
94 - "offsetLimit": false,  
95 - }); err2 != nil { 154 + if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil {
96 return nil, err2 155 return nil, err2
97 } else { 156 } else {
98 if countRelative > 0 { 157 if countRelative > 0 {
@@ -110,18 +169,24 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -110,18 +169,24 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
110 } 169 }
111 } 170 }
112 171
113 - // 分红订单或分红退货单状态变更 172 + // 分红订单
114 var orderNums []string 173 var orderNums []string
  174 +
  175 + // 分红退货单
115 var returnedOrderNums []string 176 var returnedOrderNums []string
116 177
117 if len(orderOrReturnOrderNums) > 0 { 178 if len(orderOrReturnOrderNums) > 0 {
118 // 订单/退货单号数组去重 179 // 订单/退货单号数组去重
119 orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums) 180 orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums)
  181 +
  182 + // 分离订单和退货单
120 for _, orderNullNum := range orderOrReturnOrderNumsWithoutDup { 183 for _, orderNullNum := range orderOrReturnOrderNumsWithoutDup {
121 - if orderNullNum[:2] == "RE" { // 分红退后单  
122 - returnedOrderNums = append(returnedOrderNums, orderNullNum)  
123 - } else if orderNullNum[:2] == "SL" { // 分红订单  
124 - orderNums = append(orderNums, orderNullNum) 184 + if len(orderNullNum) > 0 {
  185 + if orderNullNum[:2] == "RE" { // 分红退后单
  186 + returnedOrderNums = append(returnedOrderNums, orderNullNum)
  187 + } else if orderNullNum[:2] == "SL" { // 分红订单
  188 + orderNums = append(orderNums, orderNullNum)
  189 + }
125 } 190 }
126 } 191 }
127 192
@@ -307,6 +307,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte @@ -307,6 +307,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
307 if dividendsType, ok := queryOptions["dividendsType"]; ok && dividendsType.(int32) != 0 { 307 if dividendsType, ok := queryOptions["dividendsType"]; ok && dividendsType.(int32) != 0 {
308 query.Where("dividends_type = ?", dividendsType) 308 query.Where("dividends_type = ?", dividendsType)
309 } 309 }
  310 + if dividendsTypes, ok := queryOptions["dividendsTypes"]; ok && len(dividendsTypes.([]int32)) > 0 {
  311 + query.Where("dividends_type in (?)", pg.In(dividendsTypes.([]int32)))
  312 + }
310 if dividendsEstimateOrderNumber, ok := queryOptions["dividendsEstimateOrderNumber"]; ok && dividendsEstimateOrderNumber != "" { 313 if dividendsEstimateOrderNumber, ok := queryOptions["dividendsEstimateOrderNumber"]; ok && dividendsEstimateOrderNumber != "" {
311 query.Where("dividends_estimate_order_number ilike ?", fmt.Sprintf("%%%s%%", dividendsEstimateOrderNumber)) 314 query.Where("dividends_estimate_order_number ilike ?", fmt.Sprintf("%%%s%%", dividendsEstimateOrderNumber))
312 } 315 }
@@ -325,6 +328,12 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte @@ -325,6 +328,12 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
325 if dividendsParticipateType, ok := queryOptions["dividendsParticipateType"]; ok && dividendsParticipateType.(int32) != 0 { 328 if dividendsParticipateType, ok := queryOptions["dividendsParticipateType"]; ok && dividendsParticipateType.(int32) != 0 {
326 query.Where("dividends_participate_type = ?", dividendsParticipateType) 329 query.Where("dividends_participate_type = ?", dividendsParticipateType)
327 } 330 }
  331 + if dividendsParticipateTypes, ok := queryOptions["dividendsParticipateTypes"]; ok && len(dividendsParticipateTypes.([]int32)) > 0 {
  332 + query.Where("dividends_participate_type in (?)", pg.In(dividendsParticipateTypes.([]int32)))
  333 + }
  334 + if dividendsStage, ok := queryOptions["dividendsStage"]; ok && dividendsStage.(int32) > 0 {
  335 + query.Where("dividends_stage = ?", dividendsStage)
  336 + }
328 if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" { 337 if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
329 query.Where("cooperation_contract_number = ?", cooperationContractNumber) 338 query.Where("cooperation_contract_number = ?", cooperationContractNumber)
330 } 339 }