作者 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
// 校验是否能够取消
if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红/退货冲销
// 自定义查询
queryOptions := make(map[string]interface{})
//参与分红类型,1承接人,2推荐人,3关联业务员
if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
queryOptions = map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
"dividendsParticipateTypes": []int32{2, 3},
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsTypes": []int32{1, 2},
}
} else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单
queryOptions = map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
"dividendsParticipateTypes": []int32{1, 3},
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsTypes": []int32{1, 2},
}
} else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单
queryOptions = map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
"dividendsParticipateTypes": []int32{1, 2},
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsTypes": []int32{1, 2},
}
}
if countRelativeDividendsEstimates, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil {
//// 自定义查询
//queryOptions := make(map[string]interface{})
//
////参与分红类型,1承接人,2推荐人,3关联业务员
//if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
// queryOptions = map[string]interface{}{
// "companyId": dividendsEstimate.Company.CompanyId,
// "orgId": dividendsEstimate.Org.OrgId,
// "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
// "dividendsParticipateTypes": []int32{2, 3},
// "offsetLimit": false,
// "dividendsStage": dividendsEstimate.DividendsStage,
// "dividendsTypes": []int32{1, 2},
// }
//} else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单
// queryOptions = map[string]interface{}{
// "companyId": dividendsEstimate.Company.CompanyId,
// "orgId": dividendsEstimate.Org.OrgId,
// "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
// "dividendsParticipateTypes": []int32{1, 3},
// "offsetLimit": false,
// "dividendsStage": dividendsEstimate.DividendsStage,
// "dividendsTypes": []int32{1, 2},
// }
//} else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单
// queryOptions = map[string]interface{}{
// "companyId": dividendsEstimate.Company.CompanyId,
// "orgId": dividendsEstimate.Org.OrgId,
// "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
// "dividendsParticipateTypes": []int32{1, 2},
// "offsetLimit": false,
// "dividendsStage": dividendsEstimate.DividendsStage,
// "dividendsTypes": []int32{1, 2},
// }
//}
if countRelativeDividendsEstimates, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
"dividendsParticipateTypes": []int32{1, 2, 3},
"cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsTypes": []int32{1, 2},
"orderGoodId": dividendsEstimate.OrderGoodId,
}); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
} else {
if countRelativeDividendsEstimates > 0 {
... ... @@ -404,43 +415,53 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
}
}
} else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红
// 自定义查询
queryOptions := make(map[string]interface{})
//参与分红类型,1承接人,2推荐人,3关联业务员
if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
queryOptions = map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
"dividendsParticipateTypes": []int32{2, 3},
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsType": int32(3),
}
} else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单
queryOptions = map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
"dividendsParticipateTypes": []int32{1, 3},
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsType": int32(3),
}
} else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单
queryOptions = map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
"dividendsParticipateTypes": []int32{1, 2},
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsType": int32(3),
}
}
if countRelativeDividendsEstimates, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(queryOptions); err3 != nil {
//// 自定义查询
//queryOptions := make(map[string]interface{})
//
////参与分红类型,1承接人,2推荐人,3关联业务员
//if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
// queryOptions = map[string]interface{}{
// "companyId": dividendsEstimate.Company.CompanyId,
// "orgId": dividendsEstimate.Org.OrgId,
// "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
// "dividendsParticipateTypes": []int32{2, 3},
// "offsetLimit": false,
// "dividendsStage": dividendsEstimate.DividendsStage,
// "dividendsType": int32(3),
// }
//} else if dividendsEstimate.DividendsParticipateType == 2 { // 当前取消的是推荐人的分红预算单
// queryOptions = map[string]interface{}{
// "companyId": dividendsEstimate.Company.CompanyId,
// "orgId": dividendsEstimate.Org.OrgId,
// "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
// "dividendsParticipateTypes": []int32{1, 3},
// "offsetLimit": false,
// "dividendsStage": dividendsEstimate.DividendsStage,
// "dividendsType": int32(3),
// }
//} else if dividendsEstimate.DividendsParticipateType == 3 { // 当前取消的是关联业务员的分红预算单
// queryOptions = map[string]interface{}{
// "companyId": dividendsEstimate.Company.CompanyId,
// "orgId": dividendsEstimate.Org.OrgId,
// "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
// "dividendsParticipateTypes": []int32{1, 2},
// "offsetLimit": false,
// "dividendsStage": dividendsEstimate.DividendsStage,
// "dividendsType": int32(3),
// }
//}
if countRelativeDividendsEstimates, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
"cooperationContractUndertakerId": dividendsEstimate.CooperationContractUndertakerId,
"dividendsParticipateTypes": []int32{1, 2, 3},
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsType": int32(3),
}); err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
} else {
if countRelativeDividendsEstimates > 0 {
... ... @@ -1393,7 +1414,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
}
// 获取订单产品
searchDividendsIncentivesEstimateQuery.OrderGoodDividendsStatus = int32(1) // 查询分红的产品
searchDividendsIncentivesEstimateQuery.OrderGoodDividendsStatus = int32(1) // 查询分红的产品
if count, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(searchDividendsIncentivesEstimateQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -76,6 +76,18 @@ func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface
if undertakerUid, ok := queryOptions["undertakerUid"]; ok && undertakerUid.(int64) != 0 {
query = query.Where(`dividends_estimate.dividends_user @> '{"userId":"?"}'`, undertakerUid)
}
if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
query = query.Where("cooperation_contract_number = ?", cooperationContractNumber.(string))
}
if cooperationContractUndertakerId, ok := queryOptions["cooperationContractUndertakerId"]; ok && cooperationContractUndertakerId.(int64) != 0 {
query = query.Where("cooperation_contract_undertaker_id = ?", cooperationContractUndertakerId)
}
if dividendsParticipateType, ok := queryOptions["dividendsParticipateType"]; ok && dividendsParticipateType.(int32) != 0 {
query = query.Where("dividends_participate_type = ?", dividendsParticipateType)
}
if dividendsStage, ok := queryOptions["dividendsStage"]; ok && dividendsStage.(int32) != 0 {
query = query.Where("dividends_stage = ?", dividendsStage)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
... ...
... ... @@ -66,6 +66,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
if count > 0 {
var dividendsEstimatesCanceled []*domain.DividendsEstimate
var orderOrReturnOrderNums []string
var orderGoodIds []int64
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
// 自定义查询
... ... @@ -132,6 +133,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
dividendsEstimatesRelative[i].Operator = operator
// 获取相关订单/退货单号
orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId)
}
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
if err3 != nil {
... ... @@ -229,7 +231,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
// 分红退货单
var returnedOrderNums []string
if len(orderOrReturnOrderNums) > 0 {
if len(orderOrReturnOrderNums) > 0 { // 业绩分红
// 订单/退货单号数组去重
orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums)
... ... @@ -253,23 +255,41 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
}); err4 != nil {
return nil, err4
} else {
// orderGoodIds去重
newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)
if countDividendsOrder > 0 {
for i, _ := range orders {
orders[i].DividendStatus = 1
for i, order := range orders {
goods := make([]*domain.OrderGood, 0)
for _, good := range order.Goods {
if good.OrderGoodDividendsStatus == 2 {
goods = append(goods, good)
}
}
if len(goods) == len(newOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,订单分红状态变更为未分红
orders[i].DividendStatus = 1
} else if len(goods) > len(newOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,订单分红状态变更为部分分红
orders[i].DividendStatus = 3
}
orders[i].DividendStatus = order.DividendStatus
}
// 保存订单状态
if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil {
return nil, err6
}
// 获取订单编号
ordersNumbers := make([]string, 0)
for _, order := range orders {
ordersNumbers = append(ordersNumbers, order.DividendsOrderNumber)
}
// 获取分红订单产品并更新产品状态
if len(ordersNumbers) > 0 {
if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
"orderNumbers": ordersNumbers,
//"orderNumbers": ordersNumbers,
"orderGoodIds": orderGoodIds,
"companyId": dividendsEstimates[0].Company.CompanyId,
"orgId": dividendsEstimates[0].Org.OrgId,
}); err != nil {
... ... @@ -299,24 +319,33 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
return nil, err5
} else {
if countDividendsReturnedOrder > 0 {
for i, _ := range returnedOrders {
returnedOrders[i].DividendStatus = 1
for i, returnedOrder := range returnedOrders {
if len(returnedOrder.Goods) == len(orderGoodIds) { // 1.全部产品取消分红预算
returnedOrders[i].DividendStatus = 1
} else if len(returnedOrder.Goods) > len(orderGoodIds) { // 3.部分产品被取消分红预算
returnedOrders[i].DividendStatus = 3
}
returnedOrders[i].DividendStatus = returnedOrder.DividendStatus
}
// 保存退货单状态
if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil {
return nil, err7
}
// 获取订单编号
returnedOrdersNumbers := make([]string, 0)
for _, returnedOrder := range returnedOrders {
returnedOrdersNumbers = append(returnedOrdersNumbers, returnedOrder.DividendsReturnedOrderNumber)
}
// 获取退货单产品并更新产品状态
if len(returnedOrdersNumbers) > 0 {
if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
"returnedOrderNumbers": returnedOrdersNumbers,
"companyId": dividendsEstimates[0].Company.CompanyId,
"orgId": dividendsEstimates[0].Org.OrgId,
//"returnedOrderNumbers": returnedOrdersNumbers,
"orderGoodIds": orderGoodIds,
"companyId": dividendsEstimates[0].Company.CompanyId,
"orgId": dividendsEstimates[0].Org.OrgId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -53,9 +53,13 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
if utils.IsContain64(undertakerUIDs, undertaker.UndertakerId) {
// 判断承接人在当前阶段是否已经分红
undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
"undertakerUid": undertaker.UserId,
"companyId": contract.Company.CompanyId,
"orgId": contract.Org.OrgId,
"cooperationContractUndertakerId": undertaker.UndertakerId,
"dividendsParticipateType": int32(1), // 承接人类型
"cooperationContractNumber": contract.CooperationContractNumber,
"dividendsStage": moneyIncentivesRuleMatched.MoneyIncentivesStage,
"undertakerUid": undertaker.UserId,
"companyId": contract.Company.CompanyId,
"orgId": contract.Org.OrgId,
})
if err != nil {
return nil, err
... ... @@ -89,9 +93,13 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
// 判断业务员在当前阶段是否已经分红
if undertaker.Salesman != nil {
salesmanEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
"undertakerUid": undertaker.Salesman.UserId,
"companyId": contract.Company.CompanyId,
"orgId": contract.Org.OrgId,
"cooperationContractUndertakerId": undertaker.UndertakerId,
"dividendsParticipateType": int32(3), // 承接人类型
"cooperationContractNumber": contract.CooperationContractNumber,
"dividendsStage": moneyIncentivesRuleMatched.MoneyIncentivesStage,
"undertakerUid": undertaker.Salesman.UserId,
"companyId": contract.Company.CompanyId,
"orgId": contract.Org.OrgId,
})
if err != nil {
return nil, err
... ... @@ -126,9 +134,13 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
// 判断推荐人在当前阶段是否已经分红
if undertaker.Referrer != nil {
referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
"undertakerUid": undertaker.Referrer.UserId,
"companyId": contract.Company.CompanyId,
"orgId": contract.Org.OrgId,
"cooperationContractUndertakerId": undertaker.UndertakerId,
"dividendsParticipateType": int32(2), // 承接人类型
"cooperationContractNumber": contract.CooperationContractNumber,
"dividendsStage": moneyIncentivesRuleMatched.MoneyIncentivesStage,
"undertakerUid": undertaker.Referrer.UserId,
"companyId": contract.Company.CompanyId,
"orgId": contract.Org.OrgId,
})
if err != nil {
return nil, err
... ...
... ... @@ -317,6 +317,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
if dividendsTypes, ok := queryOptions["dividendsTypes"]; ok && len(dividendsTypes.([]int32)) > 0 {
query.Where("dividends_type in (?)", pg.In(dividendsTypes.([]int32)))
}
if orderGoodId, ok := queryOptions["orderGoodId"]; ok && orderGoodId.(int64) != 0 {
query.Where("order_good_id = ?", orderGoodId)
}
if dividendsEstimateOrderNumber, ok := queryOptions["dividendsEstimateOrderNumber"]; ok && dividendsEstimateOrderNumber != "" {
query.Where("dividends_estimate_order_number ilike ?", fmt.Sprintf("%%%s%%", dividendsEstimateOrderNumber))
}
... ...
... ... @@ -126,6 +126,21 @@ func RemoveDuplication(arr []string) []string {
return arr[:j]
}
func RemoveDuplicationInt64(arr []int64) []int64 {
set := make(map[int64]struct{}, len(arr))
j := 0
for _, v := range arr {
_, ok := set[v]
if ok {
continue
}
set[v] = struct{}{}
arr[j] = v
j++
}
return arr[:j]
}
// IsContain 判断int32数组是否包含
func IsContain(items []int32, item int32) bool {
for _, eachItem := range items {
... ...