getUserInfo(); $channel_id = $userObj->channel_id; // 猜猜你喜欢 $this->sex = $userObj->sex ?? '1'; $img_reading = ''; $img_recharge = ''; $replysigntxt = ''; if ($book_id = $this->request->request('book_id')) { $user_id = $userObj->id; $guideArr = AppGuideService::instance()->getAppGuideInfo($channel_id); $dycode = ClientAppService::instance()->makeUserRegisterCode($channel_id, $userObj->openid); if($guideArr){ $img_reading = $guideArr['img_reading']; $img_recharge = $guideArr['img_recharge']; $replysigntxt = $guideArr['replysigntxt']; } $this->assign('dycode', $dycode); $cache = UserdotService::instance()->getTrackCache($user_id, $book_id); if ($cache) { $track = $cache; }else{ $track = '{}'; } $this->assign('track', $track); $this->assign('gussnovels', []); } $this->assign('img_reading', $img_reading); $this->assign('img_recharge', $img_recharge); $this->assign('replysigntxt', $replysigntxt); $showBookShelf = BookService::instance()->showBookShelfFun(); $this->is_show_tabbar = model("ChannelSpecialManage")->isWhite("show_tabbar", $channel_id); //渠道是否开启了广告功能 /*$isAdPick = model("ChannelSpecialManage")->isWhite("ad_pick", $channel_id); $this->assign('isAdPick', $isAdPick);*/ $this->assign('ad_rate_chapter', Config::get('site.ad_rate_chapter') ?? 0); //广告点击概率-阅读器中间页 $this->assign('ad_rate_end', Config::get('site.ad_rate_end') ?? 0); //广告点击概率-阅读器章末 $this->assign('ad_rate_menu', Config::get('site.ad_rate_menu') ?? 0); //广告点击概率-呼出菜单 //渠道是否开启了浮窗提醒插屏 $isFloatTips = model("ChannelSpecialManage")->isWhite("float_tips", $channel_id); $this->assign('isFloatTips', $isFloatTips); $this->assign('theme', Config::get('site.theme')); $this->assign('showBookShelf', $showBookShelf); $this->assign('channel_id', $channel_id); $this->view->assign('adminconfig',$this->adminconfig); } /** * 书籍列表页 * @param string $type 列表标示 * @return html */ function list() { $sex = input('sex'); $type = input('type', 'click'); $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); if (in_array($type, ['click', 'sell'])) { $this->assign('is_show_tabbar', 0); $this->assign('tab_choice', 'rank_list'); return $this->view->fetch('rank_list'); } return $this->view->fetch(); } /** * 首页配置的指定区块书籍列表页 * @param int $block_id 区块id * @return html */ public function blocklist() { $block_id = input('block_id'); $block = model('manage_block')::get($block_id); $this->assign('block', $block); return $this->view->fetch(); } /** * 书籍列表接口 * @param string $type 榜单类别 * @param int $page 页数 * @return json $books 书籍列表信息 已加redis缓存 */ public function booklistapi() { $type = input('type'); $page = input('page', 1); $user_id = Cookie::get('user_id'); //清水 if ($user_id) { $userInfo = UserService::instance()->getUserModel()->getUserInfo($user_id); $channel_id = $userInfo['channel_id'] ?? 0; if (empty($channel_id)) { $is_water = false; } else { $channel_id = AdminService::instance()->getAdminExtendModel()->getChannelId($channel_id); $is_water = WaterBookService::instance()->showBook($channel_id, $user_id, Ip::ip()); } } else { $is_water = false; } $books = model('index')::booklist('', $type, $page, $is_water); 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); $user_id = Cookie::get('user_id'); //清水 if ($user_id) { $userInfo = UserService::instance()->getUserModel()->getUserInfo($user_id); $channel_id = $userInfo['channel_id'] ?? 0; if (empty($channel_id)) { $is_water = false; } else { $channel_id = AdminService::instance()->getAdminExtendModel()->getChannelId($channel_id); $is_water = WaterBookService::instance()->showBook($channel_id, $user_id, Ip::ip()); } } else { $is_water = false; } $data = model('index')::blockbooklist($block_id, $page, $is_water); return json($data); } /** * 书籍详情页 */ public function info() { $book_id = input('book_id'); $user_id = Cookie::get('user_id'); $user = model('User')->getUserInfo($user_id); //是不是清水 $channelId = AdminService::instance()->getAdminExtendModel()->getChannelId($user['channel_id']); $isWater = WaterBookService::instance()->showBook($channelId,$user_id,IP::ip()); $book = model('Book')->BookInfo($book_id); if (empty($book)) { return $this->statuspage(6); //无此书籍 } if ($book['state'] == 0) { return $this->statuspage(3); //本书已下架 } if ($isWater && (!isset($book['classify_white_list']) || $book['classify_white_list'] != 1)){ 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(!isset($headTenChapters)){ return $this->statuspage(6); //当接口出问题获取不到数据,提示暂时无法阅读。 } $hasread = 0; //默认值 if(Cookie::has('user_id')){ $user_id = Cookie::get('user_id'); $v = 'U-B:' . $user_id . ':' . $book_id; if($this->redis->exists($v)){ $hasread = 1; $recent_chapter_id = $this->redis->hget($v, 'chapter_id'); $this->assign("recent_chapter_id", $recent_chapter_id); }else{ $read_history = model('UserRecentlyRead')->getone($user_id,$book_id); if(empty($read_history)){ $hasread = 0; }else{ $hasread = 1; $this->assign("recent_chapter_id", $read_history['chapter_id']); } } }else{ if(Cookie::has('read')){ $bookinfo = Cookie::get('read', $book_id); if(empty($bookinfo)){ $hasread = 0; }else{ $hasread = 1; $this->assign("recent_chapter_id", $bookinfo['chapter_id']); } } } $bookFirstChapterInfo = BookService::instance()->getBookChapterInfo($book_id, $book['first_chapter_id']); /*if ($bookFirstChapterInfo->code == ErrorCodeConstants::EXCEPTION) { $this->redirect(BookService::instance()->getBookIndexPage($book_id)->data); } elseif ($bookFirstChapterInfo->code == ErrorCodeConstants::REDIRECT) { $this->redirect($bookFirstChapterInfo->data); } elseif ($bookFirstChapterInfo->code == ErrorCodeConstants::REDIRECT_VIEW) { $bind = $bookFirstChapterInfo->data['bind']; $template = $bookFirstChapterInfo->data['tpl']; $this->assign($bind); return $this->view->fetch($template); }*/ $firstpart = $secondpart = $thirdpart = $fourthpart = ''; $secondChapterId = $book['first_chapter_id']; $firstChapterContent = ''; if($bookFirstChapterInfo->code == ErrorCodeConstants::SUCCESS){ if (isset($bookFirstChapterInfo->data['chapter']['next_id'])) { $secondChapterId = $bookFirstChapterInfo->data['chapter']['next_id']; } if (isset($bookFirstChapterInfo->data['chapter']['content'])) { $firstChapterContent = strip_tags($bookFirstChapterInfo->data['chapter']['content']); } $len_content = mb_strlen($firstChapterContent); $first_len = 120; $sections = 3; $firstpart = mb_substr($firstChapterContent, 0, $first_len); $secondpart = mb_substr($firstChapterContent, $first_len, intval(($len_content - $first_len) / $sections)); $thirdpart = mb_substr($firstChapterContent, intval($first_len + (($len_content - $first_len) / $sections)), intval(($len_content - $first_len) / $sections)); $fourthpart = mb_substr($firstChapterContent, intval($first_len + (($len_content - $first_len) / $sections) *2), intval(($len_content - $first_len) / $sections)); } //VIP用户判断书籍是否是CP书籍 $showVipCpStyle = false; if (Cookie::has('user_id') && $this->user->vip_endtime >= time() ) { if (!VipCpService::instance()->isFreeCpBookForVip($book_id, $this->user->id, $this->user->vip_endtime)) { $showVipCpStyle = true; } } // 限免书籍,不展示非VIP书籍标记 if($book['free_stime'] <= time() && $book['free_etime'] >= time()){ $showVipCpStyle = false; } // 该作者其他书籍 $authorOtherBookId = model('Book')->getBookIdByAuthor($book['author'], $book_id, $this->sex,$isWater); if($authorOtherBookId){ $authorBook = model('Book')->BookInfo($authorOtherBookId); }else{ $authorBook = []; } $vip_recharge = config('site.vip_recharge'); $this->assign('vip_recharge',$vip_recharge); $pagedata = BookService::instance()->recommendList($book_id); $this->view->assign('pagedata', $pagedata); // 是否已经加入到书架 TRUE | FALSE $showBookShelf = BookService::instance()->showBookShelfFun(); $this->assign('showBookShelf', $showBookShelf); if ($showBookShelf) { $in_shelf = (bool)BookService::instance()->checkBookInShelf($book_id)->data; $this->assign('in_shelf', $in_shelf); } //强关注弹窗 $no_menu = 0; $isSubscribe = 0; $guidChapterIdx = 0; $subscribeTipsInfo = []; if ($this->adminconfig['subscribe_method'] == 1) { //强制关注 if ($user && !$user['is_subscribe'] && !$user['subscription_extend']) { $no_menu = 1; } $isSubscribe = !$no_menu; if ($isSubscribe == 0) { //未关注 $guidChapterIdx = BookService::instance()->getGuidChapterIdx($book_id, $user['referral_id'])->data; $subscribeTipsInfo = AdminService::instance()->getQrcode()->data; if (AdminService::instance()->checkIfGuide()->data) { //不在强关注 则设置关注章节为0 前端不再弹窗 $guidChapterIdx = 0; } //广州地区IP 设置为不弹窗 $city = Ip::city(); if (in_array($city, ['广州市', '深圳市'])) { if(!model('ChannelSpecialManage')->isWhite(ChannelManageConstants::OPEN_SUBSCRIBE, $this->adminconfig['admin_id'])){ $guidChapterIdx = 0; } } } } $this->assign('showVipCpStyle', $showVipCpStyle); $this->assign('firstpart', $firstpart); $this->assign('secondpart', $secondpart); $this->assign('thirdpart', $thirdpart); $this->assign('fourthpart', $fourthpart); $this->assign('firstChapterContent', $firstChapterContent); $this->assign('second_chapter_id', $secondChapterId); $this->assign('authorBook', $authorBook); $this->assign('is_subscribe', $isSubscribe); $this->assign('guideChapterIdx', $guidChapterIdx); $this->assign('subscribe_tips_info', $subscribeTipsInfo); $this->assign('subscribe_method', $this->adminconfig['subscribe_method']); $this->assign('book', $book); $this->assign('hasread', $hasread); $this->assign('chapters', $headTenChapters); $this->assign('gussnovels', $this->_getGussNovels($book_id, $this->sex,$isWater)); $this->assign('custom_title', 1); 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'); $fromUserId = input('from_user_id',0); $shareTime = input('share_time',0); $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('index/book/menu', array('book_id' => $book_id, 'page' => $i,'from_user_id'=>$fromUserId,'share_time'=>$shareTime)), '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); if ( $chapters['code'] == 100 ){ throw new HttpException(400, '异常错误,请重试'); } $no_menu = 0; $isSubscribe = 0; $guidChapterIdx = 0; $subscribeTipsInfo = []; if ($this->adminconfig['subscribe_method'] == 1) { //强制关注 $user_id = Cookie::get('user_id'); $user = model('User')->getUserInfo($user_id); if ($user && !$user['is_subscribe'] && !$user['subscription_extend']) { $no_menu = 1; } $isSubscribe = !$no_menu; if ($isSubscribe == 0) { //未关注 $guidChapterIdx = BookService::instance()->getGuidChapterIdx($book_id, $user['referral_id'])->data; $subscribeTipsInfo = AdminService::instance()->getQrcode()->data; if (AdminService::instance()->checkIfGuide()->data) { //不在强关注 则设置关注章节为0 前端不再弹窗 $guidChapterIdx = 0; } //如果是分享活动,关注章节和二维码优先取分享活动得 if ($fromUserId){ $guidChapterIdx = (int)Config::get('site.share_chapter_num'); $share_default_qrcode = Config::get('site.share_default_qrcode'); if ($share_default_qrcode){ $subscribeTipsInfo['qrcode_image'] = $share_default_qrcode; } } } //广州地区IP 设置为不弹窗 $city = Ip::city(); if (in_array($city, ['广州市', '深圳市'])) { if(!model('ChannelSpecialManage')->isWhite(ChannelManageConstants::OPEN_SUBSCRIBE, $this->adminconfig['admin_id'])){ $guidChapterIdx = 0; } } } $this->assign('from_user_id',$fromUserId); $this->assign('share_time',$shareTime); $this->assign('subscribe_tips_info', $subscribeTipsInfo); $this->assign('subscribe_method', $this->adminconfig['subscribe_method']); $this->assign('no_menu', $no_menu); $this->assign('is_subscribe', $isSubscribe); $this->assign('guideChapterIdx', $guidChapterIdx); $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']); return $this->view->fetch(); } /** * 书籍全部章节列表api * @param int $book_id 书籍id * @return json */ public function chapterlistapi() { $book_id = input('book_id'); $book = model('book')->bookInfo($book_id); $chapters = model('book')::getChapterList($book_id, 1, $book['chapter_num']); $chapterlist = array(); $is_charge_chapter_idx = 20; foreach ($chapters['data']['data'] as $key => $c) { if ($key < $is_charge_chapter_idx) { $is_charge = 0; } else { $is_charge = 1; } $chapterlist[] = array( 'chapterId' => $c['id'], 'chapterName' => $c['name'], 'is_charge' => $is_charge, ); } $data = array( 'bookId' => $book['id'], 'bookName' => $book['name'], 'chapterList' => $chapterlist, 'headerName' => "章节目录", 'totalChapters' => $book['chapter_num'], ); return json($data); } /** * 检查是否开启导航 * @param $channel_id * @return bool */ public function checkNav($channel_id) { $channel = Config::get('site.app_chapter_nav_channels'); if (!$channel) { return false; } $channels = explode(',', $channel); if (in_array('*', $channels) || in_array($channel_id, $channels)) { return true; } return false; } /** * @return string * @throws Exception */ public function chapter() { $book_id = input('book_id'); $user_id = UserService::instance()->getUserInfo()->id; if (!$book_id) { $soruceReadLog = BookService::instance()->getUserRecentlyRead() ->setConnect($user_id)->getRecentlyRead(0, 1, $user_id, true); if ($soruceReadLog['totalNum'] > 0) { $book_info = current($soruceReadLog['data']); $book_id = $book_info['book_id']; } } $kuaifenId = input('uid'); if (!empty($kuaifenId)) { UserVipExtendService::instance()->saveUserKuaifenId($user_id, $kuaifenId); } $chapter_id = input('chapter_id'); $sid = input('sid'); $from_read = input('from_read', 0); $this->assign('from_read', $from_read); $this->assign('channel_id', Cookie::get('channel_id') ?? 0); $this->assign('user_id', Cookie::get('user_id') ?? 0); $isShow = false; // 维护书籍阅读数, Redis B-N统计; $redis_key = CacheConstants::BOOK_USER_READ_COUNT.$book_id; Redis::instance()->pfAdd($redis_key, Cookie::get('user_id')); Redis::instance()->expire($redis_key, 86400); Redis::instance()->hSet('B-N', $book_id, Redis::instance()->pfCount($redis_key)); // $isListenBookOpen 渠道听书开关是否开启 $isListenBookOpen = 0; if(Cookie::get('channel_id')){ $isListenBookOpen = model("ChannelSpecialManage")->isWhite("listen_book", Cookie::get('channel_id')); } $this->assign('isListenBookOpen', $isListenBookOpen); // $showIntro 是否第一次阅读,用于控制弹出听书引导页 $showIntro = 0 ; if (Cookie::has('user_id')) { $res = model('UserRecentlyRead')->getRecentlyRead(0, 1, null, true); if ($res && $res['data']) { $showIntro = 1; } } $this->assign('showIntro', $showIntro); $userInfo = UserService::instance()->getUserInfo(); $channelId = AdminService::instance()->getAdminExtendModel()->getChannelId($userInfo->channel_id); $isWater = WaterBookService::instance()->showBook($channelId,$userInfo->id,IP::ip()); //书籍与章节信息获取 $bookChapterInfo = BookService::instance()->getBookChapterInfo($book_id, $chapter_id, $sid, $isWater); if ($bookChapterInfo->code == ErrorCodeConstants::EXCEPTION) { $this->redirect(BookService::instance()->getBookIndexPage($book_id)->data); } elseif ($bookChapterInfo->code == ErrorCodeConstants::REDIRECT) { $this->redirect($bookChapterInfo->data); } elseif ($bookChapterInfo->code == ErrorCodeConstants::REDIRECT_VIEW) { $bind = $bookChapterInfo->data['bind']; $template = $bookChapterInfo->data['tpl']; $this->assign($bind); return $this->view->fetch($template); } $idx = $bookChapterInfo->data['chapter']['idx']; $chapter_id = $bookChapterInfo->data['chapter']['id']; $chapter_name = $bookChapterInfo->data['chapter']['name']; $is_subscribed = $userInfo->is_subscribe || $userInfo->subscription_extend; $admin = UserService::instance()->getRunTimeObject()->adminConfig; $qrcode_image = ''; if ($userInfo->vip_endtime > time()) { $is_vip = '1'; } else { $is_vip = '0'; } $result = [ 'is_subscribed' => $is_subscribed, 'chapter_name' => $bookChapterInfo->data['chapter']['name'], 'chapter_content' => $bookChapterInfo->data['chapter']['content'], 'chapter_idx' => $bookChapterInfo->data['chapter']['idx'], 'next_link' => $bookChapterInfo->data['next_link'] ? $bookChapterInfo->data['next_link'] . '&from_read=1' : $bookChapterInfo->data['next_link'], 'pre_link' => $bookChapterInfo->data['pre_link'], 'book' => $bookChapterInfo->data['book'], 'subscribe_method' => $admin['subscribe_method'], 'book_id' => $book_id, 'chapter_id' => $chapter_id, 'sid' => $sid, 'qrcode_image' => $qrcode_image, 'need_pay' => false, 'pay_type' => $bookChapterInfo->data['book']['billing_type'], 'chapter_paid' => "0", 'is_vip' => $is_vip, 'add_to_shelf' => (bool)BookService::instance()->checkBookInShelf($book_id)->data, 'guid_chapter_idx' => 0, 'is_daofen_end' => 0, 'subscribe_url' => 0, 'dd' => 0, ]; $showBookShelf = BookService::instance()->showBookShelfFun(); $result['show_book_shelf'] = $showBookShelf; if ($showBookShelf) { $result['add_to_shelf'] = (bool)BookService::instance()->checkBookInShelf($book_id)->data; } $referral_id = UrlService::instance()->getUserReferralId()->data; //当前章节是否是强制关注的前一章节 $result['is_per_chapter'] = 0; //添加阅读设置 $result = array_merge($result, BookService::instance()->getReadingSetting()->data); //支付处理,获取免费章节 $freeChapterIds = FinancialService::instance()->getFreeChapterIdx($book_id); $result['is_need_pay'] = $is_need_pay = $freeChapterIds != -1 && $bookChapterInfo->data['chapter']['idx'] > $freeChapterIds; //查看用户是否报名了订阅活动 $actUserInfo = SubscripService::instance()->getActivityUser($userInfo); //是否需要订阅活动打卡成功的弹窗 $isSubPop = 0; if ($actUserInfo && date('Ymd') > $actUserInfo['act_date']){//如果已经报名 不需要支付 //打卡 $isSubPop = SubscripService::instance()->insertLog($actUserInfo); } //如果是订阅活动分享过来的用户 if ($this->request->has('sub_code') && $subCode = $this->request->param('sub_code')){ SubscripService::instance()->insertUserRelation($subCode,$userInfo->id); } if (Input('hide_qrcode')) { Cookie::set('pop_times', 1); } //如果书籍按本收费,且已付费,本章置为已支付 if ($bookChapterInfo->data['book']['billing_type'] == BookConstants::BOOK_BILLING_MODEL_BOOK) { $where = [ 'user_id' => $userInfo->id, 'book_id' => $book_id, 'type' => BookConstants::BOOK_BILLING_MODEL_BOOK ]; if (FinancialService::instance()->getConsumeModel()->setConnect($userInfo->id)->where($where)->find()) { $result['chapter_paid'] = '1'; } } //需要支付的情况 if ($is_need_pay) { $result['need_pay'] = true; $result['chapter_paid'] = '1'; //扣费处理 $payInfo = FinancialService::instance()->getConsumeInfo($book_id, $chapter_id, $bookChapterInfo->data['chapter']['name']); //扣费异常 if (in_array($payInfo->code, [ErrorCodeConstants::DB_ERROR_UPDATE, ErrorCodeConstants::EXCEPTION])) { //todo 扣书币失败的情况 $this->error("异常错误,请稍后重试", BookService::instance()->getBookIndexPage($book_id)->data); } //书币不足,重定向到支付 if ($payInfo->code == ErrorCodeConstants::REDIRECT) { $this->redirect(UrlService::instance()->getPayUrl(get_url_no_port(true), $book_id, $chapter_id)->data); } if ($payInfo->data > 0) { $result['dd'] = 1; } } //关注逻辑 //获取导粉章节 $guid_chapter_idx = BookService::instance()->getGuidChapterIdx($book_id, $referral_id)->data; $result['guid_chapter_idx'] = $guid_chapter_idx; //如果是分享链接 $isShareUrl = 0;//是不是分享链接 $isSharePop = 0;//分享链接的弹窗 $fromUserId = $this->request->has('from_user_id') ? $this->request->get('from_user_id'): 0; $shareTime = $this->request->get('time'); $shareTime = !empty($shareTime) ? $shareTime : time(); // && $userInfo->is_first_unfollow == 2 && $userInfo->subscribe_time == 0 //&& Config::get('site.is_open_share') == "1" 增加拉新活动是否开启 if( $fromUserId && $userInfo->is_subscribe == 0 && Config::get('site.is_open_share') == "1"){ logService::info('被分享者 进入链接'.$userInfo->id.':'.$userInfo->is_first_unfollow); $shareChapterNum = Config::get('site.share_chapter_num'); $shareParams = "&share_chapter_num=".$shareChapterNum."&time=".$shareTime."&from_user_id=".$fromUserId."&is_first_click=1"; //if($shareTime+300 > time() ){//判断链接是不是过期 //在下一章和上一章地址中拼接参数 $result['next_link'] .= $shareParams; $result['pre_link'] .= $shareParams; // 判断是不是第一次点击,是不是首次关注,判断链接是不是过期 if ( $shareTime+24*3600 > time() && $userInfo->is_first_unfollow == 2 && !$this->request->has('is_first_click') ){ ShareService::instance()->ClickShareLink($userInfo->id,$fromUserId,$shareTime); } $isShareUrl = 1; if ( $shareChapterNum-1 <= $idx ){ $isSharePop = 1; $ewm = AdminService::instance()->getQrcode()->data; $newCode = Config::get('site.share_default_qrcode'); $result['qrcode_image'] = !empty($newCode) ? $newCode : $ewm['qrcode_image']; $result['subscribe_url'] = $ewm['subscribe_url']; $result['is_daofen_end'] = 1; $this->view->assign('is_show', $isShow); $this->view->assign('qrcode_image', $result['qrcode_image']); $this->view->assign('isSharePop', $isSharePop); $this->view->assign('isShareUrl', $isShareUrl); $this->view->assign('is_mishu', 0); $this->assign('showSubscribeTips',0); LogService::info('分享活动弹窗'.json_encode($result)); // return $this->assign($result)->view->fetch(); } // } LogService::info('分享活动-点击001'.$shareParams.'chapter_id'.$chapter_id); } $this->view->assign('isSubPop', $isSubPop); $this->view->assign('isSharePop', $isSharePop); $this->view->assign('from_user_id', $fromUserId); $this->view->assign('share_time', $shareTime); $this->view->assign('isShareUrl', $isShareUrl); //未关注 $showSubscribeTips = 0; if (!$is_subscribed && $guid_chapter_idx && $result['subscribe_method'] != AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_NOT && !$isShareUrl ) { //获取二维码 $ewm = AdminService::instance()->getQrcode()->data; $result['subscribe_url'] = $ewm['subscribe_url']; if ($admin['subscribe_method'] == AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_FORCE && AdminService::instance()->checkIfGuide()->data) { $result['subscribe_method'] = AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_NOT; } $result['qrcode_image'] = $ewm['qrcode_image']; if ($bookChapterInfo->data['chapter']['idx'] >= $guid_chapter_idx) { //subscribe_url存在即重定向 if ($ewm['subscribe_url']) { $this->redirect($ewm['subscribe_url']); } } if ($admin['subscribe_method'] == AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_FORCE && ($guid_chapter_idx - $bookChapterInfo->data['chapter']['idx']) == 1) { $result['is_per_chapter'] = 1; } if ($admin['subscribe_method'] == AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_FORCE && ($guid_chapter_idx <= $bookChapterInfo->data['chapter']['idx'])) { $result['is_daofen_end'] = 1; //添加最近阅读 BookService::instance()->setRecentlyRead($bookChapterInfo->data['chapter']['name'], $chapter_id, $bookChapterInfo->data['book']['id'], $idx); //有二维码则不进行弹窗 $this->assign('isAddBackDom', 0); $this->view->assign('is_mishu', 0); $this->view->assign('img_times', 0); //return $this->assign($result)->view->fetch(); } if ($admin['subscribe_method'] == AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_GUID && ($guid_chapter_idx <= $bookChapterInfo->data['chapter']['idx'])) { //二维码已弹出的情况 if (!(Cookie::has('pop_times') && Cookie::get('pop_times') == 1)) { $result['is_daofen_end'] = 1; //添加最近阅读 BookService::instance()->setRecentlyRead($bookChapterInfo->data['chapter']['name'], $chapter_id, $book_id, $idx); //有二维码则不进行弹窗 $this->assign('isAddBackDom', 0); $this->view->assign('is_mishu', 0); $this->view->assign('img_times', 0); //return $this->assign($result)->view->fetch(); } } //广州地区IP 设置为引导关注 $city = Ip::city(); if (in_array($city, ['广州市', '深圳市'])) { if (!model('ChannelSpecialManage')->isWhite(ChannelManageConstants::OPEN_SUBSCRIBE, $userInfo->channel_id)) { $result['subscribe_method'] = $admin['subscribe_method'] = AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_NOT; } } if (in_array($admin['subscribe_method'], [ AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_FORCE, AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_GUID ]) && $guid_chapter_idx <= $bookChapterInfo->data['chapter']['idx']) { $showSubscribeTips = 1; } } $this->assign('showSubscribeTips', $showSubscribeTips); if (UserService::instance()->isLogin()) { //添加最近阅读 BookService::instance()->setRecentlyRead($bookChapterInfo->data['chapter']['name'], $chapter_id, $book_id, $idx); } //收藏时关注参数 /*if ($admin['qrcode_image']) { $result['pop_qrcode'] = $admin['qrcode_image']; } else { $result['pop_qrcode'] = 'https://open.weixin.qq.com/qr/code?username=' . $admin['json']['authorizer_info']['user_name']; }*/ // 引导位访问展示打点 AppGuideService::instance()->appGuideViewDot(Cookie::get('channel_id') ?? 0, Cookie::get('user_id') ?? 0, MqConstants::APP_GUIDE_POSITION_IDX_1); AppGuideService::instance()->appGuideViewDot(Cookie::get('channel_id') ?? 0, Cookie::get('user_id') ?? 0, MqConstants::APP_GUIDE_POSITION_IDX_2); //加文件缓存 if ($this->checkNav($userInfo->channel_id)) { $navCacheKey = 'CCN'; $nav = Cache::get($navCacheKey); if ($nav === false) { $nav = (new ReadNavigation())->where('status', 'normal')->field('title,url')->order('weight', 'desc')->select(); if ($nav) { foreach ($nav as $item) { if (strstr($item['url'], '?')) { $item['url'] .= '&from=chapter'; } else { $item['url'] .= '?from=chapter'; } } } Cache::set($navCacheKey, (array)$nav, 600); } } $nav = $nav ?? []; $export = ExportFansService::instance()->checkFansLead($userInfo->channel_id, $userInfo->id)->data; if ($export) { if ($export['status'] == '1' && $export['limittime'] > time()) { $url = '/index/share/leadpage?id='.$export['id']; if ($url) { if ($nav) { $bakNav = $nav; $nav = []; $navTotal = count($bakNav); if ($navTotal > 3) { foreach ($bakNav as $k => $item) { if ($item['title'] == '书架' || $item['title'] == '最近阅读') { continue; } else { $nav[] = [ 'url' => $item['url'], 'type' => 'txt', 'title' => $item['title'] ]; } } } else { foreach ($bakNav as $k => $item) { $nav[] = [ 'url' => $item['url'], 'type' => 'txt', 'title' => $item['title'] ]; } } } } } $lastNav = [ 'url' => '/index/share/leadpage?id='.$export['id'].'&from=chapter', 'type' => 'icon', 'title' => '', ]; $this->assign('lastNav', $lastNav); reset($nav); } //消耗活动章节计数 if ($campActivity = CampaignService::instance()->getActiveByUser($userInfo->id)) { $readNumber = $campActivity['read_number']; $campKey = CampaignConstants::getUserMatchReadKey($userInfo->id); $readCount = Redis::instance()->get($campKey); if ($readCount === false || $readCount < $readNumber) { if (Redis::instance()->incr($campKey) == '1') { Redis::instance()->expire($campKey, 86400); } } } //秘书图片弹框 $isOpenMishuTips = 0; $imgTimes = 1; if (Config::get('site.is_open_mishu_tip') == 1) { if ($userInfo && $is_subscribed) { $isOpenMishuTips = 1; //是哪张图 第一次还是 第二次弹 或者永久不弹 $mishuTipsNum = Cookie::get("mishu_1_num"); if ($mishuTipsNum >= 2) { $isOpenMishuTips = 0; } else { if ($mishuTipsNum >= 1) { $imgTimes = 2; } } //判断IP 北京区域不弹 $city = Ip::city(); if (strrpos('北京市', $city) !== false) { $isOpenMishuTips = 0; } if (!in_array(Config::get('site.theme'), ['px', 'sf'])) { $isOpenMishuTips = 0; } } } //验证cookie $float_tip = ['id' => 0]; if (model('ChannelSpecialManage')->isWhite('float_tip', $userInfo->channel_id)) { $float_tip = FloatTipsService::instance()->getFloatTipsForUser($userInfo->id, $idx, Cookie::get('sell_val'))->data; if ($float_tip['id'] && $float_tip['book_id'] == $book_id) { $float_tip['id'] = 0; } if ( isset($float_tip['link']) && strstr($float_tip['link'],'http') === false ){ $host = getCurrentDomain($userInfo->channel_id); $float_tip['link'] = $host.$float_tip['link']; } } $export_fans = ExportFansService::instance()->checkFansReadToExport($userInfo->channel_id, $userInfo->id, $chapter_id)->data; if ($export_fans) { $float_tip = ['id' => 0]; } $this->assign('fans', $export_fans); $this->assign('float_tip', $float_tip); $chapter_end = false; if (model('ChannelSpecialManage')->isWhite('chapter_end', $userInfo->channel_id)) { $chapter_end = BookService::instance()->getChapterEndRecommendBook($book_id, $idx)->data; } $this->assign('chapter_end', $chapter_end); $this->view->assign('is_mishu', $isOpenMishuTips); $this->view->assign('img_times', $imgTimes); $this->assign('nav', $nav); return $this->assign($result)->view->fetch(); } /** * 阅读页的插屏广告 * @return string * @throws Exception */ public function ad_chapter() { if(!Config::get('template.view_theme')){ $read_theme = 'read_theme_2'; //西瓜 }else{ $read_theme = 'read_theme_1'; //袋鼠 沙发 美书 } $read_body_fontsize = 'read_body_fontsize_2'; $day_night = ''; if (Cookie::has('cs')) { $cs['l'] = 1; $cs = json_decode(Cookie::get('cs'), true); //章节排序 l=1正序 l=2倒序 if ($cs['l'] == 2) { //$chapterlist['data']['data'] = array_reverse($chapterlist['data']['data']); } if ($cs['f']) { //字号 $read_body_fontsize = 'read_body_fontsize_' . intval($cs['f']); } if ($cs['b']) { //背景色 $read_theme = 'read_theme_' . intval($cs['b']); } if ($cs['d'] == 2) { //白天/夜间 主题 $day_night = 'read_theme_5'; } } $this->view->assign('read_body_fontsize', $read_body_fontsize); $this->view->assign('read_theme', $read_theme); $this->view->assign('day_night', $day_night); return $this->view->fetch(); } /** * 章节详情页 * @param int $book_id 书籍id * @param int $chapter_id 章节id * @return html */ public function chapter_back() { $book_id = input('book_id'); $chapter_id = input('chapter_id'); $user_id = Cookie::get('user_id'); $sid = input('sid'); if (empty($book_id)) { $this->redirect('/'); } $bookinfo = model('Book')->BookInfo($book_id); //调试 if ($this->request->get('debug')) { echo '
';
            var_dump($bookinfo);
            echo  '
'; } if (empty($bookinfo)) { return $this->statuspage(6); //无此书籍 } if ($bookinfo['state'] == 0) { return $this->statuspage(3); //本书已下架 } if (empty($chapter_id)) { if (Cookie::has('read') && empty($user_id)) { $readlog = Cookie::get('read'); if (is_array($readlog) && array_key_exists($book_id, $readlog)) { $chapter_id = $readlog[$book_id]['chapter_id']; } } if ($user_id) { $readlog = model('UserRecentlyRead')->getone($user_id, $book_id); if (!empty($readlog)) { $chapter_id = $readlog['chapter_id']; } } if(empty($chapter_id) && !$sid){ //第一章ID $chapter_id = $bookinfo['first_chapter_id']; } } if ($sid) { if (Cookie::has('read') && empty($user_id)) { $readlog = Cookie::get('read'); if (is_array($readlog) && array_key_exists($book_id, $readlog)) { $chapter_id = $readlog[$book_id]['chapter_id']; } } if ($user_id) { $readlog = model('UserRecentlyRead')->getone($user_id, $book_id); if (!empty($readlog)) { $chapter_id = $readlog['chapter_id']; } } if (empty($chapter_id)) { $chapter_id = $sid; } } if (empty($chapter_id)) { $this->redirect('/index/book/info?book_id=' . $book_id); } //调试 if ($this->request->get('debug')) { echo '当前书籍ID
'; echo $book_id; echo '--当前章节ID' . $chapter_id; echo '
'; } $chapter = model('Book')->getChapterInfo($book_id, $chapter_id); //调试 if ($this->request->get('debug')) { var_dump($chapter); echo 'urlAgentId:'.$this->urlAgentId; echo 'urlChannelId:'.$this->urlChannelId; echo 'urlAdminId:'.$this->urlAdminId; } if ($sid) { $chapter['data']['sid'] = $sid; } else { $chapter['data']['sid'] = ''; } if ($chapter['code']) { return $this->statuspage(5); //接口错误跳404 } //处理章节和书籍信息 $chapter['data']['author'] = $bookinfo['author']; $chapter['data']['book_id'] = $bookinfo['id']; $chapter['data']['book_name'] = $bookinfo['name']; $chapter['data']['image'] = $bookinfo['image']; $chapter['data']['description'] = $bookinfo['description']; $chapter['data']['last_chapter_name'] = $bookinfo['last_chapter_name']; $chapter['data']['last_chapter_id'] = $bookinfo['last_chapter_id']; $chapter['data']['is_finish_text'] = $bookinfo['is_finish_text']; $chapter['data']['word_count'] = $bookinfo['word_count']; $chapter['data']['chapter_num'] = $bookinfo['chapter_num']; $chapter['data']['status'] = 4; //返回状态码,0-支付页面;1-需要登录;2-章节错误;3-参数错误;4-成功 $chapter['data']['read_date'] = time(); $chapter['data']['state'] = $bookinfo['state']; if (empty(strip_tags($chapter['data']['content'])) && !isset($chapter['data']['next_id'])) { return $this->statuspage(6); //空章节,并且没有下一章 } if (empty(strip_tags($chapter['data']['content'])) && isset($chapter['data']['next_id'])) { return $this->statuspage(4, $chapter['data']); //空章节 } $this->view->assign('statuspage', 0); if ($bookinfo['is_finish'] == 1 && empty($chapter['data']['next_id'])) { $this->view->assign('statuspage', 2); //完本 $this->view->assign('statuspage_link', '/index/book/statuspage/code/2/book_id/'.$chapter['data']['book_id']); } if ($bookinfo['is_finish'] == 0 && empty($chapter['data']['next_id'])) { $this->view->assign('statuspage', 1); //连载 $this->view->assign('statuspage_link', '/index/book/statuspage/code/1/book_id/'.$chapter['data']['book_id']); } //调取导粉 只有微信环境导粉 $chapter['data']['alias'] = ''; $chapter['data']['subscribe_method'] = 0; $chapter['data']['daofen'] = ''; $chapter['data']['true_subscribe_method'] = 0; $chapter['data']['need_subscript'] = 0; $userinfo = model('user')->setConnect($user_id)->getUserInfo($user_id, 1); if(empty($userinfo)){ $userinfo = []; $is_subscribe = 0; }else{ if($userinfo['is_subscribe'] || $userinfo['subscription_extend']){ $is_subscribe =1; }else{ $is_subscribe =0; } } //获取公众号信息 if(empty($chapter['data']['alias'])){ $df_config = $this->adminconfig; $chapter['data']['subscribe_method'] = $df_config['subscribe_method']; $chapter['data']['qrcode_image'] = $df_config['qrcode_image']; $chapter['data']['alias'] = $df_config['json']['authorizer_info']['user_name']; if(isset($df_config['subscribe_url']) && $df_config['subscribe_url']){ $chapter['data']['subscribe_url'] = $df_config['subscribe_url']; } } //引导关注 每天弹一次二维码 $ewm_pop = 0; if($chapter['data']['subscribe_method'] == 2 ){ if(Cookie::has('tiao') && Cookie::get('tiao')==2){ $ewm_pop = 1;//已弹出 }else{ $ewm_pop = 0;//未弹出 } if(isset($_GET['tiao']) && $_GET['tiao']==2){ $ewm_pop = 1;//已弹出 Cookie::set('tiao',2); } } $chapter['data']['next_link'] = '/index/book/chapter?book_id=' . $chapter['data']['book_id'] . '&chapter_id=' . $chapter['data']['next_id']; if (Ua::isWeiXin()) { $referral_id = UrlService::instance()->getUserReferralId()->data; $df_chapter = model('Guide')->isguide($this->urlAgentId, $book_id, $chapter['data']['idx'], $is_subscribe, $referral_id,$this->urlChannelId); /* * 李聪聪添加的导粉逻辑 */ if($chapter['data']['subscribe_method'] == 1){ //如果是强制关注 $df_config = $this->adminconfig; $chapter['data']['true_subscribe_method'] = 1; if($this->user->isLogin()){ //如果登陆了没关注 if($userinfo['is_subscribe'] == 0 && $userinfo['subscription_extend'] ==0 ){ $chapter['data']['need_subscript'] = 1; } }else{ //游客 $chapter['data']['need_subscript'] = 1; } //判断关注数有没有到上限 $Scount = 0; $redis = Redis::instance(); $countKey = 'SC:'.$df_config['admin_id'].':'.date('Ymd',$this->time); if($redis->exists($countKey)){ $Scount = intval($redis->get($countKey)); } try{ if($df_config['fans_count'] !=0 ){ //如果是-1的话,会走随机导粉。如果随机导粉公众号为空,降级为不关注 if($Scount>=$df_config['fans_count']){ //如果关注数大于设置的关注数上限 //查看该代理商有没有设置导粉账号 $guideWx = new GuideWx; $qrcodeImage = $guideWx->getGw($df_config['admin_id']); //得到随机一个导粉二维码图片 if($qrcodeImage){ //如果配置了导粉账号,则随机分配导导粉账号 if(is_array($qrcodeImage)){ $chapter['data']['qrcode_image'] = $qrcodeImage['qrcode_image']; if(isset($qrcodeImage['subscribe_url']) && $qrcodeImage['subscribe_url']){ $chapter['data']['subscribe_url'] = $qrcodeImage['subscribe_url']; }else{ if(isset($chapter['data']['subscribe_url'])){ unset($chapter['data']['subscribe_url']); } } }else{ if(isset($chapter['data']['subscribe_url'])){ unset($chapter['data']['subscribe_url']); } $chapter['data']['qrcode_image'] = $qrcodeImage; } }else{ //没有配置导粉账号,降级为不关注 $chapter['data']['need_subscript'] = 0; $chapter['data']['subscribe_method'] = 3; $df_chapter['clear_data'] = 3; } } }else{ } }catch(Exception $e) { throw $e; } } /* * 李聪聪添加的导粉逻辑结束 */ if ($df_chapter && $ewm_pop == 0) { if ($df_chapter['clear_data'] == 1) { $chapter['data']['next_id'] = ''; $chapter['data']['daofen'] = 1; // if(isset($chapter['data']['subscribe_url']) && $chapter['data']['subscribe_url']){ // $this->redirect($chapter['data']['subscribe_url']); // } } if ($df_chapter['clear_data'] == 2) { $chapter['data']['next_id'] = ''; $chapter['data']['pre_id'] = ''; $chapter['data']['content'] = ''; $chapter['data']['daofen'] = 1; } } //调试 if ($this->request->get('debug')) { if (isset($df_chapter)) { echo '
导粉数据打印'; var_dump($df_chapter); } } //如果关注 则不展示二维码 if($is_subscribe){ $chapter['data']['subscribe_method'] = 3; } } //未登录用户阅读记录 if (empty($user_id)) { model('UserRecentlyRead')->recentCookie($book_id, $chapter['data']); } //调取计费逻辑 包含阅读记录 $checkfee = new Fee(); $chapter['data']['need_pay'] = '0'; $fee_admin_id = $this->urlAgentId?$this->urlAgentId:$this->urlChannelId; $fee_res = $checkfee->bookfee($fee_admin_id, $bookinfo, $chapter['data']['name'], $chapter['data']['idx'], $chapter_id, $userinfo); if (array_key_exists('isRecharge', $fee_res) && $fee_res['isRecharge'] == 1) { //当前章节是否扣费 $chapter['data']['need_pay'] = 1; } if ($fee_res['type'] == 2 || $fee_res['type'] == 7) { //书币不足,提示充值||游客充值 if (!empty($user_id)) { $params['user_id'] = $user_id; } elseif (Cookie::has('visitor')) { $params['visitor'] = Cookie::get('visitor'); } $params['book_id'] = $book_id; $params['chapter_id'] = $chapter_id; $redirect_url = get_url_no_port(true); $admin_info = model('adminConfig')->getAdminInfoAll($this->urlAdminId); if(!empty($admin_info) && $admin_info['appid']){ $redirect_url = str_replace($this->adminconfig['appid'],$admin_info['appid'],$redirect_url); } $params['redirect'] = $redirect_url; //Log::write($redirect_url,'cctest3'); $info = model("AdminConfig")->getAdminInfoAll($this->urlChannelId); //有菜单支付域名时,跳转菜单支付域名 $menuophost = $info['menuophost'] ?? null; $menuwxpay_host = $info['menuwxpay_host'] ?? null; if($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()){ //Log::write(Config::get('site.scheme') . '://' . $info['menuwxpay_host'] . '/index/recharge/pay?' . http_build_query($params),'cctestBook1'); $this->redirect(Config::get('site.scheme') . '://' . $info['menuwxpay_host'] . '/index/recharge/pay?' . http_build_query($params)); }else{ //Log::write(Config::get('site.scheme') . '://' . $info['wxpay_pay_host'] . '/index/recharge/pay?' . http_build_query($params),'cctestBook2'); $this->redirect(Config::get('site.scheme') . '://' . $info['wxpay_pay_host'] . '/index/recharge/pay?' . http_build_query($params)); } } if (empty($chapter['data']['pre_id'])) { $chapter['data']['pre_link'] = "javascript:consoleMain('已经是第一章了');"; } else { $chapter['data']['pre_link'] = '/index/book/chapter?book_id=' . $chapter['data']['book_id'] . '&chapter_id=' . $chapter['data']['pre_id']; } //章节列表 //$chapterlist = model('book')::getChapterList($chapter['data']['book_id']); // switch (Config::get('template.view_theme')){ // case 'qy': // $read_theme = 'read_theme_1'; //袋鼠 // break; // default: // $read_theme = 'read_theme_2'; //西瓜 // } if(!Config::get('template.view_theme')){ $read_theme = 'read_theme_2'; //西瓜 }else{ $read_theme = 'read_theme_1'; //袋鼠 沙发 美书 } $read_body_fontsize = 'read_body_fontsize_2'; $day_night = ''; if (Cookie::has('cs')) { $cs['l'] = 1; $cs = json_decode(Cookie::get('cs'), true); //章节排序 l=1正序 l=2倒序 if ($cs['l'] == 2) { //$chapterlist['data']['data'] = array_reverse($chapterlist['data']['data']); } if ($cs['f']) { //字号 $read_body_fontsize = 'read_body_fontsize_' . intval($cs['f']); } if ($cs['b']) { //背景色 $read_theme = 'read_theme_' . intval($cs['b']); } if ($cs['d'] == 2) { //白天/夜间 主题 $day_night = 'read_theme_5'; } } if (Ua::isWeiXin() && isset($df_chapter) && !empty($df_chapter) && $ewm_pop == 0) { if ($df_chapter['clear_data'] == 2 && isset($chapter['data']['subscribe_url']) && $chapter['data']['subscribe_url']) { $this->redirect($chapter['data']['subscribe_url']); } } $this->view->assign('read_body_fontsize', $read_body_fontsize); $this->view->assign('read_theme', $read_theme); $this->view->assign('day_night', $day_night); //$this->view->assign('chapterlist', $chapterlist['data']['data']); $this->view->assign('chapter', $chapter['data']); //调试 if ($this->request->get('debug')) { echo '输出章节数据'; var_dump($chapter); echo '输出未登录阅读记录'; var_dump(Cookie::get('read')); } $this->view->assign('signstr','sign'.Date('Ymd',time())); //dump($chapter['data']);die; return $this->view->fetch(); } /** * 状态页 * $code 1 正在码字| 2 已完结| 3 已下架| 4 章节内容为空| 5 404[并不处理] | 6 提示此本书暂时无法阅读 * $chapter * $book_id */ public function statuspage($code, $chapter = [],$book_id='') { if (strpos($book_id,'&')){ $book_id = substr($book_id,0,strpos($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'] = '/index/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){ 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']; } }else{ return $this->statuspage(6); } } $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); $channel_id = AdminService::instance()->getAdminExtendModel()->getChannelId($this->user->channel_id); $isWater = WaterBookService::instance()->showBook($channel_id,$this->user->id,IP::ip()); $ranklist = BookService::instance()->ranklist($sex_type, $isWater); if($book_id){ foreach ($ranklist['idx'] as $k=>$value){ if($value['id']==$book_id){ unset($ranklist['idx'][$k]); } } } $this->view->assign('ranklist', $ranklist); $this->assign('gussnovels', $this->_getGussNovels($book_id, $this->sex, $isWater)); } /** * 关注子公众号302跳转 */ public function sub(){ $userId = Cookie::get('user_id'); if(empty($userId)){ $userId = $this->user->id; } $user = UserService::instance()->getUserModel()->getUserInfo($userId); // $user = model('User')->setConnect($userId)->where('id',$userId)->find(); try { $recetly = model('UserRecentlyRead')->getRecentlyRead(0, 1, null, true); if ($recetly['totalNum'] > 0) { $book_name = $recetly['data'][0]['book_name']; $book_id = $recetly['data'][0]['book_id']; } else { $rankList = controller('index/index')->ranklist($user['sex'] ?? 0); $book_name = $rankList['idx'][0]['name']; $book_id = $rankList['idx'][0]['id']; } if ($book_name && $book_id) { $book_url = getCurrentDomain($this->adminconfig['admin_id'],'/index/book/chapter',['book_id'=>$book_id]); header('Location:'.$book_url); //302跳转到最近阅读的书 } } catch (\Exception $exception) { Log::error('微信子公众号关注获取最近阅读记录失败!'); } } /** * 保存书籍 * @param $url * @param $zone * @param $adid * @param $book_id * @return \think\response\Json */ public function saveBookInfo($url, $zone, $adid, $book_id) { $track_ids = [ 'pre_id' => $this->request->post('pre_id') ?? '', 'current_id' => $this->request->post('current_id') ?? '', ]; return UserdotService::instance()->saveTrackInfo($url, $zone, $adid, $book_id, $track_ids); } public function getreturnchapterbook() { return BookService::instance()->getReturnRecommandBook(); } /** * 测书场景(猜你喜欢) * @param $book_id 排重书籍ID * @param string $sex * @param $isWater * @return array */ private function _getGussNovels($book_id, $sex = '1', $isWater=false) { if(empty($sex)){ $sex = '1'; } $novels = GussNovelService::instance()->getLikedNovels($sex, 5,$isWater); //过滤书籍 确保书籍唯一,且不包含 当前书籍 $bookList = []; foreach ($novels as $novel) { if ($book_id != $novel['book_id']) { $bookList[] = $novel; } } return $bookList; } /** * 书架列表 */ public function shelf() { $this->assign('is_show_tabbar', $this->is_show_tabbar); $this->assign('tab_choice', 'bookshelf'); if (Cookie::has('user_id')) { $this->view->assign('login',1);//登录 }else { $this->view->assign('login',0);//未登录 } $result = BookService::instance()->getBookShelf(); if ($result->code == ErrorCodeConstants::SUCCESS) { $this->view->assign('shelflist', $result->data); $this->view->assign('totalNum', count($result->data)); return $this->view->fetch(); } else { $this->error($result->msg); } } public function setNextPageCache() { $bookId = Request::instance()->request('book_id'); $userId = Cookie::get('user_id'); $cacheKey = CacheConstants::getBookSubCache($userId); Redis::instance()->setex($cacheKey, 3600, $bookId); $this->success(); } }