dyjh 6 år sedan
förälder
incheckning
1b53f089e2

+ 2 - 0
.env.example

xqd
@@ -3,6 +3,8 @@ APP_KEY=
 APP_DEBUG=true
 APP_LOG_LEVEL=debug
 APP_URL=http://localhost
+APP_ID=
+APP_SECRET=
 
 DB_CONNECTION=mysql
 DB_HOST=127.0.0.1

+ 17 - 0
app/Http/Controllers/Api/V1/IndexController.php

xqd
@@ -0,0 +1,17 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2018/7/12
+ * Time: 16:03
+ */
+
+namespace App\Http\Controllers\Api\V1;
+
+
+class IndexController extends Controller
+{
+    public function index() {
+
+    }
+}

+ 120 - 0
app/Http/Controllers/Api/V1/LoginController.php

xqd
@@ -0,0 +1,120 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2018/7/11
+ * Time: 15:59
+ */
+
+namespace App\Http\Controllers\Api\V1;
+
+use App\Models\UserInfoModel;
+use EasyWeChat\Factory;
+use Illuminate\Http\Request;
+
+class LoginController extends Controller
+{
+    private $config;
+
+    public function __construct()
+    {
+        $this->config = [
+            'app_id' => env('APP_ID'),
+            'secret' => env('APP_SECRET'),
+            'response_type' => 'array',
+        ];
+    }
+
+    /**
+     * @api {post} /api//login 登陆(login)
+     * @apiDescription 登陆(login)login
+     * @apiGroup Auth
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string}  nickname   手机号码
+     * @apiParam {string} avatar
+     * @apiParam {string} password   password
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "state": true,
+     *     "code": 0,
+     *     "message": "",
+     *     "data": {
+     *         "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjdjYWUyYzFmYTUwMTIyZDI0ZTRiYTZhZGZhNmQxYmZlOWNiMzIxMTBmYWJlZjNjYzIyNmViZjRmNGExNWM3NjllNmU2ZTNiYWE5OGNhOWUzIn0.eyJhdWQiOiIxIiwianRpIjoiN2NhZTJjMWZhNTAxMjJkMjRlNGJhNmFkZmE2ZDFiZmU5Y2IzMjExMGZhYmVmM2NjMjI2ZWJmNGY0YTE1Yzc2OWU2ZTZlM2JhYTk4Y2E5ZTMiLCJpYXQiOjE0NzU0MTE1NTgsIm5iZiI6MTQ3NTQxMTU1OCwiZXhwIjo0NjMxMDg1MTU4LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.E9YGEzuRUOk02aV1EiWLJ_pD0hKoCyW0k_sGy63hM3u5X8K_HI1kVhaU6JNLqLZeszIAroTEDB8XMgZKAqTLlwtL8PLCJcuDoxfk1BRHbfjhDheTsahBysKGalvNEpzRCrGlao0mS0Cg9qDpEsndtypPFS8sfaflToOzbJjiSK2DvQiHSH8xZI3zHJTezgZMz-pB_hPTxp8ajdv0ve1gWtWjs3vERr0Y91X4hngO8X7LuXtAYtfxGZRIye12YE7TuLBMYzj8CCfiRt7Smhyf4palNW5mzKlZpa2l87n6NQ14Iy4oMzQ2PON1j_swrosuE2yZohGOn6fDdSCBRdJ6dLD_emjBdQCQOoB63R7BbhFZgvFX25TjzFJ7r9AdVMiGmebuRKEVSZV_JCGu1C71OIbQk-UK35s00gSr2fmJGBbN2cZTXBRTJpfuMZ_ihFYEZrvVq_Ih2X0xkd36JUuxaUld1BXRgPZvH-9jBuhe0YW2OOlgwpdm6ZB8BMcuS4ftLoi6FipgzFqfIuy-0ZqPMDnJaG7Gycrdpxza00mgOFxYxJtqwZNsUWFRZEVU881l6VC_cy294YXSPQxUwEoyKg-G5Pm8AEB9bqv5z4EU4B8-XTd3zKNqtNba_snHbc711i4EytCiZfYSjNB1hwenq45YYOAhPTwOpFI0kxyRazc",
+     *         "user": {
+     *             "id": 1,
+     *             "name": "15888888888",
+     *             "email": "abcdefg@gmail.com",
+     *             "type": 2,
+     *             "phone": "15888888888",
+     *             "avatar": null,
+     *             "last_ip": null,
+     *             "created_at": "2016-09-30 00:45:13",
+     *             "updated_at": "2016-09-29 16:43:36"
+     *         }
+     *     }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     *    1102    INCORRECT_USER_OR_PASS          用户名或密码不正确
+     */
+    public function login(Request $request)
+    {
+        $data = $request->input();
+        $app = Factory::miniProgram($this->config);
+        $res = $app->auth->session($data['code']);
+        if (!$res || empty($res['openid'])) {
+            $user= [
+                'code' => 1,
+                'msg' => '获取用户OpenId失败',
+                'data' => $res,
+            ];
+            return $this->api($user);
+        }
+        $check_user = UserInfoModel::where('openid',$res['openid'])->first();
+        if(!$check_user){
+            $add['nickname'] = preg_replace('/[\xf0-\xf7].{3}/', '', $data['nickname']);
+            $add['wechat_open_id'] = $res['openid'];
+            $add['avatar'] = $data['avatar'];
+            $res = UserInfoModel::create($add);
+            if($res){
+                $data_user = UserInfoModel::where('wechat_open_id',$res['openid'])->first();
+                $user = [
+                    'user_id'=>$data_user['id'],
+                    'avatar'=>$data_user['avatar'],
+                    'username'=>$data_user['nickname'],
+                ];
+            } else {
+                $user= [
+                    'code' => 1,
+                    'msg' => '登陆失败',
+                ];
+            }
+        } else {
+            //print_r($check);die;
+            $save['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $data['nickname']);
+            $save['avatar'] = $data['avatar'];
+            $res = UserInfoModel::where('wechat_open_id',$res['openid'])->update($save);
+            //echo 111;
+            if($res){
+                $user = [
+                    'user_id'=>$check_user->id,
+                    'avatar'=>$data['avatar'],
+                    //'avatar'=>$check_user->avatar,
+                    'username'=>$data['nickname'],
+                    //'username'=>$check_user->naciname,
+                ];
+            }
+        }
+        $this->api($user);
+    }
+}

+ 33 - 0
database/migrations/2018_07_11_082811_add_clounm_state_to_messages_followers.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddClounmStateToMessagesFollowers extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('messages_followers', function (Blueprint $table) {
+            //
+            $table->unsignedInteger('state')->default(0)->comment('信息状态 0 已领取 1 已完成');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('messages_followers', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2018_07_12_082532_del_site_id_to_user.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class DelSiteIdToUser extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('user_info', function (Blueprint $table) {
+            //
+            $table->dropColumn('site_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('user_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2018_07_12_082734_del_site_id_to_messages_info.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class DelSiteIdToMessagesInfo extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('messages_info', function (Blueprint $table) {
+            //
+            $table->dropColumn('site_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('messages_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2018_07_12_082928_del_site_id_to_messages_tag.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class DelSiteIdToMessagesTag extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('messages_tag', function (Blueprint $table) {
+            //
+            $table->dropColumn('site_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('messages_tag', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2018_07_12_083113_del_site_id_to_messages_tag_relation.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class DelSiteIdToMessagesTagRelation extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('messages_tag_relation', function (Blueprint $table) {
+            //
+            $table->dropColumn('site_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('messages_tag_relation', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2018_07_12_083232_del_site_id_to_payment_info.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class DelSiteIdToPaymentInfo extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('payment_info', function (Blueprint $table) {
+            //
+            $table->dropColumn('site_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('payment_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 13 - 13
routes/api.php

xqd xqd
@@ -20,20 +20,20 @@ use Illuminate\Http\Request;
 
 
 //
-//$api = app('Dingo\Api\Routing\Router');
+$api = app('Dingo\Api\Routing\Router');
 //
-//$api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($api) {
+$api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($api) {
 //    // test
-//    $api->get('test', [
-//        'as' => 'test',
-//        'uses' => 'AuthController@test',
-//    ]);
-//    // Auth
-//    // signin
-//    $api->post('auth/login', [
-//        'as' => 'auth.login',
-//        'uses' => 'AuthController@login',
-//    ]);
+    $api->get('login', [
+        'as' => 'login.login',
+        'uses' => 'LoginController@login',
+    ]);
+
+    $api->get('index', [
+        'as' => 'index.index',
+        'uses' => 'IndexController@index',
+    ]);
+
 //    $api->post('auth/logout', [
 //        'as' => 'auth.logout',
 //        'uses' => 'AuthController@logout',
@@ -63,4 +63,4 @@ use Illuminate\Http\Request;
 //        'as' => 'auth.is_login',
 //        'uses' => 'AuthController@isLogin',
 //    ]);
-//});
+});