123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <?php
- namespace app\clientwebapi\controller;
- use app\api\library\OrderDeduction;
- use app\common\controller\Api;
- use app\common\controller\ClientWebApi;
- use app\common\library\Redis;
- use app\main\service\ClientAppService;
- use Think\Db;
- /**
- * 首页接口
- */
- class Index extends ClientWebApi
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- * 必选参数:无<br>
- * 可选参数: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('签名错误');
- }
- }
|