BookController.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Book;
  3. use App\Modules\RecommendBook\Services\RecommendService;
  4. use App\Modules\Book\Services\RecoBannerService;
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\QuickApp\BaseController;
  7. use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
  8. use App\Modules\Book\Services\BookConfigService;
  9. use App\Modules\Book\Services\BookService;
  10. use App\Modules\Book\Services\BookUrgeUpdateService;
  11. use App\Modules\Book\Services\UserShelfBooksService;
  12. use App\Modules\Book\Services\ChapterService;
  13. use App\Modules\Subscribe\Services\BookOrderService;
  14. use App\Modules\Subscribe\Services\ChapterOrderService;
  15. use App\Modules\User\Services\ReadRecordService;
  16. use Hashids;
  17. use Log;
  18. class BookController extends BaseController
  19. {
  20. /**
  21. * @apiDefine Book 图书
  22. */
  23. /**
  24. * @apiVersion 1.0.0
  25. * @apiDescription 获取图书详情
  26. * @api {get} book/{bid} 获取图书详情
  27. * @apiGroup Book
  28. * @apiName index
  29. * @apiParam {String} [token] token
  30. * @apiHeader {String} [Authorization] token 两个token任选其一
  31. * @apiSuccess {int} code 状态码
  32. * @apiSuccess {String} msg 信息
  33. * @apiSuccess {object} data 结果集
  34. * @apiSuccess {Int} data.book_id bid
  35. * @apiSuccess {String} data.book_name 书名
  36. * @apiSuccess {String} data.book_summary 简介
  37. * @apiSuccess {String} data.book_author 作者
  38. * @apiSuccess {String} data.cover_url 封面
  39. * @apiSuccess {Int} data.book_word_count 字数
  40. * @apiSuccess {Int} data.book_chapter_total 章节数
  41. * @apiSuccess {Int} data.book_category_id 分类
  42. * @apiSuccess {String} data.book_category 分类名
  43. * @apiSuccess {Int} data.book_end_status 是否完结
  44. * @apiSuccess {String} data.book_published_time 发布时间
  45. * @apiSuccess {String} data.copyright 版权信息
  46. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  47. * @apiSuccess {String} data.update_time 更新时间
  48. * @apiSuccess {Int} data.is_on_user_shelf 是否加入架
  49. * @apiSuccess {Int} data.book_price 是否上架
  50. * @apiSuccess {String} data.charge_type 收费类型
  51. * @apiSuccess {String} data.keyword 关键词
  52. * @apiSuccess {String} data.recommend_index 推荐指数
  53. * @apiSuccess {String} data.is_show_index_content 是否显示推荐指数文本
  54. * @apiSuccess {Int} data.click_count 点击数
  55. * @apiSuccess {Int} data.product_id product_id
  56. * @apiSuccess {Int} data.last_cid 最后一张cid
  57. * @apiSuccess {Int} data.last_chapter 第254章 婚礼(大结局)
  58. * @apiSuccess {Int} data.last_chapter_is_vip 第254章 婚礼(大结局)
  59. * @apiSuccess {Int} data.first_cid 第一章cid
  60. * @apiSuccessExample {json} Success-Response:
  61. * HTTP/1.1 200 OK
  62. * {
  63. * code: 0,
  64. * msg: "",
  65. * data: {
  66. * book_id: 5,
  67. * book_name: "肌缘巧合",
  68. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  69. * book_author: "妖火",
  70. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  71. * book_word_count: 0,
  72. * book_chapter_total: 0,
  73. * book_category_id: null,
  74. * book_category: "爆笑,宠文,潜规则",
  75. * book_end_status: 8,
  76. * book_published_time: null,
  77. * copyright: null,
  78. * charge_type: null,
  79. * force_subscribe_chapter_id: 0,
  80. * update_time: null,
  81. * is_on_user_shelf: 0,
  82. * book_price: null,
  83. * keyword: 关键词,
  84. * recommend_index:2,
  85. * is_show_index_content:0,
  86. * click_count:0,
  87. * product_id:0,
  88. * last_cid:0,
  89. * last_chapter:0,
  90. * last_chapter_is_vip:0,
  91. * }
  92. * }
  93. */
  94. public function index(Request $request, $bid)
  95. {
  96. $bid = BookService::decodeBidStatic($bid);
  97. $book_info = BookConfigService::getBookById($bid);
  98. if (!$book_info) {
  99. return response()->error('QAPP_SYS_ERROR');
  100. }
  101. if (!in_array($book_info->is_on_shelf, [2])) {
  102. return response()->error('QAPP_OFF _SHELF');
  103. }
  104. $is_on_shelf = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid, $bid);
  105. $book_info['is_on_user_shelf'] = 0;
  106. if ($is_on_shelf) {
  107. $book_info['is_on_user_shelf'] = 1;
  108. }
  109. $last_chapter = ChapterService::getChapterNameById($book_info['last_cid'], $bid);
  110. $book_info['last_chapter_is_vip'] = $last_chapter['is_vip'];
  111. $book_info['is_need_charge'] = $this->isNeedCharge($bid, $last_chapter, $book_info);
  112. $record = ReadRecordService::getBookReadRecordStatic($this->uid, $bid);
  113. if($record)
  114. {
  115. $book_info['record_chapter_id'] = $record['record_chapter_id'];
  116. $book_info['record_chapter_name'] = $record['record_chapter_name'];
  117. }
  118. return response()->item(new BookTransformer(), $book_info);
  119. }
  120. /**
  121. * 判断是否需要充值
  122. */
  123. private function isBookNeedCharge(int $bid, float $price)
  124. {
  125. $book_order = BookOrderService::getRecordByuidBid($this->uid, $bid);
  126. if ($book_order) {
  127. return false;
  128. } else {
  129. $user_info = $this->user_info;
  130. return $user_info['balance'] < $price;
  131. }
  132. }
  133. /**
  134. * 判断章节是否需要充值
  135. */
  136. private function isChapterNeedCharge(int $bid, int $cid, float $price)
  137. {
  138. $chapter_order = ChapterOrderService::checkIsOrderedStatic($this->uid, $bid, $cid);
  139. if ($chapter_order) {
  140. return false;
  141. } else {
  142. $user_info = $this->user_info;
  143. return $user_info['balance'] < $price;
  144. }
  145. }
  146. /**
  147. * 判断是否需要充值
  148. */
  149. private function isNeedCharge(int $bid, $last_chapter, $book_info)
  150. {
  151. switch ($book_info->charge_type) {
  152. case 'BOOK':
  153. $price = $this->getPrice($book_info);
  154. return $this->isBookNeedCharge($bid, $price);
  155. default:
  156. $price = $last_chapter->is_vip ? $this->getPrice($book_info, $last_chapter->size) : 0;
  157. return $last_chapter->is_vip ? $this->isChapterNeedCharge($bid, $last_chapter->id, $price) : false;
  158. }
  159. }
  160. /**
  161. * 计算价格
  162. * @param $book_info
  163. * @param $chapter_size
  164. * @return float
  165. */
  166. protected function getPrice($book_info, $chapter_size = 0)
  167. {
  168. if ($book_info->charge_type == 'BOOK')
  169. return $book_info->price * 100;
  170. return ceil($chapter_size / 100);
  171. }
  172. /**
  173. * @apiVersion 1.0.0
  174. * @apiDescription 首页(male|female)
  175. * @api {get} books/{sex}/index 首页(male|female)
  176. * @apiGroup Book
  177. * @apiParam {String} [token] token
  178. * @apiHeader {String} [Authorization] token 两个token任选其一
  179. * @apiName getBookLists
  180. * @apiSuccess {int} code 状态码
  181. * @apiSuccess {String} msg 信息
  182. * @apiSuccess {object} data 结果集
  183. * @apiSuccessExample {json} Success-Response:
  184. * HTTP/1.1 200 OK
  185. * {
  186. * code: 0,
  187. * msg: "",
  188. * data: [
  189. * {
  190. * type: "lunbo",
  191. * lable: "男频",
  192. * books: [
  193. * {},{}
  194. * ]
  195. * },
  196. * {
  197. * type: "hot",
  198. * lable: "热门推荐",
  199. * books: [
  200. * {},{}
  201. * ]
  202. * }
  203. * ]
  204. * }
  205. */
  206. public function getBookLists(Request $request, $sex)
  207. {
  208. if ($sex == 'male') {
  209. $type = [
  210. 'BOOK_MALE_LOOP',
  211. 'BOOK_MALE_HOT',
  212. 'BOOK_MALE_ZHIBO',
  213. 'BOOK_MALE_RECOM',
  214. 'BOOK_MALE_NEW_RECOM'
  215. ];
  216. $channel = 1;
  217. $reco_banner_type = ['MALE', 'PUBLIC'];
  218. } else {
  219. $type = [
  220. 'BOOK_FEMALE_LOOP',
  221. 'BOOK_FEMALE_HOT',
  222. 'BOOK_FEMALE_ZHIBO',
  223. 'BOOK_FEMALE_RECOM',
  224. 'BOOK_FEMALE_NEW_RECOM'
  225. ];
  226. $reco_banner_type = ['FEMALE', 'PUBLIC'];
  227. $channel = 2;
  228. }
  229. $books = RecoBannerService::getByTypeStatic($reco_banner_type);
  230. $books->transform(function ($item) {
  231. $result = $this->getBidCidFromUrl($item->redirect_url);
  232. $item->bid = $result['bid'];
  233. $item->cid = $result['cid'];
  234. if ($result['cid']) {
  235. $item->redirect_url = "views/Reader";
  236. } else {
  237. $item->redirect_url = "views/Detail";
  238. }
  239. return $item;
  240. });
  241. $result = [
  242. ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
  243. ['type' => 'hot', 'lable' => '热门推荐', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(RecommendService::getRecommendBooksIds($channel, 'hot')))],
  244. ['type' => 'zhibo', 'lable' => '神书直播', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(RecommendService::getRecommendBooksIds($channel, 'live')))],
  245. ['type' => 'recom', 'lable' => '编辑推荐', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(RecommendService::getRecommendBooksIds($channel, 'recom')))],
  246. ['type' => 'new_recom', 'lable' => '新书推荐', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(RecommendService::getRecommendBooksIds($channel, 'new_recom')))],
  247. ];
  248. return response()->success($result);
  249. }
  250. private function getBidCidFromUrl(string $url)
  251. {
  252. if (preg_match('/\?bid=(\w+)\S+cid=(\w+)/', $url, $matches) || preg_match('/\?id=(\w+)/', $url, $matches)) {
  253. return [
  254. 'bid' => $matches[1],
  255. 'cid' => isset($matches[2]) ? $matches[2] : 0,
  256. ];
  257. } else {
  258. return [
  259. 'bid' => '',
  260. 'cid' => 0,
  261. ];
  262. }
  263. }
  264. /**
  265. * @apiVersion 1.0.0
  266. * @apiDescription 书库
  267. * @api {get} books/library 书库
  268. * @apiParam {String} key
  269. * @apiParam {Int} category_id 分类id
  270. * @apiParam {String} order_field 排序字段(推荐指数:recommend_index|点击数:click_count|字数:size|update:时间)
  271. * @apiParam {String} order_seq 排序顺序(顺序:asc|逆序:desc)
  272. * @apiParam {String} [page_size] 分页大小
  273. * @apiParam {String} [page] 页码
  274. * @apiParam {String} [status] 完结与否(0|1)完结1 连载0
  275. * @apiParam {String} [token] token
  276. * @apiHeader {String} [Authorization] token 两个token任选其一
  277. * @apiGroup Book
  278. * @apiName library
  279. * @apiSuccess {int} code 状态码
  280. * @apiSuccess {String} msg 信息
  281. * @apiSuccess {object} data 结果集
  282. * @apiSuccess {Array} data.list 结果数据集
  283. * @apiSuccess {Int} data.list.book_id bid
  284. * @apiSuccess {String} data.list.book_name 书名
  285. * @apiSuccess {String} data.list.book_summary 简介
  286. * @apiSuccess {String} data.list.book_author 作者
  287. * @apiSuccess {String} data.list.cover_url 封面
  288. * @apiSuccess {Int} data.list.book_word_count 字数
  289. * @apiSuccess {Int} data.list.book_chapter_total 章节数
  290. * @apiSuccess {Int} data.list.book_category_id 分类
  291. * @apiSuccess {String} data.list.book_category 分类名
  292. * @apiSuccess {String} data.list.book_end_status 是否完结
  293. * @apiSuccess {String} data.list.book_published_time 发布时间
  294. * @apiSuccess {String} data.list.copyright 版权信息
  295. * @apiSuccess {Int} data.list.force_subscribe_chapter_id 强制关注的章节数
  296. * @apiSuccess {String} data.list.update_time 更新时间
  297. * @apiSuccess {Int} data.list.is_on_shelf 是否上架
  298. * @apiSuccess {String} data.list.book_price 是否上架
  299. * @apiSuccess {String} data.list.recommend_index 推荐指数
  300. * @apiSuccess {Int} data.list.charge_type 收费类型
  301. * @apiSuccess {Int} data.list.keyword 关键词
  302. * @apiSuccess {Int} data.list.is_show_index_content 是否显示推荐指数文本
  303. * @apiSuccess {Int} data.list.click_count 点击数
  304. * @apiSuccess {Int} data.list.product_id product_id
  305. * @apiSuccess {Int} data.list.last_cid 1224
  306. * @apiSuccess {Int} data.list.last_chapter 第254章 婚礼(大结局)
  307. * @apiSuccess {object} data.meta 分页信息
  308. * @apiSuccess {Int} data.meta.total 总条数
  309. * @apiSuccess {Int} data.meta.per_page 每页条数
  310. * @apiSuccess {Int} data.meta.current_page 当前页
  311. * @apiSuccess {Int} data.meta.last_page 最后页
  312. * @apiSuccess {String} data.meta.next_page_url 下一页
  313. * @apiSuccess {String} data.meta.prev_page_url 上一页
  314. * @apiSuccessExample {json} Success-Response:
  315. * HTTP/1.1 200 OK
  316. * {
  317. * code: 0,
  318. * msg: "",
  319. * data: {
  320. * list: [
  321. * {
  322. * book_id: 5,
  323. * book_name: "肌缘巧合",
  324. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  325. * book_author: "妖火",
  326. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  327. * book_word_count: 0,
  328. * book_chapter_total: 0,
  329. * book_category_id: null,
  330. * book_category: "爆笑,宠文,潜规则",
  331. * book_end_status: 8,
  332. * book_published_time: null,
  333. * copyright: null,
  334. * charge_type: null,
  335. * force_subscribe_chapter_id: 0,
  336. * update_time: null,
  337. * is_on_shelf: 1,
  338. * book_price: null,
  339. * keyword: "温馨,虐心,清水",
  340. * recommend_index:2,
  341. * is_show_index_content:0,
  342. * click_count:0,
  343. * product_id:0,
  344. * last_cid:0,
  345. * last_chapter:第254章 婚礼(大结局),
  346. * },
  347. * ],
  348. * meta: {
  349. * total: 18,
  350. * per_page: 15,
  351. * current_page: 1,
  352. * last_page: 2,
  353. * next_page_url: "http://myapi.cn/api/hotrank/books?page=2",
  354. * prev_page_url: ""
  355. * }
  356. * }
  357. * }
  358. */
  359. public function library(Request $request)
  360. {
  361. $where = [];
  362. $order = [];
  363. $where['is_on_shelf'] = [2];
  364. $category_id = $request->input('category_id');
  365. if ($category_id) {
  366. if ($category_id == 1) {
  367. $where['channel_name'] = '男频';
  368. } elseif ($category_id == 2) {
  369. $where['channel_name'] = '女频';
  370. } else {
  371. $where['category_id'] = $category_id;
  372. }
  373. }
  374. $key = $request->input('key');
  375. $where['key'] = $key;
  376. $order_field = $request->input('order_field');
  377. $order_seq = $request->input('order_seq');
  378. if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
  379. if ($order_field == 'update') {
  380. $order = ['book_configs.updated_at', 'desc'];
  381. } elseif ($order_field == 'create') {
  382. $order = ['book_configs.created_at', 'desc'];
  383. } else {
  384. $order = [$order_field, 'desc'];
  385. }
  386. if ($order_seq == 'asc') {
  387. $order = [$order_field, 'asc'];
  388. }
  389. if ($order_seq == 'desc') {
  390. $order = [$order_field, 'desc'];
  391. }
  392. }
  393. $status = $request->input('status');
  394. if ($status != '') {
  395. $where['status'] = $status;
  396. }
  397. $page_size = $request->input('page_size', 15);
  398. $books = BookConfigService::getBooks($where, $order, $page_size);
  399. return response()->pagination(new BookTransformer, $books);
  400. }
  401. /**
  402. * @apiVersion 1.0.0
  403. * @apiDescription 相似推荐
  404. * @api {get} books/similar 相似推荐
  405. * @apiParam {Int} category_id
  406. * @apiParam {Int} bid
  407. * @apiGroup Book
  408. * @apiName similarRecom
  409. * @apiParam {String} [token] token
  410. * @apiHeader {String} [Authorization] token 两个token任选其一
  411. * @apiSuccess {int} code 状态码
  412. * @apiSuccess {String} msg 信息
  413. * @apiSuccess {object} data 结果集
  414. * @apiSuccess {Array} data 结果数据集
  415. * @apiSuccess {Int} data.book_id bid
  416. * @apiSuccess {String} data.book_name 书名
  417. * @apiSuccess {String} data.book_summary 简介
  418. * @apiSuccess {String} data.book_author 作者
  419. * @apiSuccess {String} data.cover_url 封面
  420. * @apiSuccess {Int} data.book_word_count 字数
  421. * @apiSuccess {Int} data.book_chapter_total 章节数
  422. * @apiSuccess {Int} data.book_category_id 分类
  423. * @apiSuccess {String} data.book_category 分类名
  424. * @apiSuccess {String} data.book_end_status 是否完结
  425. * @apiSuccess {String} data.book_published_time 发布时间
  426. * @apiSuccess {String} data.copyright 版权信息
  427. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  428. * @apiSuccess {String} data.update_time 更新时间
  429. * @apiSuccess {Int} data.is_on_shelf 是否上架
  430. * @apiSuccess {String} data.book_price 是否上架
  431. * @apiSuccess {String} data.recommend_index 推荐指数
  432. * @apiSuccess {Int} data.charge_type 收费类型
  433. * @apiSuccess {Int} data.keyword 关键词
  434. * @apiSuccess {Int} data.is_show_index_content 是否显示推荐指数文本
  435. * @apiSuccess {Int} data.click_count 点击数
  436. * @apiSuccess {Int} data.product_id product_id
  437. * @apiSuccess {Int} data.last_cid 123
  438. * @apiSuccess {Int} data.last_chapter 第254章 婚礼(大结局)
  439. * @apiSuccessExample {json} Success-Response:
  440. * HTTP/1.1 200 OK
  441. * {
  442. * code: 0,
  443. * msg: "",
  444. * data: {
  445. * [
  446. * {
  447. * book_id: 5,
  448. * book_name: "肌缘巧合",
  449. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  450. * book_author: "妖火",
  451. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  452. * book_word_count: 0,
  453. * book_chapter_total: 0,
  454. * book_category_id: null,
  455. * book_category: "爆笑,宠文,潜规则",
  456. * book_end_status: 8,
  457. * book_published_time: null,
  458. * copyright: null,
  459. * charge_type: null,
  460. * force_subscribe_chapter_id: 0,
  461. * update_time: null,
  462. * is_on_shelf: 1,
  463. * book_price: null,
  464. * keyword: "温馨,虐心,清水",
  465. * recommend_index:2,
  466. * is_show_index_content:0,
  467. * click_count:0,
  468. * product_id:0,
  469. * last_cid:0,
  470. * last_chapter:第254章 婚礼(大结局),
  471. * },
  472. * ],
  473. * }
  474. * }
  475. */
  476. public function similarRecom(Request $request)
  477. {
  478. $category_id = $request->input('category_id');
  479. $bid = $request->input('bid');
  480. if (empty($bid) || empty($category_id)) {
  481. return response()->error('PARAM_ERROR');
  482. }
  483. $bid = BookService::decodeBidStatic($bid);
  484. $where = ['category_id' => $category_id, 'is_on_shelf' => [2]];
  485. $books = BookConfigService::getBooks($where, [], 4);
  486. $data = [];
  487. foreach ($books as $v) {
  488. if ($v->bid != $bid && count($data) < 3) {
  489. $data[] = $v;
  490. }
  491. }
  492. return response()->collection(new BookTransformer(), $data);
  493. }
  494. /**
  495. * @apiVersion 1.0.0
  496. * @apiDescription 尾页推荐
  497. * @api {get} books/readOverRecommend 尾页推荐
  498. * @apiParam {Int} bid
  499. * @apiGroup Book
  500. * @apiParam {String} [token] token
  501. * @apiHeader {String} [Authorization] token 两个token任选其一
  502. * @apiName readOverRecommend
  503. * @apiSuccess {int} code 状态码
  504. * @apiSuccess {String} msg 信息
  505. * @apiSuccess {object} data 结果集
  506. * @apiSuccess {Array} data 结果数据集
  507. * @apiSuccess {Int} data.book_id bid
  508. * @apiSuccess {String} data.book_name 书名
  509. * @apiSuccess {String} data.book_summary 简介
  510. * @apiSuccess {String} data.book_author 作者
  511. * @apiSuccess {String} data.cover_url 封面
  512. * @apiSuccess {Int} data.book_word_count 字数
  513. * @apiSuccess {Int} data.book_chapter_total 章节数
  514. * @apiSuccess {Int} data.book_category_id 分类
  515. * @apiSuccess {String} data.book_category 分类名
  516. * @apiSuccess {String} data.book_end_status 是否完结
  517. * @apiSuccess {String} data.book_published_time 发布时间
  518. * @apiSuccess {String} data.copyright 版权信息
  519. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  520. * @apiSuccess {String} data.update_time 更新时间
  521. * @apiSuccess {Int} data.is_on_shelf 是否上架
  522. * @apiSuccess {String} data.book_price 是否上架
  523. * @apiSuccess {String} data.recommend_index 推荐指数
  524. * @apiSuccess {Int} data.charge_type 收费类型
  525. * @apiSuccess {Int} data.keyword 关键词
  526. * @apiSuccess {Int} data.is_show_index_content 是否显示推荐指数文本
  527. * @apiSuccess {Int} data.click_count 点击数
  528. * @apiSuccess {Int} data.product_id product_id
  529. * @apiSuccess {Int} data.last_cid 123
  530. * @apiSuccess {Int} data.last_chapter 第254章 婚礼(大结局)
  531. * @apiSuccessExample {json} Success-Response:
  532. * HTTP/1.1 200 OK
  533. * {
  534. * code: 0,
  535. * msg: "",
  536. * data: {
  537. * [
  538. * {
  539. * book_id: 5,
  540. * book_name: "肌缘巧合",
  541. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  542. * book_author: "妖火",
  543. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  544. * book_word_count: 0,
  545. * book_chapter_total: 0,
  546. * book_category_id: null,
  547. * book_category: "爆笑,宠文,潜规则",
  548. * book_end_status: 8,
  549. * book_published_time: null,
  550. * copyright: null,
  551. * charge_type: null,
  552. * force_subscribe_chapter_id: 0,
  553. * update_time: null,
  554. * is_on_shelf: 1,
  555. * book_price: null,
  556. * keyword: "温馨,虐心,清水",
  557. * recommend_index:2,
  558. * is_show_index_content:0,
  559. * click_count:0,
  560. * product_id:0,
  561. * last_cid:0,
  562. * last_chapter:第254章 婚礼(大结局),
  563. * },
  564. * ],
  565. * }
  566. * }
  567. */
  568. public function readOverRecommend(Request $request)
  569. {
  570. $bid = $request->input('bid');
  571. if (empty($bid)) {
  572. return response()->error('PARAM_ERROR');
  573. }
  574. $bid = BookService::decodeBidStatic($bid);
  575. $book_info = BookConfigService::getBookById($bid);
  576. $res = BookConfigService::getRecommendBooks($bid, $book_info->channel_name);
  577. $urge_status = 0;
  578. if ($book_info->status == 0 && !BookUrgeUpdateService::isHadUrged($this->uid, $bid)) {
  579. $urge_status = 1;
  580. }
  581. $recommend_result = collectionTransform(new BookTransformer(), $res);
  582. $book_status = [
  583. 'status' => $book_info->status,
  584. 'urge_status' => $urge_status
  585. ];
  586. $data = [
  587. 'recommend_result' => $recommend_result,
  588. 'book_status' => $book_status
  589. ];
  590. return response()->success($data);
  591. }
  592. /**
  593. * @apiVersion 1.0.0
  594. * @apiDescription 排行帮
  595. * @api {get} books/rank 排行帮
  596. * @apiParam {Int} type (点击帮:1|字数帮:2|新书榜|3)
  597. * @apiParam {Int} time (周:1|月:2|总|3)
  598. * @apiParam {String} [token] token
  599. * @apiHeader {String} [Authorization] token 两个token任选其一
  600. * @apiGroup Book
  601. * @apiName rank
  602. * @apiSuccess {int} code 状态码
  603. * @apiSuccess {String} msg 信息
  604. * @apiSuccess {object} data 结果集
  605. * @apiSuccess {Array} data 结果数据集
  606. * @apiSuccess {Int} data.book_id bid
  607. * @apiSuccess {String} data.book_name 书名
  608. * @apiSuccess {String} data.book_summary 简介
  609. * @apiSuccess {String} data.book_author 作者
  610. * @apiSuccess {String} data.cover_url 封面
  611. * @apiSuccess {Int} data.book_word_count 字数
  612. * @apiSuccess {Int} data.book_chapter_total 章节数
  613. * @apiSuccess {Int} data.book_category_id 分类
  614. * @apiSuccess {String} data.book_category 分类名
  615. * @apiSuccess {String} data.book_end_status 是否完结
  616. * @apiSuccess {String} data.book_published_time 发布时间
  617. * @apiSuccess {String} data.copyright 版权信息
  618. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  619. * @apiSuccess {String} data.update_time 更新时间
  620. * @apiSuccess {Int} data.is_on_shelf 是否上架
  621. * @apiSuccess {String} data.book_price 是否上架
  622. * @apiSuccess {String} data.recommend_index 推荐指数
  623. * @apiSuccess {Int} data.charge_type 收费类型
  624. * @apiSuccess {Int} data.keyword 关键词
  625. * @apiSuccess {Int} data.is_show_index_content 是否显示推荐指数文本
  626. * @apiSuccess {Int} data.click_count 点击数
  627. * @apiSuccess {Int} data.product_id product_id
  628. * @apiSuccess {Int} data.last_cid 123
  629. * @apiSuccess {Int} data.last_chapter 第254章 婚礼(大结局)
  630. * @apiSuccessExample {json} Success-Response:
  631. * HTTP/1.1 200 OK
  632. * {
  633. * code: 0,
  634. * msg: "",
  635. * data: {
  636. * male:[
  637. * {
  638. * book_id: 5,
  639. * book_name: "肌缘巧合",
  640. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  641. * book_author: "妖火",
  642. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  643. * book_word_count: 0,
  644. * book_chapter_total: 0,
  645. * book_category_id: null,
  646. * book_category: "爆笑,宠文,潜规则",
  647. * book_end_status: 8,
  648. * book_published_time: null,
  649. * copyright: null,
  650. * charge_type: null,
  651. * force_subscribe_chapter_id: 0,
  652. * update_time: null,
  653. * is_on_shelf: 1,
  654. * book_price: null,
  655. * keyword: "温馨,虐心,清水",
  656. * recommend_index:2,
  657. * is_show_index_content:0,
  658. * click_count:0,
  659. * product_id:0,
  660. * last_cid:0,
  661. * last_chapter:第254章 婚礼(大结局),
  662. * },
  663. * ],
  664. * female:[{},{}]
  665. * }
  666. * }
  667. */
  668. public function rank(Request $request)
  669. {
  670. $type = $request->input('type');
  671. $time = $request->input('time');
  672. if ($type == 1) {
  673. //点击帮
  674. if ($time == 1) {
  675. //周
  676. $midstr = env('CLICK_RANK_MALE_WEEK', '677,694,638,642,641,673,635,639,637,4');
  677. $fidstr = env('CLICK_RANK_FEMALE_WEEK', '614,636,587,48,1,6,354,99,159,355');
  678. } elseif ($time == 2) {
  679. //月
  680. $midstr = env('CLICK_RANK_MALE_MONTH', '757,775,780,612,638,635,694,639,642,693');
  681. $fidstr = env('CLICK_RANK_FEMALE_MONTH', '324,614,6,1,5,10,48,57,41,58');
  682. } else {
  683. $midstr = env('CLICK_RANK_MALE_TOTAL', '757,775,780,612,634,677,694,638,642,635');
  684. $fidstr = env('CLICK_RANK_FEMALE_TOTAL', '324,614,636,1,5,6,521,10,41,48');
  685. }
  686. $female = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $fidstr)));
  687. $male = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $midstr)));
  688. } elseif ($type == 2) {
  689. //字数帮
  690. if ($time == 1) {
  691. //周
  692. $midstr = env('WORD_RANK_MALE_WEEK', '638,673,635,637,680,642,86,774,764,736');
  693. $fidstr = env('WORD_RANK_FEMALE_WEEK', '48,58,324,354,159,262,7,9,11,525');
  694. } elseif ($time == 2) {
  695. //月
  696. $midstr = env('WORD_RANK_MALE_MONTH', '2,638,642,635,639,4,743,680,736,73');
  697. $fidstr = env('WORD_RANK_FEMALE_MONTH', '1,10,48,58,324,354,159,442,355,464');
  698. } else {
  699. $midstr = env('WORD_RANK_MALE_TOTAL', '638,677,694,635,612,693,634,642,775,780');
  700. $fidstr = env('WORD_RANK_FEMALE_TOTAL', '57,636,614,1,10,48,58,324,354,99');
  701. }
  702. $female = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $fidstr)));
  703. $male = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $midstr)));
  704. } elseif ($type == 3) {
  705. //新书榜
  706. if ($time == 1) {
  707. //周
  708. $midstr = env('NEW_RANK_MALE_WEEK', '635,639,4,642,629,446,741,737,731,86');
  709. $fidstr = env('NEW_RANK_FEMALE_WEEK', '135,587,617,625,627,467,213,233,529,357');
  710. } elseif ($time == 2) {
  711. //月
  712. $midstr = env('NEW_RANK_MALE_MONTH', '757,775,780,612,634,677,694,638,642,635');
  713. $fidstr = env('NEW_RANK_FEMALE_MONTH', '33,39,40,51,587,617,625,627,50,60');
  714. } else {
  715. $midstr = env('NEW_RANK_MALE_TOTAL', '693,641,673,637,4,3,612,634,677,694');
  716. $fidstr = env('NEW_RANK_FEMALE_TOTAL', '284,30,33,39,40,51,587,50,60,357');
  717. }
  718. $female = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $fidstr)));
  719. $male = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $midstr)));
  720. } else {
  721. return response()->error('PARAM_ERROR');
  722. }
  723. $data = ['male' => $male, 'female' => $female];
  724. return response()->success($data);
  725. }
  726. }