BookController.php 31 KB

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