李浩杰 4 lat temu
rodzic
commit
df42d384eb

+ 10 - 6
app/Http/Controllers/Api/mini/AuthController.php

xqd xqd
@@ -53,9 +53,7 @@ class AuthController extends BaseController
                     'avatar' => $data['avatarUrl']
                 ]);
                 $user->updateToken();
-                $user = User::find($user->id);
-                $user->topRole = $user->getTopRole();
-                $user->session_key = $session_key;
+                $user = $user->getUserInfo($session_key);
                 return $this->success(['data' => $user]);
             }
         }
@@ -72,10 +70,16 @@ class AuthController extends BaseController
         }
         if($session_key) {
             $data = $app->encryptor->decryptData($session_key, $request->input('iv'), $request->input('encryptedData'));
-            $data['session_key'] = $session_key;
-            return $this->success(['data' => $data]);
+            if(isset($data['phoneNumber'])) {
+                $user = Auth::guard('mini')->user();
+                $user->update(['phone' => $data['phoneNumber']]);
+                $user = $user->getUserInfo($session_key);
+                return $this->success(['data' => $user]);
+            }
+
+            return $this->error(['msg' => '获取失败']);
         }
-        return $this->error(['msg' => '登陆失败']);
+        return $this->error(['msg' => '获取失败']);
     }
 
     public function reset(Request $request)

+ 7 - 0
app/Models/User.php

xqd
@@ -121,4 +121,11 @@ class User extends Authenticatable
         }
         return 0;
     }
+
+    public function getUserInfo($session_key)
+    {
+        $user = User::find($this['id']);
+        $user->topRole = $user->getTopRole();
+        $user->session_key = $session_key;
+    }
 }

+ 1 - 1
mini/app.json

xqd xqd
@@ -1,5 +1,6 @@
 {
   "pages": [
+    "pages/user/index",
     "pages/account/index",
     "pages/index/index",
     "pages/bind/index",
@@ -18,7 +19,6 @@
     "pages/about/index",
     "pages/feedback/index",
     "pages/password/index",
-    "pages/user/index",
     "pages/note-detail/index",
     "pages/draft/index",
     "pages/use-record/index",

+ 11 - 1
mini/pages/account/index.js

xqd xqd
@@ -1,6 +1,7 @@
 // pages/account/index.js
 import http from '../../utils/http'
 import api from '../../utils/api'
+import util from '../../utils/util'
 const app = getApp()
 Page({
 
@@ -20,7 +21,16 @@ Page({
   },
 
   navigate: function (e) {
-    // if()
+    var url = e.currentTarget.dataset.url
+    if(!this.data.userInfo.phone && url == '/pages/bind/index') {
+      util.error('请先进入个人信息页面进行授权')
+      setTimeout(function() {
+        wx.navigateTo({
+          url: '/pages/user/index',
+        })
+      }, 1000)
+      return false;
+    }
     app.navigate(e)
   },
 

+ 40 - 0
mini/pages/user/index.js

xqd
@@ -31,6 +31,46 @@ Page({
     }
   },
 
+  updatePhoneNumber(e) {
+    var that = this
+    if (e.detail.errMsg == 'getPhoneNumber:ok') {
+      wx.checkSession({
+        success: () => {
+          var data = Object.assign({}, e.detail, {
+            session_key: wx.getStorageSync('session_key')
+          })
+          that.parsePhone(data)
+        },
+        fail: () => {
+          wx.login({
+            success: function(res) {
+              var data = Object.assign({}, e.detail, {
+                code: res.code
+              })
+              that.parsePhone(data)
+            }
+          })
+        }
+      })
+    }
+  },
+
+  parsePhone(data) {
+    var that = this
+    http({
+      url: 'parsePhone',
+      data: data,
+      success: function (res) {
+        if(res.code == 0) {
+          getApp().updateUserInfo(res.data)
+          that.userInfo = res.data
+        } else {
+          util.error('发生错误')
+        }
+      }
+    })
+  },
+
   chooseImage() {
     var that = this
     wx.chooseImage({

+ 2 - 1
mini/pages/user/index.wxml

xqd
@@ -11,7 +11,8 @@
     </view>
     <view class="sg-flex sg-align-center sg-space-between sg-pad sg-bottom-border">
       <view class="sg-gray-color">手机号码</view>
-      <input class="sg-input sg-text-right" value="{{phone}}" bindinput="updateInput" data-name="phone"></input>
+      <input class="sg-input sg-text-right" value="{{phone}}" bindinput="updateInput" data-name="phone" wx:if="{{userInfo.phone}}"></input>
+      <van-button type="info" open-type="getPhoneNumber" bind:getphonenumber="updatePhoneNumber" size="small" wx:else>点击授权获取</van-button>
     </view>
   </view>
   <view class="sg-fix-bottom sg-pad sg-text-center sg-white-bg" bindtap="save">保存</view>