BookController.php 35 KB

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