BookController.php 34 KB

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