123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- namespace App\Http\Controllers\Api\V1;
- use App\Models\BaseSettingsModel;
- use App\Models\DreamInfoModel;
- use App\Models\SearchInfoModel;
- use App\Models\UserInfoModel;
- use Illuminate\Http\Request;
- use App\Services\Base\ErrorCode;
- class IndexController extends Controller
- {
- /**
- * @api {get} /api/index/hot 热门(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调通后取消
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function hot(Request $request)
- {
- $user = $this->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;
- }
- }
|