BookController.php 35 KB

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