李浩杰 4 年 前
コミット
69cc5e0b11

+ 1 - 1
app/Http/Controllers/Admin/UserAuthController.php

xqd
@@ -73,7 +73,7 @@ class UserAuthController extends BaseController
                 'user_id' => $item['user_id'],
                 'project_role_id' => $item['project_role_id']
             ]);
-            User::where('user_id', $item['user_id'])->update(['name' => $item['name']]);
+            User::where('user_id', $item['user_id'])->update(['name' => $item['name'], 'phone' => $item['phone']]);
             $item->update(['active' => 1]);
         }
         return response()->json(['status' => 'success', 'info' => '操作成功']);

+ 1 - 0
app/Http/Controllers/Api/mini/AuthController.php

xqd
@@ -65,6 +65,7 @@ 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]);
         }
         return $this->error(['msg' => '登陆失败']);

+ 1 - 1
app/Http/Controllers/Api/mini/UserAuthController.php

xqd
@@ -17,7 +17,7 @@ class UserAuthController extends BaseController
 
     public function create(Request $request)
     {
-        $data = $request->only(['name', 'project_id', 'project_role_id', 'remark']);
+        $data = $request->only(['name', 'project_id', 'project_role_id', 'remark', 'phone']);
         $user = Auth::guard('mini')->user();
         $user_id = $user ? $user->id : '';
         $data['user_id'] = $user_id;

+ 30 - 0
database/migrations/2021_01_10_171241_add_phone_to_user_auths.php

xqd
@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddPhoneToUserAuths extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('user_auths', function (Blueprint $table) {
+            $table->string('phone', 20)->after('id')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

+ 1 - 1
mini/pages/account/index.wxml

xqd
@@ -14,7 +14,7 @@
           <view wx:if="userInfo">所属项目个数 | {{project_num}}个</view>
           <view bindtap="navigate" data-url="{{userInfo ? '/pages/user/index' : '/pages/login/index'}}">{{ userInfo ? '修改用户信息' : '点击按钮进行登录操作' }}</view>
         </view>
-        <view wx:if="{{project_num <= 0}}" class="sg-margin-tb-sm sg-pad-sm sg-primary sg-font-xs sg-white sg-flex sg-align-center sg-space-between" style="background: #4281F0; border-radius: 5px" bindtap="navigate" data-url="/pages/bind/index">
+        <view class="sg-margin-tb-sm sg-pad-sm sg-primary sg-font-xs sg-white sg-flex sg-align-center sg-space-between" style="background: #4281F0; border-radius: 5px" bindtap="navigate" data-url="/pages/bind/index">
           <view>联系管理员进行授权,进行项目查看</view>
           <van-icon name="arrow"></van-icon>
         </view>

+ 63 - 19
mini/pages/bind/index.js

xqd xqd xqd xqd xqd
@@ -13,7 +13,8 @@ Page({
     roles: [],
     roleIndex: -1,
     name: '',
-    remark: ''
+    remark: '',
+    phone: ''
   },
 
   /**
@@ -23,7 +24,7 @@ Page({
 
   },
 
-  onInputChange: function(e) {
+  onInputChange: function (e) {
     var name = e.currentTarget.dataset.name
     var val = e.detail.value
     this.setData({
@@ -32,41 +33,81 @@ Page({
   },
 
   updatePhoneNumber(e) {
-    if(e.detail.errMsg == 'errMsg') {
-      http({
-        url: 'auth/parsePhone',
-        data: e.detail,
-        success: function(res) {
-          util.success('手机号获取成功')
+    var that = this
+    if (e.detail.errMsg == 'getPhoneNumber:ok') {
+      wx.checkSession({
+        success: () => {
+          var data = Object.assign({}, e.detail, {
+            session_key: wx.getStorageSync('session_key')
+          })
+          console.log(data)
+          that.parsePhone(data)
+        },
+        fail: () => {
+          wx.login({
+            success: function(res) {
+              var data = Object.assign({}, e.detail, {
+                code: res.code
+              })
+              console.log(data)
+              that.parsePhone(data)
+            }
+          })
         }
       })
     }
   },
 
-  getUserInfo: function(e) {
+  parsePhone(data) {
+    var that = this
+    http({
+      url: 'parsePhone',
+      data: data,
+      success: function (res) {
+        console.log(res)
+        if(res.code == 0 && res.data.phoneNumber) {
+          that.setData({
+            phone: res.data.phoneNumber
+          })
+          if(res.data.session_key) {
+            wx.setStorageSync('session_key', res.data.session_key)
+          }
+          util.success('手机号获取成功')
+        } else {
+          util.error('发生错误')
+        }
+      }
+    })
+  },
+
+  getUserInfo: function (e) {
     var that = this;
-    util.wechatLogin(e, false, function(res) {
+    util.wechatLogin(e, false, function (res) {
       that.submit()
     }, true)
   },
 
-  submit: function() {
-    if(!this.data.name) {
+  submit: function () {
+    if (!this.data.name) {
       util.error('真实姓名必填')
       return false;
     }
-    if(!this.data.projectIndex < 0) {
+    if (!this.data.projectIndex < 0) {
       util.error('所属项目必填')
       return false;
     }
-    if(!this.data.roleIndex < 0) {
+    if (!this.data.roleIndex < 0) {
       util.error('申请角色不能为空')
       return false;
     }
-    if(this.data.remark.length < 10) {
+    if (this.data.remark.length < 10) {
       util.error('备注需10个字以上')
       return false;
     }
+    if(!this.data.phone) {
+      util.error('手机号不能为空')
+      return false;
+    }
     var project = this.data.projects[this.data.projectIndex]
     var role = this.data.roles[this.data.roleIndex]
     http({
@@ -75,15 +116,16 @@ Page({
         name: this.data.name,
         project_id: project ? project.id : '',
         project_role_id: role ? role.id : '',
-        remark: this.data.remark
+        remark: this.data.remark,
+        phone: this.data.phone
       },
-      success: function(res) {
+      success: function (res) {
         util.success('操作成功')
       }
     })
   },
 
-  bindPickerChange: function(e) {
+  bindPickerChange: function (e) {
     var name = e.currentTarget.dataset.name
     this.setData({
       [name]: e.detail.value
@@ -102,7 +144,9 @@ Page({
    */
   onShow: function () {
     api.getByName(this, 'projects/getAll', 'projects')
-    api.getByName(this, 'project-roles/getAll', 'roles', {'limit': true})
+    api.getByName(this, 'project-roles/getAll', 'roles', {
+      'limit': true
+    })
   },
 
   /**

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

xqd
@@ -8,7 +8,8 @@
       </view>
       <view class="sg-pick-item sg-pad-tb-sm sg-flex sg-align-center sg-bottom-border sg-space-between">
         <view class="sg-pick-name">手机号</view>
-        <van-button type="primary" open-type="getPhoneNumber" bind:getphonenumber="updatePhoneNumber" size="small">授权获取手机号</van-button>
+        <view wx:if="{{phone}}">{{phone}}</view>
+        <van-button type="primary" open-type="getPhoneNumber" bind:getphonenumber="updatePhoneNumber" size="small" wx:else>授权获取手机号</van-button>
       </view>
       <view class="sg-pick-item sg-pad-tb-sm sg-flex sg-align-center sg-bottom-border sg-space-between">
         <view class="sg-pick-name">所属项目</view>