作者 yangfu

Merge branch 'test' of http://gitlab.fjmaimaimai.com/allied-creation/allied-crea…

…tion-cooperation into test
@@ -356,43 +356,54 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs @@ -356,43 +356,54 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
356 356
357 // 校验是否能够取消 357 // 校验是否能够取消
358 if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红/退货冲销 358 if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红/退货冲销
359 - // 自定义查询  
360 - queryOptions := make(map[string]interface{})  
361 359
362 - //参与分红类型,1承接人,2推荐人,3关联业务员  
363 - if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单  
364 - queryOptions = map[string]interface{}{ 360 + //// 自定义查询
  361 + //queryOptions := make(map[string]interface{})
  362 + //
  363 + ////参与分红类型,1承接人,2推荐人,3关联业务员
  364 + //if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
  365 + // queryOptions = map[string]interface{}{
  366 + // "companyId": dividendsEstimate.Company.CompanyId,
  367 + // "orgId": dividendsEstimate.Org.OrgId,
  368 + // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  369 + // "dividendsParticipateTypes": []int32{2, 3},
  370 + // "offsetLimit": false,
  371 + // "dividendsStage": dividendsEstimate.DividendsStage,
  372 + // "dividendsTypes": []int32{1, 2},
  373 + // }
  374 + //} else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单
  375 + // queryOptions = map[string]interface{}{
  376 + // "companyId": dividendsEstimate.Company.CompanyId,
  377 + // "orgId": dividendsEstimate.Org.OrgId,
  378 + // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  379 + // "dividendsParticipateTypes": []int32{1, 3},
  380 + // "offsetLimit": false,
  381 + // "dividendsStage": dividendsEstimate.DividendsStage,
  382 + // "dividendsTypes": []int32{1, 2},
  383 + // }
  384 + //} else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单
  385 + // queryOptions = map[string]interface{}{
  386 + // "companyId": dividendsEstimate.Company.CompanyId,
  387 + // "orgId": dividendsEstimate.Org.OrgId,
  388 + // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  389 + // "dividendsParticipateTypes": []int32{1, 2},
  390 + // "offsetLimit": false,
  391 + // "dividendsStage": dividendsEstimate.DividendsStage,
  392 + // "dividendsTypes": []int32{1, 2},
  393 + // }
  394 + //}
  395 +
  396 + if countRelativeDividendsEstimates, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
365 "companyId": dividendsEstimate.Company.CompanyId, 397 "companyId": dividendsEstimate.Company.CompanyId,
366 "orgId": dividendsEstimate.Org.OrgId, 398 "orgId": dividendsEstimate.Org.OrgId,
367 "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum, 399 "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
368 - "dividendsParticipateTypes": []int32{2, 3},  
369 - "offsetLimit": false,  
370 - "dividendsStage": dividendsEstimate.DividendsStage,  
371 - "dividendsTypes": []int32{1, 2},  
372 - }  
373 - } else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单  
374 - queryOptions = map[string]interface{}{  
375 - "companyId": dividendsEstimate.Company.CompanyId,  
376 - "orgId": dividendsEstimate.Org.OrgId,  
377 - "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
378 - "dividendsParticipateTypes": []int32{1, 3},  
379 - "offsetLimit": false,  
380 - "dividendsStage": dividendsEstimate.DividendsStage,  
381 - "dividendsTypes": []int32{1, 2},  
382 - }  
383 - } else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单  
384 - queryOptions = map[string]interface{}{  
385 - "companyId": dividendsEstimate.Company.CompanyId,  
386 - "orgId": dividendsEstimate.Org.OrgId,  
387 - "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
388 - "dividendsParticipateTypes": []int32{1, 2}, 400 + "dividendsParticipateTypes": []int32{1, 2, 3},
  401 + "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
389 "offsetLimit": false, 402 "offsetLimit": false,
390 "dividendsStage": dividendsEstimate.DividendsStage, 403 "dividendsStage": dividendsEstimate.DividendsStage,
391 "dividendsTypes": []int32{1, 2}, 404 "dividendsTypes": []int32{1, 2},
392 - }  
393 - }  
394 -  
395 - if countRelativeDividendsEstimates, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil { 405 + "orderGoodId": dividendsEstimate.OrderGoodId,
  406 + }); err2 != nil {
396 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) 407 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
397 } else { 408 } else {
398 if countRelativeDividendsEstimates > 0 { 409 if countRelativeDividendsEstimates > 0 {
@@ -404,43 +415,53 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs @@ -404,43 +415,53 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
404 } 415 }
405 } 416 }
406 } else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红 417 } else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红
407 - // 自定义查询  
408 - queryOptions := make(map[string]interface{})  
409 418
410 - //参与分红类型,1承接人,2推荐人,3关联业务员  
411 - if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单  
412 - queryOptions = map[string]interface{}{ 419 + //// 自定义查询
  420 + //queryOptions := make(map[string]interface{})
  421 + //
  422 + ////参与分红类型,1承接人,2推荐人,3关联业务员
  423 + //if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
  424 + // queryOptions = map[string]interface{}{
  425 + // "companyId": dividendsEstimate.Company.CompanyId,
  426 + // "orgId": dividendsEstimate.Org.OrgId,
  427 + // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  428 + // "dividendsParticipateTypes": []int32{2, 3},
  429 + // "offsetLimit": false,
  430 + // "dividendsStage": dividendsEstimate.DividendsStage,
  431 + // "dividendsType": int32(3),
  432 + // }
  433 + //} else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单
  434 + // queryOptions = map[string]interface{}{
  435 + // "companyId": dividendsEstimate.Company.CompanyId,
  436 + // "orgId": dividendsEstimate.Org.OrgId,
  437 + // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  438 + // "dividendsParticipateTypes": []int32{1, 3},
  439 + // "offsetLimit": false,
  440 + // "dividendsStage": dividendsEstimate.DividendsStage,
  441 + // "dividendsType": int32(3),
  442 + // }
  443 + //} else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单
  444 + // queryOptions = map[string]interface{}{
  445 + // "companyId": dividendsEstimate.Company.CompanyId,
  446 + // "orgId": dividendsEstimate.Org.OrgId,
  447 + // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  448 + // "dividendsParticipateTypes": []int32{1, 2},
  449 + // "offsetLimit": false,
  450 + // "dividendsStage": dividendsEstimate.DividendsStage,
  451 + // "dividendsType": int32(3),
  452 + // }
  453 + //}
  454 +
  455 + if countRelativeDividendsEstimates, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(map[string]interface{}{
413 "companyId": dividendsEstimate.Company.CompanyId, 456 "companyId": dividendsEstimate.Company.CompanyId,
414 "orgId": dividendsEstimate.Org.OrgId, 457 "orgId": dividendsEstimate.Org.OrgId,
415 "cooperationContractNumber": dividendsEstimate.CooperationContractNumber, 458 "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
416 - "dividendsParticipateTypes": []int32{2, 3}, 459 + "cooperationContractUndertakerId": dividendsEstimate.CooperationContractUndertakerId,
  460 + "dividendsParticipateTypes": []int32{1, 2, 3},
417 "offsetLimit": false, 461 "offsetLimit": false,
418 "dividendsStage": dividendsEstimate.DividendsStage, 462 "dividendsStage": dividendsEstimate.DividendsStage,
419 "dividendsType": int32(3), 463 "dividendsType": int32(3),
420 - }  
421 - } else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单  
422 - queryOptions = map[string]interface{}{  
423 - "companyId": dividendsEstimate.Company.CompanyId,  
424 - "orgId": dividendsEstimate.Org.OrgId,  
425 - "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
426 - "dividendsParticipateTypes": []int32{1, 3},  
427 - "offsetLimit": false,  
428 - "dividendsStage": dividendsEstimate.DividendsStage,  
429 - "dividendsType": int32(3),  
430 - }  
431 - } else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单  
432 - queryOptions = map[string]interface{}{  
433 - "companyId": dividendsEstimate.Company.CompanyId,  
434 - "orgId": dividendsEstimate.Org.OrgId,  
435 - "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
436 - "dividendsParticipateTypes": []int32{1, 2},  
437 - "offsetLimit": false,  
438 - "dividendsStage": dividendsEstimate.DividendsStage,  
439 - "dividendsType": int32(3),  
440 - }  
441 - }  
442 -  
443 - if countRelativeDividendsEstimates, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(queryOptions); err3 != nil { 464 + }); err3 != nil {
444 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error()) 465 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
445 } else { 466 } else {
446 if countRelativeDividendsEstimates > 0 { 467 if countRelativeDividendsEstimates > 0 {
@@ -1393,7 +1414,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti @@ -1393,7 +1414,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
1393 } 1414 }
1394 1415
1395 // 获取订单产品 1416 // 获取订单产品
1396 - searchDividendsIncentivesEstimateQuery.OrderGoodDividendsStatus = int32(1) // 查询分红的产品 1417 + searchDividendsIncentivesEstimateQuery.OrderGoodDividendsStatus = int32(1) // 查询分红的产品
1397 if count, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(searchDividendsIncentivesEstimateQuery)); err != nil { 1418 if count, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(searchDividendsIncentivesEstimateQuery)); err != nil {
1398 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1419 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1399 } else { 1420 } else {
@@ -76,6 +76,18 @@ func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface @@ -76,6 +76,18 @@ func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface
76 if undertakerUid, ok := queryOptions["undertakerUid"]; ok && undertakerUid.(int64) != 0 { 76 if undertakerUid, ok := queryOptions["undertakerUid"]; ok && undertakerUid.(int64) != 0 {
77 query = query.Where(`dividends_estimate.dividends_user @> '{"userId":"?"}'`, undertakerUid) 77 query = query.Where(`dividends_estimate.dividends_user @> '{"userId":"?"}'`, undertakerUid)
78 } 78 }
  79 + if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
  80 + query = query.Where("cooperation_contract_number = ?", cooperationContractNumber.(string))
  81 + }
  82 + if cooperationContractUndertakerId, ok := queryOptions["cooperationContractUndertakerId"]; ok && cooperationContractUndertakerId.(int64) != 0 {
  83 + query = query.Where("cooperation_contract_undertaker_id = ?", cooperationContractUndertakerId)
  84 + }
  85 + if dividendsParticipateType, ok := queryOptions["dividendsParticipateType"]; ok && dividendsParticipateType.(int32) != 0 {
  86 + query = query.Where("dividends_participate_type = ?", dividendsParticipateType)
  87 + }
  88 + if dividendsStage, ok := queryOptions["dividendsStage"]; ok && dividendsStage.(int32) != 0 {
  89 + query = query.Where("dividends_stage = ?", dividendsStage)
  90 + }
79 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { 91 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
80 query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId) 92 query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
81 } 93 }
@@ -66,6 +66,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -66,6 +66,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
66 if count > 0 { 66 if count > 0 {
67 var dividendsEstimatesCanceled []*domain.DividendsEstimate 67 var dividendsEstimatesCanceled []*domain.DividendsEstimate
68 var orderOrReturnOrderNums []string 68 var orderOrReturnOrderNums []string
  69 + var orderGoodIds []int64
69 for _, dividendsEstimate := range dividendsEstimates { 70 for _, dividendsEstimate := range dividendsEstimates {
70 if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销 71 if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
71 // 自定义查询 72 // 自定义查询
@@ -132,6 +133,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -132,6 +133,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
132 dividendsEstimatesRelative[i].Operator = operator 133 dividendsEstimatesRelative[i].Operator = operator
133 // 获取相关订单/退货单号 134 // 获取相关订单/退货单号
134 orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum) 135 orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
  136 + orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId)
135 } 137 }
136 dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative) 138 dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
137 if err3 != nil { 139 if err3 != nil {
@@ -229,7 +231,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -229,7 +231,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
229 // 分红退货单 231 // 分红退货单
230 var returnedOrderNums []string 232 var returnedOrderNums []string
231 233
232 - if len(orderOrReturnOrderNums) > 0 { 234 + if len(orderOrReturnOrderNums) > 0 { // 业绩分红
233 // 订单/退货单号数组去重 235 // 订单/退货单号数组去重
234 orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums) 236 orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums)
235 237
@@ -253,23 +255,41 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -253,23 +255,41 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
253 }); err4 != nil { 255 }); err4 != nil {
254 return nil, err4 256 return nil, err4
255 } else { 257 } else {
  258 + // orderGoodIds去重
  259 + newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)
  260 +
256 if countDividendsOrder > 0 { 261 if countDividendsOrder > 0 {
257 - for i, _ := range orders { 262 + for i, order := range orders {
  263 + goods := make([]*domain.OrderGood, 0)
  264 + for _, good := range order.Goods {
  265 + if good.OrderGoodDividendsStatus == 2 {
  266 + goods = append(goods, good)
  267 + }
  268 + }
  269 + if len(goods) == len(newOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,订单分红状态变更为未分红
258 orders[i].DividendStatus = 1 270 orders[i].DividendStatus = 1
  271 + } else if len(goods) > len(newOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,订单分红状态变更为部分分红
  272 + orders[i].DividendStatus = 3
259 } 273 }
  274 + orders[i].DividendStatus = order.DividendStatus
  275 + }
  276 +
260 // 保存订单状态 277 // 保存订单状态
261 if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil { 278 if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil {
262 return nil, err6 279 return nil, err6
263 } 280 }
  281 +
264 // 获取订单编号 282 // 获取订单编号
265 ordersNumbers := make([]string, 0) 283 ordersNumbers := make([]string, 0)
266 for _, order := range orders { 284 for _, order := range orders {
267 ordersNumbers = append(ordersNumbers, order.DividendsOrderNumber) 285 ordersNumbers = append(ordersNumbers, order.DividendsOrderNumber)
268 } 286 }
  287 +
269 // 获取分红订单产品并更新产品状态 288 // 获取分红订单产品并更新产品状态
270 if len(ordersNumbers) > 0 { 289 if len(ordersNumbers) > 0 {
271 if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{ 290 if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
272 - "orderNumbers": ordersNumbers, 291 + //"orderNumbers": ordersNumbers,
  292 + "orderGoodIds": orderGoodIds,
273 "companyId": dividendsEstimates[0].Company.CompanyId, 293 "companyId": dividendsEstimates[0].Company.CompanyId,
274 "orgId": dividendsEstimates[0].Org.OrgId, 294 "orgId": dividendsEstimates[0].Org.OrgId,
275 }); err != nil { 295 }); err != nil {
@@ -299,22 +319,31 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -299,22 +319,31 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
299 return nil, err5 319 return nil, err5
300 } else { 320 } else {
301 if countDividendsReturnedOrder > 0 { 321 if countDividendsReturnedOrder > 0 {
302 - for i, _ := range returnedOrders { 322 + for i, returnedOrder := range returnedOrders {
  323 + if len(returnedOrder.Goods) == len(orderGoodIds) { // 1.全部产品取消分红预算
303 returnedOrders[i].DividendStatus = 1 324 returnedOrders[i].DividendStatus = 1
  325 + } else if len(returnedOrder.Goods) > len(orderGoodIds) { // 3.部分产品被取消分红预算
  326 + returnedOrders[i].DividendStatus = 3
  327 + }
  328 + returnedOrders[i].DividendStatus = returnedOrder.DividendStatus
304 } 329 }
  330 +
305 // 保存退货单状态 331 // 保存退货单状态
306 if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil { 332 if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil {
307 return nil, err7 333 return nil, err7
308 } 334 }
  335 +
309 // 获取订单编号 336 // 获取订单编号
310 returnedOrdersNumbers := make([]string, 0) 337 returnedOrdersNumbers := make([]string, 0)
311 for _, returnedOrder := range returnedOrders { 338 for _, returnedOrder := range returnedOrders {
312 returnedOrdersNumbers = append(returnedOrdersNumbers, returnedOrder.DividendsReturnedOrderNumber) 339 returnedOrdersNumbers = append(returnedOrdersNumbers, returnedOrder.DividendsReturnedOrderNumber)
313 } 340 }
  341 +
314 // 获取退货单产品并更新产品状态 342 // 获取退货单产品并更新产品状态
315 if len(returnedOrdersNumbers) > 0 { 343 if len(returnedOrdersNumbers) > 0 {
316 if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{ 344 if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
317 - "returnedOrderNumbers": returnedOrdersNumbers, 345 + //"returnedOrderNumbers": returnedOrdersNumbers,
  346 + "orderGoodIds": orderGoodIds,
318 "companyId": dividendsEstimates[0].Company.CompanyId, 347 "companyId": dividendsEstimates[0].Company.CompanyId,
319 "orgId": dividendsEstimates[0].Org.OrgId, 348 "orgId": dividendsEstimates[0].Org.OrgId,
320 }); err != nil { 349 }); err != nil {
@@ -53,6 +53,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -53,6 +53,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
53 if utils.IsContain64(undertakerUIDs, undertaker.UndertakerId) { 53 if utils.IsContain64(undertakerUIDs, undertaker.UndertakerId) {
54 // 判断承接人在当前阶段是否已经分红 54 // 判断承接人在当前阶段是否已经分红
55 undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{ 55 undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
  56 + "cooperationContractUndertakerId": undertaker.UndertakerId,
  57 + "dividendsParticipateType": int32(1), // 承接人类型
  58 + "cooperationContractNumber": contract.CooperationContractNumber,
  59 + "dividendsStage": moneyIncentivesRuleMatched.MoneyIncentivesStage,
56 "undertakerUid": undertaker.UserId, 60 "undertakerUid": undertaker.UserId,
57 "companyId": contract.Company.CompanyId, 61 "companyId": contract.Company.CompanyId,
58 "orgId": contract.Org.OrgId, 62 "orgId": contract.Org.OrgId,
@@ -89,6 +93,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -89,6 +93,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
89 // 判断业务员在当前阶段是否已经分红 93 // 判断业务员在当前阶段是否已经分红
90 if undertaker.Salesman != nil { 94 if undertaker.Salesman != nil {
91 salesmanEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{ 95 salesmanEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
  96 + "cooperationContractUndertakerId": undertaker.UndertakerId,
  97 + "dividendsParticipateType": int32(3), // 承接人类型
  98 + "cooperationContractNumber": contract.CooperationContractNumber,
  99 + "dividendsStage": moneyIncentivesRuleMatched.MoneyIncentivesStage,
92 "undertakerUid": undertaker.Salesman.UserId, 100 "undertakerUid": undertaker.Salesman.UserId,
93 "companyId": contract.Company.CompanyId, 101 "companyId": contract.Company.CompanyId,
94 "orgId": contract.Org.OrgId, 102 "orgId": contract.Org.OrgId,
@@ -126,6 +134,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -126,6 +134,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
126 // 判断推荐人在当前阶段是否已经分红 134 // 判断推荐人在当前阶段是否已经分红
127 if undertaker.Referrer != nil { 135 if undertaker.Referrer != nil {
128 referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{ 136 referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
  137 + "cooperationContractUndertakerId": undertaker.UndertakerId,
  138 + "dividendsParticipateType": int32(2), // 承接人类型
  139 + "cooperationContractNumber": contract.CooperationContractNumber,
  140 + "dividendsStage": moneyIncentivesRuleMatched.MoneyIncentivesStage,
129 "undertakerUid": undertaker.Referrer.UserId, 141 "undertakerUid": undertaker.Referrer.UserId,
130 "companyId": contract.Company.CompanyId, 142 "companyId": contract.Company.CompanyId,
131 "orgId": contract.Org.OrgId, 143 "orgId": contract.Org.OrgId,
@@ -317,6 +317,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte @@ -317,6 +317,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
317 if dividendsTypes, ok := queryOptions["dividendsTypes"]; ok && len(dividendsTypes.([]int32)) > 0 { 317 if dividendsTypes, ok := queryOptions["dividendsTypes"]; ok && len(dividendsTypes.([]int32)) > 0 {
318 query.Where("dividends_type in (?)", pg.In(dividendsTypes.([]int32))) 318 query.Where("dividends_type in (?)", pg.In(dividendsTypes.([]int32)))
319 } 319 }
  320 + if orderGoodId, ok := queryOptions["orderGoodId"]; ok && orderGoodId.(int64) != 0 {
  321 + query.Where("order_good_id = ?", orderGoodId)
  322 + }
320 if dividendsEstimateOrderNumber, ok := queryOptions["dividendsEstimateOrderNumber"]; ok && dividendsEstimateOrderNumber != "" { 323 if dividendsEstimateOrderNumber, ok := queryOptions["dividendsEstimateOrderNumber"]; ok && dividendsEstimateOrderNumber != "" {
321 query.Where("dividends_estimate_order_number ilike ?", fmt.Sprintf("%%%s%%", dividendsEstimateOrderNumber)) 324 query.Where("dividends_estimate_order_number ilike ?", fmt.Sprintf("%%%s%%", dividendsEstimateOrderNumber))
322 } 325 }
@@ -126,6 +126,21 @@ func RemoveDuplication(arr []string) []string { @@ -126,6 +126,21 @@ func RemoveDuplication(arr []string) []string {
126 return arr[:j] 126 return arr[:j]
127 } 127 }
128 128
  129 +func RemoveDuplicationInt64(arr []int64) []int64 {
  130 + set := make(map[int64]struct{}, len(arr))
  131 + j := 0
  132 + for _, v := range arr {
  133 + _, ok := set[v]
  134 + if ok {
  135 + continue
  136 + }
  137 + set[v] = struct{}{}
  138 + arr[j] = v
  139 + j++
  140 + }
  141 + return arr[:j]
  142 +}
  143 +
129 // IsContain 判断int32数组是否包含 144 // IsContain 判断int32数组是否包含
130 func IsContain(items []int32, item int32) bool { 145 func IsContain(items []int32, item int32) bool {
131 for _, eachItem := range items { 146 for _, eachItem := range items {