wangshan 5 жил өмнө
parent
commit
5aefe57949

+ 10 - 9
src/jfw/front/swordfish.go

@@ -2379,8 +2379,10 @@ func (f *Front) HasPushHistory() {
 		var oneRemind = int64(1 * 24 * 60 * 60)
 		var o_vipjy map[string]interface{}
 		o_vipjy, _ = (*user)["o_vipjy"].(map[string]interface{})
-		a_itmes := util.ObjArrToMapArr(o_vipjy["a_items"].([]interface{}))
-		hasKeyFlag = len(a_itmes) > 0
+		if o_vipjy["a_items"] != nil {
+			a_itmes := util.ObjArrToMapArr(o_vipjy["a_items"].([]interface{}))
+			hasKeyFlag = len(a_itmes) > 0
+		}
 		isVipFlag = true
 		isPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+tedayNum+"_"+userId) > 2000
 		isOnTail = util.IntAll((*user)["i_vip_status"])
@@ -2405,19 +2407,18 @@ func (f *Front) HasPushHistory() {
 		}
 		isPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+tedayNum+"_"+userId) > 50
 	}
-	//	hasNextPage, list, err := public.HistoryPush.Datas(userId, 1, firstPushTime, formatTime)
-	//	if err == nil && hasKeyFlag && len(list) == 0 && formatTime == "" && !isVipFlag {
-	//		flag, data := public.HistoryPush.MakeHistoryDatas(userId, bidSearch_field_1)
-	//		if flag && data != nil {
-	//			list = data
-	//		}
-	//	}
 	pageNum, _ := f.GetInteger("pageNum")
 	if pageNum == 0 {
 		pageNum = 1
 	}
 	area := f.GetString("area")
 	hasNextPage, list := public.HistoryPush.Datas_Mysql(userId, pageNum, formatTime, area)
+	if hasKeyFlag && len(list) == 0 && formatTime == "" && !isVipFlag {
+		flag, data := public.HistoryPush.MakeHistoryDatas(userId, bidSearch_field_1)
+		if flag && data != nil {
+			list = data
+		}
+	}
 	//
 	f.ServeJson(map[string]interface{}{
 		"haskey":      hasKeyFlag,

+ 23 - 13
src/jfw/public/historypush.go

@@ -426,15 +426,25 @@ func (h *historyPush) getInfoByIds(pushCas []*jy.PushCa) []map[string]interface{
 func (h *historyPush) MakeHistoryDatas(userId, field string) (bool, []map[string]interface{}) {
 	allquery := `{"range":{"publishtime":{"gt":%s}}}`
 	allquery = fmt.Sprintf(allquery, fmt.Sprint(time.Now().AddDate(0, 0, -7).Unix()))
-	//allquery := ``
-	_, list := PushView(userId, allquery, field, 1, 50)
+	allquery = ``
+	keys, list := PushView(userId, allquery, field, 1, 50)
 	if list == nil || len(*list) == 0 {
 		return true, nil
 	}
+	matchkeys := []string{}
+	if len(keys) > 0 {
+		for _, v := range keys {
+			for _, k := range util.ObjArrToStringArr(v.([]interface{})) {
+				matchkeys = append(matchkeys, k)
+			}
+		}
+	}
 	result := []map[string]interface{}{}
-	pushinfo := []string{}
+	fields := []string{"userid", "infoid", "date", "matchkeys", "area", "city", "type", "subscopeclass"}
+	values := []interface{}{}
 	publishTitle := map[string]bool{}
 	now := time.Now()
+	keystr := strings.Join(matchkeys, " ")
 	for k, v := range *list {
 		title := strings.Replace(v["title"].(string), "\n", "", -1)
 		area_check := util.ObjToString(v["area"])
@@ -443,8 +453,7 @@ func (h *historyPush) MakeHistoryDatas(userId, field string) (bool, []map[string
 		} else {
 			publishTitle[area_check+title] = true
 		}
-		pushinfo = append(pushinfo, util.ObjToString(v["_id"]))
-
+		values = append(values, userId, util.ObjToString(v["_id"]), now.Unix(), keystr, area_check, "", 0, v["s_subscopeclass"])
 		info := map[string]interface{}{
 			"area":             area_check,
 			"_id":              util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"])),
@@ -462,6 +471,8 @@ func (h *historyPush) MakeHistoryDatas(userId, field string) (bool, []map[string
 			"title":            title,
 			"ca_isvisit_index": k + 1,
 			"ca_date":          now.Unix(),
+			"ca_isvisit":       0,
+			"matchkeys":        matchkeys,
 		}
 		area := util.ObjToString(info["area"])
 		if area == "A" {
@@ -505,14 +516,13 @@ func (h *historyPush) MakeHistoryDatas(userId, field string) (bool, []map[string
 
 		result = append(result, info)
 	}
-	wxpush := map[string]interface{}{
-		"dateymd":  now.Format(util.Date_yyyyMMdd),
-		"date":     now.Unix(),
-		"uid":      userId,
-		"pushinfo": strings.Join(pushinfo, ","),
-	}
-	flag := Ca_Push.SaveCacheByTimeOut("jy_pushhistory", wxpush, 10)
-	return flag, result
+	go func(fields []string, values []interface{}) {
+		count := Mysql.InsertBatch("pushsubscribe", fields, values)
+		if int(count) == len(values) {
+			log.Println("mysql insert  true")
+		}
+	}(fields, values)
+	return true, result
 }
 
 //获取用户信息

+ 4 - 4
src/web/staticres/vipsubscribe/js/keyWord.js

@@ -1,4 +1,5 @@
-$(function () {
+
+var reloadFunc = function(){
     
     //去空格方法
     // String.prototype.trim = function () {
@@ -41,7 +42,7 @@ $(function () {
     // 添加 确认按钮的点击事件
     $('.content .addkeyWord .btn button').on('click', function () {
         var keyWord = $('.addkeyWord input.enterOne').val();
-		if($.inArray(keyWord, kws_arr)>-1){
+		if(kws_arr[keyWord]!=undefined){
             weui.toast('您设置的关键词已存在,请调整后再添加。', {
                 duration: 2000,
                 className: 'custom-toast',
@@ -285,5 +286,4 @@ $(function () {
         $('.classify-edit-pop').hide()
         $('input.classify-keyword').val('')
     })
-
-})
+}

+ 2 - 2
src/web/templates/weixin/historypush.html

@@ -149,8 +149,8 @@
 				setSessionStorage();
 				window.location.href='/wxkeyset/keyset/index';
 			});
-			console.log(firstPage.length)
-			if(firstPage.length==0){
+			//console.log(firstPage.length)
+			if(firstPage==null||firstPage.length==0){
 				//最开始没有数据 
 				hasNoData();
 				$(".findnull_").show();

+ 67 - 44
src/web/templates/weixin/vipsubscribe/keyWord.html

@@ -232,15 +232,7 @@
 	<script src="{{Msg "seo" "cdn"}}/wxswordfish/share.js?v={{Msg "seo" "version"}}"></script>
     <script>
 		initShare({{.T.signature}},{{.T.openid}},2,"jy_extend",{{.T.nickname}},{{.T.avatar}});
-        weui.loading();
-        setTimeout(function(){
-            weui.loading().hide();
-            if(window.location.search.indexOf("page=1")>-1){
-				history.replaceState("{id:1}","","/front/vipsubscribe/toSetKeyWordPage")
-            }else if(history.state){
-                window.history.go(-1)
-			}
-        },500)
+        
         var a_items = [];//全部数据
         var classify_name = "";//分类名称
         var classify_index = 0;//分类索引
@@ -251,15 +243,69 @@
         var addition_kws = []; //附加词
         var not_kws = []; //排除词
         var classify_arr = [];//分类对象
-        var kws_arr = [];//所有关键词对象
+        var kws_arr = {};//所有关键词对象
         var kws_tips = 0;
         // 页面状态
         var pageState = {
             //是否第一次设置关键词
             isFirstSetKeyword: true
         }
+		//
+		function initSess(){
+			weui.loading();
+	        setTimeout(function(){
+	            weui.loading().hide();
+	            if(window.location.search.indexOf("page=2")>-1){
+					history.replaceState("{id:1}","","/front/vipsubscribe/toSetKeyWordPage")
+	            }else if(history.state){
+	                window.history.go(-1)
+				}
+	        },500)
+		}
+		//
         $(function(){
-            init();
+			var isinitpage = false;
+			$(window).bind("pageshow", function(event){
+				if(event.originalEvent.persisted){
+					initpage();
+					isinitpage = true;
+					initSess();
+					reloadFunc();
+				}
+			});
+			if(!isinitpage) {
+				initpage();
+				initSess();
+				reloadFunc();
+			}
+			window.addEventListener('popstate', function(event){
+				if(!isinitpage){
+					if(a_items.length==0){
+		                window.history.go(-1)
+		            }
+		            var loading = weui.loading('loading...', {
+		                className: 'custom-classname'
+		            })
+		            $('.classify-show-pop').hide();
+		            $('.classify-edit-pop').hide();
+		            //重新加载数据
+		            initpage();
+		            // 用定时器模拟请求耗时
+		            setTimeout(function () {
+		                loading.hide(function() {
+		                    console.log('`loading` has been hidden');
+		                })
+		                // 判断是否是第一次(没有关键词进入)
+		                // 隐藏关键词列表section,显示分类列表section
+		                var isClassifyColumnShow = $('.add-keyword-container').is(':hidden')
+		                if (!isClassifyColumnShow) {
+		                    $('.add-keyword-container').hide()
+		                    $('.all-classify-column').show()
+		                }
+		            }, 500)
+				}
+				isinitpage = false
+			})
             // 关键词分类 - 去设置按钮点击事件
             $('.classify-show-pop .dialog__btn_confirm').on('click', function() {
                 $('.classify-show-pop').hide();
@@ -275,7 +321,6 @@
                     $('.classify-edit-pop').show();
                 },200)
             })
-
             // 关键词分类 - 取消按钮点击事件
             $('.classify-show-pop .dialog__btn_cancel').on('click', function() {
 				$('.enterOne').focus();
@@ -283,7 +328,7 @@
             })
         })
         //获取数据
-        function init(){
+        function initpage(){
             if(sessionStorage&&sessionStorage.kwspage){
                 if(sessionStorage.addition_kws!=undefined){
                     addition_kws = JSON.parse(sessionStorage.addition_kws);
@@ -293,6 +338,7 @@
                 }
                 showKorshowC(sessionStorage.kwspage);
                 a_items = JSON.parse(sessionStorage.a_items)
+                kws_arr = JSON.parse(sessionStorage.kws_arr)
                 classify_name = sessionStorage.classify_name;
                 classify_index = sessionStorage.classify_index;
                 kws_name = sessionStorage.kws_name;
@@ -352,6 +398,7 @@
             kws_count = 0;
             var classifyHtml = '';
             classify_arr = [];//每次初始化分类对象
+			kws_arr = {};//每次初始化关键词对象
             for (var i = 0;  i < kwsdata.length; i++) {
                 var s_item = kwsdata[i]["s_item"]
                 if(s_item==""){
@@ -366,7 +413,7 @@
                         keystr += "、"
                     }
                     keystr += a_key[j]["key"].join('、');
-					kws_arr = kws_arr.concat(a_key[j]["key"])
+					kws_arr[a_key[j]["key"].join(' ')]=j+"-"+i
                 } 
                 classifyHtml +='<li class="classify-item">'
                             +'<div><span class="classify-item-l">'+s_item+'</span>'
@@ -501,7 +548,7 @@
         }
         //跳转附加词
         function toappendkey(th){
-			history.replaceState("","","/front/vipsubscribe/toSetKeyWordPage?page=1")
+			history.replaceState("","","/front/vipsubscribe/toSetKeyWordPage?page=211")
             if(!$('.enter.addkeyWord').is(':hidden')){
                 if($('.addkeyWord input.enterOne').val()==""){
                     return
@@ -519,7 +566,7 @@
         }
         //
         function tonotkey(th){
-			history.replaceState("","","/front/vipsubscribe/toSetKeyWordPage?page=1")
+			history.replaceState("","","/front/vipsubscribe/toSetKeyWordPage?page=211")
             if(!$('.enter.addkeyWord').is(':hidden')){
                 if($('.addkeyWord input.enterOne').val()==""){
                     return
@@ -545,6 +592,7 @@
             sessionStorage.a_items = JSON.stringify(a_items);//当前数据
             sessionStorage.addition_kws =  JSON.stringify(addition_kws);//当前编辑关键词附加词
             sessionStorage.not_kws =  JSON.stringify(not_kws);//当前编辑关键词排除词
+            sessionStorage.kws_arr =  JSON.stringify(kws_arr);//当前所有关键词排
 
             sessionStorage.kws_count=kws_count;//关键词个数
         }
@@ -562,12 +610,13 @@
             sessionStorage.removeItem("addition_kws");
             sessionStorage.removeItem("not_kws");
             sessionStorage.removeItem("kws_count");
+            sessionStorage.removeItem("kws_arr");
         }
         //保存关键词
         function saveK(th,i){
             var $this = $(th);
             kws_name = $(th).siblings('textarea').val();
-			if($.inArray(kws_name, kws_arr)>-1){
+			if(kws_arr[kws_name]!=undefined&&kws_arr[kws_name]!=(kws_index+"-"+classify_index)){
                 weui.toast('您设置的关键词已存在,请调整后再添加。', {
                     duration: 2000,
                     className: 'custom-toast',
@@ -661,7 +710,7 @@
             not_kws = [];
         }
     </script>
-    <script src="{{Msg "seo" "cdn"}}/vipsubscribe/js/keyWord.js?v={{Msg "seo" "version"}}1"></script>
+    <script src="{{Msg "seo" "cdn"}}/vipsubscribe/js/keyWord.js?v={{Msg "seo" "version"}}124"></script>
     <script>
         // 设置一条空记录,用户第一次进入添加关键词点击确定时候调用
         function setEmptyHistory() {
@@ -672,7 +721,6 @@
         }
         //
         $(function(){
-
             $(".addNewKeyword div").on('click', function () {
                 history.pushState({id:1}, "","");
                 classify_index = $(".classify-list li").length;
@@ -741,31 +789,6 @@
                 toSetKws();
             })
         })
-        window.addEventListener('popstate', function(event){
-            if(a_items.length==0){
-                window.history.go(-1)
-            }
-            var loading = weui.loading('loading...', {
-                className: 'custom-classname'
-            })
-            $('.classify-show-pop').hide();
-            $('.classify-edit-pop').hide();
-            //重新加载数据
-            init();
-            // 用定时器模拟请求耗时
-            setTimeout(function () {
-                loading.hide(function() {
-                    console.log('`loading` has been hidden');
-                })
-                // 判断是否是第一次(没有关键词进入)
-                // 隐藏关键词列表section,显示分类列表section
-                var isClassifyColumnShow = $('.add-keyword-container').is(':hidden')
-                if (!isClassifyColumnShow) {
-                    $('.add-keyword-container').hide()
-                    $('.all-classify-column').show()
-                }
-            }, 500)
-        })
     </script>
 	{{include "/common/baiducc.html"}}
 </body>