Commit c32adf7299c2331243aba04aad8624af56878285

Authored by yvan.ni
1 parent f515fc86

自动登录的优化

Showing 1 changed file with 43 additions and 0 deletions
... ... @@ -135,6 +135,49 @@ App({
135 135 }
136 136 })
137 137 }
  138 + else {
  139 + //--拿下code--
  140 + wx.login({
  141 + success: function (o) {
  142 + var dd = {
  143 + js_code: o.code,
  144 + store_id: os.stoid,
  145 + };
  146 + //-- 导购会员ID --
  147 + if (app.globalData.guide_id) {
  148 + dd.guide_id = app.globalData.guide_id;
  149 + }
  150 +
  151 + app.request.get("/api/weshop/users/openidandkey", {
  152 + data: dd,
  153 + success: function (e) {
  154 + if (e.data.code == 0) {
  155 + //如果有会员的话,没有sessionKey
  156 + if (!e.data.data.sessionKey) {
  157 + // getApp().showWarning("登录成功");
  158 +
  159 + app.globalData.userInfo = e.data.data;
  160 + app.globalData.user_id = e.data.data.user_id;
  161 + app.globalData.openid = e.data.data.weapp_openid;
  162 + //把会员的信息存在内存
  163 + wx.setStorageSync("userinfo", e.data.data);
  164 +
  165 + //调用接口判断是不是会员
  166 + app.promiseGet("/api/weshop/shoppingGuide/get/" + os.stoid + "/" + e.data.data.user_id, {}).then(res => {
  167 + if (res.data.code == 0) {
  168 + app.globalData.guide_id = res.data.data.id;
  169 + app.globalData.guide_pick_id = res.data.data.pickup_id
  170 + }
  171 + })
  172 +
  173 +
  174 + }
  175 + }
  176 + }
  177 + })
  178 + }
  179 + })
  180 + }
138 181  
139 182 // else if(app.globalData.user_id){ //-- 启用默认的user_id --
140 183 // app.promiseGet("/api/weshop/users/get/" + app.globalData.setting.stoid + "/" + app.globalData.user_id,{}).then(res=>{
... ...