BookController.php 35 KB

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