Переглянути джерело

Merge branch 'feature/v4.7.16' of http://192.168.3.207:8080/qmx/jy into feature/v4.7.16

wangshan 3 роки тому
батько
коміт
d7c11f6953

+ 10 - 4
src/jfw/modules/bigmember/src/entity/followEnterprise.go

@@ -5,6 +5,7 @@ import (
 	"db"
 	"errors"
 	"fmt"
+	"log"
 	"mongodb"
 	qutil "qfw/util"
 	"qfw/util/elastic"
@@ -116,12 +117,14 @@ func (this *EntFollow) EntFollowedShow(entId string) (followed, showFollow bool,
 // param A默认分组 B竞争对手 C合作伙伴 逗号分隔
 // db  0||nil 默认分组、1 竞争对手、2 合作伙伴、3 竞争对手和合作伙伴
 func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, group string) (followData []map[string]interface{}, hasNext bool, count, total int, err error) {
+	log.Print("我关注的企业列表开始查询")
 	flistSql := fmt.Sprintf(`SELECT id,f_capital,i_apppushunread,l_establishdate,l_lastpushtime,s_area,s_city,s_employeeno,s_entId,s_entname,i_group,s_phone FROM follow_ent_monitor WHERE  s_userid="%s" ORDER BY l_createtime DESC LIMIT %d,%d`, this.UserId, 0, this.MaxNum)
 	res := db.Base.SelectBySql(flistSql)
 	if res == nil || len(*res) == 0 {
 		//err = errors.New("查询异常")
 		return
 	}
+	log.Print("我关注的企业列表查询结束")
 	count = len(*res)
 	//var names []string
 	//for _, data := range *res {
@@ -203,11 +206,14 @@ func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, group string) (f
 	}
 	total = len(followDataAll)
 	//分页
-	if (pNum+1)*pSize >= len(followDataAll) {
-		followData = followDataAll[pNum*pSize:]
-	} else {
-		followData = followDataAll[pNum*pSize : (pNum+1)*pSize]
+	if total > 0 {
+		if (pNum+1)*pSize >= len(followDataAll) {
+			followData = followDataAll[pNum*pSize:]
+		} else {
+			followData = followDataAll[pNum*pSize : (pNum+1)*pSize]
+		}
 	}
+
 	hasNext = qutil.If((pNum+1)*pSize >= len(followDataAll), false, true).(bool)
 	/*if this.HasPower { //购买企业情报的用户直接查询
 	  	res, _ := db.Mgo.Find(this.SaveTable, query, `{"l_lastpushtime":-1}`, `{"_id":1,"s_entname":1,"s_area":1,"s_city":1,"s_phone":1,"f_capital":1,"s_employeeno":1,"l_establishdate":1,"i_apppushunread":1,"s_entId":1,"l_lastpushtime":1,"i_group":1}`, false, pNum*size, pSize)

+ 6 - 5
src/jfw/modules/bigmember/src/service/follow/project.go

@@ -141,12 +141,13 @@ func (this *FollowProject) FollowList() {
 		}
 
 		var sList []map[string]interface{}
-		if (pNum+1)*pSize >= len(list) {
-			sList = list[pNum*pSize:]
-		} else {
-			sList = list[pNum*pSize : (pNum+1)*pSize]
+		if len(list) > 0 {
+			if (pNum+1)*pSize >= len(list) {
+				sList = list[pNum*pSize:]
+			} else {
+				sList = list[pNum*pSize : (pNum+1)*pSize]
+			}
 		}
-
 		return map[string]interface{}{
 			"total":     count,
 			"hasNext":   qutil.If((pNum+1)*pSize >= len(list), false, true),

+ 224 - 221
src/jfw/modules/publicapply/src/customer/entity/entiy.go

@@ -1,269 +1,272 @@
 package entity
 
 import (
-	"config"
-	"db"
-	"fmt"
-	qu "qfw/util"
-	"qfw/util/elastic"
-	"qfw/util/jy"
-	"qfw/util/redis"
-	"strings"
-	"time"
+    "config"
+    "db"
+    "fmt"
+    qu "qfw/util"
+    "qfw/util/elastic"
+    "qfw/util/jy"
+    "qfw/util/redis"
+    "strings"
+    "time"
 )
 
 type CustomerOperation struct {
-	UserId   string `json:"userId"`
-	EntId    int    `json:"entId"`
-	Name     string `json:"name"`
-	Province string `json:"province"`
-	City     string `json:"city"`
-	B        bool   `json:"b"` //true 取关;默认 false 关注。
+    UserId   string `json:"userId"`
+    EntId    int    `json:"entId"`
+    Name     string `json:"name"`
+    Province string `json:"province"`
+    City     string `json:"city"`
+    B        bool   `json:"b"` //true 取关;默认 false 关注。
 }
 
 func NewCustomerOperation() CustomerOperation {
-	return CustomerOperation{}
+    return CustomerOperation{}
 }
 
 var (
-	fc              = "follow_customer"  //关注客户表
-	ec              = "exclude_customer" //不是我的客户表
-	redisName       = "other"
-	redisListKey    = "customer_list_%s"
-	redisCountKey   = "customer_count_%s"
-	redisExcludeKey = "customer_exclude_%s"
-	redisCRIndex    = "CRIndex_C_%s" //首页潜在客户关注
+    fc              = "follow_customer"  //关注客户表
+    ec              = "exclude_customer" //不是我的客户表
+    redisName       = "other"
+    redisListKey    = "customer_list_%s"
+    redisCountKey   = "customer_count_%s"
+    redisExcludeKey = "customer_exclude_%s"
+    redisCRIndex    = "CRIndex_C_%s" //首页潜在客户关注
 )
 
 type CustomerInfo struct {
-	Name       string `json:"name"`
-	Province   string `json:"province"`
-	Buyerclass string `json:"buyerclass"`
-	Followdate string `json:"followdate"`
-	CustomerId string `json:"customerId"`
+    Name       string `json:"name"`
+    Province   string `json:"province"`
+    Buyerclass string `json:"buyerclass"`
+    Followdate string `json:"followdate"`
+    CustomerId string `json:"customerId"`
 }
 
 // 是否关注此企业客户
 func (this *CustomerOperation) CheckIsFollow() bool {
-	return db.Mgo.Count(fc, map[string]interface{}{
-		"userId": this.UserId,
-		"name":   this.Name,
-	}) > 0
+    return db.Mgo.Count(fc, map[string]interface{}{
+        "userId": this.UserId,
+        "name":   this.Name,
+    }) > 0
 }
 
 // 不是我的客户
 func (this *CustomerOperation) Exclude() (B bool) {
-	timeNow := time.Now()
-	updateMap := map[string]interface{}{
-		"$set": map[string]interface{}{
-			"date":     timeNow.Unix(),
-			"userId":   this.UserId,
-			"name":     this.Name,
-			"province": this.Province,
-			"city":     this.City,
-		},
-	}
-	B = db.Mgo.Update(ec, map[string]interface{}{
-		"userId": this.UserId,
-		"name":   this.Name,
-	}, updateMap, true, false)
-	if B {
-		redis.Del(redisName, fmt.Sprintf(redisCRIndex, this.UserId))
-		redis.Del(redisName, fmt.Sprintf(redisExcludeKey, this.UserId))
-		//删除首页客户缓存
-		redis.DelByCodePattern(redisName, fmt.Sprintf("CRIndex_new_%s_*", this.UserId))
-	}
-	return B
+    timeNow := time.Now()
+    updateMap := map[string]interface{}{
+        "$set": map[string]interface{}{
+            "date":     timeNow.Unix(),
+            "userId":   this.UserId,
+            "name":     this.Name,
+            "province": this.Province,
+            "city":     this.City,
+        },
+    }
+    B = db.Mgo.Update(ec, map[string]interface{}{
+        "userId": this.UserId,
+        "name":   this.Name,
+    }, updateMap, true, false)
+    if B {
+        redis.Del(redisName, fmt.Sprintf(redisCRIndex, this.UserId))
+        redis.Del(redisName, fmt.Sprintf(redisExcludeKey, this.UserId))
+        //删除首页客户缓存
+        redis.DelByCodePattern(redisName, fmt.Sprintf("CRIndex_new_%s_*", this.UserId))
+    }
+    return B
 }
 
 // 列表
 func (this *CustomerOperation) CList(pageSize, pageNo, entUserId int, keyword, isCliam string) ([]*CustomerInfo, int, int, int) {
-	var cinfoarr, cinfoarrAll = []*CustomerInfo{}, []*CustomerInfo{}
-	entnames := []string{}
-	total := 0
-	query := map[string]interface{}{
-		"userId": this.UserId,
-	}
-	total = redis.GetInt(redisName, fmt.Sprintf(redisCountKey, this.UserId))
-	if total < 1 {
-		total = db.Mgo.Count(fc, query)
-		redis.Put(redisName, fmt.Sprintf(redisCountKey, this.UserId), total, 2*60*60)
-	}
+    var cinfoarr, cinfoarrAll = []*CustomerInfo{}, []*CustomerInfo{}
+    entnames := []string{}
+    total := 0
+    query := map[string]interface{}{
+        "userId": this.UserId,
+    }
+    total = redis.GetInt(redisName, fmt.Sprintf(redisCountKey, this.UserId))
+    if total < 1 {
+        total = db.Mgo.Count(fc, query)
+        redis.Put(redisName, fmt.Sprintf(redisCountKey, this.UserId), total, 2*60*60)
+    }
 
-	//大会员客户关注上限
-	BigMsg := jy.GetBigVipUserBaseMsg(this.UserId, db.Mysql, db.Mgo)
-	entVip := jy.GetEntnicheState(this.UserId, db.Mysql, db.Mgo)
-	customerMap := map[string]interface{}{}
-	if entVip.EntnicheStatus > 0 {
-		//非大会员商机管理用户兼容查询商机管理权限
-		if BigMsg.Customers < config.Config.FollowCustomer.CustomerNumb {
-			BigMsg.Customers = config.Config.FollowCustomer.CustomerNumb
-		}
-		customerList := db.Mysql.SelectBySql("SELECT ec.name,euu.customer_id FROM entniche_user_customer euu LEFT JOIN entniche_customer ec ON ec.id = euu.customer_id  WHERE user_id = ? AND (source_type =1 or source_type =4) ", entUserId)
-		for _, value := range *customerList {
-			customerMap[qu.ObjToString(value["name"])] = value["customer_id"]
-		}
-	}
+    //大会员客户关注上限
+    BigMsg := jy.GetBigVipUserBaseMsg(this.UserId, db.Mysql, db.Mgo)
+    entVip := jy.GetEntnicheState(this.UserId, db.Mysql, db.Mgo)
+    customerMap := map[string]interface{}{}
+    if entVip.EntnicheStatus > 0 {
+        //非大会员商机管理用户兼容查询商机管理权限
+        if BigMsg.Customers < config.Config.FollowCustomer.CustomerNumb {
+            BigMsg.Customers = config.Config.FollowCustomer.CustomerNumb
+        }
+        customerList := db.Mysql.SelectBySql("SELECT ec.name,euu.customer_id FROM entniche_user_customer euu LEFT JOIN entniche_customer ec ON ec.id = euu.customer_id  WHERE user_id = ? AND (source_type =1 or source_type =4) ", entUserId)
+        for _, value := range *customerList {
+            customerMap[qu.ObjToString(value["name"])] = value["customer_id"]
+        }
+    }
 
-	clist, ok := db.Mgo.Find(fc, query, `{"date":-1}`, `{"name":1,"date":1}`, false, 0, BigMsg.Customers)
-	if ok && clist != nil && len(*clist) > 0 {
-		total = len(*clist)
-		for _, v := range *clist {
-			if keyword != "" && !strings.Contains(qu.ObjToString(v["name"]), keyword) {
-				continue
-			}
-			switch isCliam {
-			case "0":
-				if customerMap[qu.ObjToString(v["name"])] != nil {
-					continue
-				}
-			case "1":
-				if customerMap[qu.ObjToString(v["name"])] == nil {
-					continue
-				}
-			}
-			entnames = append(entnames, v["name"].(string))
-			date := v["date"]
-			cinfoarrAll = append(cinfoarrAll, &CustomerInfo{
-				Name:       v["name"].(string),
-				Followdate: qu.FormatDateWithObj(&date, "2006/01/02"),
-			})
-		}
-	}
-	if (pageNo+1)*pageSize >= len(cinfoarrAll) {
-		cinfoarr = cinfoarrAll[pageNo*pageSize:]
-	} else {
-		cinfoarr = cinfoarrAll[pageNo*pageSize : (pageNo+1)*pageSize]
-	}
-	count := len(cinfoarrAll)
-	entinfolist := GetEntCusInfo(entnames)
-	if len(entinfolist) > 0 {
-	L:
-		for _, v := range entinfolist {
-			for _, ev := range cinfoarr {
-				(*ev).CustomerId = qu.SE.Encode2HexByCheck(fmt.Sprint(customerMap[(*ev).Name]))
-				if (*ev).Name == qu.ObjToString(v["buyer_name"]) {
-					(*ev).Province = qu.ObjToString(v["province"])
-					(*ev).Buyerclass = qu.ObjToString(v["buyerclass"])
-					continue L
-				}
-			}
-		}
-	}
-	return cinfoarr, total, BigMsg.Customers, count
+    clist, ok := db.Mgo.Find(fc, query, `{"date":-1}`, `{"name":1,"date":1}`, false, 0, BigMsg.Customers)
+    if ok && clist != nil && len(*clist) > 0 {
+        total = len(*clist)
+        for _, v := range *clist {
+            if keyword != "" && !strings.Contains(qu.ObjToString(v["name"]), keyword) {
+                continue
+            }
+            switch isCliam {
+            case "0":
+                if customerMap[qu.ObjToString(v["name"])] != nil {
+                    continue
+                }
+            case "1":
+                if customerMap[qu.ObjToString(v["name"])] == nil {
+                    continue
+                }
+            }
+            entnames = append(entnames, v["name"].(string))
+            date := v["date"]
+            cinfoarrAll = append(cinfoarrAll, &CustomerInfo{
+                Name:       v["name"].(string),
+                Followdate: qu.FormatDateWithObj(&date, "2006/01/02"),
+            })
+        }
+    }
+    count := len(cinfoarrAll)
+    if count > 0 {
+        if (pageNo+1)*pageSize >= len(cinfoarrAll) {
+            cinfoarr = cinfoarrAll[pageNo*pageSize:]
+        } else {
+            cinfoarr = cinfoarrAll[pageNo*pageSize : (pageNo+1)*pageSize]
+        }
+    }
+
+    entinfolist := GetEntCusInfo(entnames)
+    if len(entinfolist) > 0 {
+    L:
+        for _, v := range entinfolist {
+            for _, ev := range cinfoarr {
+                (*ev).CustomerId = qu.SE.Encode2HexByCheck(fmt.Sprint(customerMap[(*ev).Name]))
+                if (*ev).Name == qu.ObjToString(v["buyer_name"]) {
+                    (*ev).Province = qu.ObjToString(v["province"])
+                    (*ev).Buyerclass = qu.ObjToString(v["buyerclass"])
+                    continue L
+                }
+            }
+        }
+    }
+    return cinfoarr, total, BigMsg.Customers, count
 }
 
 var pcquery = `{"query": {"bool": {"must": [{"terms": {"%s": [%s]}}],"must_not": [],"should": []}},"sort": []}`
 
 // 获取企业-客户信息
 func GetEntCusInfo(entnames []string) []map[string]interface{} {
-	query := fmt.Sprintf(pcquery, "buyer_name", `"`+strings.Join(entnames, `","`)+`"`)
-	list := *elastic.Get("buyer", "buyer", query)
-	return list
+    query := fmt.Sprintf(pcquery, "buyer_name", `"`+strings.Join(entnames, `","`)+`"`)
+    list := *elastic.Get("buyer", "buyer", query)
+    return list
 }
 
 // 权限查询
 func (this *CustomerOperation) CheckPower() string {
-	msg := ""
-	if this.UserId == "" {
-		msg = "登录异常"
-	} else {
-		//查询是否是大会员
-		if userPower := jy.GetBigVipUserBaseMsg(this.UserId, db.Mysql, db.Mgo); userPower.Status > 0 {
-			count := redis.GetInt(redisName, fmt.Sprintf(redisCountKey, this.UserId))
-			if count < 1 {
-				query := map[string]interface{}{
-					"userId": this.UserId,
-				}
-				count = db.Mgo.Count(fc, query)
-			}
-			if count >= userPower.Customers {
-				msg = fmt.Sprintf("对不起,您最多可关注%d个客户", userPower.Customers)
-			}
-		} else if entUser := jy.GetEntnicheState(this.UserId, db.Mysql, db.Mgo); entUser.EntnicheStatus > 0 {
-			//兼容商机管理用户权限搜索
-			return EntCheckPower(this.UserId, this.EntId)
+    msg := ""
+    if this.UserId == "" {
+        msg = "登录异常"
+    } else {
+        //查询是否是大会员
+        if userPower := jy.GetBigVipUserBaseMsg(this.UserId, db.Mysql, db.Mgo); userPower.Status > 0 {
+            count := redis.GetInt(redisName, fmt.Sprintf(redisCountKey, this.UserId))
+            if count < 1 {
+                query := map[string]interface{}{
+                    "userId": this.UserId,
+                }
+                count = db.Mgo.Count(fc, query)
+            }
+            if count >= userPower.Customers {
+                msg = fmt.Sprintf("对不起,您最多可关注%d个客户", userPower.Customers)
+            }
+        } else if entUser := jy.GetEntnicheState(this.UserId, db.Mysql, db.Mgo); entUser.EntnicheStatus > 0 {
+            //兼容商机管理用户权限搜索
+            return EntCheckPower(this.UserId, this.EntId)
 
-		} else {
-			msg = "暂无关注客户权限"
-		}
-	}
-	return msg
+        } else {
+            msg = "暂无关注客户权限"
+        }
+    }
+    return msg
 }
 
 func EntCheckPower(userId string, entId int) (msg string) {
-	query := map[string]interface{}{
-		"ent_id": entId,
-	}
+    query := map[string]interface{}{
+        "ent_id": entId,
+    }
 
-	res, _ := db.Mgo.Find(fc, query, nil, `{"name":1}`, false, -1, -1)
-	if len((*res)) > config.Config.FollowCustomer.EnterpriseNumb {
-		data := map[string]interface{}{}
-		i := 0
-		for _, value := range *res {
-			if data[qu.ObjToString(value["name"])] == nil {
-				i++
-				data[qu.ObjToString(value["name"])] = 1
-			}
-		}
-		if i >= config.Config.FollowCustomer.EnterpriseNumb {
-			msg = fmt.Sprintf("您的企业关注客户数量已经超过%d,请取消关注部分后再操作。", config.Config.FollowCustomer.EnterpriseNumb)
-		}
-	}
+    res, _ := db.Mgo.Find(fc, query, nil, `{"name":1}`, false, -1, -1)
+    if len((*res)) > config.Config.FollowCustomer.EnterpriseNumb {
+        data := map[string]interface{}{}
+        i := 0
+        for _, value := range *res {
+            if data[qu.ObjToString(value["name"])] == nil {
+                i++
+                data[qu.ObjToString(value["name"])] = 1
+            }
+        }
+        if i >= config.Config.FollowCustomer.EnterpriseNumb {
+            msg = fmt.Sprintf("您的企业关注客户数量已经超过%d,请取消关注部分后再操作。", config.Config.FollowCustomer.EnterpriseNumb)
+        }
+    }
 
-	query = map[string]interface{}{
-		"userId": userId,
-	}
-	delete(query, "ent_id")
-	count := db.Mgo.Count(fc, query)
-	if count >= config.Config.FollowCustomer.EnterpriseNumb {
-		msg = fmt.Sprintf("您的关注客户数量已经超过%d,请取消关注部分后再操作。", config.Config.FollowCustomer.CustomerNumb)
-	}
-	return
+    query = map[string]interface{}{
+        "userId": userId,
+    }
+    delete(query, "ent_id")
+    count := db.Mgo.Count(fc, query)
+    if count >= config.Config.FollowCustomer.EnterpriseNumb {
+        msg = fmt.Sprintf("您的关注客户数量已经超过%d,请取消关注部分后再操作。", config.Config.FollowCustomer.CustomerNumb)
+    }
+    return
 }
 func (this *CustomerOperation) Coperation() (B bool) {
-	queryMap := map[string]interface{}{
-		"userId": this.UserId,
-		"name":   this.Name,
-	}
-	//取关
-	if this.B {
-		B = db.Mgo.Del(fc, queryMap)
-	} else {
-		timeNow := time.Now()
-		updateMap := map[string]interface{}{
-			"$set": map[string]interface{}{
-				"date":     timeNow.Unix(),
-				"userId":   this.UserId,
-				"name":     this.Name,
-				"province": this.Province,
-				"city":     this.City,
-			},
-		}
-		B = db.Mgo.Update(fc, queryMap, updateMap, true, false)
-	}
-	redis.Del(redisName, fmt.Sprintf(redisCountKey, this.UserId))
-	if B {
-		go func(userId string) {
-			//删除首页客户缓存
-			redis.DelByCodePattern(redisName, fmt.Sprintf("CRIndex_new_%s_*", userId))
-			//首页潜在客户缓存
-			redis.Del(redisName, fmt.Sprintf(redisCRIndex, this.UserId))
-			//更新redis 客户数据
-			clist, ok := db.Mgo.Find(fc, map[string]interface{}{
-				"userId": userId,
-			}, nil, `{"name":1}`, false, -1, -1)
-			// fmt.Println(clist)
-			if ok && clist != nil && len(*clist) > 0 {
-				names := []string{}
-				for _, v := range *clist {
-					names = append(names, v["name"].(string))
-				}
-				if len(names) > 0 {
-					redis.Put(redisName, fmt.Sprintf(redisListKey, userId), strings.Join(names, ","), 2*60*60)
-				}
-			}
-		}(this.UserId)
-	}
-	return B
+    queryMap := map[string]interface{}{
+        "userId": this.UserId,
+        "name":   this.Name,
+    }
+    //取关
+    if this.B {
+        B = db.Mgo.Del(fc, queryMap)
+    } else {
+        timeNow := time.Now()
+        updateMap := map[string]interface{}{
+            "$set": map[string]interface{}{
+                "date":     timeNow.Unix(),
+                "userId":   this.UserId,
+                "name":     this.Name,
+                "province": this.Province,
+                "city":     this.City,
+            },
+        }
+        B = db.Mgo.Update(fc, queryMap, updateMap, true, false)
+    }
+    redis.Del(redisName, fmt.Sprintf(redisCountKey, this.UserId))
+    if B {
+        go func(userId string) {
+            //删除首页客户缓存
+            redis.DelByCodePattern(redisName, fmt.Sprintf("CRIndex_new_%s_*", userId))
+            //首页潜在客户缓存
+            redis.Del(redisName, fmt.Sprintf(redisCRIndex, this.UserId))
+            //更新redis 客户数据
+            clist, ok := db.Mgo.Find(fc, map[string]interface{}{
+                "userId": userId,
+            }, nil, `{"name":1}`, false, -1, -1)
+            // fmt.Println(clist)
+            if ok && clist != nil && len(*clist) > 0 {
+                names := []string{}
+                for _, v := range *clist {
+                    names = append(names, v["name"].(string))
+                }
+                if len(names) > 0 {
+                    redis.Put(redisName, fmt.Sprintf(redisListKey, userId), strings.Join(names, ","), 2*60*60)
+                }
+            }
+        }(this.UserId)
+    }
+    return B
 }