gq 8 سال پیش
والد
کامیت
09cb390f76

+ 12 - 5
server/app/Http/Controllers/Api/V1/AuthController.php

xqd xqd xqd
@@ -4,7 +4,8 @@ namespace App\Http\Controllers\Api\V1;
 
 use App\Http\HelperTraits\SmsHelper;
 use App\Models\UserBanks;
-
+use Illuminate\Foundation\Auth\AuthenticatesUsers;
+use App\Models\UserInfoModel;
 use Illuminate\Http\Request;
 use App\Services\Base\ErrorCode;
 use App\User;
@@ -13,7 +14,7 @@ use Validator, Auth, Cache;
 
 class AuthController extends Controller
 {
-    use SmsHelper;
+    use SmsHelper,AuthenticatesUsers;
 
     private $expireTime     = 1;
     private $keySmsCode     = 'auth:sms:';
@@ -86,11 +87,17 @@ class AuthController extends Controller
         $phone = $request->phone;
         $key = $this->keySmsCode . $phone;
         $code = Cache::store('file')->get($key);
-
+        $password = bcrypt(123456);
         if ($request->verify_code != $code)
             return $this->error(ErrorCode::SERVICE_CODE_FAILED);
-        session(['tel' => $phone]);
-        return $this->api(['verify_code' => $code]);
+        UserInfoModel::firstOrCreate(['tel'=>$phone,'password'=>bcrypt(123456)]);
+        if (Auth::attempt(['tel'=>$phone,'password'=>$password])) {
+            $user = Auth::user();
+            $token = $user->createToken($user->tel)->accessToken;
+            return $this->api(compact( 'user', 'code','token'));
+        }else{
+            return $this->error(ErrorCode::INCORRECT_USER_OR_PASS);
+        }
 
     }
 

+ 8 - 1
server/app/Http/Controllers/Api/V1/Controller.php

xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Api\V1;
 
+use App\Models\UserInfoModel;
 use Illuminate\Foundation\Bus\DispatchesJobs;
 use Illuminate\Routing\Controller as BaseController;
 use Illuminate\Foundation\Validation\ValidatesRequests;
@@ -14,9 +15,15 @@ class Controller extends BaseController
     use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
 
 //    protected $_data = null;
-    protected $_user = null;
+    protected $user = null;
 
 
+    public function getUser()
+    {
+        $this->user = UserInfoModel::where('tel','13880642880')->first();
+        return $this->user;
+    }
+
     public function __construct() {
 /*
         $this->middleware('auth:api', [

+ 3 - 46
server/app/Http/Controllers/Api/V1/HomeController.php

xqd
@@ -2,53 +2,10 @@
 
 namespace App\Http\Controllers\Api\V1;
 
-use App\Models\BaseSettingsModel;
-use App\Models\DreamInfoModel;
-use App\Models\UserInfoModel;
 use Illuminate\Http\Request;
-use App\Services\Base\ErrorCode;
+use App\Http\Controllers\Controller;
+
 class HomeController extends Controller
 {
-    /**
-     * @api {get} /api/home/index 首页(home)
-     * @apiSuccessExample {json} Success-Response:
-     * HTTP/1.1 200 OK
-     * {
-     *     "state": true,
-     *     "code": 0,
-     *     "message": "",
-     *     "data": {
-     *         "verify_code": "1234"//该值调试时使用,sms调通后取消
-     *     }
-     * }
-     * @apiErrorExample {json} Error-Response:
-     * HTTP/1.1 400 Bad Request
-     * {
-     *     "state": false,
-     *     "code": 1000,
-     *     "message": "传入参数不正确",
-     *     "data": null or []
-     * }
-     * 可能出现的错误代码:
-     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
-     */
-
-    public function index(Request $request)
-    {
-//        $tel = $request->session()->get('tel');
-        $a = 1234235434534;
-        return $a;
-        $user = UserInfoModel::where('tel',$tel)->frist();
-//获取轮播图
-        $banner = BaseSettingsModel::where([['category' => 'banner'],['status' => '1']])
-            ->orderBy('sort')->limit('3')->get()->toArray();
-//        关注的用户
-       $other_user =  $user->UserCareUser;
-        return $other_user;
-        dd($other_user);
-//        获取其他用户信息 及梦想
-        $user_info = UserInfoModel::orderBy('id')->get()->toArray();
-        $dream = DreamInfoModel::orderBy('created_at')->get()->toArray();
-        return $this->error(ErrorCode::SERVICE_CODE_FAILED);
-    }
+    //
 }

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

xqd
@@ -0,0 +1,51 @@
+<?php
+
+namespace App\Http\Controllers\Api\V1;
+
+use App\Models\BaseSettingsModel;
+use App\Models\DreamInfoModel;
+use App\Models\UserInfoModel;
+use Illuminate\Http\Request;
+use App\Services\Base\ErrorCode;
+class IndexController extends Controller
+{
+    /**
+     * @api {get} /api/home/hot 热门(hot)
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "state": true,
+     *     "code": 0,
+     *     "message": "",
+     *     "data": {
+     *         "verify_code": "1234"//该值调试时使用,sms调通后取消
+     *     }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     */
+
+    public function hot(Request $request)
+    {
+        $user = $this->getUser();
+//获取轮播图
+        $banner = BaseSettingsModel::where(['category' => 'banner'])->where(['status' => '1'])
+            ->orderBy('sort')->limit('3')->get()->toArray();
+//        关注的用户
+       $other_user =  $user->UserCareUser;
+//        获取其他用户信息 及梦想
+        $dreams = DreamInfoModel::orderBy('created_at')->get();
+        foreach ($dreams as $k => $dream) {
+            $dream->dream_find_user =  $dream->dreamFindUser;
+        }
+        return $this->api(compact('banner','other_user','dreams'));
+    }
+}

+ 66 - 0
server/app/Http/Controllers/Api/V1/MyController.php

xqd
@@ -0,0 +1,66 @@
+<?php
+
+namespace App\Http\Controllers\Api\V1;
+
+use Illuminate\Http\Request;
+class MyController extends Controller
+{
+    /**
+     * @api {get} /api/my/index 个人首页(index)
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+    {
+    "status": true,
+    "status_code": 0,
+    "message": "",
+    "data": {
+    "my_care_num": 4,关注
+    "my_fens_num": 3,粉丝
+    "my_collection_num": 2,收藏
+    "my_dream_num": 1,发帖
+    "user": {
+    "id": 1,
+    "tel": "13880642880",
+    "password": "",
+    "nickname": "",
+    "pic": "",
+    "sign": 0,
+    "money": 0,余额
+    "sex": 1,
+    "signture": "",
+    "tall": "",
+    "job": "",
+    "emotion": 1,
+    "address": "",
+    "detail_address": "",
+    "status": 1,
+    "remember_token": "",
+    "created_at": "2017-06-02 02:30:12",
+    "updated_at": "2017-06-02 02:30:12",
+    "deleted_at": null,
+    }
+     */
+    public function index()
+    {
+        $user = $this->getUser();
+        /*
+         * 我的关注人数,我的粉丝,收藏
+         * 点赞?徽章?
+         * */
+        $data1 = $user->myCareNum;
+        $data2 = $user->myFens;
+        $data3 = $user->myCollection;
+        $data4 = $user->UserDream;
+        $my_care_num = count($data1);
+        $my_fens_num = count($data2);
+        $my_collection_num = count($data3);
+        $my_dream_num = count($data4);//发帖数
+        return $this->api(compact('my_care_num','my_fens_num','my_collection_num','my_dream_num','user'));
+    }
+
+    public function persona()
+    {
+        $user = $this->getUser();
+        return $this->api(compact('user'));
+    }
+}

+ 1 - 0
server/app/Http/Controllers/Controller.php

xqd
@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Models\UserInfoModel;
 use Illuminate\Foundation\Bus\DispatchesJobs;
 use Illuminate\Routing\Controller as BaseController;
 use Illuminate\Foundation\Validation\ValidatesRequests;

+ 6 - 0
server/app/Models/DreamInfoModel.php

xqd
@@ -45,4 +45,10 @@ class DreamInfoModel extends BaseModel
         return $this->belongsToMany('App\Models\UserInfoModel','user_dream','user_id','dream_id');
     }
 
+    public function dreamFindUser()
+    {
+        return $this->belongsToMany('App\Models\UserInfoModel','user_dream','dream_id','user_id');
+    }
+
+
 }

+ 5 - 0
server/app/Models/UserDream.php

xqd
@@ -7,4 +7,9 @@ use Illuminate\Database\Eloquent\Model;
 class UserDream extends Model
 {
     protected $table = 'user_dream';
+
+    public function DreamUser()
+    {
+        return $this->belongsTo('App\Models\UserInfoModel','user_id','id');
+    }
 }

+ 39 - 12
server/app/Models/UserInfoModel.php

xqd xqd xqd xqd
@@ -1,6 +1,9 @@
 <?php
 namespace App\Models;
 use App\Models\BaseModel;
+use Illuminate\Foundation\Auth\User as Authenticatable;
+use Laravel\Passport\HasApiTokens;
+use Illuminate\Notifications\Notifiable;
 /**
  *  @description 用户表
  *  @author  system;
@@ -8,8 +11,9 @@ use App\Models\BaseModel;
  *  @date 2017-05-30 12:16:56
  *
  */
-class UserInfoModel extends BaseModel
+class UserInfoModel extends Authenticatable
 {
+    use HasApiTokens, Notifiable;
     /**
      * 数据表名
      *
@@ -31,17 +35,21 @@ class UserInfoModel extends BaseModel
      * @var string
      */
     protected $fillable = [
-                           'password',
-                           'email',
-                           'area',
-                           'name',
-                           'vip',
-                           'level',
-                           'idcard',
-                           'contact',
-                           'prize',
-                           'openid',
-                           'remember_token'
+                           'tel',
+                           'pwd',
+                           'nickname',
+                           'sign',
+                           'pic',
+                           'money',
+                           'sex',
+                           'signture',
+                           'tall',
+                           'job',
+                           'emotion',
+                           'address',
+                           'detail_address',
+                           'status',
+                           'remember_token',
                           ];
 
     public function UserCareUser()
@@ -49,4 +57,23 @@ class UserInfoModel extends BaseModel
         return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','user_id','other_user_id');
     }
 
+    public function UserDream()
+    {
+        return $this->belongsToMany('App\Models\DreamInfoModel','user_dream','user_id','dream_id');
+    }
+
+    public function myCareNum()
+    {
+        return $this->hasMany('App\Models\UserCareUser','user_id','id');
+    }
+
+    public function myFens()
+    {
+        return $this->hasMany('App\Models\UserCareUser','other_user_id','id');
+    }
+    public function myCollection()
+    {
+        return $this->hasMany('App\Models\UserCareDream','user_id','id');
+    }
+
 }

+ 2 - 0
server/app/Providers/AuthServiceProvider.php

xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Providers;
 
 use Illuminate\Support\Facades\Gate;
+use Laravel\Passport\Passport;
 use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
 
 class AuthServiceProvider extends ServiceProvider
@@ -24,6 +25,7 @@ class AuthServiceProvider extends ServiceProvider
     public function boot()
     {
         $this->registerPolicies();
+        Passport::routes();
 
         //
     }

+ 3 - 3
server/config/auth.php

xqd xqd xqd
@@ -45,7 +45,7 @@ return [
             'provider' => 'admin_users',
         ],
         'api' => [
-            'driver' => 'token',
+            'driver' => 'passport',
             'provider' => 'users',
         ],
     ],
@@ -70,7 +70,7 @@ return [
     'providers' => [
         'users' => [
             'driver' => 'eloquent',
-            'model' => App\User::class,
+            'model' => App\Models\UserInfoModel::class,
         ],
 
         'admin_users' => [
@@ -102,7 +102,7 @@ return [
     'passwords' => [
         'users' => [
             'provider' => 'users',
-            'table' => 'password_resets',
+            'table' => 'user_info',
             'expire' => 60,
         ],
 

+ 3 - 1
server/database/migrations/2017_04_01_091442_create_user_info_table.php → server/database/migrations/2017_04_01_091443_create_user_info_table.php

xqd xqd
@@ -22,6 +22,8 @@ class CreateUserInfoTable extends Migration
             $table->char('tel',11)->unique()->comment('电话');
             $table->string('pwd',100)->default('')->comment('密码');
             $table->string('nickname',100)->default('')->comment('昵称');
+            $table->string('pic',100)->default('')->comment('用户头像');
+            $table->integer('sign')->default(0)->comment('用户标签');
             $table->integer('money')->default(0)->comment('余额');
             $table->tinyInteger('sex')->default(1)->comment('性别');
             $table->string('signture',200)->default('')->comment('个性签名');
@@ -31,7 +33,7 @@ class CreateUserInfoTable extends Migration
             $table->string('address')->default('')->comment('省市区地址');
             $table->string('detail_address')->default('')->comment('详细地址');
             $table->tinyInteger('status')->default(1)->comment('状态');
-            $table->string('remember_token')->comment('token');
+            $table->string('remember_token')->default('')->comment('token');
             $table->timestamps();
             $table->softDeletes();
         });

+ 0 - 77
server/database/migrations/2017_05_30_203526_create_user_info_table.php

xqd
@@ -1,77 +0,0 @@
-<?php
-
-use Illuminate\Support\Facades\Schema;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Database\Migrations\Migration;
-
-/**
- * Migration auto-generated by Sequel Pro Laravel Export
- * @see https://github.com/cviebrock/sequel-pro-laravel-export
- */
-class CreateUserInfoTable extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        Schema::create('user_info', function (Blueprint $table) {
-            $table->increments('id')->comment('用户ID');
-            $table->integer('site_id')->nullable()->comment('站点ID');
-            $table->char('username', 64)->nullable()->comment('登录名');
-            $table->char('real_name', 20)->comment('姓名');
-            $table->string('password', 255)->nullable()->comment('密码');
-            $table->string('email', 100)->comment('EMAIL');
-            $table->char('mobile', 11)->comment('手机号');
-            $table->string('avatar', 255)->comment('用户头像');
-            $table->tinyInteger('gender')->comment('性别,1:男,2:女,参照数据字典');
-            $table->integer('province')->nullable()->comment('居住地址省');
-            $table->integer('city')->nullable()->comment('居住地址市');
-            $table->integer('county')->nullable()->comment('居住地址区县');
-            $table->tinyInteger('work_type')->nullable()->comment('工作类型:上班,自由职业者');
-            $table->text('other_info')->nullable()->comment('配偶或其他信息');
-            $table->string('address', 255)->comment('详细地址');
-            $table->unsignedTinyInteger('address_time')->nullable()->comment('居住时长');
-            $table->unsignedTinyInteger('home_type')->nullable()->comment('居住类型');
-            $table->char('idcard', 20)->nullable()->comment('身份证号');
-            $table->string('idcard_positive', 500)->nullable()->comment('身份证正面');
-            $table->string('idcard_back', 500)->nullable()->comment('身份证背面');
-            $table->string('photo', 500)->nullable()->comment('正面照');
-            $table->string('zhima_img', 500)->nullable()->comment('芝麻信用');
-            $table->string('other_img', 500)->nullable();
-            $table->string('driver_img', 500)->nullable();
-            $table->tinyInteger('educational')->nullable()->comment('学历');
-            $table->tinyInteger('marital')->nullable()->comment('婚姻状况');
-            $table->tinyInteger('contact_bind')->nullable()->comment('直系亲属联系人关系');
-            $table->char('contact_name', 32)->nullable()->comment('直系亲属联系人姓名');
-            $table->char('contact_mobile', 11)->nullable()->comment('直系亲属联系人手机');
-            $table->tinyInteger('other_contact_bind')->nullable()->comment('其他联系人关系');
-            $table->char('other_contact_name', 32)->nullable()->comment('直系亲属联系人姓名');
-            $table->char('other_contact_mobile', 11)->nullable()->comment('直系亲属联系人手机');
-            $table->string('xuexin_account', 20)->nullable()->comment('学信网账号');
-            $table->string('xuexin_password', 60)->nullable()->comment('学信网密码');
-            $table->char('carrieroperator_mobile', 11)->nullable()->comment('运营商手机');
-            $table->dateTime('last_login_time')->nullable()->comment('最后一次登录时间');
-            $table->string('remember_token', 255)->nullable();
-            $table->timestamps();
-            $table->softDeletes();
-
-            $table->index('deleted_at', 'idx_deleted_at');
-
-            
-
-        });
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::dropIfExists('user_info');
-    }
-}

+ 0 - 33
server/database/migrations/2017_06_01_063149_add_columns_to_user_info_table.php

xqd
@@ -1,33 +0,0 @@
-<?php
-
-use Illuminate\Support\Facades\Schema;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Database\Migrations\Migration;
-
-class AddColumnsToUserInfoTable extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        Schema::table('user_info', function (Blueprint $table) {
-            $table->string('pic',100)->comment('用户头像')->after('nickname');
-            $table->integer('sign')->default(0)->comment('用户标签')->after('nickname');
-        });
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::table('user_info', function (Blueprint $table) {
-            //
-        });
-    }
-}

+ 63 - 3
server/routes/api.php

xqd
@@ -66,9 +66,69 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
 
 
 
+//首页
+    $api->get('index/hot', [
+        'as' => 'index.hot',
+        'uses' => 'IndexController@hot',
+    ]);
+    $api->get('index/trend', [
+        'as' => 'index.trend',
+        'uses' => 'IndexController@trend',
+    ]);
+    $api->get('index/new', [
+        'as' => 'index.new',
+        'uses' => 'IndexController@new',
+    ]);
+    $api->get('index/search', [
+        'as' => 'index.search',
+        'uses' => 'IndexController@search',
+    ]);
 
-    $api->get('home/index', [
-        'as' => 'home.index',
-        'uses' => 'HomeController@index',
+//我的
+    $api->get('my/index', [
+        'as' => 'my.index',
+        'uses' => 'MyController@index',
+    ]);
+    $api->get('my/persona', [
+        'as' => 'my.persona',
+        'uses' => 'MyController@persona',
+    ]);
+//    充值
+    $api->get('my/recharge', [
+        'as' => 'my.recharge',
+        'uses' => 'MyController@recharge',
+    ]);
+    $api->get('my/system_info', [
+        'as' => 'my.system_info',
+        'uses' => 'MyController@systemInfo',
+    ]);
+    $api->get('my/reply_my', [
+        'as' => 'my.reply_my',
+        'uses' => 'MyController@replyMy',
+    ]);
+    $api->get('my/my_reply', [
+        'as' => 'my.my_reply',
+        'uses' => 'MyController@myReply',
+    ]);
+    $api->get('my/dream', [
+        'as' => 'my.dream',
+        'uses' => 'MyController@dream',
+    ]);
+//    我的收藏
+    $api->get('my/collection', [
+        'as' => 'my.collection',
+        'uses' => 'MyController@collection',
+    ]);
+    $api->get('my/setting', [
+        'as' => 'my.setting',
+        'uses' => 'MyController@setting',
+    ]);
+    $api->get('my/add_dream', [
+        'as' => 'my.add_dream',
+        'uses' => 'MyController@addDream',
+    ]);
+    $api->get('my/dream_about', [
+        'as' => 'my.dream_about',
+        'uses' => 'MyController@dreamAbout',
     ]);
 });