Browse Source

Merge branch 'gq' of http://git.9026.com/roobe/miao

Mike 7 years ago
parent
commit
8cedbb3439

+ 33 - 0
server/app/Http/Controllers/Api/V1/DreamController.php

xqd
@@ -729,4 +729,37 @@ class DreamController extends Controller
         }
     }
 
+    /**
+     * @api {get} /api/dream/share 分享
+     * @apiDescription 分享
+     * @apiParam {int}  id          梦想id
+     * @apiGroup Dream
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     */
+//    分享梦想
+    public function share(Request $request)
+    {
+        $validator = \Validator::make($request->all(),
+            [
+                'id'  => 'required',
+            ],
+            [
+                'id.required'  => '梦想id不存在',
+            ]
+        );
+        if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
+        $url = env('APP_URL').'/api/dream/show?id='.$request->id;
+        $dream = DreamInfoModel::with('img')->find($request->id);
+        $img = !empty($dream->img) ? $dream->img->pic : '';
+        $html =
+            "<div style='text-align: center'>
+                <a href='$url'>
+                    <h1>$dream->name</h1>
+                    <img src=\"$img\" style='width: 20px;height: 20px;' alt=''>
+                </a>
+            </div>";
+        return $html;
+    }
+
 }

+ 112 - 0
server/app/Http/Controllers/Api/V1/IndexController.php

xqd
@@ -313,4 +313,116 @@ class IndexController extends Controller
 
     }
 
+    /**
+     * @api {get}  /api/index/filter 筛选
+     * @apiDescription 筛选
+     * @apiGroup Index
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @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
+     *{
+     *    "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 (($sex) == 1) {
+            $query = $query->whereHas('user', function ($select) use ($sex) {
+                $select->where('sex',0);
+            });
+        }
+        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')-29)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-26)));
+            });
+        }
+        if ($age == 4) {
+            $query = $query->whereHas('user', function ($select) use ($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.'%');
+            });
+        }
+        $arr1 =DreamInfoModel::limit(20)->select('id')->get()->toArray();
+        $id_arr1 = array_column($arr1,'id');
+        $arr2 =DreamInfoModel::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'));
+        }
+    }
 }

+ 8 - 0
server/routes/api.php

xqd xqd
@@ -97,6 +97,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'index.home',
         'uses' => 'IndexController@home',
     ]);
+    $api->get('index/filter', [
+        'as' => 'index.filter',
+        'uses' => 'IndexController@filter',
+    ]);
     $api->get('index/search', [
         'as' => 'index.search',
         'uses' => 'IndexController@search',
@@ -225,6 +229,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'dream.show',
         'uses' => 'DreamController@show',
     ]);
+    $api->get('dream/share', [
+        'as' => 'dream.share',
+        'uses' => 'DreamController@share',
+    ]);
     $api->get('dream/search', [
         'as' => 'dream.search',
         'uses' => 'DreamController@search',