* 可选参数:lng,lat */ public function index() { $this->success('请求成功'); } /** * 首页书籍榜单列表数据 * @param string $type 榜单类别(free finish click sell 免费榜 完结榜 点击榜 销售榜) * @param int $page 页数 * @return json */ public function booklistapi() { $sex = input('sex', 0); $type = input('type'); $page = input('page', 1); $books = model('Index')::booklist($sex, $type, $page); return json($books); } /** * 首页配置的指定区块书籍列表接口 * @param int $block_id 区块id * @param int $page 页数 * @return json $books 书籍列表信息 */ public function blockbookapi() { $block_id = input('block_id'); $page = input('page', 1); $data = model('AppIndex')::blockbooklist($block_id, $page); return json($data); } /** * 热门搜索(搜索页推荐书籍)接口 * @param int $sex 性别 * @return json */ public function hotsearchapi() { $redis = Redis::instance(); $sex = input('sex'); if ($sex == 'girl') { $sexVal = 2; } else { $sexVal = 1; } $key = 'CHS:' . $sexVal; if ($redis->exists($key)) { $data = $redis->get($key); $data = json_decode($data, true); } else { $data = Db::table('client_search_keyword')->field('keyword as name,book_id')->where("sex", $sexVal)->order('weigh', 'desc')->select(); $json = json_encode($data, JSON_UNESCAPED_UNICODE); $redis->setex($key, 86400, $json); } return json($data); } /** * 搜索接口 * @param string $keyword 关键词 * @param int $page 页码 * @return json */ public function searchapi() { $keyword = input('keyword'); $page = input('page', 1); if (!empty($keyword)) { $where = array(); $where['state'] = 1; $where['name'] = array('like', '%' . $keyword . '%'); $total = model('book')->where($where)->count(); $books = model('book')->where($where)->page($page, 10)->select(); } else { $total = 0; $books = array(); } if(!empty($books)){ $categoryArr = model("BookCategory")->getCategoryList(); foreach ($books as $k=>$v){ $books[$k]['author'] = $categoryArr[$v['book_category_id']]; } } $result = array( 'priMap' => array( 'total' => $total, 'searchList' => $books, ), 'index' => $page, 'ptype' => 'searchResult', 'keyword' => $keyword, ); return json($result); } /** * 搜索页 * @param int $sex 频道标示 */ public function search() { $userId = 0; if ($this->isLogin) { $userId = $this->userInfo['id']; } $books = model('User')->getLike($userId); $categoryArr = model("BookCategory")->getCategoryList(); foreach ($books as $k=>$v){ $books[$k]['author'] = $categoryArr[$v['book_category_id']]; } if($this->request->isAjax()){ return json_encode($books); }else{ $sex = input('sex'); $this->assign('sex', $sex); $pagedata['name'] = '精彩推荐'; $pagedata['block_resource'] = $books; $this->view->assign('value', $pagedata); return $this->view->fetch(); } } public function recommendAjax(){ $book_id = $this->request->get("book_id"); if($book_id){ $index = new \app\clientweb\controller\Index(); $pagedata = $index->recommendList($book_id); }else{ return false; } return json($pagedata); } /* public function getAppBookJson() { $book_id = input('book_id'); if (empty($book_id)) { $this->error('无此书籍'); } $book = model('Book')->BookInfo($book_id); if (empty($book)) { $this->error('无此书籍'); } //书的信息 提供js调用 $appBookInfo = ClientAppService::instance()->userReadBooksInfo([$book['id'] => $book['last_chapter_id']])->data; $appBookInfo = $appBookInfo['bookList'][0]; $jumpChapterId = input('chapter_id', 0); if (intval($jumpChapterId) > 0) { $appBookInfo['currentCid'] = $jumpChapterId; } $this->success('成功', $appBookInfo); }*/ //JS登录加密 public function getJsLoginToken() { if ($this->checkSign()) { $uid = $this->aCommon['uid']; $token = $this->aCommon['token']; if ($this->request->isAjax() && $uid && $token) { //设置cookie $arrSign['token'] = $token; $arrSign[] = 'key=ddbc9169242b479da867eb24efb735d1'; $strSign = implode('&', $arrSign); $this->success('成功', ['sign' => md5($strSign), 'uid' => $uid, 'token' => $token]); } $this->error('错误的请求'); } $this->error('签名错误'); } }