dyjh 6 jaren geleden
bovenliggende
commit
445db4e267

+ 15 - 19
app/Http/Controllers/Web/AuthController.php

xqd xqd xqd xqd xqd
@@ -8,6 +8,7 @@
 
 namespace App\Http\Controllers\Web;
 
+use App\Models\AlbumAgentModel;
 use App\Models\AlbumManufacturerModel;
 use App\Models\AlbumUserModel;
 use Illuminate\Http\Request;
@@ -23,13 +24,14 @@ class AuthController extends Controller
             $name = $request->input('name');
             if (!$phone) {
                 $message = '请输入电话号码';
-                return view('web.auth.bind', compact('message'));
+                return view('web.auth.error', compact('message'));
             } else {
-                $check = AlbumUserModel::where([['phone', $phone],['g_open_id', null]])->first();
+                $check = AlbumUserModel::where([['phone', $phone],['g_open_id', null],['is_dealer', 1]])->first();
                 if (!$check) {
                     $message = '该号码不存在或是已绑定';
+                    return view('web.auth.error', compact('message'));
                 }
-                return view('web.auth.bind', compact('message'));
+
             }
             $weChatApp = AlbumManufacturerModel::where('store_id', $store_id)->first();
             $config = [
@@ -38,7 +40,7 @@ class AuthController extends Controller
                 'response_type' => 'array',
                 'oauth' => [
                     'scopes'   => ['snsapi_userinfo'],
-                    'callback' => '/web/notify?store_id=' . $store_id,
+                    'callback' => '/web/notify?store_id=' . $store_id . "&name=$name&phone=$phone",
                 ]
 
             ];
@@ -53,6 +55,8 @@ class AuthController extends Controller
     public function notify(Request $request)
     {
         $store_id = $request->input('store_id');
+        $phone = $request->input('phone');
+        $name = $request->input('name');
         $weChatApp = AlbumManufacturerModel::where('store_id', $store_id)->first();
         $config = [
             'app_id' => $weChatApp->G_app_id,
@@ -67,21 +71,13 @@ class AuthController extends Controller
         $oauth = $app->oauth;
         $user = $oauth->user()->toArray();
         $check_user = AlbumUserModel::where([['store_id',$store_id],['wechat_union_id',$user['original']['unionid']]])->first();
-        if ($check_user) {
-            $check_user->g_open_id = $user['id'];
-            $check_user->save();
-        } else {
-            $data['username'] = $user['name'];
-            $data['wechat_union_id'] = $user['original']['unionid'];
-            $data['avatar'] = $user['avatar'];
-            $data['g_open_id'] = $user['id'];
-            $data['store_id'] = $store_id;
-            $data['is_dealer'] = 0;
-            $data['role'] = 0;
-            $data['model'] = 0;
-            $data['up_agent_id'] = 0;
-            AlbumUserModel::create($data);
-        }
+        $agent = AlbumAgentModel::where([['store_id', $store_id],['user_id', $check_user->id]])->first();
+        $agent->name = $name;
+        $agent->save();
+        $check_user->g_open_id = $user['id'];
+        $check_user->phone = $phone;
+        $check_user->save();
+
         return view('web.auth.success');
     }
 

+ 75 - 0
resources/views/web/auth/error.blade.php

xqd
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>绑定微信号</title>
+    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
+    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
+    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
+    <style>
+        body{
+            background: #fff;
+        }
+        .header{
+            width: 100%;
+            height: 160px;
+            text-align:center;
+            line-height: 160px;
+            font-size: 55px;
+            background: rgb(40,125,180);
+            color:#fff;
+            background: -webkit-linear-gradient(left, rgb(255,172,20) ,  rgb(235,127,20)); /* Safari 5.1 - 6.0 */
+            background: -o-linear-gradient(right, rgb(255,172,20) ,  rgb(235,127,20)); /* Opera 11.1 - 12.0 */
+            background: -moz-linear-gradient(right,rgb(255,172,20) ,  rgb(235,127,20)); /* Firefox 3.6 - 15 */
+            background: linear-gradient(to right, rgb(255,172,20) ,  rgb(235,127,20)); /* 标准的语法 */
+        }
+        .txtbox{
+            width: 100%;
+            height: 450px;
+        }
+        .txtbox .title{
+            display: inline-block;
+            width: 100%;
+            height: 120px;
+            text-align: center;
+            line-height: 120px;
+            font-size: 45px;
+        }
+        .txtbox .input{
+            width: 60%;
+            height: 100px;
+            margin: 50px 20% 70px 20%;
+            font-size: 40px;
+            border: 1px solid #999;
+            border-radius: 60px;
+            text-indent: 60px;
+        }
+        .txtbox button{
+            width: 80%;
+            height: 120px;
+            line-height: 120px;
+            font-size: 45px;
+            font-weight: 600;
+            text-align: center;
+            margin-left: 10%;
+            border: none;
+            border-radius: 20px;
+            background: rgba(0,0,0,0.1);
+            color: #666;
+            margin-top: 100px;
+        }
+    </style>
+</head>
+<body>
+<div class="header">绑定成功</div>
+<div class="container" style="padding: 40px;width: 100%;height: 100%;">
+    <div class="row visible-on">
+        <div class="txtbox">
+            <div class="title">您的微信号已经成功绑定!</div>
+            <!-- <input class="input" type="text" placeholder="请输入手机号">
+            <button>确认绑定</button> -->
+        </div>
+    </div>
+</div>
+</body>
+</html>

+ 2 - 2
resources/views/web/auth/success.blade.php

xqd
@@ -61,11 +61,11 @@
     </style>
 </head>
 <body>
-<div class="header">绑定成功</div>
+<div class="header">绑定失败</div>
 <div class="container" style="padding: 40px;width: 100%;height: 100%;">
     <div class="row visible-on">
         <div class="txtbox">
-            <div class="title">您的微信号已经成功绑定!</div>
+            <div class="title">{{ $message }}</div>
             <!-- <input class="input" type="text" placeholder="请输入手机号">
             <button>确认绑定</button> -->
         </div>