BookController.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  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 = (new RecoBannerService)->getByType($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. $package = $request->header('x-package', '');
  269. $checkOpen = env('CHECK_OPEN', false);
  270. if ($checkOpen && $package === 'com.juyu.kuaiying.rmyq') {
  271. $hotBids = config('home.' . $sex . '.hot');
  272. $liveBids = config('home.' . $sex . '.live');
  273. $recomBids = config('home.' . $sex . '.recom');
  274. $newBids = config('home.' . $sex . '.new_recom');
  275. } else {
  276. $hotBids = RecommendService::getRecommendIdsStatic($channel, 'hot');
  277. $liveBids = RecommendService::getRecommendIdsStatic($channel, 'live');
  278. $recomBids = RecommendService::getRecommendIdsStatic($channel, 'recom');
  279. $newBids = RecommendService::getRecommendIdsStatic($channel, 'new_recom');
  280. }
  281. $result = [
  282. ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
  283. ['type' => 'hot', 'lable' => '热门推荐', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($hotBids)->where('is_on_shelf', '=', 2))],
  284. ['type' => 'zhibo', 'lable' => '神书直播', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($liveBids)->where('is_on_shelf', '=', 2))],
  285. ['type' => 'recom', 'lable' => '编辑推荐', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($recomBids)->where('is_on_shelf', '=', 2))],
  286. ['type' => 'new_recom', 'lable' => '新书推荐', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($newBids)->where('is_on_shelf', '=', 2))],
  287. ];
  288. return response()->success($result);
  289. }
  290. private function getBidCidFromUrl(string $url)
  291. {
  292. if (preg_match('/\?bid=(\w+)\S+cid=(\w+)/', $url, $matches) || preg_match('/\?id=(\w+)/', $url, $matches)) {
  293. return [
  294. 'bid' => $matches[1],
  295. 'cid' => isset($matches[2]) ? $matches[2] : 0,
  296. ];
  297. } else {
  298. return [
  299. 'bid' => '',
  300. 'cid' => 0,
  301. ];
  302. }
  303. }
  304. /**
  305. * @apiVersion 1.0.0
  306. * @apiDescription 书库
  307. * @api {get} books/library 书库
  308. * @apiParam {String} key
  309. * @apiParam {Int} category_id 分类id
  310. * @apiParam {String} order_field 排序字段(推荐指数:recommend_index|点击数:click_count|字数:size|update:时间)
  311. * @apiParam {String} order_seq 排序顺序(顺序:asc|逆序:desc)
  312. * @apiParam {String} [page_size] 分页大小
  313. * @apiParam {String} [page] 页码
  314. * @apiParam {String} [status] 完结与否(0|1)完结1 连载0
  315. * @apiParam {String} [token] token
  316. * @apiHeader {String} [Authorization] token 两个token任选其一
  317. * @apiGroup Book
  318. * @apiName library
  319. * @apiSuccess {int} code 状态码
  320. * @apiSuccess {String} msg 信息
  321. * @apiSuccess {object} data 结果集
  322. * @apiSuccess {Array} data.list 结果数据集
  323. * @apiSuccess {Int} data.list.book_id bid
  324. * @apiSuccess {String} data.list.book_name 书名
  325. * @apiSuccess {String} data.list.book_summary 简介
  326. * @apiSuccess {String} data.list.book_author 作者
  327. * @apiSuccess {String} data.list.cover_url 封面
  328. * @apiSuccess {Int} data.list.book_word_count 字数
  329. * @apiSuccess {Int} data.list.book_chapter_total 章节数
  330. * @apiSuccess {Int} data.list.book_category_id 分类
  331. * @apiSuccess {String} data.list.book_category 分类名
  332. * @apiSuccess {String} data.list.book_end_status 是否完结
  333. * @apiSuccess {String} data.list.book_published_time 发布时间
  334. * @apiSuccess {String} data.list.copyright 版权信息
  335. * @apiSuccess {Int} data.list.force_subscribe_chapter_id 强制关注的章节数
  336. * @apiSuccess {String} data.list.update_time 更新时间
  337. * @apiSuccess {Int} data.list.is_on_shelf 是否上架
  338. * @apiSuccess {String} data.list.book_price 是否上架
  339. * @apiSuccess {String} data.list.recommend_index 推荐指数
  340. * @apiSuccess {Int} data.list.charge_type 收费类型
  341. * @apiSuccess {Int} data.list.keyword 关键词
  342. * @apiSuccess {Int} data.list.is_show_index_content 是否显示推荐指数文本
  343. * @apiSuccess {Int} data.list.click_count 点击数
  344. * @apiSuccess {Int} data.list.product_id product_id
  345. * @apiSuccess {Int} data.list.last_cid 1224
  346. * @apiSuccess {Int} data.list.last_chapter 第254章 婚礼(大结局)
  347. * @apiSuccess {object} data.meta 分页信息
  348. * @apiSuccess {Int} data.meta.total 总条数
  349. * @apiSuccess {Int} data.meta.per_page 每页条数
  350. * @apiSuccess {Int} data.meta.current_page 当前页
  351. * @apiSuccess {Int} data.meta.last_page 最后页
  352. * @apiSuccess {String} data.meta.next_page_url 下一页
  353. * @apiSuccess {String} data.meta.prev_page_url 上一页
  354. * @apiSuccessExample {json} Success-Response:
  355. * HTTP/1.1 200 OK
  356. * {
  357. * code: 0,
  358. * msg: "",
  359. * data: {
  360. * list: [
  361. * {
  362. * book_id: 5,
  363. * book_name: "肌缘巧合",
  364. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  365. * book_author: "妖火",
  366. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  367. * book_word_count: 0,
  368. * book_chapter_total: 0,
  369. * book_category_id: null,
  370. * book_category: "爆笑,宠文,潜规则",
  371. * book_end_status: 8,
  372. * book_published_time: null,
  373. * copyright: null,
  374. * charge_type: null,
  375. * force_subscribe_chapter_id: 0,
  376. * update_time: null,
  377. * is_on_shelf: 1,
  378. * book_price: null,
  379. * keyword: "温馨,虐心,清水",
  380. * recommend_index:2,
  381. * is_show_index_content:0,
  382. * click_count:0,
  383. * product_id:0,
  384. * last_cid:0,
  385. * last_chapter:第254章 婚礼(大结局),
  386. * },
  387. * ],
  388. * meta: {
  389. * total: 18,
  390. * per_page: 15,
  391. * current_page: 1,
  392. * last_page: 2,
  393. * next_page_url: "http://myapi.cn/api/hotrank/books?page=2",
  394. * prev_page_url: ""
  395. * }
  396. * }
  397. * }
  398. */
  399. public function library(Request $request)
  400. {
  401. $where = [];
  402. $order = [];
  403. $where['is_on_shelf'] = [2];
  404. $category_id = $request->input('category_id');
  405. if ($category_id) {
  406. if ($category_id == 1) {
  407. $where['channel_name'] = '男频';
  408. } elseif ($category_id == 2) {
  409. $where['channel_name'] = '女频';
  410. } else {
  411. $where['category_id'] = $category_id;
  412. }
  413. }
  414. $key = $request->input('key');
  415. $where['key'] = $key;
  416. $order_field = $request->input('order_field');
  417. $order_seq = $request->input('order_seq');
  418. if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
  419. if ($order_field == 'update') {
  420. $order = ['book_configs.updated_at', 'desc'];
  421. } elseif ($order_field == 'create') {
  422. $order = ['book_configs.created_at', 'desc'];
  423. } else {
  424. $order = [$order_field, 'desc'];
  425. }
  426. if ($order_seq == 'asc') {
  427. $order = [$order_field, 'asc'];
  428. }
  429. if ($order_seq == 'desc') {
  430. $order = [$order_field, 'desc'];
  431. }
  432. }
  433. $status = $request->input('status');
  434. if ($status != '') {
  435. $where['status'] = $status;
  436. }
  437. $page_size = $request->input('page_size', 15);
  438. $books = BookConfigService::getBooks($where, $order, $page_size);
  439. return response()->pagination(new BookTransformer, $books);
  440. }
  441. /**
  442. * @apiVersion 1.0.0
  443. * @apiDescription 相似推荐
  444. * @api {get} books/similar 相似推荐
  445. * @apiParam {Int} category_id
  446. * @apiParam {Int} bid
  447. * @apiGroup Book
  448. * @apiName similarRecom
  449. * @apiParam {String} [token] token
  450. * @apiHeader {String} [Authorization] token 两个token任选其一
  451. * @apiSuccess {int} code 状态码
  452. * @apiSuccess {String} msg 信息
  453. * @apiSuccess {object} data 结果集
  454. * @apiSuccess {Array} data 结果数据集
  455. * @apiSuccess {Int} data.book_id bid
  456. * @apiSuccess {String} data.book_name 书名
  457. * @apiSuccess {String} data.book_summary 简介
  458. * @apiSuccess {String} data.book_author 作者
  459. * @apiSuccess {String} data.cover_url 封面
  460. * @apiSuccess {Int} data.book_word_count 字数
  461. * @apiSuccess {Int} data.book_chapter_total 章节数
  462. * @apiSuccess {Int} data.book_category_id 分类
  463. * @apiSuccess {String} data.book_category 分类名
  464. * @apiSuccess {String} data.book_end_status 是否完结
  465. * @apiSuccess {String} data.book_published_time 发布时间
  466. * @apiSuccess {String} data.copyright 版权信息
  467. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  468. * @apiSuccess {String} data.update_time 更新时间
  469. * @apiSuccess {Int} data.is_on_shelf 是否上架
  470. * @apiSuccess {String} data.book_price 是否上架
  471. * @apiSuccess {String} data.recommend_index 推荐指数
  472. * @apiSuccess {Int} data.charge_type 收费类型
  473. * @apiSuccess {Int} data.keyword 关键词
  474. * @apiSuccess {Int} data.is_show_index_content 是否显示推荐指数文本
  475. * @apiSuccess {Int} data.click_count 点击数
  476. * @apiSuccess {Int} data.product_id product_id
  477. * @apiSuccess {Int} data.last_cid 123
  478. * @apiSuccess {Int} data.last_chapter 第254章 婚礼(大结局)
  479. * @apiSuccessExample {json} Success-Response:
  480. * HTTP/1.1 200 OK
  481. * {
  482. * code: 0,
  483. * msg: "",
  484. * data: {
  485. * [
  486. * {
  487. * book_id: 5,
  488. * book_name: "肌缘巧合",
  489. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  490. * book_author: "妖火",
  491. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  492. * book_word_count: 0,
  493. * book_chapter_total: 0,
  494. * book_category_id: null,
  495. * book_category: "爆笑,宠文,潜规则",
  496. * book_end_status: 8,
  497. * book_published_time: null,
  498. * copyright: null,
  499. * charge_type: null,
  500. * force_subscribe_chapter_id: 0,
  501. * update_time: null,
  502. * is_on_shelf: 1,
  503. * book_price: null,
  504. * keyword: "温馨,虐心,清水",
  505. * recommend_index:2,
  506. * is_show_index_content:0,
  507. * click_count:0,
  508. * product_id:0,
  509. * last_cid:0,
  510. * last_chapter:第254章 婚礼(大结局),
  511. * },
  512. * ],
  513. * }
  514. * }
  515. */
  516. public function similarRecom(Request $request)
  517. {
  518. $category_id = $request->input('category_id');
  519. $bid = $request->input('bid');
  520. if (empty($bid) || empty($category_id)) {
  521. return response()->error('PARAM_ERROR');
  522. }
  523. $bid = BookService::decodeBidStatic($bid);
  524. $where = ['category_id' => $category_id, 'is_on_shelf' => [2]];
  525. $books = BookConfigService::getBooks($where, [], 4);
  526. $data = [];
  527. foreach ($books as $v) {
  528. if ($v->bid != $bid && count($data) < 3) {
  529. $data[] = $v;
  530. }
  531. }
  532. return response()->collection(new BookTransformer(), $data);
  533. }
  534. /**
  535. * @apiVersion 1.0.0
  536. * @apiDescription 尾页推荐
  537. * @api {get} books/readOverRecommend 尾页推荐
  538. * @apiParam {Int} bid
  539. * @apiGroup Book
  540. * @apiParam {String} [token] token
  541. * @apiHeader {String} [Authorization] token 两个token任选其一
  542. * @apiName readOverRecommend
  543. * @apiSuccess {int} code 状态码
  544. * @apiSuccess {String} msg 信息
  545. * @apiSuccess {object} data 结果集
  546. * @apiSuccess {Array} data 结果数据集
  547. * @apiSuccess {Int} data.book_id bid
  548. * @apiSuccess {String} data.book_name 书名
  549. * @apiSuccess {String} data.book_summary 简介
  550. * @apiSuccess {String} data.book_author 作者
  551. * @apiSuccess {String} data.cover_url 封面
  552. * @apiSuccess {Int} data.book_word_count 字数
  553. * @apiSuccess {Int} data.book_chapter_total 章节数
  554. * @apiSuccess {Int} data.book_category_id 分类
  555. * @apiSuccess {String} data.book_category 分类名
  556. * @apiSuccess {String} data.book_end_status 是否完结
  557. * @apiSuccess {String} data.book_published_time 发布时间
  558. * @apiSuccess {String} data.copyright 版权信息
  559. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  560. * @apiSuccess {String} data.update_time 更新时间
  561. * @apiSuccess {Int} data.is_on_shelf 是否上架
  562. * @apiSuccess {String} data.book_price 是否上架
  563. * @apiSuccess {String} data.recommend_index 推荐指数
  564. * @apiSuccess {Int} data.charge_type 收费类型
  565. * @apiSuccess {Int} data.keyword 关键词
  566. * @apiSuccess {Int} data.is_show_index_content 是否显示推荐指数文本
  567. * @apiSuccess {Int} data.click_count 点击数
  568. * @apiSuccess {Int} data.product_id product_id
  569. * @apiSuccess {Int} data.last_cid 123
  570. * @apiSuccess {Int} data.last_chapter 第254章 婚礼(大结局)
  571. * @apiSuccessExample {json} Success-Response:
  572. * HTTP/1.1 200 OK
  573. * {
  574. * code: 0,
  575. * msg: "",
  576. * data: {
  577. * [
  578. * {
  579. * book_id: 5,
  580. * book_name: "肌缘巧合",
  581. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  582. * book_author: "妖火",
  583. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  584. * book_word_count: 0,
  585. * book_chapter_total: 0,
  586. * book_category_id: null,
  587. * book_category: "爆笑,宠文,潜规则",
  588. * book_end_status: 8,
  589. * book_published_time: null,
  590. * copyright: null,
  591. * charge_type: null,
  592. * force_subscribe_chapter_id: 0,
  593. * update_time: null,
  594. * is_on_shelf: 1,
  595. * book_price: null,
  596. * keyword: "温馨,虐心,清水",
  597. * recommend_index:2,
  598. * is_show_index_content:0,
  599. * click_count:0,
  600. * product_id:0,
  601. * last_cid:0,
  602. * last_chapter:第254章 婚礼(大结局),
  603. * },
  604. * ],
  605. * }
  606. * }
  607. */
  608. public function readOverRecommend(Request $request)
  609. {
  610. $bid = $request->input('bid');
  611. if (empty($bid)) {
  612. return response()->error('PARAM_ERROR');
  613. }
  614. $bid = BookService::decodeBidStatic($bid);
  615. $book_info = BookConfigService::getBookById($bid);
  616. $res = BookConfigService::getRecommendBooks($bid, $book_info->channel_name);
  617. $urge_status = 0;
  618. if ($book_info->status == 0 && !BookUrgeUpdateService::isHadUrged($this->uid, $bid)) {
  619. $urge_status = 1;
  620. }
  621. $recommend_result = collectionTransform(new BookTransformer(), $res);
  622. $book_status = [
  623. 'status' => $book_info->status,
  624. 'urge_status' => $urge_status
  625. ];
  626. $data = [
  627. 'recommend_result' => $recommend_result,
  628. 'book_status' => $book_status
  629. ];
  630. return response()->success($data);
  631. }
  632. /**
  633. * @apiVersion 1.0.0
  634. * @apiDescription 排行帮
  635. * @api {get} books/rank 排行帮
  636. * @apiParam {Int} type (点击帮:1|字数帮:2|新书榜|3)
  637. * @apiParam {Int} time (周:1|月:2|总|3)
  638. * @apiParam {String} [token] token
  639. * @apiHeader {String} [Authorization] token 两个token任选其一
  640. * @apiGroup Book
  641. * @apiName rank
  642. * @apiSuccess {int} code 状态码
  643. * @apiSuccess {String} msg 信息
  644. * @apiSuccess {object} data 结果集
  645. * @apiSuccess {Array} data 结果数据集
  646. * @apiSuccess {Int} data.book_id bid
  647. * @apiSuccess {String} data.book_name 书名
  648. * @apiSuccess {String} data.book_summary 简介
  649. * @apiSuccess {String} data.book_author 作者
  650. * @apiSuccess {String} data.cover_url 封面
  651. * @apiSuccess {Int} data.book_word_count 字数
  652. * @apiSuccess {Int} data.book_chapter_total 章节数
  653. * @apiSuccess {Int} data.book_category_id 分类
  654. * @apiSuccess {String} data.book_category 分类名
  655. * @apiSuccess {String} data.book_end_status 是否完结
  656. * @apiSuccess {String} data.book_published_time 发布时间
  657. * @apiSuccess {String} data.copyright 版权信息
  658. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  659. * @apiSuccess {String} data.update_time 更新时间
  660. * @apiSuccess {Int} data.is_on_shelf 是否上架
  661. * @apiSuccess {String} data.book_price 是否上架
  662. * @apiSuccess {String} data.recommend_index 推荐指数
  663. * @apiSuccess {Int} data.charge_type 收费类型
  664. * @apiSuccess {Int} data.keyword 关键词
  665. * @apiSuccess {Int} data.is_show_index_content 是否显示推荐指数文本
  666. * @apiSuccess {Int} data.click_count 点击数
  667. * @apiSuccess {Int} data.product_id product_id
  668. * @apiSuccess {Int} data.last_cid 123
  669. * @apiSuccess {Int} data.last_chapter 第254章 婚礼(大结局)
  670. * @apiSuccessExample {json} Success-Response:
  671. * HTTP/1.1 200 OK
  672. * {
  673. * code: 0,
  674. * msg: "",
  675. * data: {
  676. * male:[
  677. * {
  678. * book_id: 5,
  679. * book_name: "肌缘巧合",
  680. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  681. * book_author: "妖火",
  682. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  683. * book_word_count: 0,
  684. * book_chapter_total: 0,
  685. * book_category_id: null,
  686. * book_category: "爆笑,宠文,潜规则",
  687. * book_end_status: 8,
  688. * book_published_time: null,
  689. * copyright: null,
  690. * charge_type: null,
  691. * force_subscribe_chapter_id: 0,
  692. * update_time: null,
  693. * is_on_shelf: 1,
  694. * book_price: null,
  695. * keyword: "温馨,虐心,清水",
  696. * recommend_index:2,
  697. * is_show_index_content:0,
  698. * click_count:0,
  699. * product_id:0,
  700. * last_cid:0,
  701. * last_chapter:第254章 婚礼(大结局),
  702. * },
  703. * ],
  704. * female:[{},{}]
  705. * }
  706. * }
  707. */
  708. public function rank(Request $request)
  709. {
  710. $type = $request->input('type');
  711. $time = $request->input('time');
  712. if ($type == 1) {
  713. //点击帮
  714. if ($time == 1) {
  715. //周
  716. $midstr = env('CLICK_RANK_MALE_WEEK', '677,694,638,642,641,673,635,639,637,4');
  717. $fidstr = env('CLICK_RANK_FEMALE_WEEK', '614,636,587,48,1,6,354,99,159,355');
  718. } elseif ($time == 2) {
  719. //月
  720. $midstr = env('CLICK_RANK_MALE_MONTH', '757,775,780,612,638,635,694,639,642,693');
  721. $fidstr = env('CLICK_RANK_FEMALE_MONTH', '324,614,6,1,5,10,48,57,41,58');
  722. } else {
  723. $midstr = env('CLICK_RANK_MALE_TOTAL', '757,775,780,612,634,677,694,638,642,635');
  724. $fidstr = env('CLICK_RANK_FEMALE_TOTAL', '324,614,636,1,5,6,521,10,41,48');
  725. }
  726. $female = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $fidstr)));
  727. $male = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $midstr)));
  728. } elseif ($type == 2) {
  729. //字数帮
  730. if ($time == 1) {
  731. //周
  732. $midstr = env('WORD_RANK_MALE_WEEK', '638,673,635,637,680,642,86,774,764,736');
  733. $fidstr = env('WORD_RANK_FEMALE_WEEK', '48,58,324,354,159,262,7,9,11,525');
  734. } elseif ($time == 2) {
  735. //月
  736. $midstr = env('WORD_RANK_MALE_MONTH', '2,638,642,635,639,4,743,680,736,73');
  737. $fidstr = env('WORD_RANK_FEMALE_MONTH', '1,10,48,58,324,354,159,442,355,464');
  738. } else {
  739. $midstr = env('WORD_RANK_MALE_TOTAL', '638,677,694,635,612,693,634,642,775,780');
  740. $fidstr = env('WORD_RANK_FEMALE_TOTAL', '57,636,614,1,10,48,58,324,354,99');
  741. }
  742. $female = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $fidstr)));
  743. $male = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $midstr)));
  744. } elseif ($type == 3) {
  745. //新书榜
  746. if ($time == 1) {
  747. //周
  748. $midstr = env('NEW_RANK_MALE_WEEK', '635,639,4,642,629,446,741,737,731,86');
  749. $fidstr = env('NEW_RANK_FEMALE_WEEK', '135,587,617,625,627,467,213,233,529,357');
  750. } elseif ($time == 2) {
  751. //月
  752. $midstr = env('NEW_RANK_MALE_MONTH', '757,775,780,612,634,677,694,638,642,635');
  753. $fidstr = env('NEW_RANK_FEMALE_MONTH', '33,39,40,51,587,617,625,627,50,60');
  754. } else {
  755. $midstr = env('NEW_RANK_MALE_TOTAL', '693,641,673,637,4,3,612,634,677,694');
  756. $fidstr = env('NEW_RANK_FEMALE_TOTAL', '284,30,33,39,40,51,587,50,60,357');
  757. }
  758. $female = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $fidstr)));
  759. $male = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(explode(',', $midstr)));
  760. } else {
  761. return response()->error('PARAM_ERROR');
  762. }
  763. $data = ['male' => $male, 'female' => $female];
  764. return response()->success($data);
  765. }
  766. /**
  767. * 推荐书
  768. */
  769. public function recommen()
  770. {
  771. $reco_banner_type = ['FEMALE', 'PUBLIC'];
  772. $books = (new RecoBannerService)->getByType($reco_banner_type, 2);
  773. $books->transform(function ($item) {
  774. $result = $this->getBidCidFromUrl($item->redirect_url);
  775. $item->bid = $result['bid'];
  776. $item->cid = $result['cid'];
  777. if ($result['cid']) {
  778. $item->redirect_url = "views/Reader";
  779. } else {
  780. $item->redirect_url = "views/Detail";
  781. }
  782. return $item;
  783. });
  784. return response()->success($books);
  785. }
  786. }