Kaynağa Gözat

增加mongodb log 工具类

wangchuanjin 5 yıl önce
ebeveyn
işleme
d2cbd72fa5
34 değiştirilmiş dosya ile 1614 ekleme ve 419 silme
  1. 0 7
      src/config.json
  2. 6 82
      src/jfw/filter/logfilter.go
  3. 2 3
      src/jfw/front/adv.go
  4. 3 6
      src/jfw/front/entsearch.go
  5. 4 4
      src/jfw/front/follow.go
  6. 6 6
      src/jfw/front/front.go
  7. 3 2
      src/jfw/front/pchelper.go
  8. 3 3
      src/jfw/front/shorturl.go
  9. 2 63
      src/jfw/front/supsearch.go
  10. 5 4
      src/jfw/front/swordfish.go
  11. 6 81
      src/jfw/modules/app/src/app/filter/logfilter.go
  12. 5 4
      src/jfw/modules/app/src/app/followent/followent.go
  13. 2 1
      src/jfw/modules/app/src/app/followent/myfwent.go
  14. 2 12
      src/jfw/modules/app/src/app/front/errLogsReceive.go
  15. 4 3
      src/jfw/modules/app/src/app/front/follow.go
  16. 1 3
      src/jfw/modules/app/src/app/front/front.go
  17. 5 4
      src/jfw/modules/app/src/app/front/login.go
  18. 1 2
      src/jfw/modules/app/src/app/front/shorturl.go
  19. 3 64
      src/jfw/modules/app/src/app/front/swordfish.go
  20. 0 7
      src/jfw/modules/app/src/config.json
  21. 19 0
      src/jfw/modules/app/src/mongodb.json
  22. 66 0
      src/jfw/modules/common/src/qfw/util/jy/checksendmsg.go
  23. 298 0
      src/jfw/modules/common/src/qfw/util/jy/entnichepush.go
  24. 89 0
      src/jfw/modules/common/src/qfw/util/jy/historypush.go
  25. 199 0
      src/jfw/modules/common/src/qfw/util/jy/jy.go
  26. 65 0
      src/jfw/modules/common/src/qfw/util/jy/pushmapping.go
  27. 511 0
      src/jfw/modules/common/src/qfw/util/jy/subscribepush.go
  28. 206 0
      src/jfw/modules/common/src/qfw/util/jy/user_merge.go
  29. 49 51
      src/jfw/public/db.go
  30. 24 1
      src/jfw/public/public.go
  31. 1 1
      src/jfw/public/search.go
  32. 3 4
      src/jfw/qrmanager/qrmanager.go
  33. 2 1
      src/jfw/rpcfollow/rpc.go
  34. 19 0
      src/mongodb.json

+ 0 - 7
src/config.json

@@ -1,12 +1,5 @@
 {
     "nodeName":"node1",
-	"mongodbServers": "192.168.3.128:27080",
-    "mongodbPoolSize": "5",
-    "mongodbName": "qfw",
-	"mongodbServersEnt": "192.168.3.128:27080",
-    "mongodbNameEnt": "extract_v3",
-	"mongodbServersLog": "192.168.3.128:27080",
-    "mongodbNameLog": "qfw",
     "influxaddr": "http://192.168.3.11:8086",
     "influxdb": "jy_logs",
     "qrModelID": "2",

+ 6 - 82
src/jfw/filter/logfilter.go

@@ -9,9 +9,9 @@ package filter
 import (
 	"encoding/json"
 	"jfw/public"
-	"net"
 	"net/http"
 	"net/url"
+	"qfw/util"
 	"regexp"
 	"strings"
 	"sync"
@@ -38,7 +38,7 @@ var reg = regexp.MustCompile("^/(swordfish|list|article|wxkeyset|wxpush|front/su
 
 //继承过滤器方法
 func (l *logfilter) Do(w http.ResponseWriter, req *http.Request) bool {
-	req.Proto = GetIp(req)
+	req.Proto = util.GetIp(req)
 	session := l.App.SessionManager.Session(req, w)
 	//if url == "/" || reg.MatchString(url) {
 	go func() {
@@ -66,9 +66,7 @@ func SaveLogTask() {
 		arr = make([]map[string]interface{}, 0)
 		for _, v := range tmp {
 			go func(v map[string]interface{}) {
-				if public.MQLOG.Save("jy_flogs", v) == "" {
-					public.MQFW.Save("jy_logs", v)
-				}
+				public.Mgo_Log.Save("jy_flogs", v)
 			}(v)
 		}
 	}
@@ -131,8 +129,8 @@ func addLog(l *logfilter, session *httpsession.Session, req *http.Request) {
 		"minutes":   timeNow.Minute(),
 		"mdescribe": str,
 		"client":    agent,
-		"os":        GetOS(agent),
-		"browse":    GetBrowse(agent),
+		"os":        util.GetOS(agent),
+		"browse":    util.GetBrowse(agent),
 		"method":    req.Method,
 		"url":       s_url,
 	}
@@ -145,84 +143,10 @@ func addLog(l *logfilter, session *httpsession.Session, req *http.Request) {
 	if len(arr) >= nc || s_url == "/sl" {
 		for _, v := range arr {
 			go func(v map[string]interface{}) {
-				if public.MQLOG.Save("jy_flogs", v) == "" {
-					public.MQFW.Save("jy_logs", v)
-				}
+				public.Mgo_Log.Save("jy_flogs", v)
 			}(v)
 		}
 		arr = make([]map[string]interface{}, 0)
 	}
 	lock.Unlock()
 }
-
-//获取平台类型
-func GetOS(useros string) string {
-	osVersion := "其他"
-	if strings.Contains(useros, "NT 6.0") {
-		osVersion = "Windows Vista/Server 2008"
-	} else if strings.Contains(useros, "NT 5.2") {
-		osVersion = "Windows Server 2003"
-	} else if strings.Contains(useros, "NT 5.1") {
-		osVersion = "Windows XP"
-	} else if strings.Contains(useros, "NT 5") {
-		osVersion = "Windows 2000"
-	} else if strings.Contains(useros, "Mac") {
-		osVersion = "Mac"
-	} else if strings.Contains(useros, "Unix") {
-		osVersion = "UNIX"
-	} else if strings.Contains(useros, "Linux") {
-		osVersion = "Linux"
-	} else if strings.Contains(useros, "SunOS") {
-		osVersion = "SunOS"
-	} else if strings.Contains(useros, "NT 6.3") {
-		osVersion = "Window8"
-	} else if strings.Contains(useros, "NT 6.1") {
-		osVersion = "Window7"
-	} else if strings.Contains(useros, "NT 10.0") {
-		osVersion = "Window10"
-	}
-	return osVersion
-}
-
-//获取浏览器类型
-func GetBrowse(userbrowser string) string {
-	browserVersion := "其他"
-	if strings.Contains(userbrowser, "MSIE") {
-		browserVersion = "IE"
-	} else if strings.Contains(userbrowser, "Firefox") {
-		browserVersion = "Firefox"
-	} else if strings.Contains(userbrowser, "Chrome") {
-		browserVersion = "Chrome"
-	} else if strings.Contains(userbrowser, "Safari") {
-		browserVersion = "Safari"
-	} else if strings.Contains(userbrowser, "rv:11.0") {
-		browserVersion = "IE11"
-	}
-
-	return browserVersion
-}
-
-//获取请求ip
-func GetIp(req *http.Request) string {
-	if req == nil {
-		return ""
-	}
-	ip_real := strings.TrimSpace(req.Header.Get("X-Real-IP"))
-	if ip_real != "" {
-		return ip_real
-	}
-	ip_for := strings.TrimSpace(req.Header.Get("X-Forwarded-For"))
-	ips := strings.Split(ip_for, ",")
-	if len(ips) > 0 {
-		ip := strings.TrimSpace(ips[len(ips)-1])
-		if ip != "" {
-			return ip
-		}
-	}
-	ip_addr := strings.TrimSpace(req.Header.Get("Remote_addr"))
-	if ip_addr != "" {
-		return ip_addr
-	}
-	ip, _, _ := net.SplitHostPort(req.RemoteAddr)
-	return ip
-}

+ 2 - 3
src/jfw/front/adv.go

@@ -2,7 +2,6 @@ package front
 
 import (
 	"jfw/config"
-	"jfw/filter"
 	public "jfw/public"
 	"log"
 	"qfw/util"
@@ -43,7 +42,7 @@ func (a *Adv) DoConsult() error {
 	openId := util.ObjToString(a.GetSession("s_m_openid"))
 	nickname := util.ObjToString(a.GetSession("s_nickname"))
 	if nickname == "" && openId == "" {
-		nickname = "匿名用户(" + filter.GetIp(a.Request) + ")"
+		nickname = "匿名用户(" + util.GetIp(a.Request) + ")"
 	}
 	data["s_openid"] = openId
 	data["s_nickname"] = nickname
@@ -83,7 +82,7 @@ func (a *Adv) DoInfo() error {
 		//userId := util.ObjToStringa.GetSession("userId"))
 		nickname := util.ObjToString(a.GetSession("s_nickname"))
 		if nickname == "" && openId == "" {
-			nickname = "匿名用户(" + filter.GetIp(a.Request) + ")"
+			nickname = "匿名用户(" + util.GetIp(a.Request) + ")"
 		}
 		advList = config.Seoconfig["advList"].(map[string]interface{})
 		if PhoneNum != "" && len(PhoneNum) > 0 && len(PhoneNum) < 12 {

+ 3 - 6
src/jfw/front/entsearch.go

@@ -4,13 +4,10 @@ import (
 	"fmt"
 	"jfw/config"
 	"jfw/jylabutil"
-
-	//"math/rand"
+	"jfw/public"
 	"qfw/util"
 	"strconv"
 
-	//"time"
-
 	"github.com/go-xweb/xweb"
 )
 
@@ -59,7 +56,7 @@ func (e *Entsearch) Bidsearchforentindex() error {
 		if list != nil {
 			listSize = len(list)
 		}
-		SaveUserSearchLog(e.Request, userid, int64(count), "pc", "中标企业搜索", map[string]interface{}{
+		public.SaveUserSearchLog(e.Request, userid, int64(count), "pc", "中标企业搜索", map[string]interface{}{
 			"search_word":  searchvalue,
 			"search_area":  area,
 			"search_price": []string{s_minprice, s_maxprice},
@@ -156,7 +153,7 @@ func (e *Entsearch) PcSearchZbqyAjax() error {
 		if list != nil {
 			listSize = len(list)
 		}
-		SaveUserSearchLog(e.Request, userid, -1, "pc", "中标企业搜索", map[string]interface{}{
+		public.SaveUserSearchLog(e.Request, userid, -1, "pc", "中标企业搜索", map[string]interface{}{
 			"search_word":  searchvalue,
 			"search_area":  area,
 			"search_price": []string{s_minprice, s_maxprice},

+ 4 - 4
src/jfw/front/follow.go

@@ -8,7 +8,7 @@ import (
 	public "jfw/public"
 	"jfw/wx"
 	"log"
-
+	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
@@ -293,7 +293,7 @@ func (m *Follow) PcEntAllNotice() error {
 		res := elastic.GetPage("bidding", "bidding", `{"TERM_s_winner":"`+entname+`"}`, `{"publishtime":-1}`, fields, 0, 100)
 		if ok && len(*res) != 0 && res != nil && *res != nil {
 			for _, v := range *res {
-				v["_id"] = util.EncodeArticleId2ByCheck(util.BsonIdToSId(v["_id"]))
+				v["_id"] = util.EncodeArticleId2ByCheck(BsonIdToSId(v["_id"]))
 			}
 			data["res"] = res
 		}
@@ -530,7 +530,7 @@ func (m *Follow) AjaxReq() {
 		}
 	} else if reqType == "cancel" { //取消关注
 		if data, ok := mongodb.FindOne("follow_project", `{"s_userid":"`+userId+`","_id":"`+util.DecodeArticleId2ByCheck(m.GetString("id"))[0]+`"}`); ok && data != nil {
-			(*data)["s_followid"] = util.BsonIdToSId((*data)["_id"])
+			(*data)["s_followid"] = BsonIdToSId((*data)["_id"])
 			delete(*data, "_id")
 			(*data)["i_status"] = 1
 			mongodb.Save("follow_project_back", data)
@@ -579,7 +579,7 @@ func (m *Follow) List() error {
 	m.T["flag"] = false
 	if ok && datas != nil && len(*datas) > 0 {
 		for _, v := range *datas {
-			v["_id"] = util.EncodeArticleId2ByCheck(util.BsonIdToSId(v["_id"]))
+			v["_id"] = util.EncodeArticleId2ByCheck(BsonIdToSId(v["_id"]))
 			if v["l_lastpushtime"] == "" || v["l_lastpushtime"] == nil {
 				v["l_lastpushtime"] = v["l_createtime"]
 			}

+ 6 - 6
src/jfw/front/front.go

@@ -4,12 +4,12 @@ import (
 	"encoding/hex"
 	"fmt"
 	"jfw/config"
-	"jfw/filter"
 	"jfw/public"
 	"jfw/qrmanager"
 	"jfw/wx"
 	"log"
 	"math/rand"
+	. "qfw/mongodb"
 
 	//	"net/url"
 	"regexp"
@@ -516,9 +516,9 @@ func (f *Front) Followinfo() error {
 		rhdua = rheader["User-Agent"][0]
 	}
 	userData := make(map[string]interface{})
-	userData["Ros"] = filter.GetOS(rhdua)
-	userData["Rip"] = filter.GetIp(f.Request)
-	userData["Rbrowse"] = filter.GetBrowse(rhdua)
+	userData["Ros"] = util.GetOS(rhdua)
+	userData["Rip"] = util.GetIp(f.Request)
+	userData["Rbrowse"] = util.GetBrowse(rhdua)
 	if f.GetSession("RReferer") == nil || util.ObjToString(f.GetSession("RReferer")) == "" {
 		if Rref == "" {
 			f.SetSession("RReferer", Rurl)
@@ -812,7 +812,7 @@ func CreateSession(q map[string]interface{}, sess *httpsession.Session) (bool, *
 		"result":      "ok",
 		"s_nickname":  nickName,
 		"s_headimage": avatar,
-		"encryptId":   se.EncodeString(util.BsonIdToSId((*person)["_id"])),
+		"encryptId":   se.EncodeString(BsonIdToSId((*person)["_id"])),
 	}
 	sess.Set("s_m_openid", openid)
 	sess.Set("openid", openid)
@@ -1157,7 +1157,7 @@ func (f *Front) DownloadJyApp() error {
 			"page":       pageName,
 			"source":     source,
 			"refer":      f.Refer(),
-			"ip":         filter.GetIp(f.Request),
+			"ip":         util.GetIp(f.Request),
 			"userAgent":  userAgent,
 			"i_year":     now.Year(),
 			"i_month":    now.Month(),

+ 3 - 2
src/jfw/front/pchelper.go

@@ -8,6 +8,7 @@ import (
 	"jfw/public"
 	"log"
 	"net/url"
+	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/jy"
 	"qfw/util/redis"
@@ -478,7 +479,7 @@ func PcHelperLoginInfo(phone string, Sess interface{}) {
 			infoData["s_nickname"] = fmt.Sprint((*user)["s_nickname"])
 			infoData["s_headimage"] = fmt.Sprint((*user)["s_headimage"])
 			infoData["redisheadimg"] = fmt.Sprint(redisheadimg)
-			infoData["encryptId"] = se.EncodeString(util.BsonIdToSId((*user)["_id"]))
+			infoData["encryptId"] = se.EncodeString(BsonIdToSId((*user)["_id"]))
 			infoData["shareid"] = ""
 			infoData["openid"] = se.EncodeString(phone) //add 20181116
 			(*user)["shareid"] = ""
@@ -489,7 +490,7 @@ func PcHelperLoginInfo(phone string, Sess interface{}) {
 			sess.Set("openid", phone)
 			sess.Set("s_m_openid", phone)
 			sess.Set("user", *user)
-			sess.Set("userId", util.BsonIdToSId((*user)["_id"]))
+			sess.Set("userId", BsonIdToSId((*user)["_id"]))
 			sess.Set("rpcBackUserInfo", infoData)
 		}
 	}

+ 3 - 3
src/jfw/front/shorturl.go

@@ -8,6 +8,7 @@ import (
 	"jfw/wx"
 	"math/rand"
 	"net/url"
+	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/redis"
 	"regexp"
@@ -27,7 +28,6 @@ type Short struct {
 }
 
 var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
-var mongodbEnt = public.MQFWENT
 
 var Map_stype = map[string]bool{
 	"content":     true,
@@ -113,7 +113,7 @@ func (s *Short) Article(stype, id string) error {
 	userId, _ := s.GetSession("userId").(string)
 	if userId == "" && ssOpenid != "" {
 		data1, _ := mongodb.FindOneByField("user", bson.M{"s_m_openid": ssOpenid}, `{"_id":1}`)
-		userId = util.BsonIdToSId((*data1)["_id"])
+		userId = BsonIdToSId((*data1)["_id"])
 	}
 	//判断用户是否是vip
 	res, _ := public.MQFW.FindById("user", userId, nil)
@@ -347,7 +347,7 @@ func isbid(typ interface{}) bool {
 
 func getwinnertel(company interface{}) string {
 	if company != nil {
-		data, _ := mongodbEnt.FindOne("winner_enterprise", map[string]interface{}{
+		data, _ := public.Mgo_Ent.FindOne("winner_enterprise", map[string]interface{}{
 			"company_name": util.ObjToString(company),
 		})
 		if (*data)["company_phone"] != nil {

+ 2 - 63
src/jfw/front/supsearch.go

@@ -3,12 +3,10 @@ package front
 import (
 	"fmt"
 	"jfw/config"
-	"jfw/filter"
 	"jfw/jylabutil"
 	"jfw/public"
 	"log"
 	"math/rand"
-	"net/http"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/jy"
@@ -16,11 +14,9 @@ import (
 	"strconv"
 	"strings"
 	"time"
-	uc "ucbsutil"
 
 	"github.com/SKatiyar/qr"
 	"github.com/go-xweb/xweb"
-	"github.com/gocql/gocql"
 )
 
 type Pcsearch struct {
@@ -123,7 +119,7 @@ func (p *Pcsearch) ProposedProject() error {
 		if list != nil {
 			listSize = len(*list)
 		}
-		SaveUserSearchLog(p.Request, util.ObjToString(p.GetSession("userId")), count, "pc", "拟建", map[string]interface{}{
+		public.SaveUserSearchLog(p.Request, util.ObjToString(p.GetSession("userId")), count, "pc", "拟建", map[string]interface{}{
 			"search_word":        s_word,
 			"search_area":        area,
 			"search_publishtime": publishtime,
@@ -300,7 +296,7 @@ func (p *Pcsearch) PcSearchIndex() error {
 			}
 		}
 		//		s_word = strings.Replace(s_word, "+", " ", -1)
-		SaveUserSearchLog(p.Request, util.ObjToString(p.GetSession("userId")), count, "pc", "超级搜索", map[string]interface{}{
+		public.SaveUserSearchLog(p.Request, util.ObjToString(p.GetSession("userId")), count, "pc", "超级搜索", map[string]interface{}{
 			"search_word":        s_word,
 			"search_area":        area,
 			"search_price":       []string{minprice, maxprice},
@@ -502,60 +498,3 @@ func (p *Pcsearch) Qr(t string) error {
 	_, err := w.Write(pngdat)
 	return err
 }
-
-//保存用户搜索日志
-func SaveUserSearchLog(request *http.Request, userid string, count int64, platform, source string, condition map[string]interface{}) {
-	go func() {
-		data := map[string]interface{}{
-			"ip":     filter.GetIp(request),
-			"count":  count,
-			"openid": userid,
-			"pform":  platform,
-			"source": source,
-			"date":   time.Now(),
-			"uagent": request.Header.Get("User-Agent"),
-		}
-		for _, v := range []string{"pagenum", "pagesize", "search_word", "search_area", "search_publishtime", "search_industry", "search_price", "search_type"} {
-			if vv := condition[v]; vv != nil {
-				//替换key
-				if v == "search_word" {
-					v = "word"
-				} else if v == "search_area" {
-					v = "area"
-				} else if v == "search_publishtime" {
-					v = "ptime"
-				} else if v == "search_industry" {
-					v = "indst"
-				} else if v == "search_price" {
-					v = "price"
-				} else if v == "search_type" {
-					v = "type"
-				} else if v == "pagenum" {
-					v = "pnum"
-				} else if v == "pagesize" {
-					v = "psize"
-				}
-				data[v] = vv
-			}
-		}
-		data["id"] = uc.DayShortTime()
-		data["tuid"] = gocql.TimeUUID()
-		if public.MQLOG.Save("jy_search", data) == "" {
-			data := map[string]interface{}{
-				"ip":         filter.GetIp(request),
-				"count":      count,
-				"s_userid":   userid,
-				"platform":   platform,
-				"source":     source,
-				"createtime": time.Now().Unix(),
-				"userAgent":  request.Header.Get("User-Agent"),
-			}
-			for _, v := range []string{"pagenum", "pagesize", "search_word", "search_area", "search_publishtime", "search_industry", "search_price", "search_type"} {
-				if vv := condition[v]; vv != nil {
-					data[v] = vv
-				}
-			}
-			mongodb.Save("jy_search_log", data)
-		}
-	}()
-}

+ 5 - 4
src/jfw/front/swordfish.go

@@ -13,6 +13,7 @@ import (
 	"log"
 	"math/rand"
 	"net/url"
+	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
@@ -215,7 +216,7 @@ func detailLikeRpc(Interest []string, res *[]map[string]interface{}, flag bool)
 			title = `[<span class='area'>` + province + `</span>]` + title
 		}
 		i++
-		str += "<div class='tslist'><span class='xh'>" + fmt.Sprintf("%d", i) + ".</span><a class='bt' target='_blank' sid='" + util.EncodeArticleId2ByCheck(util.BsonIdToSId(k2["_id"])) + "' eid='" + util.EncodeArticleId2ByCheck(util.BsonIdToSId(k2["_id"])) + "'  href='" + k2["href"].(string) + "'>" + title + "</a></div>"
+		str += "<div class='tslist'><span class='xh'>" + fmt.Sprintf("%d", i) + ".</span><a class='bt' target='_blank' sid='" + util.EncodeArticleId2ByCheck(BsonIdToSId(k2["_id"])) + "' eid='" + util.EncodeArticleId2ByCheck(BsonIdToSId(k2["_id"])) + "'  href='" + k2["href"].(string) + "'>" + title + "</a></div>"
 		o_pushinfo[strconv.Itoa(i)] = map[string]interface{}{
 			"publishtime": k2["publishtime"],
 			"stype":       k2["type"],
@@ -525,7 +526,7 @@ func (m *Front) PcAjaxReq() {
 						pcAjaxFlag = "T"
 					}
 				}
-				SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "pc", "超级搜索", map[string]interface{}{
+				public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "pc", "超级搜索", map[string]interface{}{
 					"search_word":        s_word,
 					"search_area":        area,
 					"search_price":       []string{minprice, maxprice},
@@ -895,7 +896,7 @@ func (m *Front) WxsearchlistPaging() {
 						secondKWS = ""
 					}
 				}
-				SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "wx", "超级搜索", map[string]interface{}{
+				public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "wx", "超级搜索", map[string]interface{}{
 					"search_word":        searchvalue,
 					"search_area":        scope,
 					"search_price":       []string{minprice, maxprice},
@@ -1139,7 +1140,7 @@ func MFollow(userId, pname, pcode, title, openid string) (bool, string) {
 			pn, _ := v["s_projectname"].(string)
 			if (pc != "" && pc == pcode) || (pn != "" && pn == pname) {
 				followFlag = true
-				followId = util.EncodeArticleId2ByCheck(util.BsonIdToSId(v["_id"]))
+				followId = util.EncodeArticleId2ByCheck(BsonIdToSId(v["_id"]))
 				break
 			}
 		}

+ 6 - 81
src/jfw/modules/app/src/app/filter/logfilter.go

@@ -9,18 +9,16 @@ package filter
 import (
 	"encoding/json"
 	"jfw/public"
-	"net"
 	"net/http"
 	"net/url"
+	"qfw/util"
 	"regexp"
 	"strings"
 	"sync"
 	"time"
-	uc "ucbsutil"
 
 	"github.com/go-xweb/httpsession"
 	"github.com/go-xweb/xweb"
-	"github.com/gocql/gocql"
 )
 
 //日志过滤器
@@ -38,7 +36,7 @@ var reg = regexp.MustCompile("^/(swordfish|list|article|wxkeyset|wxpush|front/su
 
 //继承过滤器方法
 func (l *logfilter) Do(w http.ResponseWriter, req *http.Request) bool {
-	req.Proto = GetIp(req)
+	req.Proto = util.GetIp(req)
 	session := l.App.SessionManager.Session(req, w)
 	//if url == "/" || reg.MatchString(url) {
 	go func() {
@@ -64,7 +62,7 @@ func SaveLogTask() {
 		arr = make([]map[string]interface{}, 0)
 		for _, v := range tmp {
 			go func(v map[string]interface{}) {
-				if public.MQLOG.Save("jy_fapp", v) == "" {
+				if public.Mgo_Log.Save("jy_fapp", v) == "" {
 					public.MQFW.Save("jyapp_logs", v)
 				}
 			}(v)
@@ -116,8 +114,6 @@ func addLog(l *logfilter, session *httpsession.Session, req *http.Request) {
 	md, _ := json.Marshal(req.Form)
 	str := string(md)
 	logs := map[string]interface{}{
-		"id":        uc.DayShortTime(),
-		"tuid":      gocql.TimeUUID(),
 		"date":      timeNow,
 		"ip":        req.Proto,
 		"refer":     ref,
@@ -128,8 +124,8 @@ func addLog(l *logfilter, session *httpsession.Session, req *http.Request) {
 		"minutes":   timeNow.Minute(),
 		"mdescribe": str,
 		"client":    agent,
-		"os":        GetOS(agent),
-		"browse":    GetBrowse(agent),
+		"os":        util.GetOS(agent),
+		"browse":    util.GetBrowse(agent),
 		"method":    req.Method,
 		"url":       s_url,
 	}
@@ -142,81 +138,10 @@ func addLog(l *logfilter, session *httpsession.Session, req *http.Request) {
 	if len(arr) >= nc || s_url == "/sl" {
 		for _, v := range arr {
 			go func(v map[string]interface{}) {
-				if public.MQLOG.Save("jy_fapp", v) == "" {
-					public.MQFW.Save("jyapp_logs", v)
-				}
+				public.Mgo_Log.Save("jy_fapp", v)
 			}(v)
 		}
 		arr = make([]map[string]interface{}, 0)
 	}
 	lock.Unlock()
 }
-
-//获取平台类型
-func GetOS(useros string) string {
-	osVersion := "其他"
-	if strings.Contains(useros, "NT 6.0") {
-		osVersion = "Windows Vista/Server 2008"
-	} else if strings.Contains(useros, "NT 5.2") {
-		osVersion = "Windows Server 2003"
-	} else if strings.Contains(useros, "NT 5.1") {
-		osVersion = "Windows XP"
-	} else if strings.Contains(useros, "NT 5") {
-		osVersion = "Windows 2000"
-	} else if strings.Contains(useros, "Mac") {
-		osVersion = "Mac"
-	} else if strings.Contains(useros, "Unix") {
-		osVersion = "UNIX"
-	} else if strings.Contains(useros, "Linux") {
-		osVersion = "Linux"
-	} else if strings.Contains(useros, "SunOS") {
-		osVersion = "SunOS"
-	} else if strings.Contains(useros, "NT 6.3") {
-		osVersion = "Window8"
-	} else if strings.Contains(useros, "NT 6.1") {
-		osVersion = "Window7"
-	} else if strings.Contains(useros, "NT 10.0") {
-		osVersion = "Window10"
-	}
-	return osVersion
-}
-
-//获取浏览器类型
-func GetBrowse(userbrowser string) string {
-	browserVersion := "其他"
-	if strings.Contains(userbrowser, "MSIE") {
-		browserVersion = "IE"
-	} else if strings.Contains(userbrowser, "Firefox") {
-		browserVersion = "Firefox"
-	} else if strings.Contains(userbrowser, "Chrome") {
-		browserVersion = "Chrome"
-	} else if strings.Contains(userbrowser, "Safari") {
-		browserVersion = "Safari"
-	} else if strings.Contains(userbrowser, "rv:11.0") {
-		browserVersion = "IE11"
-	}
-
-	return browserVersion
-}
-
-//获取请求ip
-func GetIp(req *http.Request) string {
-	if req == nil {
-		return ""
-	}
-	ip_for := req.Header.Get("x-forwarded-for")
-	ip_client := req.Header.Get("http_client_ip")
-	ip_addr := req.Header.Get("Remote_addr")
-	un := "unknown"
-	if (ip_for != un) && (len(strings.TrimSpace(ip_for)) > 0) {
-		return ip_for
-	}
-	if (ip_client != un) && (len(strings.TrimSpace(ip_client)) > 0) {
-		return ip_client
-	}
-	if (ip_addr != un) && (len(strings.TrimSpace(ip_addr)) > 0) {
-		return ip_addr
-	}
-	ip, _, _ := net.SplitHostPort(req.RemoteAddr)
-	return ip
-}

+ 5 - 4
src/jfw/modules/app/src/app/followent/followent.go

@@ -4,6 +4,7 @@ import (
 	"app/jylabutil"
 	"jfw/config"
 	"jfw/public"
+	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/redis"
 	"strconv"
@@ -68,8 +69,8 @@ func (f *FollowEnt) GetEntList() {
 	flag := false
 	if ok && datas != nil && len(*datas) > 0 {
 		for _, v := range *datas {
-			v["_id"] = util.EncodeArticleId2ByCheck(util.BsonIdToSId(v["_id"]))
-			v["s_id"] = util.EncodeArticleId2ByCheck(util.BsonIdToSId(v["s_id"]))
+			v["_id"] = util.EncodeArticleId2ByCheck(BsonIdToSId(v["_id"]))
+			v["s_id"] = util.EncodeArticleId2ByCheck(BsonIdToSId(v["s_id"]))
 			if v["l_lastpushtime"] == "" || v["l_lastpushtime"] == nil {
 				v["l_lastpushtime"] = v["l_createtime"]
 			}
@@ -170,7 +171,7 @@ func (f *FollowEnt) NewInfo(param string) error {
 		if (*oneQy)["a_visited"] != nil {
 			a_visited = (*oneQy)["a_visited"]
 		}
-		f.T["_id"] = util.EncodeArticleId2ByCheck(util.BsonIdToSId((*oneQy)["_id"]))
+		f.T["_id"] = util.EncodeArticleId2ByCheck(BsonIdToSId((*oneQy)["_id"]))
 	}
 	f.T["data"] = public.GetWinnerNewestDatas(winner)
 	f.T["winner"] = winner
@@ -223,7 +224,7 @@ func createId(winner string) string {
 		data["_id"] = winnerid
 	} else {
 		//log.Println(*tem, "---------", util.BsonIdToSId((*tem)["_id"]))
-		winnerid = util.ObjToString(util.BsonIdToSId((*tem)["_id"]))
+		winnerid = util.ObjToString(BsonIdToSId((*tem)["_id"]))
 	}
 	return winnerid
 }

+ 2 - 1
src/jfw/modules/app/src/app/followent/myfwent.go

@@ -4,6 +4,7 @@ import (
 	"jfw/config"
 	"jfw/public"
 	"log"
+	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"strings"
@@ -78,7 +79,7 @@ func Findent(entname string) string {
 		}
 	} else {
 		//log.Println(*tem, "---------", util.BsonIdToSId((*tem)["_id"]))
-		winnerid = util.ObjToString(util.BsonIdToSId((*tem)["_id"]))
+		winnerid = util.ObjToString(BsonIdToSId((*tem)["_id"]))
 	}
 	return winnerid
 }

+ 2 - 12
src/jfw/modules/app/src/app/front/errLogsReceive.go

@@ -2,8 +2,7 @@ package front
 
 import (
 	"encoding/json"
-	"jfw/config"
-	jymg "jy/mongodb"
+	"jfw/public"
 	qutil "qfw/util"
 
 	"github.com/go-xweb/xweb"
@@ -14,15 +13,6 @@ type ErrLogServer struct {
 	receive xweb.Mapper `xweb:"/jyapp/errLogs/Receive"` //app异常 or 加载超时日志
 }
 
-var logMgo *jymg.MongodbSim
-
-func init() {
-	xweb.AddAction(&ErrLogServer{})
-	logMgo = jymg.NewMgo(config.Sysconfig["logMongodbServers"].(string),
-		config.Sysconfig["logMongodbName"].(string),
-		qutil.IntAll(config.Sysconfig["logMongodbPoolSize"]))
-}
-
 type ErrLog struct {
 	PhoneType  string `json:"phoneType"`  //手机型号
 	AppVersion string `json:"appVersion"` //版本号
@@ -60,7 +50,7 @@ func (this *ErrLogServer) Receive() {
 				"i_reqTime":    data.ReqTime,
 			})
 		}
-		if !logMgo.SaveBulk("jyapp_errlogs", saveArr...) {
+		if !public.Mgo_Log.SaveBulk("jyapp_errlogs", saveArr...) {
 			return false, "数据保存异常"
 		}
 		return true, ""

+ 4 - 3
src/jfw/modules/app/src/app/front/follow.go

@@ -6,6 +6,7 @@ import (
 	"jfw/config"
 	public "jfw/public"
 	"log"
+	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
@@ -400,7 +401,7 @@ func (m *Follow) AjaxReq() {
 		}
 	} else if reqType == "cancel" { //取消关注
 		if data, ok := mongodb.FindOne("follow_project", `{"s_userid":"`+userId+`","_id":"`+util.DecodeArticleId2ByCheck(m.GetString("id"))[0]+`"}`); ok && data != nil {
-			(*data)["s_followid"] = util.BsonIdToSId((*data)["_id"])
+			(*data)["s_followid"] = BsonIdToSId((*data)["_id"])
 			delete(*data, "_id")
 			(*data)["i_status"] = 1
 			mongodb.Save("follow_project_back", data)
@@ -450,8 +451,8 @@ func (m *Follow) GetList() {
 	flag := false
 	if ok && datas != nil && len(*datas) > 0 {
 		for _, v := range *datas {
-			v["followid"] = util.BsonIdToSId(v["_id"])
-			v["_id"] = util.EncodeArticleId2ByCheck(util.BsonIdToSId(v["_id"]))
+			v["followid"] = BsonIdToSId(v["_id"])
+			v["_id"] = util.EncodeArticleId2ByCheck(BsonIdToSId(v["_id"]))
 			if v["l_lastpushtime"] == "" || v["l_lastpushtime"] == nil {
 				v["l_lastpushtime"] = v["l_createtime"]
 			}

+ 1 - 3
src/jfw/modules/app/src/app/front/front.go

@@ -13,7 +13,6 @@ import (
 	"strings"
 	"sync"
 	"time"
-	uc "ucbsutil"
 
 	"github.com/dchest/captcha"
 	"github.com/go-xweb/xweb"
@@ -206,8 +205,7 @@ func mesCaLog(mid, url, userId, recType string) {
 	userData, ok1 := mongodb.FindById("user", userId, `{"s_province":1,"s_city":1,"s_nickname":1}`)
 	mesData, ok2 := mongodb.FindById("message_app", mid, `{"s_title":1,"s_subtitle":1}`)
 	if ok1 && ok2 && *mesData != nil && *userData != nil {
-		mongodb.Save("jy_message", map[string]interface{}{
-			"id":       uc.DayShortTime(),
+		public.Mgo_Log.Save("jy_message", map[string]interface{}{
 			"openid":   userId, //之前存的是openid,用户合并以后存的是userid
 			"mid":      mid,
 			"title":    util.ObjToString((*mesData)["s_title"]),

+ 5 - 4
src/jfw/modules/app/src/app/front/login.go

@@ -8,6 +8,7 @@ import (
 	"jfw/config"
 	"log"
 	"net/http"
+	. "qfw/mongodb"
 	qutil "qfw/util"
 	"qfw/util/jy"
 	"qfw/util/redis"
@@ -882,7 +883,7 @@ func createSession(s *httpsession.Session, person map[string]interface{}, loginI
 			}, false, false)
 		}()
 	}
-	s.Set("userId", qutil.BsonIdToSId(person["_id"]))
+	s.Set("userId", BsonIdToSId(person["_id"]))
 	s.Set("s_jpushid", person["s_jpushid"])
 	s.Set("s_m_openid", person["s_m_openid"])
 	s.Set("s_opushid", person["s_opushid"])
@@ -953,7 +954,7 @@ func getSign(u *UserSign) (string, string) {
 
 //
 func afterLogin(user map[string]interface{}, session *httpsession.Session, rid, oid, phoneType, channel, deviceId string, t int, isNewUser bool) string {
-	userid := qutil.BsonIdToSId(user["_id"])
+	userid := BsonIdToSId(user["_id"])
 	old_rid, _ := user["s_jpushid"].(string)
 	old_oid, _ := user["s_opushid"].(string)
 	old_ponetype, _ := user["s_appponetype"].(string)
@@ -1108,7 +1109,7 @@ func analySign(text, sign string) (*UserSign, int) {
 		}
 		user, ok := mongodb.FindOneByField("user", query, `{"_id":1}`)
 		if ok && user != nil && len(*user) > 0 {
-			u.UserId = qutil.BsonIdToSId((*user)["_id"])
+			u.UserId = BsonIdToSId((*user)["_id"])
 		}
 		return u, 1
 	} else if u.Sign == newSign {
@@ -1128,7 +1129,7 @@ func checkRepeatLogin(user *map[string]interface{}, rid, oid string) {
 	ponetype := qutil.ObjToString((*user)["s_appponetype"])
 	//同一账号在不同设备登录,极光id不一样,给之前的设备推送自定义的下线消息,离线消息保持10天
 	if jpushid != "" && jpushid != rid {
-		userid := qutil.BsonIdToSId((*user)["_id"])
+		userid := BsonIdToSId((*user)["_id"])
 		go func() {
 			mongodb.UpdateById("user", userid, map[string]interface{}{
 				"$pull": map[string]interface{}{"a_jpushid": rid},

+ 1 - 2
src/jfw/modules/app/src/app/front/shorturl.go

@@ -26,7 +26,6 @@ func init() {
 }
 
 var regex = regexp.MustCompile("(Android|Mobile)")
-var mongodbEnt = public.MQFWENT
 
 var Map_stype = map[string]bool{
 	"content":   true,
@@ -101,7 +100,7 @@ func isbid(typ interface{}) bool {
 
 func getwinnertel(company interface{}) string {
 	if company != nil {
-		data, _ := mongodbEnt.FindOne("winner_enterprise", map[string]interface{}{
+		data, _ := public.Mgo_Ent.FindOne("winner_enterprise", map[string]interface{}{
 			"company_name": util.ObjToString(company),
 		})
 		if (*data)["company_phone"] != nil {

+ 3 - 64
src/jfw/modules/app/src/app/front/swordfish.go

@@ -2,7 +2,6 @@ package front
 
 import (
 	appconfig "app/config"
-	"app/filter"
 	. "app/jyutil"
 	"encoding/json"
 	"fmt"
@@ -10,7 +9,7 @@ import (
 	"jfw/public"
 	"log"
 	"math/rand"
-	"net/http"
+	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/jy"
@@ -19,10 +18,8 @@ import (
 	"strings"
 	"sync"
 	"time"
-	uc "ucbsutil"
 
 	"github.com/go-xweb/httpsession"
-	"github.com/gocql/gocql"
 	. "github.com/thinxer/go-word2vec"
 	"gopkg.in/mgo.v2/bson"
 )
@@ -497,7 +494,7 @@ func (m *Front) WxsearchlistPaging() {
 						secondKWS = ""
 					}
 				}
-				SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "app", "超级搜索", map[string]interface{}{
+				public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "app", "超级搜索", map[string]interface{}{
 					"search_word":        searchvalue,
 					"search_area":        scope,
 					"search_price":       []string{minprice, maxprice},
@@ -784,7 +781,7 @@ func MFollow(userId, pname, pcode, title string) (bool, string) {
 			pn, _ := v["s_projectname"].(string)
 			if (pc != "" && pc == pcode) || (pn != "" && pn == pname) {
 				followFlag = true
-				followId = util.EncodeArticleId2ByCheck(util.BsonIdToSId(v["_id"]))
+				followId = util.EncodeArticleId2ByCheck(BsonIdToSId(v["_id"]))
 				break
 			}
 		}
@@ -972,64 +969,6 @@ func (m *Front) DelOL() error {
 	return nil
 }
 
-//保存用户搜索日志
-
-func SaveUserSearchLog(request *http.Request, userId string, count int64, platform, source string, condition map[string]interface{}) {
-	go func() {
-		data := map[string]interface{}{
-			"ip":     filter.GetIp(request),
-			"count":  count,
-			"openid": userId,
-			"pform":  platform,
-			"source": source,
-			"date":   time.Now(),
-			"uagent": request.Header.Get("User-Agent"),
-		}
-		for _, v := range []string{"pagenum", "pagesize", "search_word", "search_area", "search_publishtime", "search_industry", "search_price", "search_type"} {
-			if vv := condition[v]; vv != nil {
-				//替换key
-				if v == "search_word" {
-					v = "word"
-				} else if v == "search_area" {
-					v = "area"
-				} else if v == "search_publishtime" {
-					v = "ptime"
-				} else if v == "search_industry" {
-					v = "indst"
-				} else if v == "search_price" {
-					v = "price"
-				} else if v == "search_type" {
-					v = "type"
-				} else if v == "pagenum" {
-					v = "pnum"
-				} else if v == "pagesize" {
-					v = "psize"
-				}
-				data[v] = vv
-			}
-		}
-		data["id"] = uc.DayShortTime()
-		data["tuid"] = gocql.TimeUUID()
-		if public.MQLOG.Save("jy_search", data) == "" {
-			data := map[string]interface{}{
-				"ip":         filter.GetIp(request),
-				"count":      count,
-				"s_userid":   userId, //之前存的openid,用户合并以后存userid
-				"platform":   platform,
-				"source":     source,
-				"createtime": time.Now().Unix(),
-				"userAgent":  request.Header.Get("User-Agent"),
-			}
-			for _, v := range []string{"pagenum", "pagesize", "search_word", "search_area", "search_publishtime", "search_industry", "search_price", "search_type"} {
-				if vv := condition[v]; vv != nil {
-					data[v] = vv
-				}
-			}
-			mongodb.Save("jy_search_log", data)
-		}
-	}()
-}
-
 func updateUserApppushunread(userid string) {
 	mongodb.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_apppushunread": 0}})
 }

+ 0 - 7
src/jfw/modules/app/src/config.json

@@ -1,11 +1,4 @@
 {
-    "mongodbServers": "192.168.3.128:27080",
-    "mongodbPoolSize": "5",
-    "mongodbName": "qfw",
-	"mongodbServersEnt": "192.168.3.128:27080",
-    "mongodbNameEnt": "extract_v3",
-	"mongodbServersLog": "192.168.3.128:27080",
-    "mongodbNameLog": "qfw",
     "influxaddr": "http://192.168.3.207:8086",
     "influxdb": "jy_logs",
     "elasticsearch": "http://192.168.3.128:9800",

+ 19 - 0
src/jfw/modules/app/src/mongodb.json

@@ -0,0 +1,19 @@
+{
+	"main":{
+		"address": "192.168.3.128:27080",
+ 		"size": 5,
+ 		"dbName": "qfw"
+	},
+	"log":{
+		"address": "192.168.3.128:27080",
+ 		"size": 5,
+ 		"dbName": "qfw",
+		"userName": "admin",
+		"password": "123456"
+	},
+	"ent":{
+		"address": "192.168.3.128:27080",
+ 		"size": 5,
+ 		"dbName": "extract_v3"
+	}
+}

+ 66 - 0
src/jfw/modules/common/src/qfw/util/jy/checksendmsg.go

@@ -0,0 +1,66 @@
+package jy
+
+import (
+	"fmt"
+	"log"
+	"net/url"
+	"qfw/util"
+	"qfw/util/redis"
+
+	//"strconv"
+	"strings"
+	"time"
+)
+
+var se *util.SimpleEncrypt = &util.SimpleEncrypt{Key: "topnet2015topnet2015"}
+var ActivityEndCode, ActivityStartCode int64
+var AC = &util.AES_CBC{
+	Key: "mGlAgnIBB8bx2nch",
+	Iv:  "1389461544135476",
+}
+
+//发短信,验证token
+func CheckSendMsg(token string) string {
+	if token == "" {
+		return ""
+	}
+	log.Println("短信解析前token", token)
+	key := fmt.Sprintf("smstoken_%s", token)
+	ok, e := redis.Exists("other", key)
+	if e != nil {
+		log.Println("redis中token error", e)
+		return ""
+	}
+	if ok {
+		log.Println("redis中token已存在", token)
+		return ""
+	}
+	token, e = url.QueryUnescape(token)
+	if e != nil {
+		log.Println("短信token QueryUnescape error", e)
+	}
+	v, err := AC.Decrypt(token)
+	if err != nil {
+		log.Println("短信token Decrypt error", err)
+		return ""
+	}
+	log.Println("短信解析后token", v)
+	vs := strings.Split(v, "_")
+	if len(vs) != 3 {
+		log.Println("短信token error", vs)
+		return ""
+	}
+	now := time.Now()
+	if !strings.HasPrefix(vs[1], util.FormatDate(&now, util.Date_yyyyMMdd)) {
+		log.Println("短信token date错误", vs)
+		return ""
+	}
+	if vs[2] != util.GetMd5String(fmt.Sprintf("%s&%s", vs[0], vs[1])) {
+		log.Println("短信token sing错误", vs)
+		return ""
+	}
+	if vs[0] != "" {
+		redis.Put("other", key, 1, 86400)
+	}
+	return vs[0]
+}

+ 298 - 0
src/jfw/modules/common/src/qfw/util/jy/entnichepush.go

@@ -0,0 +1,298 @@
+package jy
+
+import (
+	"encoding/json"
+	"fmt"
+	"log"
+	mg "qfw/mongodb"
+	. "qfw/util"
+	"qfw/util/elastic"
+	"qfw/util/mysql"
+	"qfw/util/redis"
+	"strings"
+	"time"
+
+	"gopkg.in/mgo.v2/bson"
+)
+
+var EntnichePush = &entnichePush{}
+
+type entnichePush struct {
+}
+
+//从pushcache_2_a中取
+func (e *entnichePush) GetTodayCache(entId, userId int) (*SubPush, error) {
+	pc_a, err := redis.GetNewBytes("pushcache_2_b", e.todayKey(entId, userId))
+	if err != nil {
+		return nil, err
+	}
+	if pc_a == nil {
+		return nil, nil
+	}
+	var p *SubPush
+	if err := json.Unmarshal(*pc_a, &p); err != nil {
+		return nil, err
+	}
+	return p, nil
+}
+
+//往pushcache_2_a中放
+func (e *entnichePush) PutTodayCache(entId, userId int, pc_a *SubPush) {
+	redis.Put("pushcache_2_b", e.todayKey(entId, userId), pc_a, threeDay)
+}
+
+//获取redis key
+func (e *entnichePush) todayKey(entId, userId int) string {
+	return fmt.Sprintf("entnichepush_%d_%d", entId, userId)
+}
+
+func (e *entnichePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId, userId int, pageNum int, selectTime, area string) (hasNextPage bool, result []*SubPushList) {
+	if pageNum < 1 {
+		pageNum = 1
+	}
+	now := NowFormat(Date_Short_Layout)
+	start := (pageNum - 1) * pageSize
+	end := start + pageSize
+	if now == selectTime && area == "" {
+		subPush, err := e.GetTodayCache(entId, userId)
+		if err != nil {
+			log.Println(userId, "GetTodayCache Error", err)
+		}
+		if err != nil || subPush == nil || subPush.Date != now || len(subPush.Datas) == 0 {
+			list := e.getDatasFromMysql(MQFW, PushMysql, entId, userId, pageNum, pageSize, selectTime, area, false)
+			subPush = &SubPush{
+				Date:  now,
+				Datas: list,
+			}
+			e.PutTodayCache(entId, userId, subPush)
+		}
+		length := len(subPush.Datas)
+		if end > length {
+			end = length
+		}
+		if start < length {
+			result = subPush.Datas[start:end]
+		}
+	} else if selectTime == "" && area == "" && pageNum <= 5 {
+		allCache, err := e.GetAllCache(entId, userId)
+		if err != nil {
+			log.Println(userId, "GetAllCache Error", err)
+		}
+		if err != nil || allCache == nil || len(allCache) == 0 {
+			allCache = e.getDatasFromMysql(MQFW, PushMysql, entId, userId, 1, AllSubPushCacheSize, selectTime, area, true)
+			e.PutAllCache(entId, userId, allCache)
+		}
+		length := len(allCache)
+		if end > length {
+			end = length
+		}
+		if start < length {
+			result = allCache[start:end]
+		}
+	} else {
+		result = e.getDatasFromMysql(MQFW, PushMysql, entId, userId, pageNum, pageSize, selectTime, area, true)
+	}
+	if result == nil {
+		result = []*SubPushList{}
+	}
+	hasNextPage = len(result) >= pageSize
+	return
+}
+func (e *entnichePush) getDatasFromMysql(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId, userId int, pageNum, myPageSize int, selectTime, area string, isLimit bool) (result []*SubPushList) {
+	findSQL := "select id,date,infoid,isvisit,matchkeys,type,1 as isvip from pushentniche where entid=" + fmt.Sprint(entId) + " and userid=" + fmt.Sprint(userId)
+	findStr := ""
+	if selectTime != "" {
+		startTime := selectTime + " 00:00:00"
+		endTime := selectTime + " 23:59:59"
+		st, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, time.Local)
+		et, _ := time.ParseInLocation("2006-01-02 15:04:05", endTime, time.Local)
+		findStr += " and date < " + fmt.Sprint(et.Unix()) + " and date >= " + fmt.Sprint(st.Unix())
+	}
+	if area != "" {
+		findStr += " and area in ("
+		var _area = ""
+		for _, v := range strings.Split(area, ",") {
+			if v == "全部" {
+				continue
+			}
+			if _area != "" {
+				_area += ","
+			}
+			_area += fmt.Sprint(PushMapping.Area[v])
+		}
+		findStr += _area + ")"
+	}
+	start := (pageNum - 1) * myPageSize
+	findStr += " order by id desc"
+	if isLimit {
+		findStr += " limit " + fmt.Sprint(start) + "," + fmt.Sprint(myPageSize)
+	}
+	findSQL = findSQL + findStr
+	//log.Println("findsql:", findSQL)
+	list := PushMysql.SelectBySql(findSQL)
+	if len(*list) > 0 {
+		pushCas := e.GetJyPushs(*list)
+		result = e.GetInfoByIds(MQFW, pushCas)
+	} else {
+		result = []*SubPushList{}
+	}
+	return
+}
+
+//获取历史推送
+func (e *entnichePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*PushCa) {
+	pushCas = []*PushCa{}
+	for _, v := range datas {
+		pushCas = append(pushCas, &PushCa{
+			Date:   Int64All(v["date"]),
+			InfoId: ObjToString(v["infoid"]),
+			Visit:  IntAll(v["isvisit"]),
+			Index:  Int64All(v["id"]),
+			Keys:   strings.Split(ObjToString(v["matchkeys"]), " "),
+			Type:   IntAll(v["type"]),
+			Isvip:  IntAll(v["isvip"]),
+		})
+	}
+	return
+}
+
+//根据id取内容
+func (e *entnichePush) GetInfoByIds(MQFW mg.MongodbSim, pushCas []*PushCa) []*SubPushList {
+	array := make([]*SubPushList, len(pushCas))
+	if len(pushCas) == 0 {
+		return array
+	}
+	m := map[string]bool{}
+	ids := []string{}
+	for _, v := range pushCas {
+		if m[v.InfoId] {
+			continue
+		}
+		m[v.InfoId] = true
+		ids = append(ids, v.InfoId)
+	}
+	infos := map[string]map[string]interface{}{}
+	//redis
+
+	es_ids := []string{}
+	for _, v := range ids {
+		info_i := redis.Get("pushcache_1", fmt.Sprintf("info_%d", v))
+		if info_i != nil {
+			info_m, _ := info_i.(map[string]interface{})
+			info_m["_id"] = v
+			infos[v] = info_m
+		} else {
+			es_ids = append(es_ids, v)
+		}
+	}
+	//	log.Println(es_ids)
+	//elasticsearch
+	if len(es_ids) > 0 {
+		list := elastic.Get("bidding", "bidding", fmt.Sprintf(query, strings.Join(es_ids, `","`), len(es_ids)))
+		if list != nil {
+			for _, v := range *list {
+				_id := ObjToString(v["_id"])
+				infos[_id] = v
+			}
+		}
+	}
+	//mongodb bidding
+	mgo_ids := []bson.ObjectId{}
+	for _, v := range es_ids {
+		if infos[v] == nil {
+			mgo_ids = append(mgo_ids, bson.ObjectIdHex(v))
+		}
+	}
+	if len(mgo_ids) > 0 {
+		list, ok := MQFW.Find("bidding", map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
+		if ok && *list != nil {
+			for _, v := range *list {
+				_id := mg.BsonIdToSId(v["_id"])
+				v["_id"] = _id
+				infos[_id] = v
+			}
+		}
+	}
+	//mongodb bidding_back
+	mgo_back_ids := []bson.ObjectId{}
+	for _, v := range mgo_ids {
+		if infos[mg.BsonIdToSId(v)] == nil {
+			mgo_back_ids = append(mgo_back_ids, v)
+		}
+	}
+	if len(mgo_back_ids) > 0 {
+		list, ok := MQFW.Find("bidding_back", map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
+		if ok && *list != nil {
+			for _, v := range *list {
+				_id := mg.BsonIdToSId(v["_id"])
+				v["_id"] = _id
+				infos[_id] = v
+			}
+		}
+	}
+	//
+	for k, v := range pushCas {
+		info := infos[v.InfoId]
+		if info == nil {
+			info = map[string]interface{}{}
+		}
+		array[k] = SubscribePush.InfoFormat(v, &info)
+	}
+	return array
+}
+
+func (e *entnichePush) Visit(PushMysql *mysql.Mysql, entId, userId, id int) {
+	if id <= 0 {
+		return
+	}
+	PushMysql.UpdateOrDeleteBySql("update pushentniche set isvisit=1 where userid=? and id=?", userId, id)
+	todaySubPush, err := e.GetTodayCache(entId, userId)
+	if err == nil && todaySubPush != nil {
+		for _, v := range todaySubPush.Datas {
+			if v.Ca_index == Int64All(id) {
+				v.Ca_isvisit = 1
+				break
+			}
+		}
+		e.PutTodayCache(entId, userId, todaySubPush)
+	}
+	//
+	allSubPush, err := e.GetAllCache(entId, userId)
+	if err == nil && allSubPush != nil {
+		for _, v := range allSubPush {
+			if v.Ca_index == Int64All(id) {
+				v.Ca_isvisit = 1
+				break
+			}
+		}
+		e.PutAllCache(entId, userId, allSubPush)
+	}
+}
+
+//查看全部列表缓存
+func (e *entnichePush) allKey(entId, userId int) string {
+	return fmt.Sprintf("all_entnichepush_%d_%d", entId, userId)
+}
+
+func (e *entnichePush) PutAllCache(entId, userId int, datas []*SubPushList) {
+	redis.Put("pushcache_2_a", e.allKey(entId, userId), datas, threeDay)
+}
+
+func (e *entnichePush) GetAllCache(entId, userId int) ([]*SubPushList, error) {
+	return e.GetCache("pushcache_2_a", e.allKey(entId, userId))
+}
+
+func (e *entnichePush) GetCache(code, key string) ([]*SubPushList, error) {
+	pc_a, err := redis.GetNewBytes(code, key)
+	if err != nil {
+		return nil, err
+	}
+	if pc_a == nil {
+		return nil, nil
+	}
+	var p []*SubPushList
+	if err := json.Unmarshal(*pc_a, &p); err != nil {
+		return nil, err
+	}
+	return p, nil
+}

+ 89 - 0
src/jfw/modules/common/src/qfw/util/jy/historypush.go

@@ -0,0 +1,89 @@
+package jy
+
+import (
+	"encoding/json"
+	"fmt"
+	"qfw/util/redis"
+)
+
+/*A缓存中存这个结构体,B缓存不存
+ *B缓存初始化的时候,根据A缓存中改结构体type和count属性,判断查询半年内还是半年前年还是半年内+半年前的数据,减少查询次数
+ *type==1,如果count==0,说明A缓存中正好500条数据,B缓存可以直接查半年前的数据
+ *如果count>0,说明半年内的数据在A缓存中已经有了count条,B缓存取的时候要从count后面开始取
+ *type==2,如果count==0,说明A缓存中正好500条数据,B缓存没有可以查询的数据
+ *如果count>0,说明半年前的数据在A缓存中已经有了count条,B缓存取的时候要从count后面开始取
+ *type==3,如果count==0,说明半年内+半年前的数据正好500条,B缓存没有可以查询的数据
+ *如果count>0,说明半年前的数据在A缓存中已经有了count条,B缓存取的时候要从count后面开始取
+ */
+type PushSub struct {
+	Type  int //数据构成:1 半年内 2 半年前 3 半年内+半年前
+	Count int
+	Infos []map[string]interface{} //该缓存的数据
+}
+
+var HistoryPush = &historyPush{}
+
+type historyPush struct{}
+
+//从pushcache_2_a中取
+func (h *historyPush) GetPushCache_A(userId string) (*PushSub, error) {
+	pc_a, err := redis.GetNewBytes("pushcache_2_a", h.redisKey(userId))
+	if err != nil {
+		return nil, err
+	}
+	if pc_a == nil {
+		return nil, nil
+	}
+	var p *PushSub
+	if err := json.Unmarshal(*pc_a, &p); err != nil {
+		return nil, err
+	}
+	return p, nil
+}
+
+//往pushcache_2_a中放
+func (h *historyPush) PutPushCache_A(userId string, pc_a *PushSub) {
+	if pc_a.Infos == nil || len(pc_a.Infos) == 0 {
+		return
+	}
+	redis.Put("pushcache_2_a", h.redisKey(userId), pc_a, threeDay)
+}
+
+//从pushcache_2_b中取
+func (h *historyPush) GetPushCache_B(userId string) ([]map[string]interface{}, error) {
+	pc_b, err := redis.GetNewBytes("pushcache_2_b", h.redisKey(userId))
+	if err != nil {
+		return nil, err
+	}
+	if pc_b == nil {
+		return nil, nil
+	}
+	var l []map[string]interface{}
+	if err := json.Unmarshal(*pc_b, &l); err != nil {
+		return nil, err
+	}
+	return l, nil
+}
+
+//往pushcache_2_b中放
+func (h *historyPush) PutPushCache_B(userId string, pc_b []map[string]interface{}) {
+	if pc_b == nil || len(pc_b) == 0 {
+		return
+	}
+	redis.Put("pushcache_2_b", h.redisKey(userId), pc_b, halfOfDay)
+}
+
+//获取redis key
+func (h *historyPush) redisKey(userId string) string {
+	return fmt.Sprintf("push_%s", userId)
+}
+
+func (h *historyPush) ClearPushCache(userId string) {
+	redis.Del("pushcache_2_a", h.redisKey(userId))
+	redis.Del("pushcache_2_b", h.redisKey(userId))
+}
+
+//历史推送记录中单条信息格式化
+func (h *historyPush) InfoFormat(p *PushCa, oldInfo *map[string]interface{}) *SubPushList {
+	return SubscribePush.InfoFormat(p, oldInfo)
+}

+ 199 - 0
src/jfw/modules/common/src/qfw/util/jy/jy.go

@@ -0,0 +1,199 @@
+package jy
+
+import (
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"log"
+	"net/http"
+	"net/url"
+	"qfw/util"
+	"qfw/util/mail"
+	"qfw/util/sms"
+	"regexp"
+	"strings"
+	"time"
+
+	"github.com/go-xweb/httpsession"
+)
+
+//获取用户合并以前,合并以后的openid
+func GetOldOpenid(s_m_openid, a_m_openid, s_phone string, mergeorder interface{}) string {
+	a_mergeorder, _ := mergeorder.([]interface{})
+	openid := ""
+	if len(a_mergeorder) > 0 {
+		first, _ := a_mergeorder[0].(string)
+		if first == "s_m_openid" {
+			openid = s_m_openid
+		} else if first == "a_m_openid" {
+			openid = a_m_openid
+		} else if first == "s_phone" {
+			openid = s_phone
+		}
+	} else {
+		if s_m_openid != "" {
+			openid = s_m_openid
+		} else if a_m_openid != "" {
+			openid = a_m_openid
+		} else if s_phone != "" {
+			openid = s_phone
+		}
+	}
+	return openid
+}
+
+var MatchSpace = regexp.MustCompile("\\s+")
+var filterReg_3 = regexp.MustCompile("(项目|公告|公示)$")
+var filterReg_2 = regexp.MustCompile("^[)\\)>》】\\]}}〕,,;;::'\"“”。.\\??、/+=\\_—*&……\\^%$¥@!!`~·(\\(<《【\\[{{〔]+$")
+var filterReg_1 = regexp.MustCompile("^([0-9]{1,3}|[零一二三四五六七八九十]{1,2}|联系人?|电话|地址|编号|采购|政府采购|成交|更正|招标|中标|变更|结果)$")
+var filterReg = regexp.MustCompile("^[的人号时元万公告项目地址电话邮编日期联系招标中结果成交项目项目采购采购项目政府采购公告更正公告]+$")
+
+func FilteKey(k string) string {
+	k = strings.TrimSpace(k)
+	k = filterReg_3.ReplaceAllString(k, "")
+	k = filterReg_2.ReplaceAllString(k, "")
+	k = filterReg_1.ReplaceAllString(k, "")
+	k = filterReg.ReplaceAllString(k, "")
+	return k
+}
+
+//超过20个字,截断
+//返回截取后的字符串和截取掉中的前3个字
+func InterceptSearchKW(word string, isIntercept, isFilter bool) (b_word, a_word, s_word string) {
+	if isFilter {
+		word = FilteKey(word)
+	}
+	word = MatchSpace.ReplaceAllString(strings.TrimSpace(word), " ")
+	words := []rune(word)
+	if len(words) > 20 && isIntercept {
+		b_word = string(words[:20])
+		b_word = strings.TrimSpace(b_word)
+		if len(words) > 23 {
+			a_word = string(words[20:23])
+		} else {
+			a_word = string(words[20:])
+		}
+	} else {
+		b_word = word
+	}
+	a_word = strings.TrimSpace(a_word)
+	s_word = MatchSpace.ReplaceAllString(b_word, "+")
+	return
+}
+
+//
+func HttpEs(ques, analyzer, esAddress string) (res string) {
+	surl := esAddress + "/bidding/_analyze"
+	URL, _ := url.Parse(surl)
+	Q := URL.Query()
+	Q.Add("text", ques)
+	Q.Add("analyzer", analyzer)
+	URL.RawQuery = Q.Encode()
+	resp, err := http.Get(URL.String())
+	if err != nil {
+		log.Println("err1:")
+	} else {
+		result, err := ioutil.ReadAll(resp.Body)
+		if err == nil {
+			defer resp.Body.Close()
+			var resmap map[string]interface{}
+			json.Unmarshal(result, &resmap)
+			if resmap != nil {
+				tokens := util.ObjArrToMapArr(resmap["tokens"].([]interface{}))
+				for k, v := range tokens {
+					if FilteKey(util.ObjToString(v["token"])) != "" {
+						if k > 0 {
+							res += "+"
+						}
+						res += util.ObjToString(v["token"])
+					}
+				}
+			}
+		}
+	}
+	return
+}
+
+//发送邮箱验证码
+func SendMailIdentCode(to, code string, auth []*mail.GmailAuth) bool {
+	html := fmt.Sprintf(`<div>
+		<div>
+			%s,您好!
+		</div>
+		<div style="padding: 20px 70px 10px 70px;">
+			<p>您正在进行绑定邮箱地址验证,请在邮件验证码输入框输入下方验证码:</p>
+			<span style="font-weight: bold;font-size: x-large;">%s</span>
+			<p>请勿向任何人泄露您收到的验证码。</p>
+			<p>如果您没有使用剑鱼标讯,请忽略此邮件。</p>
+			<p>此为系统邮件,请勿回复。</p>
+			<p>如有疑问,请联系客服 400-108-6670。</p>
+		</div>
+		<div>
+			<p>此致</p>
+			<p>剑鱼标讯</p>
+		</div>	
+	</div>`, to, code)
+
+	for k, v := range auth {
+		if mail.GSendMail("剑鱼标讯", to, "", "", "剑鱼标讯邮箱校验", html, "", "", v) {
+			log.Println(to, fmt.Sprintf("使用%s发送邮件成功", v.User))
+			return true
+		}
+		if k < len(auth)-1 {
+			log.Println(to, fmt.Sprintf("使用%s发送邮件失败!3s后使用其他邮箱尝试", v.User))
+		} else {
+			log.Println(to, fmt.Sprintf("使用%s发送邮件失败!", v.User))
+		}
+		time.Sleep(time.Second * 3)
+	}
+
+	return false
+}
+
+//根据模板发送短信,模板是运营商设定的。
+//第三个参数是可变参数,可以传入多个,但要和模板相匹配
+func SendSMS(tplcode /*模板代码*/, mobile /*手机号码*/ string, param map[string]string) {
+	tmp := []string{}
+	for k, v := range param {
+		tmp = append(tmp, "#"+k+"#="+v)
+	}
+	text := strings.Join(tmp, "&")
+	sms.SendSms(mobile, tplcode, text)
+}
+
+//发送验证码
+func SendPhoneIdentCode(phone string, session *httpsession.Session) bool {
+	lastSentTime := util.Int64All(session.Get("identCodeTime"))
+	//60秒之内不允许重复发
+	if lastSentTime > 0 && time.Now().Unix()-lastSentTime <= 60 {
+		return false
+	}
+	s_ranNum := util.GetRandom(6) //生成随机数
+	session.Set("identCodeValue", s_ranNum)
+	session.Set("identCodeKey", phone)
+	session.Set("identCodeTime", time.Now().Unix())
+	//发送短信
+	param := make(map[string]string)
+	param["code"] = s_ranNum
+	log.Println("短信验证码", phone, s_ranNum)
+	SendSMS("2828060", phone, param)
+	return true
+}
+
+//短信验证码校验
+func CheckPhoneIdent(session *httpsession.Session, code string) string {
+	identCodeValue, _ := session.Get("identCodeValue").(string)
+	if identCodeValue != "" && identCodeValue == code {
+		identCodeKey, _ := session.Get("identCodeKey").(string)
+		ClearPhoneIdentSession(session)
+		return identCodeKey
+	}
+	return ""
+}
+
+//删除短信验证码有关的session
+func ClearPhoneIdentSession(session *httpsession.Session) {
+	session.Del("identCodeValue")
+	session.Del("identCodeKey")
+	session.Del("identCodeTime")
+}

+ 65 - 0
src/jfw/modules/common/src/qfw/util/jy/pushmapping.go

@@ -0,0 +1,65 @@
+package jy
+
+import (
+	"log"
+	"qfw/util"
+	"qfw/util/mysql"
+)
+
+var PushMapping = &pushMapping{}
+
+type pushMapping struct {
+	Area       map[string]int
+	City       map[string]int
+	Toptype    map[string]int
+	Subtype    map[string]int
+	Buyerclass map[string]int
+}
+
+func (p *pushMapping) Init(Mysql *mysql.Mysql) {
+	infotype := Mysql.SelectBySql("select id,type,name from infotype")
+	p.Toptype = map[string]int{}
+	p.Subtype = map[string]int{}
+	p.Buyerclass = map[string]int{}
+	for _, v := range *infotype {
+		id := util.IntAll(v["id"])
+		tp := util.IntAll(v["type"])
+		name := util.ObjToString(v["name"])
+		if tp == 1 {
+			p.Toptype[name] = id
+		} else if tp == 2 {
+			p.Subtype[name] = id
+		} else if tp == 3 {
+			p.Buyerclass[name] = id
+		}
+	}
+	if len(p.Toptype) == 0 {
+		log.Fatalln("PushMapping Toptype Init Error")
+	}
+	if len(p.Subtype) == 0 {
+		log.Fatalln("PushMapping Subtype Init Error")
+	}
+	if len(p.Buyerclass) == 0 {
+		log.Fatalln("PushMapping Buyerclass Init Error")
+	}
+	//
+	p.Area = map[string]int{}
+	p.City = map[string]int{}
+	province := Mysql.SelectBySql("select id,level,name from province")
+	for _, v := range *province {
+		id := util.IntAll(v["id"])
+		level := util.IntAll(v["level"])
+		name := util.ObjToString(v["name"])
+		if level == 1 {
+			p.Area[name] = id
+		} else if level == 2 {
+			p.City[name] = id
+		}
+	}
+	if len(p.Area) == 0 {
+		log.Fatalln("PushMapping Area Init Error")
+	}
+	if len(p.City) == 0 {
+		log.Fatalln("PushMapping City Init Error")
+	}
+}

+ 511 - 0
src/jfw/modules/common/src/qfw/util/jy/subscribepush.go

@@ -0,0 +1,511 @@
+package jy
+
+import (
+	"encoding/json"
+	"fmt"
+	"log"
+	mg "qfw/mongodb"
+	. "qfw/util"
+	"qfw/util/elastic"
+	"qfw/util/mysql"
+	"qfw/util/redis"
+	"strings"
+	"time"
+
+	"gopkg.in/mgo.v2/bson"
+)
+
+const (
+	threeDay  = 172800
+	halfOfDay = 43200
+)
+
+type SubPushList struct {
+	Id              string      `json:"_id"`
+	Title           string      `json:"title"`
+	Area            string      `json:"area"`
+	Buyerclass      string      `json:"buyerclass"`
+	Type            string      `json:"type"`
+	S_subscopeclass string      `json:"s_subscopeclass"`
+	Publishtime     int64       `json:"publishtime"`
+	Ca_index        int64       `json:"ca_index"`
+	Ca_date         int64       `json:"ca_date"`
+	Ca_isvisit      int         `json:"ca_isvisit"`
+	Ca_isvip        int         `json:"ca_isvip"`
+	Ca_type         int         `json:"ca_type"`
+	Matchkeys       []string    `json:"matchkeys"`
+	Budget          interface{} `json:"budget"`
+	Bidamount       interface{} `json:"bidamount"`
+}
+
+const (
+	pageSize            = 50
+	AllSubPushCacheSize = 250
+	query               = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","area", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "buyerclass","bidamount","budget"],"from":0,"size":%d}`
+	mongodb_fields      = `{"_id":1,"area":1,"publishtime":1,"s_subscopeclass":1,"subtype":1,"title":1,"toptype":1,"type":1, "buyerclass":1,"budget":1,"bidamount":1}`
+)
+
+var Mysql_table = "pushsubscribe"
+
+//
+
+type SubPush struct {
+	Date  string
+	Datas []*SubPushList
+}
+
+type PushCa struct {
+	Date   int64
+	InfoId string
+	Visit  int
+	Index  int64
+	Keys   []string
+	Type   int
+	Isvip  int
+}
+
+var SubscribePush = &subscribePush{}
+
+type subscribePush struct {
+}
+
+//从pushcache_2_a中取
+func (h *subscribePush) GetTodayCache(userId string) (*SubPush, error) {
+	pc_a, err := redis.GetNewBytes("pushcache_2_b", h.todayKey(userId))
+	if err != nil {
+		return nil, err
+	}
+	if pc_a == nil {
+		return nil, nil
+	}
+	var p *SubPush
+	if err := json.Unmarshal(*pc_a, &p); err != nil {
+		return nil, err
+	}
+	return p, nil
+}
+
+//往pushcache_2_a中放
+func (h *subscribePush) PutTodayCache(userId string, pc_a *SubPush) {
+	redis.Put("pushcache_2_b", h.todayKey(userId), pc_a, threeDay)
+}
+
+//获取redis key
+func (s *subscribePush) todayKey(userId string) string {
+	return fmt.Sprintf("subpush_%s", userId)
+}
+
+//历史推送记录中单条信息格式化
+func (s *subscribePush) InfoFormat(p *PushCa, info *map[string]interface{}) *SubPushList {
+	area := ObjToString((*info)["area"])
+	if area == "A" {
+		area = "全国"
+	}
+	industry := ObjToString((*info)["s_subscopeclass"])
+	scs := strings.Split(industry, ",")
+	if len(scs) > 0 {
+		industry = scs[0]
+		if industry != "" {
+			iss := strings.Split(industry, "_")
+			if len(iss) > 0 {
+				industry = iss[0]
+			}
+		}
+	}
+	infotype := ObjToString((*info)["subtype"])
+	if infotype == "" {
+		infotype = ObjToString((*info)["toptype"])
+	}
+	if infotype == "" {
+		infotype = ObjToString((*info)["type"])
+		if infotype == "tender" {
+			infotype = "招标"
+		} else if infotype == "bid" {
+			infotype = "中标"
+		}
+	}
+	_id := p.InfoId
+	if _id == "" {
+		_id = ObjToString((*info)["_id"])
+	}
+	return &SubPushList{
+		Id:              EncodeArticleId2ByCheck(_id),
+		Title:           ObjToString((*info)["title"]),
+		Area:            area,
+		Buyerclass:      ObjToString((*info)["buyerclass"]),
+		Type:            infotype,
+		S_subscopeclass: industry,
+		Publishtime:     Int64All((*info)["publishtime"]),
+		Ca_index:        p.Index,
+		Ca_date:         p.Date,
+		Ca_isvisit:      p.Visit,
+		Ca_isvip:        p.Isvip,
+		Ca_type:         p.Type,
+		Matchkeys:       p.Keys,
+		Budget:          (*info)["budget"],
+		Bidamount:       (*info)["bidamount"],
+	}
+}
+
+func (s *subscribePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId string, pageNum int, selectTime, area string) (hasNextPage bool, result []*SubPushList) {
+	if userId == "" {
+		return
+	}
+	if pageNum < 1 {
+		pageNum = 1
+	}
+	now := NowFormat(Date_Short_Layout)
+	start := (pageNum - 1) * pageSize
+	end := start + pageSize
+	if now == selectTime && area == "" {
+		subPush, err := s.GetTodayCache(userId)
+		if err != nil {
+			log.Println(userId, "GetTodayCache Error", err)
+		}
+		if err != nil || subPush == nil || subPush.Date != now || len(subPush.Datas) == 0 {
+			list := s.getDatasFromMysql(MQFW, PushMysql, userId, pageNum, pageSize, selectTime, area, false)
+			subPush = &SubPush{
+				Date:  now,
+				Datas: list,
+			}
+			s.PutTodayCache(userId, subPush)
+		}
+		length := len(subPush.Datas)
+		if end > length {
+			end = length
+		}
+		if start < length {
+			result = subPush.Datas[start:end]
+		}
+	} else if selectTime == "" && area == "" && pageNum <= 5 {
+		allCache, err := s.GetAllCache(userId)
+		if err != nil {
+			log.Println(userId, "GetAllCache Error", err)
+		}
+		if err != nil || allCache == nil || len(allCache) == 0 {
+			allCache = s.getDatasFromMysql(MQFW, PushMysql, userId, 1, AllSubPushCacheSize, selectTime, area, true)
+			s.PutAllCache(userId, allCache)
+		}
+		length := len(allCache)
+		if end > length {
+			end = length
+		}
+		if start < length {
+			result = allCache[start:end]
+		}
+	} else {
+		result = s.getDatasFromMysql(MQFW, PushMysql, userId, pageNum, pageSize, selectTime, area, true)
+	}
+	if result == nil {
+		result = []*SubPushList{}
+	}
+	hasNextPage = len(result) >= pageSize
+	return
+}
+func (s *subscribePush) getDatasFromMysql(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId string, pageNum, myPageSize int, selectTime, area string, isLimit bool) (result []*SubPushList) {
+	findSQL := "select id,date,infoid,isvisit,matchkeys,type,isvip from pushsubscribe where userid = '" + userId + "'"
+	findStr := ""
+	if selectTime != "" {
+		startTime := selectTime + " 00:00:00"
+		endTime := selectTime + " 23:59:59"
+		st, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, time.Local)
+		et, _ := time.ParseInLocation("2006-01-02 15:04:05", endTime, time.Local)
+		findStr += " and date < " + fmt.Sprint(et.Unix()) + " and date >= " + fmt.Sprint(st.Unix())
+	}
+	if area != "" {
+		findStr += " and city in ("
+		var _area = ""
+		for _, v := range strings.Split(area, ",") {
+			if v == "全部" {
+				continue
+			}
+			if _area != "" {
+				_area += ","
+			}
+			_area += fmt.Sprint(PushMapping.City[v])
+		}
+		findStr += _area + ")"
+	}
+	start := (pageNum - 1) * myPageSize
+	findStr += " order by id desc"
+	if isLimit {
+		findStr += " limit " + fmt.Sprint(start) + "," + fmt.Sprint(myPageSize)
+	}
+	findSQL = findSQL + findStr
+	//	log.Println("findsql:", findSQL)
+	list := PushMysql.SelectBySql(findSQL)
+	if len(*list) > 0 {
+		pushCas := s.GetJyPushs(*list)
+		result = s.GetInfoByIds(MQFW, pushCas)
+	} else {
+		result = []*SubPushList{}
+	}
+	return
+}
+
+//获取历史推送
+func (s *subscribePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*PushCa) {
+	pushCas = []*PushCa{}
+	for _, v := range datas {
+		pushCas = append(pushCas, &PushCa{
+			Date:   Int64All(v["date"]),
+			InfoId: ObjToString(v["infoid"]),
+			Visit:  IntAll(v["isvisit"]),
+			Index:  Int64All(v["id"]),
+			Keys:   strings.Split(ObjToString(v["matchkeys"]), " "),
+			Type:   IntAll(v["type"]),
+			Isvip:  IntAll(v["isvip"]),
+		})
+	}
+	return
+}
+
+//根据id取内容
+func (s *subscribePush) GetInfoByIds(MQFW mg.MongodbSim, pushCas []*PushCa) []*SubPushList {
+	array := make([]*SubPushList, len(pushCas))
+	if len(pushCas) == 0 {
+		return array
+	}
+	m := map[string]bool{}
+	ids := []string{}
+	for _, v := range pushCas {
+		if m[v.InfoId] {
+			continue
+		}
+		m[v.InfoId] = true
+		ids = append(ids, v.InfoId)
+	}
+	infos := map[string]map[string]interface{}{}
+	//redis
+
+	es_ids := []string{}
+	for _, v := range ids {
+		info_i := redis.Get("pushcache_1", fmt.Sprintf("info_%s", v))
+		if info_i != nil {
+			info_m, _ := info_i.(map[string]interface{})
+			info_m["_id"] = v
+			infos[v] = info_m
+		} else {
+			es_ids = append(es_ids, v)
+		}
+	}
+	//	log.Println(es_ids)
+	//elasticsearch
+	if len(es_ids) > 0 {
+		list := elastic.Get("bidding", "bidding", fmt.Sprintf(query, strings.Join(es_ids, `","`), len(es_ids)))
+		if list != nil {
+			for _, v := range *list {
+				_id := ObjToString(v["_id"])
+				infos[_id] = v
+			}
+		}
+	}
+	//mongodb bidding
+	mgo_ids := []bson.ObjectId{}
+	for _, v := range es_ids {
+		if infos[v] == nil {
+			mgo_ids = append(mgo_ids, bson.ObjectIdHex(v))
+		}
+	}
+	if len(mgo_ids) > 0 {
+		list, ok := MQFW.Find("bidding", map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
+		if ok && *list != nil {
+			for _, v := range *list {
+				_id := mg.BsonIdToSId(v["_id"])
+				v["_id"] = _id
+				infos[_id] = v
+			}
+		}
+	}
+	//mongodb bidding_back
+	mgo_back_ids := []bson.ObjectId{}
+	for _, v := range mgo_ids {
+		if infos[mg.BsonIdToSId(v)] == nil {
+			mgo_back_ids = append(mgo_back_ids, v)
+		}
+	}
+	if len(mgo_back_ids) > 0 {
+		list, ok := MQFW.Find("bidding_back", map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
+		if ok && *list != nil {
+			for _, v := range *list {
+				_id := mg.BsonIdToSId(v["_id"])
+				v["_id"] = _id
+				infos[_id] = v
+			}
+		}
+	}
+	//
+	for k, v := range pushCas {
+		info := infos[v.InfoId]
+		if info == nil {
+			info = map[string]interface{}{}
+		}
+		array[k] = s.InfoFormat(v, &info)
+	}
+	return array
+}
+
+//保存最近7天的数据到历史记录
+func (s *subscribePush) MakeHistoryDatas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId string, PushView func(userid, allquery, field string, pageNum, pageSize int) (keys []interface{}, list *[]map[string]interface{})) (bool, []*SubPushList) {
+	log.Println("匹配最近7天数据", userId)
+	field := `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","buyerclass","budget","bidamount"`
+	allquery := `{"range":{"publishtime":{"gt":%s}}}`
+	allquery = fmt.Sprintf(allquery, fmt.Sprint(time.Now().AddDate(0, 0, -7).Unix()))
+	//allquery = ``
+	keys, list := PushView(userId, allquery, field, 1, 50)
+	if list == nil || len(*list) == 0 {
+		return true, nil
+	}
+	matchkeys := []string{}
+	for _, v := range keys {
+		matchkeys = append(matchkeys, strings.Join(ObjArrToStringArr(v.([]interface{})), "+"))
+	}
+	publishTitle := map[string]bool{}
+	now := time.Now().Unix()
+	var array []*SubPushList
+	for i := len(*list) - 1; i >= 0; i-- {
+		v := (*list)[i]
+		var myInsert = make(map[string]interface{})
+		title := strings.Replace(v["title"].(string), "\n", "", -1)
+		area_check := ObjToString(v["area"])
+		if area_check == "A" {
+			area_check = "全国"
+		}
+		if publishTitle[area_check+title] {
+			continue
+		} else {
+			publishTitle[area_check+title] = true
+		}
+		myInsert["userid"] = userId
+		_id := ObjToString(v["_id"])
+		myInsert["infoid"] = _id
+		redisKey := fmt.Sprintf("pushinfo_%s_%s", userId, _id)
+		if isExists, _ := redis.Exists("pushcache_2_a", redisKey); isExists {
+			continue
+		}
+		myInsert["date"] = now
+		myInsert["matchkeys"] = strings.Join(matchkeys, " ")
+		if area_check != "" {
+			if area_check == "全国" {
+				myInsert["area"] = 0
+			} else if area_mapping, ok := PushMapping.Area[area_check]; ok {
+				myInsert["area"] = area_mapping
+			}
+		}
+		if city_check := ObjToString(v["city"]); city_check != "" {
+			if city_mapping, ok := PushMapping.City[city_check]; ok {
+				myInsert["city"] = city_mapping
+			}
+		}
+		if subtype := ObjToString(v["subtype"]); subtype != "" {
+			if subtype_mapping, ok := PushMapping.Subtype[subtype]; ok {
+				myInsert["subtype"] = subtype_mapping
+			}
+		}
+		if toptype := ObjToString(v["toptype"]); toptype != "" {
+			if toptype_mapping, ok := PushMapping.Toptype[toptype]; ok {
+				myInsert["toptype"] = toptype_mapping
+			}
+		}
+		if buyerclass := ObjToString(v["buyerclass"]); buyerclass != "" {
+			if buyerclass_mapping, ok := PushMapping.Buyerclass[buyerclass]; ok {
+				myInsert["buyerclass"] = buyerclass_mapping
+			}
+		}
+		id := PushMysql.Insert("pushsubscribe", myInsert)
+		if id > 0 {
+			redis.Put("pushcache_2_a", redisKey, 1, 86400)
+		} else {
+			continue
+		}
+		array = append(array, s.InfoFormat(&PushCa{
+			InfoId: _id,
+			Date:   now,
+			Index:  id,
+			Keys:   matchkeys,
+		}, &v))
+	}
+	var resultList []*SubPushList
+	for i := len(array) - 1; i >= 0; i-- {
+		resultList = append(resultList, array[i])
+	}
+	return true, resultList
+}
+
+//获取用户信息
+func (s *subscribePush) UserInfo(MQFW mg.MongodbSim, userId string) (*map[string]interface{}, int64) {
+	user, ok := MQFW.FindById("user", userId, `{"s_m_openid":1,"a_m_openid":1,"s_phone":1,"a_mergeorder":1,"o_jy":1,"l_firstpushtime":1,"i_vip_status":1,"l_vip_endtime":1,"o_vipjy":1}`)
+	if !ok || user == nil {
+		return nil, 0
+	}
+	return user, Int64All((*user)["l_firstpushtime"])
+}
+func (s *subscribePush) Visit(PushMysql *mysql.Mysql, userId string, id int) {
+	if userId == "" {
+		return
+	}
+	PushMysql.UpdateOrDeleteBySql("update pushsubscribe set isvisit=1 where userid=? and id=?", userId, id)
+	todaySubPush, err := s.GetTodayCache(userId)
+	if err == nil && todaySubPush != nil {
+		for _, v := range todaySubPush.Datas {
+			if v.Ca_index == Int64All(id) {
+				v.Ca_isvisit = 1
+				break
+			}
+		}
+		s.PutTodayCache(userId, todaySubPush)
+	}
+	//
+	allSubPush, err := s.GetAllCache(userId)
+	if err == nil && allSubPush != nil {
+		for _, v := range allSubPush {
+			if v.Ca_index == Int64All(id) {
+				v.Ca_isvisit = 1
+				break
+			}
+		}
+		s.PutAllCache(userId, allSubPush)
+	}
+}
+
+//查看全部列表缓存
+func (s *subscribePush) allKey(userId string) string {
+	return fmt.Sprintf("all_subpush_%s", userId)
+}
+
+func (s *subscribePush) PutAllCache(userId string, datas []*SubPushList) {
+	redis.Put("pushcache_2_a", s.allKey(userId), datas, threeDay)
+}
+
+func (s *subscribePush) GetAllCache(userId string) ([]*SubPushList, error) {
+	return s.GetCache("pushcache_2_a", s.allKey(userId))
+}
+
+//最近7天50条缓存
+func (s *subscribePush) sevenDayKey(userId string) string {
+	return fmt.Sprintf("7day_subpush_%s", userId)
+}
+
+func (s *subscribePush) PutSevenDayCache(userId string, datas []*SubPushList) {
+	redis.Put("pushcache_2_a", s.sevenDayKey(userId), datas, 7*24*60*60)
+}
+
+//从pushcache_2_a中取
+func (s *subscribePush) GetSevenDayCache(userId string) ([]*SubPushList, error) {
+	return s.GetCache("pushcache_2_a", s.sevenDayKey(userId))
+}
+
+func (s *subscribePush) GetCache(code, key string) ([]*SubPushList, error) {
+	pc_a, err := redis.GetNewBytes(code, key)
+	if err != nil {
+		return nil, err
+	}
+	if pc_a == nil {
+		return nil, nil
+	}
+	var p []*SubPushList
+	if err := json.Unmarshal(*pc_a, &p); err != nil {
+		return nil, err
+	}
+	return p, nil
+}

+ 206 - 0
src/jfw/modules/common/src/qfw/util/jy/user_merge.go

@@ -0,0 +1,206 @@
+package jy
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"log"
+	. "qfw/mongodb"
+	qutil "qfw/util"
+	"qfw/util/redis"
+	"regexp"
+	"strings"
+	"time"
+
+	"github.com/go-xweb/httpsession"
+	"gopkg.in/mgo.v2/bson"
+)
+
+var WxClientReg = regexp.MustCompile(`.*micromessenger.*`)
+var aboutTableRemove = []string{"pushspace", "pushspace_entniche", "pushspace_entniche_project", "pushspace_entniche_temp", "pushspace_entniche_wait", "pushspace_fail", "pushspace_project", "pushspace_statistic", "pushspace_temp", "pushspace_vip", "pushspace_fail"}
+
+//自动合并两个账户、其中一个为空(无订阅、无关注项目、无关注企业)
+func AutoMerge(mg MongodbSim, sess *httpsession.Session) (bool, error) {
+	userId := qutil.ObjToString(sess.Get("userId"))
+	if userId == "" {
+		return false, errors.New("未获取到userId")
+	}
+	thisUser, _ := mg.FindById("user", userId, nil)
+	if thisUser == nil || len(*thisUser) == 0 {
+		return false, errors.New("未获取到用户信息")
+	}
+	s_m_phone := qutil.ObjToString((*thisUser)["s_m_phone"])
+	s_phone := qutil.ObjToString((*thisUser)["s_phone"])
+	if s_phone == s_m_phone {
+		return true, nil
+	}
+	otherUser := &map[string]interface{}{}
+	if s_m_phone != "" {
+		otherUser, _ = mg.FindOneByField("user", bson.M{"i_appid": 2, "s_phone": s_m_phone, "s_m_phone": bson.M{"$ne": s_m_phone}}, nil)
+		if otherUser == nil || len(*otherUser) == 0 { //微信端合并 app端
+			return true, nil
+		}
+	} else {
+		otherUser, _ = mg.FindOneByField("user", bson.M{"i_appid": 2, "s_m_phone": s_phone, "s_phone": bson.M{"$ne": s_phone}}, nil)
+		if otherUser == nil || len(*otherUser) == 0 { //app端合并 微信端
+			return true, nil
+		}
+	}
+
+	thisNull, otherNull := func() (t, o bool) {
+		t, o = true, true
+		if checNullkeyset((*qutil.ObjToMap((*thisUser)["o_jy"]))["a_key"]) || (*thisUser)["o_vipjy"] != nil {
+			t = false
+		}
+		if checNullkeyset((*qutil.ObjToMap((*otherUser)["o_jy"]))["a_key"]) || (*otherUser)["o_vipjy"] != nil {
+			o = false
+		}
+		if !t && !o { //账户都不为空
+			return
+		}
+		if t {
+			id := BsonIdToSId((*thisUser)["_id"])
+			if mg.Count("jylab_followent", bson.M{"s_userid": id}) != 0 {
+				t = false
+			} else {
+				if mg.Count("follow_project", bson.M{"s_userid": id}) != 0 {
+					t = false
+				}
+			}
+		}
+		if o {
+			id := BsonIdToSId((*otherUser)["_id"])
+			if mg.Count("jylab_followent", bson.M{"s_userid": id}) != 0 {
+				o = false
+			} else {
+				if mg.Count("follow_project", bson.M{"s_userid": id}) != 0 {
+					o = false
+				}
+			}
+		}
+		return
+	}()
+
+	if !thisNull && !otherNull {
+		return true, nil
+	}
+	log.Println("null log", thisNull, otherNull)
+	//存在一个空账户
+	var finalUser, removeUser *map[string]interface{}
+	if thisNull {
+		finalUser = otherUser
+		removeUser = thisUser
+	} else {
+		finalUser = thisUser
+		removeUser = otherUser
+	}
+
+	if !MergeData(mg, finalUser, removeUser) {
+		return false, errors.New("数据库操作出错")
+	}
+	log.Printf("[%s,%s]账户自动合并 合并结果 %+v\n", BsonIdToSId((*finalUser)["_id"]), BsonIdToSId((*removeUser)["_id"]), finalUser)
+	go MoveUser(mg, removeUser)
+	FlushSession(sess, finalUser, true)
+	return true, nil
+}
+
+func checNullkeyset(a_key interface{}) bool {
+	if a_key == nil {
+		return false
+	}
+	arr, ok := a_key.([]interface{})
+	if ok && len(arr) > 0 {
+		return true
+	}
+	return false
+}
+
+func MergeData(mg MongodbSim, saveRes, otherRes *map[string]interface{}) bool {
+	saveResIsWx := qutil.ObjToString((*saveRes)["s_phone"]) == ""
+	for k, v := range *otherRes {
+		if _, ok := (*saveRes)[k]; !ok {
+			(*saveRes)[k] = v
+		} else if k == "s_unionid" { //s_unionid保留微信
+			if !saveResIsWx {
+				(*saveRes)[k] = (*otherRes)[k]
+			}
+		} else if k == "o_jy" || k == "o_vipjy" {
+			if saveResIsWx { //保留app推送开关设置
+				(*qutil.ObjToMap((*saveRes)[k]))["i_apppush"] = (*qutil.ObjToMap((*otherRes)[k]))["i_apppush"]
+			} else { //保留微信推送开关设置
+				(*qutil.ObjToMap((*saveRes)[k]))["i_wxpush"] = (*qutil.ObjToMap((*otherRes)[k]))["i_wxpush"]
+			}
+		}
+	}
+	(*saveRes)["i_ispush"] = 1
+	delete(*saveRes, "s_m_phone")
+	if !mg.UpdateById("user", BsonIdToSId((*saveRes)["_id"]), saveRes) {
+		return false
+	}
+	return true
+}
+
+func FlushSession(sess *httpsession.Session, userData *map[string]interface{}, isWx bool) {
+	sess.Set("userId", BsonIdToSId((*userData)["_id"]))
+	sess.Set("s_jpushid", (*userData)["s_jpushid"])
+	sess.Set("s_m_openid", (*userData)["s_m_openid"])
+	sess.Set("s_opushid", (*userData)["s_opushid"])
+	sess.Set("s_appponetype", (*userData)["s_appponetype"])
+	sess.Set("s_appversion", (*userData)["s_appversion"])
+	sess.Set("s_headimageurl", strings.Replace(qutil.ObjToString((*userData)["s_headimageurl"]), "http://", "https://", 1))
+	log.Println("isWx", isWx)
+	if phone := qutil.ObjToString((*userData)["s_phone"]); phone != "" && !isWx {
+		sess.Set("s_phone", phone)
+		phone = string(phone[0:3]) + "****" + string(phone[len(phone)-4:])
+		sess.Set("s_nickname", phone)
+	} else {
+		sess.Set("s_nickname", (*userData)["s_nickname"])
+	}
+}
+
+func MoveUser(mg MongodbSim, otherRes *map[string]interface{}) {
+	(*otherRes)["l_mergeData"] = time.Now().Unix()
+	userId := BsonIdToSId((*otherRes)["_id"])
+	(*otherRes)["s_userId"] = userId
+	if mg.Save("user_merge", otherRes) == "" {
+		log.Println("保存user_merge失败", otherRes)
+		return
+	}
+	if !mg.Del("user", map[string]interface{}{"_id": StringTOBsonId(userId)}) {
+		log.Println("删除user信息失败", otherRes)
+		return
+	}
+	redis.Put("session", fmt.Sprintf("usermerge_delete_%s", userId), 1, 7*24*60*60) //session最长期限7天
+	//删除mysql表相关数据
+	for _, tableName := range aboutTableRemove {
+		if !mg.Del(tableName, map[string]interface{}{"userid": userId}) {
+			log.Printf("用户合并删除相关数据出错:用户%s,表明%s\n", userId, tableName)
+		}
+	}
+}
+
+//生成签名,返回手机端
+func CreateAppSign(userid, rid string) string {
+	u := &struct {
+		CreateTime int64  `json:"createtime"`
+		OpenId     string `json:"openid"`
+		UserId     string `json:"userid"`
+		Rid        string `json:"rid"`
+		Sign       string `json:"sign"`
+		Type       int    `json:"type"`
+	}{
+		UserId:     userid,
+		Type:       2,
+		CreateTime: time.Now().Unix(),
+		Rid:        rid,
+	}
+	u.Sign = qutil.GetMd5String(fmt.Sprintf("createtime=%d&userid=%s&rid=%s&type=%d", u.CreateTime, u.UserId, u.Rid, u.Type))
+	b, err := json.Marshal(u)
+	if err != nil {
+		log.Println(err)
+	}
+	sign := string(b)
+	sign = se.EncodeString(sign)
+	sign = strings.Replace(sign, "+", "%2B", -1)
+	return sign
+}

+ 49 - 51
src/jfw/public/db.go

@@ -4,71 +4,77 @@ import (
 	. "jfw/config"
 	"log"
 	mg "qfw/mongodb"
+	mg_v1 "qfw/mongodb_v1"
 	"qfw/util"
 	"qfw/util/jy"
 	"qfw/util/mysql"
 	"qfw/util/redis"
-	// ca "ucbsutil/cassandra"
 )
 
-var MQFW mg.MongodbSim
-var MQFWENT mg.MongodbSim
-var Mysql *mysql.Mysql
-var PushMysql *mysql.Mysql
+type mgoConf struct {
+	Main *mgo
+	Log  *mgo
+	Ent  *mgo
+}
+type mgo struct {
+	Address  string
+	Size     int
+	DbName   string
+	UserName string
+	Password string
+}
 
-// var Ca_Log = &ca.Cassandra{}
-// var Ca_Push = &ca.Cassandra{}
-var MQLOG mg.MongodbSim
+var MgoConf *mgoConf
+
+var (
+	Mysql     *mysql.Mysql
+	PushMysql *mysql.Mysql
+	MQFW      mg.MongodbSim
+	Mgo_Ent   mg.MongodbSim
+	Mgo_Log   mg_v1.MongodbSim
+)
 
 func init() {
-	//初始化cassandra
-	// cass, _ := Sysconfig["cassandra"].(map[string]interface{})
-	// if cass != nil {
-	// 	ca_log := cass["log"].(map[string]interface{})
-	// 	Ca_Log.ViewCacheLen = true
-	// 	Ca_Log.InitCassandra("jianyu",
-	// 		util.IntAll(ca_log["size"]),
-	// 		util.ObjArrToStringArr(ca_log["host"].([]interface{})),
-	// 		map[string]int{
-	// 			"port": util.IntAll(ca_log["port"]),
-	// 		},
-	// 	)
-	// 	ca_push := cass["push"].(map[string]interface{})
-	// 	Ca_Push.ViewCacheLen = true
-	// 	Ca_Push.InitCassandra("jianyu",
-	// 		util.IntAll(ca_push["size"]),
-	// 		util.ObjArrToStringArr(ca_push["host"].([]interface{})),
-	// 		map[string]int{
-	// 			"port": util.IntAll(ca_push["port"]),
-	// 		},
-	// 	)
-	// }
+	util.ReadConfig("./mongodb.json", &MgoConf)
 	//初始化redis
 	redisConfig, _ := Sysconfig["redisaddrs"].(string)
 	if redisConfig != "" {
+		log.Println("初始化 mongodb redis")
 		redis.InitRedisBySize(Sysconfig["redisaddrs"].(string), 100, 30, 300)
 	}
 	//
-	if Sysconfig["mongodbServers"] != nil {
+	if MgoConf.Main != nil {
+		log.Println("初始化 mongodb main")
 		MQFW = mg.MongodbSim{
-			MongodbAddr: Sysconfig["mongodbServers"].(string),
-			Size:        util.IntAll(Sysconfig["mongodbPoolSize"]),
-			DbName:      Sysconfig["mongodbName"].(string),
+			MongodbAddr: MgoConf.Main.Address,
+			Size:        MgoConf.Main.Size,
+			DbName:      MgoConf.Main.DbName,
 		}
 		MQFW.InitPool()
 	}
-	//
-	if Sysconfig["mongodbServersEnt"] != nil {
-		MQFWENT = mg.MongodbSim{
-			MongodbAddr: Sysconfig["mongodbServersEnt"].(string),
-			Size:        util.IntAll(Sysconfig["mongodbPoolSize"]),
-			DbName:      Sysconfig["mongodbNameEnt"].(string),
+	if MgoConf.Ent != nil {
+		log.Println("初始化 mongodb ent")
+		Mgo_Ent = mg.MongodbSim{
+			MongodbAddr: MgoConf.Ent.Address,
+			Size:        MgoConf.Ent.Size,
+			DbName:      MgoConf.Ent.DbName,
 		}
-		MQFWENT.InitPool()
+		Mgo_Ent.InitPool()
+	}
+	if MgoConf.Log != nil {
+		log.Println("初始化 mongodb log")
+		Mgo_Log = mg_v1.MongodbSim{
+			MongodbAddr: MgoConf.Log.Address,
+			Size:        MgoConf.Log.Size,
+			DbName:      MgoConf.Log.DbName,
+			UserName:    MgoConf.Log.UserName,
+			Password:    MgoConf.Log.Password,
+		}
+		Mgo_Log.InitPool()
 	}
-	//
 	mysqlConfig, _ := Sysconfig["mysql"].(map[string]interface{})
 	if mysqlConfig != nil {
+		log.Println("初始化 mysql")
 		Mysql = &mysql.Mysql{
 			Address:      util.ObjToString(mysqlConfig["address"]),
 			UserName:     util.ObjToString(mysqlConfig["userName"]),
@@ -82,6 +88,7 @@ func init() {
 	//
 	pushMysqlConfig, _ := Sysconfig["pushMysql"].(map[string]interface{})
 	if pushMysqlConfig != nil {
+		log.Println("初始化 pushMysql")
 		PushMysql = &mysql.Mysql{
 			Address:      util.ObjToString(pushMysqlConfig["address"]),
 			UserName:     util.ObjToString(pushMysqlConfig["userName"]),
@@ -93,13 +100,4 @@ func init() {
 		PushMysql.Init()
 		jy.PushMapping.Init(PushMysql)
 	}
-	if Sysconfig["mongodbServersEnt"] != nil {
-		log.Println("初始化LOG")
-		MQLOG = mg.MongodbSim{
-			MongodbAddr: Sysconfig["mongodbServersLog"].(string),
-			Size:        util.IntAll(Sysconfig["mongodbPoolSize"]),
-			DbName:      Sysconfig["mongodbNameLog"].(string),
-		}
-		MQLOG.InitPool()
-	}
 }

+ 24 - 1
src/jfw/public/public.go

@@ -9,12 +9,14 @@ import (
 	"math/big"
 	"net/http"
 	"net/url"
+	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/jy"
 	"qfw/util/redis"
 	"regexp"
 	"strings"
+	"time"
 
 	"gopkg.in/mgo.v2/bson"
 )
@@ -175,7 +177,7 @@ func GetWinnerNewestDatas(winner string) *[]map[string]interface{} {
 	data := elastic.GetPage("bidding", "bidding", `{"TERM_s_winner":"`+winner+`"}`, `{"publishtime":-1}`, fields, 0, 100)
 	if *data != nil {
 		for _, v := range *data {
-			v["_id"] = util.EncodeArticleId2ByCheck(util.BsonIdToSId(v["_id"]))
+			v["_id"] = util.EncodeArticleId2ByCheck(BsonIdToSId(v["_id"]))
 			v["bidamount"], _ = v["bidamount"].(float64)
 		}
 	}
@@ -302,3 +304,24 @@ func getesResp(ques, analyzer string, addrs []string) (resp *http.Response, err
 	}
 	return resp, err
 }
+
+//保存用户搜索日志
+func SaveUserSearchLog(request *http.Request, userid string, count int64, platform, source string, condition map[string]interface{}) {
+	go func() {
+		data := map[string]interface{}{
+			"ip":         util.GetIp(request),
+			"count":      count,
+			"s_userid":   userid,
+			"platform":   platform,
+			"source":     source,
+			"createtime": time.Now().Unix(),
+			"userAgent":  request.Header.Get("User-Agent"),
+		}
+		for _, v := range []string{"pagenum", "pagesize", "search_word", "search_area", "search_publishtime", "search_industry", "search_price", "search_type"} {
+			if vv := condition[v]; vv != nil {
+				data[v] = vv
+			}
+		}
+		Mgo_Log.Save("jy_search_log", data)
+	}()
+}

+ 1 - 1
src/jfw/public/search.go

@@ -387,7 +387,7 @@ func FormatExportData(data *[]map[string]interface{}, webdomain string, dataType
 		if len(EntArr) > 0 && dataType == "2" {
 			//查询企业公示 法人 公司电话 公司邮箱地址
 			query := bson.M{"company_name": bson.M{"$in": EntArr}} //
-			if entData, ok := MQFWENT.Find(EntTable, query, nil, `{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
+			if entData, ok := Mgo_Ent.Find(EntTable, query, nil, `{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
 				if entData != nil && *entData != nil && len(*entData) > 0 {
 					for _, ev := range *entData {
 						if v["s_winner"] == ev["company_name"] {

+ 3 - 4
src/jfw/qrmanager/qrmanager.go

@@ -2,7 +2,6 @@ package qrmanager
 
 import (
 	. "jfw/config"
-	"jfw/filter"
 	"net/http"
 	"qfw/util"
 	"qfw/util/redis"
@@ -26,9 +25,9 @@ func RedisInfo(oid, action, sione, sitwo string, i int, hsn *httpsession.Session
 		rhdua = rheader["User-Agent"][0]
 	}
 	userData := make(map[string]interface{})
-	userData["Ros"] = filter.GetOS(rhdua)
-	userData["Rip"] = filter.GetIp(hrt)
-	userData["Rbrowse"] = filter.GetBrowse(rhdua)
+	userData["Ros"] = util.GetOS(rhdua)
+	userData["Rip"] = util.GetIp(hrt)
+	userData["Rbrowse"] = util.GetBrowse(rhdua)
 	if hsn.Get("RReferer") == nil || util.ObjToString(hsn.Get("RReferer")) == "" {
 		if Rref == "" {
 			hsn.Set("RReferer", Rurl)

+ 2 - 1
src/jfw/rpcfollow/rpc.go

@@ -4,6 +4,7 @@ package rpcfollow
 import (
 	"jfw/front"
 	public "jfw/public"
+	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	frpc "qfw/util/rpc"
@@ -36,7 +37,7 @@ func setMyFollowKey(openid, projectname string) string {
 	if !ok || user == nil || len(*user) == 0 {
 		return rep
 	}
-	userid := util.BsonIdToSId((*user)["_id"])
+	userid := BsonIdToSId((*user)["_id"])
 	projects, ok := public.MQFW.Find("follow_project", `{"s_userid":"`+userid+`"}`, nil, `{"s_projectname":1}`, false, -1, -1)
 	if !ok {
 		return rep

+ 19 - 0
src/mongodb.json

@@ -0,0 +1,19 @@
+{
+	"main":{
+		"address": "192.168.3.128:27080",
+ 		"size": 5,
+ 		"dbName": "qfw"
+	},
+	"log":{
+		"address": "192.168.3.128:27080",
+ 		"size": 5,
+ 		"dbName": "qfw",
+		"userName": "admin",
+		"password": "123456"
+	},
+	"ent":{
+		"address": "192.168.3.128:27080",
+ 		"size": 5,
+ 		"dbName": "extract_v3"
+	}
+}