Browse Source

feat: 直接订阅判断修改

zhangyuhan 3 years ago
parent
commit
ee02f6d29c

+ 96 - 54
src/jfw/modules/app/src/web/staticres/jyapp/js/searchindex.js

@@ -439,73 +439,115 @@ var SuperSearch = {
       SuperSearch.dyDiv=true;
     });
 
-    //订阅
-    $("#supersearchPage #zjdy").on("tap",function(even){
-      if(userId == ""||userId == null){
-        SuperSearch.setSessionStorage();
-        window.location.href = "/jyapp/free/login?to=back";
-        return;
-      }
-      var rFlag = false;
-      if(SuperSearch.isVip || window.jyUserPower.member){
-        $.ajax({
-          type: "post",
-          url: "/publicapply/subscribe/setUserInfo",
-          data: {
-            pageType:'keyWords',
-            actionType: 'directSubKWS',
-            kws_name:SuperSearch.s_words,
-            vSwitch: vSwitch
-          },
-          // dataType: "json",
-          async: false,
-          success: function(r){
-            if(r.flag=="y"){
-              rFlag = true;
-            }else if(r.flag=="o"){
-              EasyAlert.show("您已经订阅过此关键字");
-            }else if(r.flag=="m"){
-              EasyAlert.show("您已经超过订阅<br>关键字上限");
+    // 获取用户信息-用于立即订阅按钮
+    function getKeyUserInfo () {
+      // 免费用户
+      // --> 已设置10组关键词,订阅失败提示
+      // --> 小于10组
+      //    --> 历史老用户-未选择区域-提示更新
+      //           --> -选择区域-关键词列表
+      //    --> 新用户-未选择区域-关键词列表
+
+      var isOldUser = false
+      var nowKeyLength = 8
+      var isSelectArea = false
+
+     // 获取用户关键词数据
+      $.ajax({
+        url: '/publicapply/free/subscribe',
+        type: 'post',
+        success: function (res) {
+          if (res.error_code === 0 && res.data) {
+            try {
+              isSelectArea = !!res.data.area
+              nowKeyLength = res.data.keys.length
+            } catch (e) {
+              console.warn('error format keys length')
             }
-          },error: function(){
-            rFlag = true;
           }
-        });
-        if(rFlag){
+        },
+      })
+
+      // S-直接订阅
+      $("#supersearchPage #zjdy").on("tap",function(even){
+        if(userId == ""||userId == null){
           SuperSearch.setSessionStorage();
-          window.location.href = "/jyapp/vipsubscribe/toSetKeyWordPage";
+          window.location.href = "/jyapp/free/login?to=back";
+          return;
         }
-      }else{
-        $.ajax({
-          type: "post",
-          url: "/jyapp/member/swordfish/ajaxReq",
-          data: {keys:SuperSearch.s_words,reqType: "subscribe"},
-          dataType: "json",
-          async: false,
-          success: function(r){
-            if(r.flag=="y"){
+        var rFlag = false;
+        if(SuperSearch.isVip || window.jyUserPower.member){
+          $.ajax({
+            type: "post",
+            url: "/publicapply/subscribe/setUserInfo",
+            data: {
+              pageType:'keyWords',
+              actionType: 'directSubKWS',
+              kws_name:SuperSearch.s_words,
+              vSwitch: vSwitch
+            },
+            // dataType: "json",
+            async: false,
+            success: function(r){
+              if(r.flag=="y"){
+                rFlag = true;
+              }else if(r.flag=="o"){
+                EasyAlert.show("您已经订阅过此关键字");
+              }else if(r.flag=="m"){
+                EasyAlert.show("您已经超过订阅<br>关键字上限");
+              }
+            },error: function(){
               rFlag = true;
-            }else if(r.flag=="o"){
-              EasyAlert.show("您已经超过订阅<br>关键字上限");
             }
-          },error: function(){
-            rFlag = true;
+          });
+          if(rFlag){
+            SuperSearch.setSessionStorage();
+            window.location.href = "/jyapp/vipsubscribe/toSetKeyWordPage";
           }
-        });
-        if(rFlag){
-          //JyObj.redirectKeyset();
-          if (!newUserType) {
-            $('#tipsType').show()
+        }else{
+          // 免费用户
+          isOldUser = !jyAddInfo.isUpgrade
+          if (nowKeyLength >= 10) {
+            return EasyAlert.show("您已经超过订阅<br>关键字上限");
           } else {
+            if (isSelectArea) {
+              // 执行下方原有逻辑
+            } else if (isOldUser) {
+              return $('#tipsType').show()
+            }
+          }
+
+          $.ajax({
+            type: "post",
+            url: "/jyapp/member/swordfish/ajaxReq",
+            data: {keys:SuperSearch.s_words,reqType: "subscribe"},
+            dataType: "json",
+            async: false,
+            success: function(r){
+              if(r.flag=="y"){
+                rFlag = true;
+              }else if(r.flag=="o"){
+                EasyAlert.show("您已经超过订阅<br>关键字上限");
+              }
+            },
+            error: function(){
+              rFlag = true;
+            }
+          });
+          if(rFlag){
             SuperSearch.setSessionStorage();
             setTimeout(function(){
-              window.location.href = "/jyapp/wxkeyset/keyset/index";
+              window.location.href = "/jyapp/vipsubscribe/toSetKeyWordPage";
             },100);
           }
         }
-      }
-    });
-    //订阅结束==========================================================================
+      });
+      // E-直接订阅
+    }
+
+    getKeyUserInfo()
+
+
     //删除历史搜索
     $("#supersearchPage").on("click", " #del_history", function(){
       if(localStorage){

+ 10 - 15
src/jfw/modules/app/src/web/templates/weixin/search/mainSearch.html

@@ -729,7 +729,7 @@
     var distance = {{Msg "seo" "distance"}};
     var member_status;
     var isMember = false;
-    var vSwitch = 'v'
+    var vSwitch = 'f'
     // 消息总数
     try {
         checkMsgCount(true, 0)
@@ -737,25 +737,20 @@
         console.log(e)
     }
     // 子账户判断
+    window.jyAddInfo = {
+        isUpgrade: false
+    }
     $.ajax({
         type:'POST',
         url:'/bigmember/use/isAdd?t' + new Date().getTime(),
         success: function (r) {
             if (r && r.data) {
-                $.ajax({
-                    url: '/publicapply/subscribe/vipSwitch',
-                    type: 'POST',
-                    success: function(res) {
-                        if(res.error_code == 0) {
-                            vSwitch = res.data.vt
-                            if(vSwitch == 'm' && r.data.isSubCount) {
-                                $('#resbm').hide()
-                            } else {
-                                $('#resbm').show()
-                            }
-                        }
-                    }
-                })
+                window.jyAddInfo = r.data
+                if(res.data.memberStatus > 0 && r.data.isSubCount) {
+                    $('#resbm').hide()
+                } else {
+                    $('#resbm').show()
+                }
                 if (r.data.isSubCount) {
                     $("#mainSearch-tab4").attr('data-sub','true')
                 }

+ 93 - 46
src/web/staticres/js/wxSupersearch.js

@@ -10,11 +10,9 @@ function getUserType() {
       type: 'POST',
       url: '/publicapply/subscribe/vipSwitch',
       success: function(res) {
-          if (res.data.vt !== 'v' ) {
-              vSwitch = 'f'
-          } else {
-              vSwitch = 'v'
-          }
+        if (res && res.data) {
+          vSwitch = res.data.vt || 'f'
+        }
       }
   })
 }
@@ -28,11 +26,16 @@ function gotoPay() {
 }
 // 获取用户是否为新用户
 function getUserNewType() {
+  window.jyAddInfo = {
+    isUpgrade: false
+  }
   $.ajax({
       url: '/bigmember/use/isAdd',
       type: 'POST',
-      success: function (res) {
-        newUserType = res.data.isUpgrade
+      success: function (r) {
+        if (r && r.data) {
+          window.jyAddInfo = r.data
+        }
       }
   })
 }
@@ -50,7 +53,7 @@ function updateJump2() {
       location.href = '/front/vipsubscribe/toSubVipSetPage'
     }
   })
-  
+
 }
 var nowClientHeight = document.documentElement.clientHeight || document.body.clientHeight
 // 监听banner高度变化
@@ -420,18 +423,52 @@ var SuperSearch = {
       SuperSearch.dyDiv=true;
     });
 
-    //订阅
+        // 获取用户信息-用于立即订阅按钮
+    function getKeyUserInfo () {
+      // 免费用户
+      // --> 已设置10组关键词,订阅失败提示
+      // --> 小于10组
+      //    --> 历史老用户-未选择区域-提示更新
+      //           --> -选择区域-关键词列表
+      //    --> 新用户-未选择区域-关键词列表
+
+      var isOldUser = false
+      var nowKeyLength = 8
+      var isSelectArea = false
+
+     // 获取用户关键词数据
+      $.ajax({
+        url: '/publicapply/free/subscribe',
+        type: 'post',
+        success: function (res) {
+          if (res.error_code === 0 && res.data) {
+            try {
+              isSelectArea = !!res.data.area
+              nowKeyLength = res.data.keys.length
+            } catch (e) {
+              console.warn('error format keys length')
+            }
+          }
+        },
+      })
+
+      // S-直接订阅
     $("#supersearchPage #zjdy").on("tap",function(){
       var rFlag = false;
       if (SuperSearch.s_words==""){
         SuperSearch.s_words=$.trim($("#supersearchPage [name='super_searchinput']").val());
         SuperSearch.s_words=SuperSearch.s_words.replace(/\s+/g," ");
       }
-      if(SuperSearch.isVip){
+      if(SuperSearch.isVip ||  window.jyUserPower.member){
         $.ajax({
           type: "post",
-          url: "/subscribepay/afterPay/directSubKWS",
-          data: {keys:SuperSearch.s_words},
+          url: "/publicapply/subscribe/setUserInfo",
+          data: {
+            pageType:'keyWords',
+            actionType: 'directSubKWS',
+            kws_name:SuperSearch.s_words,
+            vSwitch: vSwitch
+          },
           dataType: "json",
           async: false,
           success: function(r){
@@ -451,6 +488,17 @@ var SuperSearch = {
           window.location.href = "/front/vipsubscribe/toSetKeyWordPage";
         }
       }else{
+      // 免费用户
+          isOldUser = !jyAddInfo.isUpgrade
+          if (nowKeyLength >= 10) {
+            return EasyAlert.show("您已经超过订阅<br>关键字上限");
+          } else {
+            if (isSelectArea) {
+              // 执行下方原有逻辑
+            } else if (isOldUser) {
+              return $('#tipsType').show()
+            }
+          }
         $.ajax({
           type: "post",
           url: "/member/swordfish/ajaxReq",
@@ -468,16 +516,15 @@ var SuperSearch = {
           }
         });
         if(rFlag){
-          if (!newUserType) {
-            $('#tipsType').show()
-          } else {
             SuperSearch.setSessionStorage();
-            window.location.href = "/wxkeyset/keyset/index";
-          }
+            window.location.href = "/front/vipsubscribe/toSetKeyWordPage";
         }
       }
     });
-    //订阅结束==========================================================================
+      // E-直接订阅
+    }
+
+    getKeyUserInfo()
     //删除历史搜索
     $("#supersearchPage").on("click", " #del_history", function(){
       if(localStorage){
@@ -1377,26 +1424,26 @@ var SuperSearch = {
       $(".newdialog .sub-show-list").find("li[dataval='showlist']").addClass("active");
     }
     var IframeOnClick = {
-      resolution: 200,  
-      iframes: [],  
-      interval: null,  
-      Iframe: function() {  
-          this.element = arguments[0];  
-          this.cb = arguments[1];   
-          this.hasTracked = false;  
-      },  
-      track: function(element, cb) {  
-          this.iframes.push(new this.Iframe(element, cb));  
-          var _this = this;  
-              this.interval = setInterval(function() { _this.checkClick(); }, this.resolution);  
-      },  
-      checkClick: function() {  
-          if (document.activeElement) {  
-              var activeElement = document.activeElement;  
-              for (var i in this.iframes) {  
-                  if (activeElement === this.iframes[i].element) { // user is in this Iframe  
-                      if (this.iframes[i].hasTracked == false) {   
-                          this.iframes[i].cb.apply(window, []);   
+      resolution: 200,
+      iframes: [],
+      interval: null,
+      Iframe: function() {
+          this.element = arguments[0];
+          this.cb = arguments[1];
+          this.hasTracked = false;
+      },
+      track: function(element, cb) {
+          this.iframes.push(new this.Iframe(element, cb));
+          var _this = this;
+              this.interval = setInterval(function() { _this.checkClick(); }, this.resolution);
+      },
+      checkClick: function() {
+          if (document.activeElement) {
+              var activeElement = document.activeElement;
+              for (var i in this.iframes) {
+                  if (activeElement === this.iframes[i].element) { // user is in this Iframe
+                      if (this.iframes[i].hasTracked == false) {
+                          this.iframes[i].cb.apply(window, []);
                           this.iframes[i].hasTracked = true;
                           $.ajax({
                               type: 'POST',
@@ -1410,15 +1457,15 @@ var SuperSearch = {
                                   console.log(res)
                               }
                           })
-                      }  
-                  } else {  
-                      this.iframes[i].hasTracked = false;  
-                  }  
-              }  
-          }  
-      }  
+                      }
+                  } else {
+                      this.iframes[i].hasTracked = false;
+                  }
+              }
+          }
+      }
   };
-    
+
     $.ajax({
       type: "post",
       url: "/swordfish/searchlist/paging",