| xqd
@@ -139,12 +139,12 @@ class IndexController extends Controller
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @api {get} /api/index/search 搜索(search) get post
|
|
|
+ * @api {get} /api/index/search 搜索(search)
|
|
|
* @apiDescription 搜索(search)
|
|
|
* @apiGroup Index
|
|
|
* @apiPermission none
|
|
|
* @apiVersion 0.1.0
|
|
|
- * @apiParam {string} keyword 关键字
|
|
|
+ * @apiParam {string} keyword 关键字可选
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
|
* HTTP/1.1 200 OK
|
|
|
* get
|
| xqd
@@ -186,42 +186,31 @@ class IndexController extends Controller
|
|
|
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();
|
|
|
+ if (empty($request->keyword)) {
|
|
|
+// 历史搜索
|
|
|
+ $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'));
|
|
|
+ }
|
|
|
+
|
|
|
return $this->api(compact('data1','data2','data3'));
|
|
|
}
|
|
|
|