BookController.php 36 KB

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