| 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|