Index.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\library\OrderDeduction;
  4. use app\common\controller\Api;
  5. use app\common\library\Ip;
  6. use app\common\library\Redis;
  7. use app\common\service\WaterBookService;
  8. use app\main\service\AdminService;
  9. use app\main\service\ExportFansService;
  10. use app\main\service\LogService;
  11. use app\main\service\UserService;
  12. use think\Cookie;
  13. use Think\Db;
  14. /**
  15. * 首页接口
  16. */
  17. class Index extends Api
  18. {
  19. protected $noNeedLogin = ['*'];
  20. protected $noNeedRight = ['*'];
  21. /**
  22. * 首页
  23. *
  24. * 必选参数:无<br>
  25. * 可选参数:lng,lat
  26. */
  27. public function index()
  28. {
  29. $this->success('请求成功');
  30. }
  31. /**
  32. * 首页书籍榜单列表数据
  33. * @param string $type 榜单类别(free finish click sell 免费榜 完结榜 点击榜 销售榜)
  34. * @param int $page 页数
  35. * @return json
  36. */
  37. public function booklistapi()
  38. {
  39. $sex = input('sex', 0);
  40. $type = input('type');
  41. $page = input('page', 1);
  42. $user_id = Cookie::get('user_id');
  43. //清水
  44. if ($user_id) {
  45. $userInfo = UserService::instance()->getUserModel()->getUserInfo($user_id);
  46. $channel_id = $userInfo['channel_id'] ?? 0;
  47. if (empty($channel_id)) {
  48. $is_water = false;
  49. } else {
  50. $channel_id = AdminService::instance()->getAdminExtendModel()->getChannelId($channel_id);
  51. $is_water = WaterBookService::instance()->showBook($channel_id, $user_id, Ip::ip());
  52. }
  53. } else {
  54. $is_water = false;
  55. }
  56. $books = model('index')::booklist($sex, $type, $page, $is_water);
  57. if ($books) {
  58. foreach ($books as &$book) {
  59. $book['read_num_txt'] = formatNumber($book['read_num']);
  60. $book['is_finish_text'] = $book['is_finish'] == '0' ? '连载' : '完本';
  61. $book['category_text'] = $book['category_text'] ?? $book['author'];
  62. }
  63. }
  64. return json($books);
  65. }
  66. /**
  67. * 首页配置的指定区块书籍列表接口
  68. * @param int $block_id 区块id
  69. * @param int $page 页数
  70. * @return json $books 书籍列表信息
  71. */
  72. public function blockbookapi()
  73. {
  74. $block_id = input('block_id');
  75. $page = input('page', 1);
  76. $user_id = Cookie::get('user_id');
  77. //清水
  78. if ($user_id) {
  79. $userInfo = UserService::instance()->getUserModel()->getUserInfo($user_id);
  80. $channel_id = $userInfo['channel_id'] ?? 0;
  81. if (empty($channel_id)) {
  82. $is_water = false;
  83. } else {
  84. $channel_id = AdminService::instance()->getAdminExtendModel()->getChannelId($channel_id);
  85. $is_water = WaterBookService::instance()->showBook($channel_id, $user_id, Ip::ip());
  86. }
  87. } else {
  88. $is_water = false;
  89. }
  90. $data = model('index')::blockbooklist($block_id, $page, $is_water);
  91. return json($data);
  92. }
  93. /**
  94. * 热门搜索(搜索页推荐书籍)接口
  95. * @param int $sex 性别
  96. * @return json
  97. */
  98. public function hotsearchapi()
  99. {
  100. $redis = Redis::instance();
  101. $sex = input('sex');
  102. $userInfo = UserService::instance()->getUserInfo();
  103. $channelId = AdminService::instance()->getAdminExtendModel()->getChannelId($userInfo->channel_id);
  104. $isWater = WaterBookService::instance()->showBook($channelId,$userInfo->id,Ip::ip());
  105. if ($sex == 'girl') {
  106. $sexVal = 2;
  107. } else {
  108. $sexVal = 1;
  109. }
  110. $key = $isWater ? 'HS:W:' . $sexVal : 'HS:' . $sexVal;
  111. if ($redis->exists($key)) {
  112. $data = $redis->get($key);
  113. $data = json_decode($data, true);
  114. } else {
  115. $waterWhere = $isWater ? ' and classify_white_list=1 ' :'';
  116. $obj = Db::table('search_keyword')->alias('sk');
  117. $obj->join('book','book.id=book_id and book.state=1'.$waterWhere,'inner');
  118. $data = $obj->field('sk.keyword as name,sk.book_id')->where("sk.sex", $sexVal)->order('sk.weigh', 'desc')->select();
  119. $json = json_encode($data, JSON_UNESCAPED_UNICODE);
  120. $redis->setex($key, 900, $json);
  121. }
  122. return json($data);
  123. }
  124. /**
  125. * 获取弹窗配置
  126. * @return \think\response\Json
  127. */
  128. public function checkTips()
  129. {
  130. $position = $this->request->param('position_name', '');
  131. //导粉
  132. $uid = Cookie::get('user_id');
  133. $user = UserService::instance()->getUserModel()->getUserInfo($uid);
  134. $showTips = false;
  135. $tipsImg = '';
  136. $tipsUrl = '';
  137. $export = ExportFansService::instance()->checkFansLead($user['channel_id'], $user['id'])->data;
  138. switch ($position) {
  139. case 'sign':
  140. if ($export) {
  141. $key = $position.'_tips_show_times';
  142. $cookie = Cookie::get($key);
  143. if (is_null($cookie) || $cookie < 1) {
  144. if ($export['status'] == '1' && $export['limittime'] > time() && $export['sign_success_img']) {
  145. $showTips = true;
  146. $tipsImg = $export['sign_success_img'];
  147. $tipsUrl = '/index/user/recent';
  148. }
  149. }
  150. }
  151. break;
  152. }
  153. return json(['err' => 0, 'show_tips' => $showTips, 'tips_img' => $tipsImg, 'jump_url' => $tipsUrl]);
  154. }
  155. /**
  156. * 设置cookie
  157. * @return \think\response\Json
  158. */
  159. public function setTipsCache()
  160. {
  161. $position = $this->request->param('position_name', '');
  162. $key = $position.'_tips_show_times';
  163. $cookie = Cookie::get($key);
  164. $expire = strtotime(date("Ymd", strtotime("+1 days"))) - time();
  165. if (is_null($cookie)) {
  166. Cookie::set($key, 1, ['expire' => $expire]);
  167. } else {
  168. Cookie::set($key, $cookie+1, ['expire' => $expire]);
  169. }
  170. return json(['err' => 0]);
  171. }
  172. }