BookController.php 35 KB

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