Pārlūkot izejas kodu

feat:潜在客户 竞争对手调整

wangshan 3 gadi atpakaļ
vecāks
revīzija
6bdacece34

+ 2 - 1
src/jfw/modules/bigmember/src/config.json

@@ -148,5 +148,6 @@
     "vip": ["/article","demand/detail"],
     "bigMember": ["/subscribe"],
     "entNiche": []
-  }
+  },
+	"potentialSwitch":true
 }

+ 1 - 0
src/jfw/modules/bigmember/src/config/config.go

@@ -53,6 +53,7 @@ type config struct {
 		BigMember []string `json:"bigMember"`
 		EntNiche  []string `json:"entNiche"`
 	}
+	PotentialSwitch bool `json:"potentialSwitch"` //潜在客户 潜在竞争对手 新逻辑开关
 }
 
 type customerInfo struct {

+ 3 - 3
src/jfw/modules/bigmember/src/entity/analysisEntName.go

@@ -75,7 +75,7 @@ type EnterQYXYInfo struct {
 }
 
 //企业库是否有此企业信息
-func GetEntInfo(entName []string, p string) (entName_r map[string]*EnterQYXYInfo) {
+func GetEntInfo(entName []string, p string) (entName_r []*EnterQYXYInfo) {
 	if len(entName) > 0 {
 		query := map[string]interface{}{}
 		if p == "C" {
@@ -92,12 +92,12 @@ func GetEntInfo(entName []string, p string) (entName_r map[string]*EnterQYXYInfo
 		it := sess.DB(db.Mgo_Ent.DbName).C("qyxy_std").Find(query).Select(map[string]interface{}{"company_name": 1, "_id": 1, "company_area": 1, "company_city": 1}).Iter()
 		for m := make(map[string]interface{}); it.Next(&m); {
 			if m["company_name"] != nil && m["company_name"].(string) != "" {
-				entName_r[qutil.ObjToString(m["company_name"])] = &EnterQYXYInfo{
+				entName_r = append(entName_r, &EnterQYXYInfo{
 					Id:   m["_id"].(string),
 					Name: qutil.ObjToString(m["company_name"]),
 					Area: qutil.ObjToString(m["company_area"]),
 					City: qutil.ObjToString(m["company_city"]),
-				}
+				})
 			}
 		}
 	}

+ 98 - 21
src/jfw/modules/bigmember/src/service/analysis/potential.go

@@ -3,6 +3,7 @@ package analysis
 
 import (
 	. "api"
+	"config"
 	"db"
 	"encoding/json"
 	"entity"
@@ -11,6 +12,7 @@ import (
 	qutil "qfw/util"
 	"qfw/util/jy"
 	"qfw/util/redis"
+	"sort"
 	"strings"
 	"sync"
 	"time"
@@ -175,8 +177,25 @@ func (this *Analysis) CsORRsList() {
 				//客户
 				if getRes.PCOR == "C" {
 					potComQ := PCQuery(getRes.Area, getRes.Industry, getRes.BuyerClass, getRes.Business_scope, getRes.Sort_no, getRes.PCOR)
-					list := getPCostomers(main_userId, entName, potComQ, getRes.PCOR)
-					surpluscount := -1 //剩余数量
+					var list []*PTComs
+					if config.Config.PotentialSwitch {
+						list = CustomersInfo(main_userId, entName, potComQ, getRes.PCOR)
+					} else {
+						list = getPCostomers(main_userId, entName, potComQ, getRes.PCOR)
+					}
+					surpluscount := -1
+					//排序
+					if len(list) > 0 && config.Config.PotentialSwitch {
+						if getRes.Sort_no == 0 {
+							sort.Slice(list, func(i, j int) bool {
+								return list[i].PNCount > list[j].PNCount
+							})
+						} else {
+							sort.Slice(list, func(i, j int) bool {
+								return list[i].Budget > list[j].Budget
+							})
+						}
+					} //剩余数量
 					if isTrial {
 						c_limitcount = getBAmountInfo(main_userId, getRes.ServiceId)
 						if len(list) > c_limitcount {
@@ -199,7 +218,24 @@ func (this *Analysis) CsORRsList() {
 					}
 				} else if getRes.PCOR == "R" {
 					potRivQ := PCQuery(getRes.Area, getRes.Industry, getRes.BuyerClass, getRes.Business_scope, getRes.Sort_no, getRes.PCOR)
-					list := getPRivals(main_userId, potRivQ, getRes.PCOR)
+					var list []*PTComs
+					if config.Config.PotentialSwitch {
+						list = PRivals(main_userId, potRivQ, getRes.PCOR)
+					} else {
+						list = getPRivals(main_userId, potRivQ, getRes.PCOR)
+					}
+					//排序
+					if len(list) > 0 && config.Config.PotentialSwitch {
+						if getRes.Sort_no == 0 {
+							sort.Slice(list, func(i, j int) bool {
+								return list[i].PNCount > list[j].PNCount
+							})
+						} else {
+							sort.Slice(list, func(i, j int) bool {
+								return list[i].Budget > list[j].Budget
+							})
+						}
+					}
 					surpluscount := -1 //剩余数量
 					if isTrial {
 						r_limitcount = getBAmountInfo(main_userId, getRes.ServiceId)
@@ -393,7 +429,31 @@ type AggregationsBucket struct {
 	} `json:"count"`
 }
 
-//潜在客户
+//潜在竞争对手--new
+func PRivals(userId string, potRivQ, pcor string) []*PTComs {
+	var regMap = []*PTComs{}
+	//我关注的企业
+	MyFollowEnts := getMyFollowEnts(userId)
+	//非我的潜在竞争对手
+	OutLMyRivals := gerOutLMyRivals(userId)
+	aggs, _ := GetAggs(P_INDEX, P_TYPE, potRivQ)
+	if aggs != nil {
+		if aggsMap_g, ok := aggs.Children("group_field"); ok {
+			var aggsMap []*AggregationsBucket
+			bs, _ := aggsMap_g.Aggregations["buckets"].MarshalJSON()
+			if len(bs) > 0 {
+				json.Unmarshal(bs, &aggsMap)
+				if len(aggsMap) > 0 {
+					regMap = analysisData(aggsMap, MyFollowEnts, OutLMyRivals, pcor)
+					//regMap = analysisDataByWinner(aggsMap, MyFollowEnts, OutLMyRivals, pcor)
+				}
+			}
+		}
+	}
+	return regMap
+}
+
+//潜在客户--new
 func CustomersInfo(userId, entName string, potComQ, pcor string) []*PTComs {
 	var regMap = []*PTComs{}
 	//获取用户默认企业的客户信息+手动关注的企业信息+不是我的客户信息 此三项都不展示在我的客户列表
@@ -407,7 +467,7 @@ func CustomersInfo(userId, entName string, potComQ, pcor string) []*PTComs {
 			if len(bs) > 0 {
 				json.Unmarshal(bs, &aggsMap)
 				if len(aggsMap) > 0 {
-					regMap = analysisData(aggsMap, MyCustomers)
+					regMap = analysisData(aggsMap, MyCustomers, nil, pcor)
 				}
 			}
 		}
@@ -424,13 +484,12 @@ func getPCostomers(userId, entName string, potComQ, pcor string) []*PTComs {
 	aggs, _ := GetAggs(P_INDEX, P_TYPE, potComQ)
 	if aggs != nil {
 		if aggs_g, ok := aggs.Children("group_field"); ok {
-			var aggsMap []*AggregationsBucket
+			var aggsMap []map[string]interface{}
 			bs, _ := aggs_g.Aggregations["buckets"].MarshalJSON()
 			if len(bs) > 0 {
 				json.Unmarshal(bs, &aggsMap)
 				if len(aggsMap) > 0 {
-					//regMap = analysisDataByBuyer(aggsMap, MyCustomers)
-					regMap = analysisData(aggsMap, MyCustomers)
+					regMap = analysisDataByBuyer(aggsMap, MyCustomers)
 				}
 			}
 		}
@@ -529,13 +588,14 @@ type PCInfo struct {
 }
 
 //采购单位
-func analysisData(res []*AggregationsBucket, mycs map[string]interface{}) []*PTComs {
+func analysisData(res []*AggregationsBucket, mycs map[string]interface{}, omyr map[string]interface{}, pcor string) []*PTComs {
 	var (
 		ADRes_r     []*PTComs
 		entersFifty []string
+		entInfos    []*entity.EnterQYXYInfo
 		wg          = sync.WaitGroup{}
 		wc          = make(chan bool, 10)
-		entInfos    = map[string]*entity.EnterQYXYInfo{}
+		entMap      = map[string]*AggregationsBucket{}
 	)
 	for ak, av := range res {
 		//清洗无效数据
@@ -546,13 +606,18 @@ func analysisData(res []*AggregationsBucket, mycs map[string]interface{}) []*PTC
 		if mycs != nil && mycs[av.Key] != nil {
 			continue
 		}
+		//排除移除的我的潜在竞争对手
+		if omyr != nil && omyr[av.Key] != nil {
+			continue
+		}
+		entMap[av.Key] = av
 		//并发查询企业库是否包含此企业信息
 		entersFifty = append(entersFifty, av.Key)
 		if len(entersFifty)%50 == 0 || (len(res) == ak+1 && len(entersFifty) > 0) {
 			wg.Add(1)
 			wc <- true
 			go func(entersFifty []string) {
-				entInfos = entity.GetEntInfo(entersFifty, "C")
+				entInfos = append(entInfos, entity.GetEntInfo(entersFifty, pcor)...)
 				wg.Done()
 				<-wc
 			}(entersFifty)
@@ -560,16 +625,28 @@ func analysisData(res []*AggregationsBucket, mycs map[string]interface{}) []*PTC
 		}
 		wg.Wait()
 	}
-
-	for _, av := range res {
-		if av.Key != "" && entInfos[av.Key] != nil {
-			ADRes_r = append(ADRes_r, &PTComs{
-				Budget:    av.Count.Value,
-				Buyer:     av.Key,
-				PNCount:   av.Doc_count,
-				WCity:     entInfos[av.Key].City,
-				WProvince: entInfos[av.Key].Area,
-			})
+	if len(entInfos) > 0 {
+		for _, ev := range entInfos {
+			if (ev.Name != "" && entMap[ev.Name] != nil) || (len([]rune(ev.Id)) > 12 && entMap[ev.Id] != nil) {
+				var budget float64 = 0
+				pnCount := 0
+				if entMap[ev.Name] != nil {
+					budget = entMap[ev.Name].Count.Value
+					pnCount = entMap[ev.Name].Doc_count
+				}
+				if entMap[ev.Id] != nil {
+					budget = entMap[ev.Id].Count.Value
+					pnCount = entMap[ev.Id].Doc_count
+				}
+				ADRes_r = append(ADRes_r, &PTComs{
+					Budget:    budget,
+					PNCount:   pnCount,
+					Buyer:     ev.Name,
+					WCity:     ev.City,
+					WProvince: ev.Area,
+					EntId:     ev.Id,
+				})
+			}
 		}
 	}
 	return ADRes_r