gq 8 gadi atpakaļ
vecāks
revīzija
eb2b42635b
1 mainītis faili ar 56 papildinājumiem un 68 dzēšanām
  1. 56 68
      server/app/Http/Controllers/Api/V1/MyController.php

+ 56 - 68
server/app/Http/Controllers/Api/V1/MyController.php

xqd xqd xqd xqd
@@ -331,6 +331,7 @@ class MyController extends Controller
      * @apiDescription 我的收藏
      * @apiGroup My
      * @apiPermission Passport
+     * @apiParam {string}  keyword   关键字可选
      * @apiVersion 0.1.0
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
@@ -362,62 +363,7 @@ class MyController extends Controller
      *       }
      *   }
      *}
-     * @apiErrorExample {json} Error-Response:
-     * HTTP/1.1 400 Bad Request
-     */
-    public function collection()
-    {
-        $user = $this->getUser();
-        $dreams = $user->collection;
-        $users = [];
-        foreach ($dreams as $item) {
-            if ($item->pivot->interaction_number > 0) {
-                $user_info = UserInfoModel::find($item->pivot->dream_user_id);
-                $avatar = $user_info ?  $user_info->avatar : '';
-                if (!array_key_exists($item->pivot->dream_user_id,$users)) {
-                    $users[$item->pivot->dream_user_id] = $avatar;
-                }
-            }
-           $item->img;
-        }
-        return $this->api(compact('dreams','users'));
-    }
-
-    /**
-     * @api {get} /api/my/setting 设置
-     * @apiDescription 设置
-     * @apiGroup My
-     * @apiPermission Passport
-     * @apiVersion 0.1.0
-     * @apiSuccessExample {json} Success-Response:
-     * HTTP/1.1 200 OK
-     *{
-     *   "status": true,
-     *   "status_code": 0,
-     *   "message": "",
-     *   "data": {
-     *       "key": "2511789",                    电话
-     *       "value": "关于喵喵介绍"              关于喵喵
-     *   }
-     *}
-     * @apiErrorExample {json} Error-Response:
-     * HTTP/1.1 400 Bad Request
-     */
-    public function setting()
-    {
-        $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
-        return $this->api($data);
-    }
-
-    /**
-     * @api {get}  /api/my/search_collection 梦想搜索
-     * @apiDescription 梦想搜索
-     * @apiGroup My
-     * @apiPermission none
-     * @apiVersion 0.1.0
-     * @apiParam {string}  keyword   关键字
-     * @apiSuccessExample {json} Success-Response:
-     * HTTP/1.1 200 OK
+     *          keyword存在
     {
         "status": true,
         "status_code": 0,
@@ -447,7 +393,7 @@ class MyController extends Controller
                         "sign": "梦想达人",
                         "created_at": "2017-06-25 13:10:56",
                         "updated_at": "2017-06-28 16:53:39"
-                        "img": {
+                        "img": {                                图片
                             "title": "",
                             "pic": "https://timgsa.baidu.com/timg9&di2f.jpg"
                         }
@@ -459,20 +405,62 @@ class MyController extends Controller
      * @apiErrorExample {json} Error-Response:
      * HTTP/1.1 400 Bad Request
      */
-    public function searchCollection(Request $request)
+    public function collection(Request $request)
     {
         $user = $this->getUser();
-        $keyword ='%'.$request->keyword.'%';
-        $data = UserCareDream::where('user_id',$user->id)->
-        whereHas('dreams',function ($query) use($keyword){
-            $query->where('end_time','<=',time())->where('name','like',$keyword);
-        })->with('dreams')->get();
-       foreach ($data as $item) {
-           foreach ($item->dreams as $dream) {
-               $dream->img;
-           }
+        if ($request->keyword) {
+            $keyword ='%'.$request->keyword.'%';
+            $data = UserCareDream::where('user_id',$user->id)->
+            whereHas('dreams',function ($query) use($keyword){
+                $query->where('end_time','>=',time())->where('name','like',$keyword);
+            })->with('dreams')->get();
+            foreach ($data as $item) {
+                foreach ($item->dreams as $dream) {
+                    $dream->img;
+                }
+            }
+            $this->insertSearchTable($user->id,$request->keyword);
+            return $this->api($data);
+        }else{
+            $dreams = $user->collection;
+            $users = [];
+            foreach ($dreams as $item) {
+                if ($item->pivot->interaction_number > 0) {
+                    $user_info = UserInfoModel::find($item->pivot->dream_user_id);
+                    $avatar = $user_info ?  $user_info->avatar : '';
+                    if (!array_key_exists($item->pivot->dream_user_id,$users)) {
+                        $users[$item->pivot->dream_user_id] = $avatar;
+                    }
+                }
+                $item->img;
+            }
+            return $this->api(compact('dreams','users'));
         }
-        $this->insertSearchTable($user->id,$request->keyword);
+    }
+
+    /**
+     * @api {get} /api/my/setting 设置
+     * @apiDescription 设置
+     * @apiGroup My
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     *{
+     *   "status": true,
+     *   "status_code": 0,
+     *   "message": "",
+     *   "data": {
+     *       "key": "2511789",                    电话
+     *       "value": "关于喵喵介绍"              关于喵喵
+     *   }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     */
+    public function setting()
+    {
+        $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
         return $this->api($data);
     }