BookController.php 35 KB

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