gq 8 anos atrás
pai
commit
f369ba786a

+ 2 - 1
server/app/Http/Controllers/Api/V1/AuthController.php

xqd
@@ -134,7 +134,8 @@ class AuthController extends Controller
      *    1104    LOGOUT_FAILED                   退出失败
      */
     public function logout() {
-        if (Auth::user()->token()->delete()) {
+        $user = Auth::user();
+        if ($user->token()->delete()) {
             return $this->api(['result' => true]);
         }
         return $this->error(ErrorCode::LOGOUT_FAILED);

+ 175 - 44
server/app/Http/Controllers/Api/V1/IndexController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Api\V1;
 use App\Models\BaseSettingsModel;
 use App\Models\DreamInfoModel;
 use App\Models\SearchInfoModel;
+use App\Models\UserCareUser;
+use App\Models\UserDream;
 use App\Models\UserInfoModel;
 use Illuminate\Http\Request;
 use App\Services\Base\ErrorCode;
@@ -12,19 +14,31 @@ class IndexController extends Controller
 {
     /**
      * @api {get} /api/index/hot 热门(hot)
-     * @apiDescription 登陆(hot)
+     * @apiDescription 热门(hot)
      * @apiGroup Index
      * @apiPermission none
      * @apiVersion 0.1.0
-     * @apiParam {string}  phone   手机号码
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
-     * {
-     *     "state": true,
-     *     "code": 0,
-     *     "message": "",
-     *     "data": {
-     *         "verify_code": "1234"//该值调试时使用,sms调通后取消
+     *{
+     *"status": true,
+     *"status_code": 0,
+     *"message": "",
+     *"data": {
+     *      "banner": [],  轮播图
+     *      "other_user": [],  动态用户
+     *      "dreams": [
+     *         "care_num": 0,   关注人数
+     *         "time": 1222222,   梦想倒计时
+     *         "dream_imgs_first": {
+     *               "pic": "",  梦想封面图片
+     *          }
+     *        dream_find_user": [
+     *             {
+     *                  ...       发布梦想的用户信息
+     *            }
+     *         ],
+     *    ]
      *     }
      * }
      * @apiErrorExample {json} Error-Response:
@@ -35,8 +49,6 @@ class IndexController extends Controller
      *     "message": "传入参数不正确",
      *     "data": null or []
      * }
-     * 可能出现的错误代码:
-     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
      */
     public function hot(Request $request)
     {
@@ -44,13 +56,16 @@ class IndexController extends Controller
 //获取轮播图
         $banner = $this->getBanner();
 //        关注的用户
-       $other_user =  $user->UserCareUser;
+        $arr =  $user->UserCareUser;
+        $other_user = [] ;
+        foreach ($arr as $k => $v){
+            if ($v->pivot->dream_num > 0) {
+                $other_user[] = $v;
+            }
+        }
 //        获取其他用户信息 及梦想
         $dreams = DreamInfoModel::orderBy('score','desc')->limit(20)->get();
-        foreach ($dreams as $k => $dream) {
-            $dream->dream_find_user =  $dream->dreamFindUser;
-            $dream->dream_first_pic =  $dream->dreamImgsFirst;
-        }
+        $this->dreams($dreams);
         return $this->api(compact('banner','other_user','dreams'));
     }
 
@@ -60,15 +75,26 @@ class IndexController extends Controller
      * @apiGroup Index
      * @apiPermission none
      * @apiVersion 0.1.0
-     * @apiParam {string}  phone   手机号码
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
-     * {
-     *     "state": true,
-     *     "code": 0,
-     *     "message": "",
-     *     "data": {
-     *         "verify_code": "1234"//该值调试时使用,sms调通后取消
+     *{
+     *"status": true,
+     *"status_code": 0,
+     *"message": "",
+     *"data": {
+     *      "other_user": [],  动态用户
+     *      "dreams": [
+     *         "care_num": 0,   关注人数
+     *         "time": 1222222,   梦想倒计时
+     *         "dream_imgs_first": {
+     *               "pic": "",  梦想封面图片
+     *          }
+     *        dream_find_user": [
+     *             {
+     *                  ...       发布梦想的用户信息
+     *            }
+     *         ],
+     *    ]
      *     }
      * }
      * @apiErrorExample {json} Error-Response:
@@ -79,20 +105,21 @@ class IndexController extends Controller
      *     "message": "传入参数不正确",
      *     "data": null or []
      * }
-     * 可能出现的错误代码:
-     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
      */
     public function trend(Request $request)
     {
         $user = $this->getUser();
 //        关注的用户
-        $other_user =  $user->UserCareUser;
+        $arr =  $user->UserCareUser;
+        $other_user = [] ;
+        foreach ($arr as $k => $v){
+            if ($v->pivot->dream_num > 0) {
+                $other_user[] = $v;
+            }
+        }
 //        获取其他用户信息 及梦想
         $dreams = DreamInfoModel::orderBy('score','desc')->offset(20)->limit(100)->get();
-        foreach ($dreams as $k => $dream) {
-            $dream->dream_find_user =  $dream->dreamFindUser;
-            $dream->dream_first_pic =  $dream->dreamImgsFirst;
-        }
+        $this->dreams($dreams);
         return $this->api(compact('other_user','dreams'));
     }
 
@@ -102,15 +129,26 @@ class IndexController extends Controller
      * @apiGroup Index
      * @apiPermission none
      * @apiVersion 0.1.0
-     * @apiParam {string}  phone   手机号码
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
-     * {
-     *     "state": true,
-     *     "code": 0,
-     *     "message": "",
-     *     "data": {
-     *         "verify_code": "1234"//该值调试时使用,sms调通后取消
+     *{
+     *"status": true,
+     *"status_code": 0,
+     *"message": "",
+     *"data": {
+     *      "other_user": [],  动态用户
+     *      "dreams": [
+     *         "care_num": 0,   关注人数
+     *         "time": 1222222,   梦想倒计时
+     *         "dream_imgs_first": {
+     *               "pic": "",  梦想封面图片
+     *          }
+     *        dream_find_user": [
+     *             {
+     *                  ...       发布梦想的用户信息
+     *            }
+     *         ],
+     *    ]
      *     }
      * }
      * @apiErrorExample {json} Error-Response:
@@ -121,20 +159,21 @@ class IndexController extends Controller
      *     "message": "传入参数不正确",
      *     "data": null or []
      * }
-     * 可能出现的错误代码:
-     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
      */
     public function news(Request $request)
     {
         $user = $this->getUser();
 //        关注的用户
-        $other_user =  $user->UserCareUser;
+        $arr =  $user->UserCareUser;
+        $other_user = [] ;
+        foreach ($arr as $k => $v){
+            if ($v->pivot->dream_num > 0) {
+                $other_user[] = $v;
+            }
+        }
 //        获取其他用户信息 及梦想
         $dreams = DreamInfoModel::orderBy('score','desc')->offset(100)->limit(500)->get();
-        foreach ($dreams as $k => $dream) {
-            $dream->dream_find_user =  $dream->dreamFindUser;
-            $dream->dream_first_pic =  $dream->dreamImgsFirst;
-        }
+        $this->dreams($dreams);
         return $this->api(compact('other_user','dreams'));
     }
 
@@ -190,7 +229,7 @@ class IndexController extends Controller
         $data1 = UserInfoModel::where('nickname','like',$keyword)->get();
         $data2 = DreamInfoModel::where('dream','like',$keyword)->
             orWhere('dream','like',$keyword)->get();
-        $data3  = BaseSettingsModel::where('category','sign')->get();
+        $data3  = BaseSettingsModel::where('category','sign')->where('value','like',$keyword)->get();
         if (empty($request->keyword)) {
 //            历史搜索
                 $data1  = $user->search()->orderBy('id','desc')->limit(10)->get();
@@ -214,6 +253,85 @@ class IndexController extends Controller
         return $this->api(compact('data1','data2','data3'));
     }
 
+    /**
+     * @api {get}  /api/index/user_search 用户搜索(search)
+     * @apiDescription 用户搜索(search)
+     * @apiGroup Index
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string}  keyword   关键字
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     *{
+     *    "status": true,
+     *   "status_code": 0,
+     *   "message": "",
+     *  "data": {
+     *       "data1": [
+     *          "nickname": "ha",  昵称
+     *          "pic": "",    头像
+     *             ...
+     *       ]
+     *   }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     */
+    public function userSearch(Request $request)
+    {
+        if (empty($request->keyword)) {
+            return $this->api('');
+        }
+        $keyword ='%'.$request->keyword.'%';
+        $data1 = UserInfoModel::where('nickname','like',$keyword)->get();
+          return $this->api(compact('data1'));
+    }
+
+    /**
+     * @api {get}  /api/index/dream_search 梦想搜索(search)
+     * @apiDescription 梦想搜索(search)
+     * @apiGroup Index
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string}  keyword   关键字
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+    {
+        "status": true,
+        "status_code": 0,
+        "message": "",
+        "data": {
+            "data": [
+                {
+                    "dream": "haha",  梦想名
+                    "user_pic": [
+                    {
+                        "pic": "",   用户头像
+                    }
+                    ],
+                    "dream_img": "",  梦想图片
+                }
+            ]
+        }
+    }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     */
+    public function dreamSearch(Request $request)
+    {
+        if (empty($request->keyword)) {
+            return $this->api('');
+        }
+        $keyword ='%'.$request->keyword.'%';
+        $data = DreamInfoModel::where('dream','like',$keyword)->
+        orWhere('dream','like',$keyword)->get();
+        foreach ($data as $k => $value) {
+            $value->user_pic = $value->dreamFindUser;
+            $value->dream_img = $value->dreamImgsFirst->pic;
+        }
+        return $this->api(compact('data'));
+    }
+
     //获取轮播图
     public function getBanner()
     {
@@ -221,4 +339,17 @@ class IndexController extends Controller
             ->orderBy('sort')->limit('3')->get()->toArray();
         return $banner;
     }
+
+//    完善梦想信息
+    public function dreams($dreams)
+    {
+        foreach ($dreams as $k => $dream) {
+            $dream->dream_find_user =  $dream->dreamFindUser;
+//            计算被关注总人数
+            $user_id = UserDream::where('dream_id',$dream->id)->first()->user_id;
+            $data = UserCareUser::where('other_user_id',$user_id)->get();
+            $dream->care_num = count($data);
+            $dream->dream_first_pic =  $dream->dreamImgsFirst;
+        }
+    }
 }

+ 10 - 6
server/app/Http/Controllers/Api/V1/MyController.php

xqd xqd xqd
@@ -738,8 +738,8 @@ class MyController extends Controller
     /**
      * @api {post} /api/my/add_dream 发布梦想(addDream)
      * @apiDescription 发布梦想(addDream)
-       * @apiParam {string}  pic   梦想图片 数组
-       * @apiParam {string}  videos   梦想视频
+       * @apiParam {string}  pics   梦想图片 数组
+       * @apiParam {string}  video   梦想视频
        * @apiParam {string}  dream   梦想标题
        * @apiParam {string}  about   梦想介绍
        * @apiParam {int}  money   梦想币
@@ -792,7 +792,11 @@ class MyController extends Controller
         $b = $key ->value;
         $t = 21*3600 / 60;
         $data = $request->except('_token','pic');
-        $data['score'] = (log($care_num) + ($a/$t) + $b)*100000000 ;
+        if ($care_num == 0) {
+            $data['score'] = (($a/$t) + $b)*100000000 ;
+        }else{
+            $data['score'] = (log($care_num) + ($a/$t) + $b)*100000000 ;
+        }
         $data['created_at'] = date('Y-m-d H:i:s');
         $data['updated_at'] = date('Y-m-d H:i:s');
         $dream_id = DreamInfoModel::insertGetId($data);
@@ -802,9 +806,9 @@ class MyController extends Controller
             $data1['user_id'] = $user->id;
             $data1['created_at'] = date('Y-m-d H:i:s');
             $data1['updated_at'] = date('Y-m-d H:i:s');
-            $arr = $request->pic;
-            $videos = $request->videos;
-            if (empty($arr) && empty($videos))   return $this->error(ErrorCode::ATTACHMENT_NOT_EXIST);
+            $arr = $request->pics;
+            $video = $request->video;
+            if (empty($arr) && empty($video))   return $this->error(ErrorCode::ATTACHMENT_NOT_EXIST);
             $ok = UserDream::create($data1);
             $arr1 = [];
             if ($ok) {

+ 1 - 1
server/app/Models/UserInfoModel.php

xqd
@@ -56,7 +56,7 @@ class UserInfoModel extends Authenticatable
 
     public function UserCareUser()
     {
-        return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','user_id','other_user_id');
+        return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','user_id','other_user_id')->withPivot('dream_num');
     }
 
 //    系统消息

+ 32 - 0
server/database/migrations/2017_06_20_135741_add_dream_num_to_user_care_user.php

xqd
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddDreamNumToUserCareUser extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('user_care_user', function (Blueprint $table) {
+            $table->integer('dream_num')->comment('被关注用户最新梦想数目')->default(0)->after('other_user_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('user_care_user', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 8 - 0
server/routes/api.php

xqd
@@ -100,6 +100,14 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'index.search',
         'uses' => 'IndexController@search',
     ]);
+    $api->get('index/user_search', [
+        'as' => 'index.user_search',
+        'uses' => 'IndexController@userSearch',
+    ]);
+    $api->get('index/dream_search', [
+        'as' => 'index.dream_search',
+        'uses' => 'IndexController@dreamSearch',
+    ]);
 
 //我的
     $api->get('my/index', [