123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <?php
- /**
- * 前台书籍控制器
- */
- namespace app\clientweb\controller;
- use app\common\controller\ClientWeb;
- use app\common\library\Redis;
- use app\common\library\Ua;
- use app\common\model\GuideWx;
- use app\main\constants\ErrorCodeConstants;
- use app\main\service\AdminService;
- use app\main\service\BookService;
- use app\main\service\ClientAppService;
- use app\main\service\FinancialService;
- use app\main\service\UrlService;
- use app\main\service\UserService;
- use think\Config;
- use think\Cookie;
- use think\Exception;
- use think\Log;
- use think\Request;
- class Book extends ClientWeb
- {
- protected $layout = '';
- public function _initialize()
- {
- parent::_initialize();
- }
- /**
- * 书籍列表页
- * @param string $type 列表标示
- * @return html
- */
- function list() {
- $sex = input('sex');
- $type = input('type');
- $description ='暂无该类别图书,换个条件试试看吧!';
- switch ($type) {
- case 'free':
- $title = '限免专区';
- $description = '暂无限免小说';
- break;
- case 'finish':
- $title = '完本书籍';
- break;
- case 'click':
- $title = '点击榜';
- break;
- case 'sell':
- $title = '畅销榜';
- break;
- default:
- $title = '书籍列表';
- break;
- }
- $this->assign('title', $title);
- $this->assign('description',$description);
- $this->assign('sex', $sex);
- $this->assign('type', $type);
- return $this->view->fetch();
- }
- /**
- * 首页配置的指定区块书籍列表页
- * @param int $block_id 区块id
- * @return html
- */
- public function blocklist()
- {
- $block_id = input('block_id');
- $block = model('client_manage_block')::get($block_id);
- $this->assign('block', $block);
- $this->assign('sex', $this->sex);
- return $this->view->fetch();
- }
- /**
- * 书籍详情页
- */
- public function info()
- {
- $book_id = input('book_id');
- $book = model('Book')->BookInfo($book_id);
- if (empty($book)) {
- return $this->statuspage(6); //无此书籍
- }
- if ($book['state'] == 0) {
- return $this->statuspage(3); //本书已下架
- }
- $book['word_count'] = formatNumber($book['word_count']);
- $book['read_num'] = formatNumber($book['read_num']);
- $headTenChapters = model('Book')::getChapterLimit($book_id, 0, 9);
- if (empty($headTenChapters)) {
- return $this->statuspage(6); //当接口出问题获取不到数据,提示暂时无法阅读。
- }
- //VIP充值地址
- $vipEndtime = 0;
- if ($this->isLogin) {
- $vipEndtime = $this->userInfo['vip_endtime'];
- }
- $this->assign('vip_endtime',$vipEndtime);
- $index = new Index();
- $pagedata = $index->recommendList($book_id);
- $this->view->assign('pagedata', $pagedata);
- $this->view->assign('sex', $this->sex);
- $this->assign('book', $book);
- $this->assign('chapters', $headTenChapters);
- //书的信息 提供js调用
- $appBookInfo = ClientAppService::instance()->userReadBooksInfo([$book['id'] => $book['last_chapter_id']])->data;
- $appBookInfo = $appBookInfo['bookList'][0];
- $this->assign('app_params', json_encode($appBookInfo));
- return $this->view->fetch();
- }
- /**
- * 书籍目录页
- * @param int $book_id 书籍id
- * @param int $page 页码
- * @param int chapter_id 如果传chapter_id 则直接显示所在page
- * @return html
- */
- public function menu()
- {
- $book_id = input('book_id');
- $page = input('page', 1);
- $chapter_id = input('chapter_id');
- $book = model('Book')->bookInfo($book_id);
- if (empty($book)) {
- return $this->statuspage(6); //无此书籍
- }
- if ($book['state'] == 0) {
- return $this->statuspage(3); //本书已下架
- }
- $page_num = ceil($book['chapter_num'] / 100);
- $menuindex = array();
- for ($i = 1; $i <= $page_num; $i++) {
- $start_num = ($i - 1) * 100;
- if ($i < $page_num) {
- $end_num = $start_num + 100;
- } else {
- $end_num = $book['chapter_num'];
- }
- $menuindex[$i] = array('url' => url('clientweb/book/menu', array('book_id' => $book_id, 'page' => $i)), 'name' => 1+$start_num . '-' . $end_num . '章');
- }
- if($chapter_id && $book_id){
- $chapter = model('Book')->getChapterInfo($book_id, $chapter_id);
- if($chapter['data']){
- $chapter_num = $chapter['data']['idx'];
- $page_chapter_idx = ceil($chapter_num / 100);
- $page = $page_chapter_idx ? $page_chapter_idx : $page;
- }
- }
- $chapters = model("Book")::getChapterList($book_id, $page, 100);
- $no_menu = 0;
- $this->assign('no_menu',$no_menu);
- $this->assign('book', $book);
- $this->assign('page', $page);
- $this->assign('chapter_id', $chapter_id);
- $this->assign('menuindex', $menuindex);
- $this->assign('menuindexjson', json_encode($menuindex));
- $this->assign('chapters', $chapters['data']['data']);
- $this->view->assign('sex', $this->sex);
- //书的信息 提供js调用
- $appBookInfo = ClientAppService::instance()->userReadBooksInfo([$book['id'] => $book['last_chapter_id']])->data;
- $appBookInfo = $appBookInfo['bookList'][0];
- $this->assign('app_params', json_encode($appBookInfo));
- return $this->view->fetch();
- }
- /**
- * 状态页
- * $code 1 正在码字| 2 已完结| 3 已下架| 4 章节内容为空| 5 404[并不处理] | 6 提示此本书暂时无法阅读
- * $chapter
- * $book_id
- */
- public function statuspage($code, $chapter = [],$book_id='')
- {
- switch ($code) {
- case 1:
- $template = 'typing';
- $this->ranklist($book_id);
- break;
- case 2:
- $template = 'finish';
- $this->ranklist($book_id);
- break;
- case 3:
- $template = 'forbiddenread';
- break;
- case 4:
- $template = 'nocontent';
- $chapter['next_link'] = '/clientweb/book/chapter?book_id=' . $chapter['book_id'] . '&chapter_id=' . $chapter['next_id'];
- $this->view->assign('chapter', $chapter);
- break;
- case 5:
- $template = '404';
- break;
- case 6:
- $template = 'nobook';
- break;
- default:
- $template = 'typing';
- $this->ranklist($book_id);
- }
- $bookinfo = [];
- if($book_id){
- $bookinfo = model('Book')->BookInfo($book_id);
- if($bookinfo['recommand_book_id']){
- $recmooand = model('Book')->BookInfo($bookinfo['recommand_book_id']);;
- $bookinfo['recommand_book_image'] =$recmooand['image'];
- $bookinfo['recommand_book_name'] =$recmooand['name'];
- }
- }
- $this->view->assign('book',$bookinfo);
- return $this->view->fetch('public/' . $template);
- }
- /*
- * 为你推荐
- * 调用页面-最近阅读页??
- * 调用页面-完结页
- * 调用页面-作者码字页
- * 从当前列表去掉当前书籍
- */
- public function ranklist($book_id){
- $sex_type = model('User')->getUserSex($this->user->sex,$this->adminconfig,true);
- $index = new Index();
- $ranklist = $index->ranklist($sex_type);
- if($book_id){
- foreach ($ranklist['idx'] as $k=>$value){
- if($value['id']==$book_id){
- unset($ranklist['idx'][$k]);
- }
- }
- }
- $this->view->assign('ranklist', $ranklist);
- }
- }
|