|
@@ -313,4 +313,91 @@ class IndexController extends Controller
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @api {get} /api/index/filter 筛选
|
|
|
|
+ * @apiDescription 筛选
|
|
|
|
+ * @apiGroup Index
|
|
|
|
+ * @apiPermission none
|
|
|
|
+ * @apiVersion 0.1.0
|
|
|
|
+ * @apiParam {string} [sex] 性别 0男1女
|
|
|
|
+ * @apiParam {string} [age] 年龄段 区间传数组[18,21] 否则传字符串38
|
|
|
|
+ * @apiParam {string} [area] 地区 例:成都
|
|
|
|
+ * @apiSuccessExample {json} Success-Response:
|
|
|
|
+ * HTTP/1.1 200 OK
|
|
|
|
+ *{
|
|
|
|
+ * "status": true,
|
|
|
|
+ * "status_code": 0,
|
|
|
|
+ * "message": "",
|
|
|
|
+ * "data":[
|
|
|
|
+ * {
|
|
|
|
+ * "nickname": "ha", 昵称
|
|
|
|
+ * "pic": "", 头像
|
|
|
|
+ * ...
|
|
|
|
+ * },
|
|
|
|
+ * ]
|
|
|
|
+ *}
|
|
|
|
+ * @apiErrorExample {json} Error-Response:
|
|
|
|
+ * HTTP/1.1 400 Bad Request
|
|
|
|
+ */
|
|
|
|
+ public function filter(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $sex = $request->sex;
|
|
|
|
+ $age = $request->age;
|
|
|
|
+ $area = $request->area;
|
|
|
|
+ $login_user = $this->getUser();
|
|
|
|
+ $id = $login_user->id;
|
|
|
|
+ $query = new DreamInfoModel();
|
|
|
|
+ if (!is_null($sex)) {
|
|
|
|
+ $query = $query->whereHas('user', function ($select) use ($sex) {
|
|
|
|
+ $select->where('sex',$sex);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (is_array($age)) {
|
|
|
|
+ $query = $query->whereHas('user', function ($select) use ($age) {
|
|
|
|
+ $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-$age[1])))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-$age[0])));
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (is_string($age)) {
|
|
|
|
+ $query = $query->whereHas('user', function ($select) use ($age) {
|
|
|
|
+ $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-$age)));
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (!empty($area)) {
|
|
|
|
+ $query = $query->whereHas('user', function ($select) use ($area) {
|
|
|
|
+ $select->where('city','like','%'.$area.'%');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ $arr1 =$query->limit(20)->select('id')->get()->toArray();
|
|
|
|
+ $id_arr1 = array_column($arr1,'id');
|
|
|
|
+ $arr2 =$query->orderBy('score','desc')->limit(120)->select('id')->get()->toArray();
|
|
|
|
+ $id_arr2 = array_column($arr2,'id');
|
|
|
|
+ $dtusers =UserCareUser::where('user_id',$id)->with('other_user')->
|
|
|
|
+ where('dream_number','>',0)->orderBy('created_at')->get()->toArray();
|
|
|
|
+ $hdusers = CommentInfoModel::where(function ($query) use ($id) {
|
|
|
|
+ $query->where('user_id',$id)->orWhere('to_user_id',$id);
|
|
|
|
+ })->where('is_read',0)->with('to_user')->orderBy('created_at')->get()->toArray();
|
|
|
|
+ $users = [] ;
|
|
|
|
+ foreach ($dtusers as $k => $v){
|
|
|
|
+ $users[] = $v['other_user'];
|
|
|
|
+ }
|
|
|
|
+ foreach ($hdusers as $k => $v){
|
|
|
|
+ $users[] = $v['to_user'];
|
|
|
|
+ }
|
|
|
|
+ $type = $request->type;
|
|
|
|
+ if ($type == 'trend') {
|
|
|
|
+ $dreams = $query->orderBy('score','desc')->with('user')->whereNotIn('id', $id_arr1)->limit(100)->paginate(20);
|
|
|
|
+ $this->dreams($dreams);
|
|
|
|
+ return $this->api(compact('users','dreams'));
|
|
|
|
+ } elseif ($type == 'news') {
|
|
|
|
+ $dreams = $query->orderBy('score','desc')->orderBy('created_at','desc')->with('user')->whereNotIn('id', $id_arr2)->limit(500)->paginate(20);
|
|
|
|
+ $this->dreams($dreams);
|
|
|
|
+ return $this->api(compact('users','dreams'));
|
|
|
|
+ } else{
|
|
|
|
+ $banners = $this->getBanner();
|
|
|
|
+ $dreams = $query->orderBy('score','desc')->with('user')->limit(20)->paginate(20);
|
|
|
|
+ $this->dreams($dreams);
|
|
|
|
+ return $this->api(compact('banners','users','dreams'));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|