Commit d660e2f89f45371a6dfd9fe1cd3265f4ffeba36d

Authored by yvan.ni
1 parent 6786f6ca

小程序过期的程序优化

Showing 1 changed file with 103 additions and 37 deletions
... ... @@ -101,6 +101,29 @@ App({
101 101 },
102 102 })
103 103  
  104 + var th=this;
  105 + var pages = getCurrentPages(); //获取加载的页面
  106 + var currentPage = pages[pages.length - 1]; //获取当前页面的对象
  107 + if(!currentPage || currentPage.route.indexOf('error/error')==-1){
  108 + var tt=this.globalData.wxapp_buy_obj;
  109 + if (!tt){
  110 + this.get_isbuy(function (){
  111 + tt=th.globalData.wxapp_buy_obj;
  112 + if (tt.isout == 1){
  113 + th.promiseGet('/api/weshop/store/get/'+t.stoid,{}).then(res=>{
  114 + wx.reLaunch({
  115 + url: "/pages/error/error?msg=该商城已到期,暂停浏览!\r\n可联系:"+res.data.data.store_tel,
  116 + });
  117 + })
  118 + }
  119 + else if (tt.isbuy == 0)
  120 + wx.reLaunch({
  121 + url: "/pages/error/error?msg=还未购买小程序",
  122 + });
  123 + })
  124 + }
  125 + }
  126 +
104 127 },
105 128  
106 129 //---初始化第三方----
... ... @@ -287,9 +310,11 @@ App({
287 310 },
288 311  
289 312 //同步化,在调用的时候要await
290   - async get_isbuy() {
291   - var th=this;
292   - await api.check_isbuy({ store_id: t.stoid, type: 5 }).then(res=>{
  313 + async get_isbuy(func) {
  314 + var th=this
  315 + var stoid=os.stoid;
  316 +
  317 + await this.promiseGet("/store/storemoduleendtime/page?store_id=" +stoid + "&type=5",{}).then(res=>{
293 318 var o=res;
294 319 if (o.data.code == 0) {
295 320 var ob = { isout: 0, isbuy: 1 };
... ... @@ -308,6 +333,9 @@ App({
308 333 }
309 334 ob.isbuy = isbuy;
310 335 th.globalData.wxapp_buy_obj=ob;
  336 + if(func){
  337 + func();
  338 + }
311 339 }
312 340 })
313 341 },
... ... @@ -384,44 +412,61 @@ App({
384 412 }
385 413 //---如果会员没有设置默认门店,同时也没有再注册的时候选择门店--
386 414 if(pick_id==0) return func(null);
387   - //获取用户注册时候的门店,这个门店不能关闭,同时这个门店的分类不能关闭
388   - th.request.get("/api/weshop/pickup/get/"+os.stoid+"/"+pick_id,{
389   - data:{},
390   - success:function (res) {
391   - th.globalData.pk_store=null;
392   - if(res.data.code==0 && res.data.data && res.data.data.isstop==0){
393   - if(res.data.data.category_id){
394   - th.request.get( "/api/weshop/storagecategory/get/"+os.stoid+"/"+res.data.data.category_id, {
395   - data: {},
396   - success: function (ee) {
397   - if(ee.data.code==0 && ee.data.data ){
398   - if(ee.data.data.is_show==1){
399   - th.globalData.pk_store = res.data.data;
400   - func(th.globalData.pk_store);
401   - }else{
402   - func(null);
403   - }
404   - }else{
405   - func(null);
406   - }
407   - }
408   - })
409   - }else{
410   - th.globalData.pk_store = res.data.data;
411   - func(th.globalData.pk_store);
412   - }
413   - }else{
414   - func(null);
415   - }
416   - }
417   - })
  415 +
  416 + //返回门店的数量
  417 + th.get_pk_num(function(num){
  418 + //获取用户注册时候的门店,这个门店不能关闭,同时这个门店的分类不能关闭
  419 + th.request.get("/api/weshop/pickup/get/"+os.stoid+"/"+pick_id,{
  420 + data:{},
  421 + success:function (res) {
  422 + th.globalData.pk_store=null;
  423 + if(res.data.code==0 && res.data.data && res.data.data.isstop==0){
  424 + //--门店的数量大于5个才要关心门店的分类有没有关闭--
  425 + if(res.data.data.category_id && num>5){
  426 + th.request.get( "/api/weshop/storagecategory/get/"+os.stoid+"/"+res.data.data.category_id, {
  427 + data: {},
  428 + success: function (ee) {
  429 + if(ee.data.code==0 && ee.data.data ){
  430 + if(ee.data.data.is_show==1){
  431 + th.globalData.pk_store = res.data.data;
  432 + func(th.globalData.pk_store);
  433 + }else{
  434 + func(null);
  435 + }
  436 + }else{
  437 + func(null);
  438 + }
  439 + }
  440 + })
  441 + }else{
  442 + th.globalData.pk_store = res.data.data;
  443 + func(th.globalData.pk_store);
  444 + }
  445 + }else{
  446 + func(null);
  447 + }
  448 + }
  449 + })
  450 +
  451 + })
  452 +
418 453 }else{
419 454 func(th.globalData.pk_store);
420 455 }
421 456 })
422   -
423 457 },
424   -
  458 +
  459 + //-- 获取门店的数量 --
  460 + get_pk_num:function(func){
  461 + this.request.get("/api/weshop/pickup/page",{
  462 + data:{page:1,pageSize:1,isstop:0,store_id:os.stoid},
  463 + success:function (res) {
  464 + if(res.data.code==0){
  465 + func(res.data.data.total); //门店数量
  466 + }
  467 + }
  468 + });
  469 + },
425 470 //-------获取购物车数量----------
426 471 requestCardNum: function(th) {
427 472 if(!this.globalData.user_id) return false;
... ... @@ -538,7 +583,28 @@ App({
538 583 }
539 584 return index;
540 585  
541   - }
  586 + },
  587 +
  588 + //---promise的使用get----
  589 + promiseGet:function(url,data){
  590 + if(url.indexOf("http")==-1) url=this.globalData.setting.url +url;
  591 + return new Promise((resolve, reject) => {
  592 + data.isShowLoading && wx.showLoading();
  593 + wx.request({
  594 + url,
  595 + method: 'GET',
  596 + header: {"content-type": "application/x-www-form-urlencoded" },
  597 + data:data.data,
  598 + success(res) {
  599 + data.isShowLoading && wx.hideLoading();
  600 + resolve(res);
  601 + },
  602 + fail(err) { data.isShowLoading && wx.hideLoading(); reject(err); }
  603 + })
  604 + })
  605 + },
  606 +
  607 +
542 608  
543 609  
544 610 });
... ...