gq 8 年之前
父节点
当前提交
176478265a
共有 1 个文件被更改,包括 60 次插入0 次删除
  1. 60 0
      server/app/Http/Controllers/Api/V1/MyController.php

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

xqd
@@ -407,4 +407,64 @@ class MyController extends Controller
         return $this->api($data);
     }
 
+    /**
+     * @api {get}  /api/dream/search_collection 梦想搜索
+     * @apiDescription 梦想搜索
+     * @apiGroup Dream
+     * @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 searchCollection(Request $request)
+    {
+        $user = $this->getUser();
+        if (empty($request->keyword)) {
+            return $this->api('');
+        }
+        $keyword ='%'.$request->keyword.'%';
+        $data = DreamInfoModel::where('dream','like',$keyword)->
+        orWhere('sign','like',$keyword)->get();
+        foreach ($data as $k => $value) {
+            $value->user_pic = $value->dreamFindUser;
+            $value->dream_img = $value->dreamImgsFirst->pic;
+        }
+        $this->insertSearchTable($user->id,$request->keyword);
+        return $this->api(compact('data'));
+    }
+
+    public function insertSearchTable($id,$keyword)
+    {
+        $info = SearchInfoModel::where('user_id',$id)->
+        where('search',trim($keyword))->first();
+        if (count($info) == 0) {
+            SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
+        }else{
+            $info->times += 1;
+            $info->save();
+        }
+
+    }
+
 }