gq 7 роки тому
батько
коміт
620dd0b9b5
1 змінених файлів з 34 додано та 9 видалено
  1. 34 9
      server/app/Http/Controllers/Api/V1/IndexController.php

+ 34 - 9
server/app/Http/Controllers/Api/V1/IndexController.php

xqd xqd xqd
@@ -319,8 +319,8 @@ class IndexController extends Controller
      * @apiGroup Index
      * @apiPermission none
      * @apiVersion 0.1.0
-     * @apiParam {string}  [sex]   性别 0男1女
-     * @apiParam {string}  [age]   年龄段 区间传数组[18,21]  否则传字符串38
+     * @apiParam {string}  [sex]   性别   //1男,2女,0:全部,
+     * @apiParam {string}  [age]   年龄段  0:全部,1:18-21,2:22-25,3:26-29,4:30-33,5:34-37,6:>37,
      * @apiParam {string}  [area]   地区   例:成都
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
@@ -347,21 +347,47 @@ class IndexController extends Controller
         $login_user = $this->getUser();
         $id = $login_user->id;
         $query = new DreamInfoModel();
-        if (!is_null($sex)) {
+        if (($sex) == 1) {
             $query = $query->whereHas('user', function ($select) use ($sex) {
-                $select->where('sex',$sex);
+                $select->where('sex',0);
             });
         }
-        if (is_array($age)) {
+        if (($sex) == 2) {
+            $query = $query->whereHas('user', function ($select) use ($sex) {
+                $select->where('sex',1);
+            });
+        }
+        if ($age == 1) {
+            $query = $query->whereHas('user', function ($select) use ($age) {
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-21)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-18)));
+            });
+        }
+        if ($age == 2) {
+            $query = $query->whereHas('user', function ($select) use ($age) {
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-25)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-22)));
+            });
+        }
+        if ($age == 3) {
             $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])));
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-29)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-26)));
             });
         }
-        if (is_string($age)) {
+        if ($age == 4) {
             $query = $query->whereHas('user', function ($select) use ($age) {
-                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-$age)));
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-33)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-30)));
             });
         }
+        if ($age == 5) {
+            $query = $query->whereHas('user', function ($select) use ($age) {
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-37)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-34)));
+            });
+        }
+        if ($age == 6) {
+            $query = $query->whereHas('user', function ($select) use ($age) {
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-38)));
+            });
+        }
+
         if (!empty($area)) {
             $query = $query->whereHas('user', function ($select) use ($area) {
                 $select->where('city','like','%'.$area.'%');
@@ -399,5 +425,4 @@ class IndexController extends Controller
             return $this->api(compact('banners','users','dreams'));
         }
     }
-
 }