app.js 4.18 KB
//app.js
var util = require('utils/util.js')
var uri = require('utils/uri.js')
const socket = require('utils/socket.js');
var mta= require('utils/mta_analysis.js')
App({
  scence:0,
  onLaunch: function (opt) {
      mta.App.init({
          "appID":"500667278",
      });

    this.getSystemInfo(uri.CACHE__SYSTEM_INFO);
    console.log(socket)
    // socket.initSocket();
  },
  onShow:function(){
      socket.resiverMessage();
      this.scence=0;
      // if(util.cache('identity')){
      //     this.getstaff();
      // }
      if (wx.canIUse('getUpdateManager')) {
          const updateManager = wx.getUpdateManager();
          updateManager.onCheckForUpdate(function (res) {
              // 请求完新版本信息的回调
              console.log('onCheckForUpdate',res)
          })

          updateManager.onUpdateReady(function (res) {
              console.log('onUpdateReady',res)
              updateManager.applyUpdate();
              wx.showToast({
                  title:'版本已更新',
                  duration:2000,
                  mask:true,
                  success:function(){

                  }
              })

          })
          updateManager.onUpdateFailed(function (res) {
              // 新的版本下载失败
              console.log('onUpdateFailed',res)
          })
      }

  },
    getstaff:function(){
        var that=this;
        wx.request({
            url: "https://dcapi.colorcun.com/?service=App.Seller.GetAuthUserLists",
            data: {sellerid:util.cache('sellerid')},
            header: {
                'content-type': 'application/json'
            },
            success: function(res) {
                if(res.data.ret==200){
                    var list=res.data.data;
                    var temp={};
                    for(var key in list){
                        list[key].forEach(function(v,i){
                            if(v.openid && v.openid!=''){
                                temp[v.openid]=true
                            }
                        })
                    }
                    if(!temp[util.cache('openid')]){
                        that.getsellerlist();
                    }
                }

            },
            complete:function (res) {
            }
        })

    },
    getsellerlist:function(){
        var that=this;
        wx.request({
            url: "https://dcapi.colorcun.com/?service=App.Seller.GetSystemByOpenid",
            data: {openid: util.cache('openid')},
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if (that.scence == 0) {
                    if (res.data.ret == 200 && res.data.data[0].auth == 0) {               //无商家
                        if (util.cache('manage')) {
                            wx.reLaunch({
                                url: '/pages/currency/c_store'
                            })
                        } else {
                            wx.reLaunch({
                                url: '/pages/login/l_login'
                            })
                        }
                    } else if (res.data.ret == 200 && res.data.data[0].length > 1) {         //有多个商家
                        wx.reLaunch({
                            url: '/pages/currency/c_store'
                        })
                    } else if (res.data.ret == 200 && res.data.data[0].length == 1) {      //有1个商家
                        wx.reLaunch({
                            url: '/pages/me/s_index?sellerid=' + res.data.data[0][0].id
                        })
                    }
                }
            }
        })
    },

  onHide:function(){
  },
  getSystemInfo:function(cb){
    var systemInfo=util.cache(uri.CACHE__SYSTEM_INFO);
    if(systemInfo){
      typeof cb == "function" && cb(systemInfo)
    }else{
      //调用设备信息接口
      wx.getSystemInfo({
        success:function(res){
            util.cache(uri.CACHE__SYSTEM_INFO,res);
            typeof cb == "function" && cb(res);
        }
      });
    }
  },
  "networkTimeout":{
      "request": 20000,
      "connectSocket": 20000,
      "uploadFile": 20000,
      "downloadFile": 20000
  },
})