* 可选参数: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); $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($sex, $type, $page, $is_water); if ($books) { foreach ($books as &$book) { $book['read_num_txt'] = formatNumber($book['read_num']); $book['is_finish_text'] = $book['is_finish'] == '0' ? '连载' : '完本'; $book['category_text'] = $book['category_text'] ?? $book['author']; } } 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); } /** * 热门搜索(搜索页推荐书籍)接口 * @param int $sex 性别 * @return json */ public function hotsearchapi() { $redis = Redis::instance(); $sex = input('sex'); $userInfo = UserService::instance()->getUserInfo(); $channelId = AdminService::instance()->getAdminExtendModel()->getChannelId($userInfo->channel_id); $isWater = WaterBookService::instance()->showBook($channelId,$userInfo->id,Ip::ip()); if ($sex == 'girl') { $sexVal = 2; } else { $sexVal = 1; } $key = $isWater ? 'HS:W:' . $sexVal : 'HS:' . $sexVal; if ($redis->exists($key)) { $data = $redis->get($key); $data = json_decode($data, true); } else { $waterWhere = $isWater ? ' and classify_white_list=1 ' :''; $obj = Db::table('search_keyword')->alias('sk'); $obj->join('book','book.id=book_id and book.state=1'.$waterWhere,'inner'); $data = $obj->field('sk.keyword as name,sk.book_id')->where("sk.sex", $sexVal)->order('sk.weigh', 'desc')->select(); $json = json_encode($data, JSON_UNESCAPED_UNICODE); $redis->setex($key, 900, $json); } return json($data); } /** * 获取弹窗配置 * @return \think\response\Json */ public function checkTips() { $position = $this->request->param('position_name', ''); //导粉 $uid = Cookie::get('user_id'); $user = UserService::instance()->getUserModel()->getUserInfo($uid); $showTips = false; $tipsImg = ''; $tipsUrl = ''; $export = ExportFansService::instance()->checkFansLead($user['channel_id'], $user['id'])->data; switch ($position) { case 'sign': if ($export) { $key = $position.'_tips_show_times'; $cookie = Cookie::get($key); if (is_null($cookie) || $cookie < 1) { if ($export['status'] == '1' && $export['limittime'] > time() && $export['sign_success_img']) { $showTips = true; $tipsImg = $export['sign_success_img']; $tipsUrl = '/index/user/recent'; } } } break; } return json(['err' => 0, 'show_tips' => $showTips, 'tips_img' => $tipsImg, 'jump_url' => $tipsUrl]); } /** * 设置cookie * @return \think\response\Json */ public function setTipsCache() { $position = $this->request->param('position_name', ''); $key = $position.'_tips_show_times'; $cookie = Cookie::get($key); $expire = strtotime(date("Ymd", strtotime("+1 days"))) - time(); if (is_null($cookie)) { Cookie::set($key, 1, ['expire' => $expire]); } else { Cookie::set($key, $cookie+1, ['expire' => $expire]); } return json(['err' => 0]); } }