BookController.php 31 KB

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