BookController.php 34 KB

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