瀏覽代碼

Merge branch 'feature/v4.10.31' of https://jygit.jydev.jianyu360.cn/qmx/jy into feature/v4.10.31

fuwencai 3 周之前
父節點
當前提交
a90c3911df

+ 1 - 1
src/jfw/filter/filter.go

@@ -60,7 +60,7 @@ func (f *Filter) Do(w http.ResponseWriter, r *http.Request) bool {
 		return false
 	}
 	(&CookieInfo{w, r, getSession["userId"] != nil, session}).Do()
-	(&fx.VisitFilter{W: w, R: r, Session: session, SessVal: getSession, MgoLog: public.Mgo_Log, Ms: public.Mysql}).Do()
+	(&fx.VisitFilter{W: w, R: r, Session: session, SessVal: getSession, MgoLog: public.MQFW, Ms: public.Mysql}).Do()
 	if !(&logFilter{w, r, session, getSession, make(map[string]interface{})}).Do() {
 		return false
 	}

+ 1 - 1
src/jfw/modules/app/src/app/filter/filter.go

@@ -47,7 +47,7 @@ func (f *Filter) Do(w http.ResponseWriter, r *http.Request) bool {
 		identity.SwitchToBest(util.Int64All(getSession["base_user_id"]), session, Middleground, &public.MQFW, false)
 	}
 	(&CookieInfo{w, r, getSession["userId"] != nil}).Do()
-	(&fx.VisitFilter{W: w, R: r, Session: session, SessVal: getSession, MgoLog: public.Mgo_Log, Ms: public.Mysql}).Do()
+	(&fx.VisitFilter{W: w, R: r, Session: session, SessVal: getSession, MgoLog: public.MQFW, Ms: public.Mysql}).Do()
 	if !(&logFilter{w, r, getSession}).Do() {
 		return false
 	}

+ 49 - 26
src/jfw/modules/app/src/app/miniprogram/miniprogram.go

@@ -84,7 +84,7 @@ func (m *MiniProgram) AutoLogin() {
 	})
 	status := m.createSession(jsonPram.Unionid, jsonPram.Openid, miniprogramCode)
 	if status == -1 {
-		if m.createUser(jsonPram.Unionid, jsonPram.Openid, miniprogramCode, jsonPram.Phone, "") > 0 {
+		if m.createUser(jsonPram.Unionid, jsonPram.Openid, miniprogramCode, jsonPram.Phone) > 0 {
 			status = m.createSession(jsonPram.Unionid, jsonPram.Openid, miniprogramCode)
 		}
 	}
@@ -121,13 +121,8 @@ func (m *MiniProgram) Login() error {
 			return 0
 		}
 		//缓存记录来源来源source
-		source := m.GetByOpenId(openid)
-		if source == "" {
-			source = jsonPram.Source
-			if source != "" {
-				//首次记录
-				m.SetByOpenId(openid, source)
-			}
+		if jsonPram.Source != "" {
+			m.SetSource(openid, jsonPram.Source)
 		}
 
 		if sessErr := m.Session().SetMultiple(map[string]interface{}{
@@ -171,19 +166,19 @@ func (m *MiniProgram) BindPhone() error {
 		sessVal := m.Session().GetMultiple()
 		unionid := common.ObjToString(sessVal["unionid"])
 		openid := common.ObjToString(sessVal["openid"])
-		source := common.ObjToString(sessVal["source"])
-		if createRes := m.createUser(unionid, openid, jsonPram.MiniProgramInfo.Code, phone, source); createRes > 0 {
+		//source := common.ObjToString(sessVal["source"])
+		if createRes := m.createUser(unionid, openid, jsonPram.MiniProgramInfo.Code, phone); createRes > 0 {
 			status := m.createSession(unionid, openid, jsonPram.MiniProgramInfo.Code)
 			nsqPath, _ := config.Sysconfig["nsq"].(string)
-			nsq_topic, _ := config.Sysconfig["nsq_topic"].(string)
-			sessVal := m.Session().GetMultiple()
+			nsqTopic, _ := config.Sysconfig["nsq_topic"].(string)
+			sessVal = m.Session().GetMultiple()
 			mgoUserId := common.ObjToString(sessVal["mgoUserId"])
 			if createRes == 1 {
-				if err := jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, jy.Jyapp_phone_register, mgoUserId, jy.Jyapp_node1, nil); err != nil {
+				if err := jy.Publish(public.Mgo_Log, nsqPath, nsqTopic, jy.Jyapp_phone_register, mgoUserId, jy.Jyapp_node1, nil); err != nil {
 					log.Println("nsq队列写入失败-->", err, jy.Jyapp_phone_register, mgoUserId)
 				}
 			} else if createRes == 2 {
-				if err := jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, "task", mgoUserId, jy.Jyweb_node2, map[string]interface{}{
+				if err := jy.Publish(public.Mgo_Log, nsqPath, nsqTopic, "task", mgoUserId, jy.Jyweb_node2, map[string]interface{}{
 					"code":       1007,
 					"types":      "bindPhone",
 					"num":        50,
@@ -252,7 +247,7 @@ func (m *MiniProgram) check(jsonParam *JsonParam) bool {
 	return true
 }
 
-func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone, source string) int {
+func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone string) int {
 	if phone == "" || unionid == "" || openid == "" {
 		log.Println("phone", phone, "unionid", unionid, "openid", openid, "创建用户失败,缺少phone、unionid、openid")
 		return 0
@@ -270,10 +265,7 @@ func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone, source
 			},
 		}, `{"s_phone":-1}`, `{"_id":1,"s_phone":1,"s_m_phone":1,"s_unionid":1}`, false, 0, 1)
 	}
-	_source := m.GetByOpenId(openid)
-	if _source != "" {
-		source = _source
-	}
+	source := m.GetSource(openid)
 	nowUnix := gtime.Timestamp()
 	if !ok {
 		log.Println(miniprogramCode, unionid, openid, phone, "查询mog库user表失败")
@@ -366,16 +358,47 @@ func (m *MiniProgram) createSession(unionid, openid, miniprogramCode string) int
 	return 1
 }
 
-func (m *MiniProgram) GetByOpenId(openId string) (source string) {
-	sourceKey := fmt.Sprintf("mini_source_%s", openId)
-	source = redis.GetStr("limitation", sourceKey)
+var (
+	redisCode           = "limitation"
+	cacheTime           = 3600 * 24 * 7
+	sourceCacheKey      = "mini_source_%s"
+	sevenSourceCacheKey = "mini_seven_source_%s"
+)
+
+func (m *MiniProgram) GetSevenByOpenId(openId string) (source string) {
+	source = redis.GetStr(redisCode, fmt.Sprintf(sevenSourceCacheKey, openId))
 	return
 }
 
-func (m *MiniProgram) SetByOpenId(openId, source string) {
-	sourceKey := fmt.Sprintf("mini_source_%s", openId)
-	ok := redis.Put("limitation", sourceKey, source, 3600*24*30)
+func (m *MiniProgram) SetSevenByOpenId(openId, source string) {
+	ok := redis.Put(redisCode, fmt.Sprintf(sevenSourceCacheKey, openId), source, cacheTime)
 	if !ok {
-		log.Println("招标网小程序来源缓存存异常")
+		log.Println("招标网小程序来源 7天 缓存存异常")
+	}
+}
+
+func (m *MiniProgram) GetSource(openId string) (source string) {
+	//七天
+	source = m.GetSevenByOpenId(openId)
+	if source == "" {
+		//永久
+		source = redis.GetStr(redisCode, fmt.Sprintf(sourceCacheKey, openId))
+	}
+	return
+}
+
+func (m *MiniProgram) SetSource(openId, source string) {
+	//七天
+	sevenSource := m.GetSevenByOpenId(openId)
+	if sevenSource == "" {
+		m.SetSevenByOpenId(openId, source)
+		//永久
+		permanentSource := redis.GetStr(redisCode, fmt.Sprintf(sourceCacheKey, openId))
+		if permanentSource == "" {
+			ok := redis.PutCKV(redisCode, fmt.Sprintf(sourceCacheKey, openId), source)
+			if !ok {
+				log.Println("招标网小程序首次来源 redis 缓存存异常")
+			}
+		}
 	}
 }