request->post('user_id'); if (!$user_id) { return $this->result('网络错误', [], 100); } $data = SearchModel::where('user_id', $user_id)->group('content')->select(); if ($data) { return $this->result('', $data, 200); } else { return $this->result('暂无数据', [], 100); } } /** * 清空历史记录 * @ApiMethod (POST) * @param string $user_id 用户id */ public function serachEmpty() { $user_id = $this->request->post('user_id'); if (!$user_id) { return $this->result('网络错误', [], 100); } $del = SearchModel::where('user_id', $user_id)->delete(); if ($del) { return $this->result('成功', [], 200); } else { return $this->result('失败', [], 100); } } /** * 关键词显示 * @ApiMethod (POST) * @param string $content 文字 */ public function keyIndex() { $content = $this->request->post('content'); if (!$content) { return $this->result('网络错误', [], 100); } $where['c_name'] = ['like', "%" . $content . '%']; $data = CommodityModel::where($where)->field('c_name')->group('c_name')->select(); if ($data) { return $this->result('', $data, 200); } else { return $this->result('暂无数据', [], 100); } } /** * 使用关键词查询 * @ApiMethod (POST) * @param string $content 文字 * @param string $user_id 用户ID * @param string $page 页数 */ public function searchKey() { $content = $this->request->post('content'); $user_id = $this->request->post('user_id'); $page = $this->request->post('page'); if (!isset($page)) { $page = 0; } if (!$user_id) { return $this->result('网络错误', [], 100); } if (!$content) { return $this->result('网络错误', [], 100); } $where['c_name'] = ['like', "%" . $content . "%"]; $data = CommodityModel::where($where)->page($page, 5)->select(); $params = array( 'user_id' => $user_id, 'content' => $content, 'type' => 1, ); $model = new SearchModel(); $addSearch = $model->allowField(true)->save($params); if ($data) { return $this->result('', $data, 200); } else { return $this->result('暂无数据', [], 100); } } /** * 不使用关键词查询 * @ApiMethod (POST) * @param string $content 文字 * @param string $user_id 用户ID * @param string $page 页数 */ public function searchTitle() { $content = $this->request->post('content'); $user_id = $this->request->post('user_id'); $page = $this->request->post('page'); if (!isset($page)) { $page = 0; } if (!$user_id) { return $this->result('网络错误', [], 100); } if (!$content) { return $this->result('网络错误', [], 100); } $where['c_title_content'] = ['like', "%" . $content . "%"]; $data = CommodityModel::where($where)->page($page, 5)->select(); $params = array( 'user_id' => $user_id, 'content' => $content, 'type' => 2, ); $model = new SearchModel(); $addSearch = $model->allowField(true)->save($params); if ($data) { return $this->result('', $data, 200); } else { return $this->result('暂无数据', [], 100); } } }