getUser(); //获取轮播图 $banner = $this->getBanner(); // 关注的用户 $other_user = $user->UserCareUser; // 获取其他用户信息 及梦想 $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; } return $this->api(compact('banner','other_user','dreams')); } /** * @api {get} /api/index/trend 潮流(trend) * @apiDescription 潮流(trend) * @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调通后取消 * } * } * @apiErrorExample {json} Error-Response: * HTTP/1.1 400 Bad Request * { * "state": false, * "code": 1000, * "message": "传入参数不正确", * "data": null or [] * } * 可能出现的错误代码: * 1000 CLIENT_WRONG_PARAMS 传入参数不正确 */ public function trend(Request $request) { $user = $this->getUser(); // 关注的用户 $other_user = $user->UserCareUser; // 获取其他用户信息 及梦想 $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; } return $this->api(compact('other_user','dreams')); } /** * @api {get} /api/index/new 最新(news) * @apiDescription 最新(news) * @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调通后取消 * } * } * @apiErrorExample {json} Error-Response: * HTTP/1.1 400 Bad Request * { * "state": false, * "code": 1000, * "message": "传入参数不正确", * "data": null or [] * } * 可能出现的错误代码: * 1000 CLIENT_WRONG_PARAMS 传入参数不正确 */ public function news(Request $request) { $user = $this->getUser(); // 关注的用户 $other_user = $user->UserCareUser; // 获取其他用户信息 及梦想 $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; } return $this->api(compact('other_user','dreams')); } /** * @api {get} {post} /api/index/search 搜索(search) get post * @apiDescription 搜索(search) * @apiGroup Index * @apiPermission none * @apiVersion 0.1.0 * @apiParam {string} keyword 关键字 * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * get *{ * "status": true, * "status_code": 0, * "message": "", * "data": { * "arr": { // 热门搜索 * ... * }, * "data1": [ * { * "search": "ha", // 历史搜索 * } * ] * } *} * post * { * "status": true, * "status_code": 0, * "message": "", * "data": { * "data1": [ * ... //用户 * ], * "data2": [ * ... //梦想 * ], * "data3": [ * ... //标签 * ] * } *} * @apiErrorExample {json} Error-Response: * HTTP/1.1 400 Bad Request */ public function search(Request $request) { $user = $this->getUser(); if ($request->method() == 'GET') { // 历史搜索 $data1 = $user->search()->orderBy('id','desc')->limit(10)->get(); // 热门搜索 $data2 = SearchInfoModel::get(); $arr = []; foreach ($data2 as $k => $v) { if (count($arr) == 8) { break; } if (!array_key_exists($v->search,$arr)) { $arr[$v->search] = $v->times; }else{ $arr[$v->search] += $v->times; } } arsort($arr); return $this->api(compact('arr','data1')); } $validator = \Validator::make($request->all(), [ 'keyword' => 'required', ], [ 'keyword.required' => '关键字必填', ] ); if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS); $keyword ='%'.$request->keyword.'%'; $data1 = UserInfoModel::where('nickname','like',$keyword)->get(); $data2 = DreamInfoModel::where('dream','like',$keyword)-> orWhere('dream','like',$keyword)->get(); $data3 = BaseSettingsModel::where('category','sign')->get(); return $this->api(compact('data1','data2','data3')); } //获取轮播图 public function getBanner() { $banner = BaseSettingsModel::where(['category' => 'banner'])->where(['status' => '1']) ->orderBy('sort')->limit('3')->get()->toArray(); return $banner; } }