BookController.php 35 KB

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