BookController.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Book;
  3. use App\Consts\BaseConst;
  4. use App\Libs\Utils;
  5. use App\Modules\Activity\Services\ActivityService;
  6. use App\Modules\Book\Models\RecoBanner;
  7. use App\Modules\Book\Services\BookAuditService;
  8. use App\Modules\Channel\Models\ChannelAdvert;
  9. use App\Modules\Channel\Services\ChannelAdvertService;
  10. use App\Modules\Channel\Services\ChannelRecommendBookConfigService;
  11. use App\Modules\Channel\Services\ChannelRecommendBooksService;
  12. use App\Modules\RecommendBook\Services\QappRecommendService;
  13. use App\Modules\RecommendBook\Services\RecommendService;
  14. use App\Modules\Book\Services\RecoBannerService;
  15. use App\Modules\Subscribe\Models\Order;
  16. use App\Modules\User\Models\ChannelAdUser;
  17. use App\Modules\User\Models\QappPackage;
  18. use App\Modules\User\Services\QappUserService;
  19. use Illuminate\Http\Request;
  20. use App\Http\Controllers\QuickApp\BaseController;
  21. use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
  22. use App\Http\Controllers\QuickApp\Book\Transformers\KeywordTransformer;
  23. use App\Modules\Book\Models\BookConfig;
  24. use App\Modules\Book\Services\BookConfigService;
  25. use App\Modules\Book\Services\BookService;
  26. use App\Modules\Book\Services\BookUrgeUpdateService;
  27. use App\Modules\Book\Services\UserShelfBooksService;
  28. use App\Modules\Book\Services\ChapterService;
  29. use App\Modules\Subscribe\Services\BookOrderService;
  30. use App\Modules\Subscribe\Services\ChapterOrderService;
  31. use App\Modules\Subscribe\Services\YearOrderService;
  32. use App\Modules\Subscribe\Services\OrderService;
  33. use App\Modules\User\Services\ReadRecordService;
  34. use Hashids;
  35. use Log;
  36. use DB;
  37. use Illuminate\Support\Facades\Redis;
  38. class BookController extends BaseController
  39. {
  40. public function index(Request $request, $bid)
  41. {
  42. $bid = BookService::decodeBidStatic($bid);
  43. $book_info = BookConfigService::getBookById($bid);
  44. if (!$book_info) {
  45. return response()->error('QAPP_SYS_ERROR');
  46. }
  47. //yuyuedu、xinghe 快应用这两个cp的书屏蔽下
  48. if(in_array($book_info->cp_source,getHiddenCp())){
  49. return response()->error('QAPP_SYS_ERROR');
  50. }
  51. if($this->distribution_channel_id == 7477 && $bid == 13765){
  52. $book_info->is_on_shelf = 2;
  53. }
  54. $special = get_special_bid();
  55. if (in_array($this->distribution_channel_id,[9487,9390]) && in_array($book_info->bid,$special)){
  56. $book_info->is_on_shelf = 2;
  57. }
  58. if($bid == 58886){
  59. $book_info->is_on_shelf = 0;
  60. }
  61. if (!in_array($book_info->is_on_shelf, [1,2])) {
  62. return response()->error('QAPP_OFF_SHELF');
  63. }
  64. $is_on_shelf = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid, $bid);
  65. $book_info['is_on_user_shelf'] = 0;
  66. if ($is_on_shelf) {
  67. $book_info['is_on_user_shelf'] = 1;
  68. }
  69. $last_chapter = ChapterService::getChapterNameById($book_info['last_cid'], $bid);
  70. $book_info->last_chapter = $last_chapter['name'];
  71. list($is_split,$is_change_chapter_name) = BookService::splitContent($bid);
  72. if($is_split && ($book_info->channel_name == '男频' || $is_change_chapter_name) ){
  73. $book_info->last_chapter = '第'.$book_info->chapter_count.'章';
  74. }
  75. $book_info['last_chapter_is_vip'] = $last_chapter['is_vip'];
  76. $book_info['is_need_charge'] = $this->isNeedCharge($bid, $last_chapter, $book_info);
  77. $record = ReadRecordService::getBookReadRecordStatic($this->uid, $bid);
  78. if ($record) {
  79. $book_info['record_chapter_id'] = $record['record_chapter_id'];
  80. $book_info['record_chapter_name'] = $record['record_chapter_name'];
  81. }
  82. return response()->item(new BookTransformer(), $book_info);
  83. }
  84. /**
  85. * 获取订购记录
  86. * @param $book_info
  87. * @param $chapter_id
  88. * @return bool
  89. */
  90. protected function getOrderRecord($bid, $chapter_id)
  91. {
  92. //包年记录
  93. $uid = $this->uid;
  94. $res = YearOrderService::getRecord($uid);
  95. if ($res) return true;
  96. $res = null;
  97. //单本订购记录
  98. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  99. if ($res) return true;
  100. $res = null;
  101. //章节订购记录
  102. $chapterOrder = new ChapterOrderService();
  103. if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
  104. return false;
  105. }
  106. /**
  107. * 判断是否需要充值
  108. */
  109. private function isBookNeedCharge(int $bid, float $price)
  110. {
  111. $book_order = $this->getOrderRecord($bid, 0);
  112. if ($book_order) {
  113. return false;
  114. } else {
  115. $user_info = $this->user_info;
  116. return $user_info['balance'] < $price;
  117. }
  118. }
  119. /**
  120. * 判断章节是否需要充值
  121. */
  122. private function isChapterNeedCharge(int $bid, int $cid, float $price)
  123. {
  124. $book_order = $this->getOrderRecord($bid, $cid);
  125. if ($book_order) {
  126. return false;
  127. } else {
  128. $user_info = $this->user_info;
  129. return $user_info['balance'] < $price;
  130. }
  131. }
  132. /**
  133. * 判断是否需要充值
  134. */
  135. private function isNeedCharge(int $bid, $last_chapter, $book_info)
  136. {
  137. $is_free = BookConfigService::judgeBookIsFree($bid);
  138. if ($is_free) {
  139. return false;
  140. }
  141. switch ($book_info->charge_type) {
  142. case 'BOOK':
  143. $price = $this->getPrice($book_info);
  144. return $this->isBookNeedCharge($bid, $price);
  145. default:
  146. $price = isset($last_chapter->is_vip) ? $this->getPrice($book_info, $last_chapter->size) : 0;
  147. return isset($last_chapter->is_vip) ? $this->isChapterNeedCharge($bid, $last_chapter->id, $price) : false;
  148. }
  149. }
  150. /**
  151. * 计算价格
  152. * @param $book_info
  153. * @param $chapter_size
  154. * @return float
  155. */
  156. protected function getPrice($book_info, $chapter_size = 0)
  157. {
  158. if ($book_info->charge_type == 'BOOK')
  159. return $book_info->price * 100;
  160. return ceil($chapter_size / 100);
  161. }
  162. /**
  163. * 首页
  164. */
  165. public function getBookLists(Request $request, $sex)
  166. {
  167. // 获取基本数据
  168. $package = $request->header('x-package', '');
  169. $brand = $request->header('x-nbrand', '');
  170. $codeVersion = $request->header('x-codeversion', '');
  171. $isAuth = check_qapp_auth($package ,0);
  172. // 根据包名、平台、版本号判断是否审核
  173. if (Utils::checkIsAudit($package, $brand, $codeVersion) || $isAuth == false) {
  174. $result = BookAuditService::getHomeBooksData($sex, $package,$isAuth);
  175. return response()->success($result);
  176. }
  177. $user = (new QappUserService)->getGolableUser();
  178. if($package == "com.beidao.kuaiying.yueai" && $sex == "male" && isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  179. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  180. if($orderRecord){
  181. $result = BookAuditService::getYueaiHomeBooksData($sex, $package,$isAuth,1);
  182. return response()->success($result);
  183. }
  184. }
  185. if ($sex == 'male') {
  186. $channel = 1;
  187. $reco_banner_type = ['MALE', 'PUBLIC'];
  188. } else {
  189. $reco_banner_type = ['FEMALE', 'PUBLIC'];
  190. $channel = 2;
  191. }
  192. if($isAuth){
  193. $books = $this->getDefaultBanner();
  194. }else{
  195. $home = config('home.ycsd');
  196. $banner = $home['reco_banner'];
  197. $books = $banner[$sex];
  198. }
  199. //新判断: 根据包名来获取对应所需的bid
  200. $qapp_package = QappPackage::getPackageByPackage($package);
  201. if($qapp_package){
  202. $package_id = $qapp_package->id;
  203. }else{
  204. $package_id = 0;
  205. }
  206. \Log::info('un_send_order_book:package_id1:'.$package_id.' $package:'.$package);
  207. if(isset($user->uid) && !empty($user->uid)){
  208. if(!$this->send_order_id || $this->send_order_id == 0 ){
  209. \Log::info('un_send_order_book:uid:'.$this->uid.' $package:'.$package);
  210. $result = $this->getCheckBids($channel,$books,$package_id,$package);
  211. if(isset($result[1]['books']) && count((array)$result[1]['books']) > 1){
  212. return response()->success($result);
  213. }
  214. $result = $this->getCheckBids($channel,$books,0,$package);
  215. return response()->success($result);
  216. }else{
  217. $package_id = 0;
  218. }
  219. \Log::info('un_send_order_book:package_id2:'.$package_id.' $package:'.$package);
  220. }else{
  221. $package_id = 0;
  222. }
  223. \Log::info('un_send_order_book:package_id3:'.$package_id.' $package:'.$package);
  224. $result = $this->getCheckBids($channel,$books,$package_id,$package);
  225. return response()->success($result);
  226. }
  227. /**
  228. * 根据包名
  229. * @param $channel
  230. * @param $books
  231. * @param $package_id
  232. * @return array
  233. */
  234. private function getCheckBids($channel,$books,$package_id,$package)
  235. {
  236. $isAuthor = check_qapp_auth($package_id,1);
  237. $hotBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id),$channel,$package,$isAuthor);
  238. $liveBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id),$channel,$package,$isAuthor);
  239. $recomBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel,$package,$isAuthor);
  240. $newBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id),$channel,$package,$isAuthor);
  241. return array_filter([
  242. ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
  243. ['type' => 'hot', 'lable' => '热门书单', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($hotBids))],
  244. ['type' => 'zhibo', 'lable' => '神书直播', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($liveBids))],
  245. ['type' => 'recom', 'lable' => '小编精选', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($recomBids))],
  246. ['type' => 'new_recom', 'lable' => '人气新书', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($newBids))]
  247. ]);
  248. }
  249. /**
  250. * 检测并补充不满足条件的书籍id
  251. * @param $bid_list
  252. * @param $channel : 频道
  253. * @param $package : 频道
  254. * @return array
  255. */
  256. private function getCheckBooks($bid_list,$channel,$package,$is_author)
  257. {
  258. $hidden_cp = getHiddenCp();
  259. if(!is_public_package($package)){
  260. $hidden_cp = array_merge($hidden_cp,['lianshang']);
  261. }
  262. //获取书本数量
  263. $count = count($bid_list);
  264. if (!$is_author){
  265. $where = [
  266. ['book_configs.charge_type','!=','BOOK'],
  267. ['book_configs.cp_source','=','ycsd'],
  268. ];
  269. }else{
  270. $where = [
  271. ['book_configs.charge_type','!=','BOOK'],
  272. ];
  273. }
  274. // //获取当前有效书本数量
  275. // $book_count = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  276. // ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  277. // ->whereIn('book_configs.bid',$bid_list)
  278. // ->where('book_configs.is_on_shelf',2)
  279. // ->where('book_configs.charge_type','!=','BOOK')
  280. // ->whereNotIn('book_configs.cp_source',$hidden_cp)
  281. // ->where($where)
  282. //
  283. // ->where('book_categories.pid',$channel)
  284. // ->count();
  285. //
  286. // if($count == $book_count){
  287. // return $bid_list;
  288. // }
  289. //获取需要补充的书籍数量
  290. // $supplement_count = (($count - $book_count) > 0) ? $count - $book_count : 0;
  291. // if($supplement_count <= 0){
  292. // return $bid_list;
  293. // }
  294. //获取书籍交集bid,过滤掉不符合要求的书
  295. $bids = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  296. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  297. ->whereIn('book_configs.bid',$bid_list)
  298. ->where('book_configs.is_on_shelf',2)
  299. ->where($where)
  300. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  301. ->where('book_categories.pid',$channel)
  302. ->pluck('book_configs.bid')->all();
  303. // $bid_list = array_intersect($bid_list,$bids);
  304. $book_count = count($bids);
  305. if ($book_count === $count){
  306. return $bid_list;
  307. }
  308. $log = ['bid_list',$bid_list,'bids' => $bids];
  309. $bid_list = $bids;
  310. $supplement_count = $count - $book_count;
  311. //获取随机的有效的书籍bid
  312. $rand_bid = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  313. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  314. ->where('book_configs.is_on_shelf',2)
  315. // ->where('book_configs.charge_type','!=','BOOK')
  316. ->where($where)
  317. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  318. ->where('book_categories.pid',$channel)
  319. ->inRandomOrder()
  320. ->limit($supplement_count)
  321. ->get()->pluck('bid')->toArray();
  322. $log['result'] = array_merge($bid_list,$rand_bid);
  323. myLog('Qapp_index_bid')->info($log);
  324. return array_filter(array_merge($bid_list,$rand_bid));
  325. }
  326. private function getBidCidFromUrl(string $url)
  327. {
  328. if (preg_match('/\?bid=(\w+)\S+cid=(\w+)/', $url, $matches) || preg_match('/\?id=(\w+)/', $url, $matches)) {
  329. return [
  330. 'bid' => $matches[1],
  331. 'cid' => isset($matches[2]) ? $matches[2] : 0,
  332. ];
  333. } else {
  334. return [
  335. 'bid' => '',
  336. 'cid' => 0,
  337. ];
  338. }
  339. }
  340. public function library(Request $request)
  341. {
  342. $package = $request->header('x-package', '');
  343. if (in_array($package ,["com.app.kyy.dmzyd","com.app.kyy.tths"])){
  344. // return $this->getSpecialLibrary($request);
  345. }
  346. $where = [];
  347. $order = [];
  348. $where['is_on_shelf'] = [2];
  349. $category_id = $request->input('category_id');
  350. if ($category_id) {
  351. if ($category_id == 1) {
  352. $where['channel_name'] = '男频';
  353. } elseif ($category_id == 2) {
  354. $where['channel_name'] = '女频';
  355. } else {
  356. $where['category_id'] = $category_id;
  357. }
  358. }
  359. $key = $request->input('key');
  360. $uid = $request->input('uid', 0);
  361. if ($key && $uid && is_numeric($uid)) {
  362. BookConfigService::saveUserSearchLog($key, $uid);
  363. }
  364. $where['key'] = $key;
  365. $order_field = $request->input('order_field');
  366. $order_seq = $request->input('order_seq');
  367. if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
  368. if ($order_field == 'update') {
  369. $order = ['book_configs.updated_at', 'desc'];
  370. } elseif ($order_field == 'create') {
  371. $order = ['book_configs.created_at', 'desc'];
  372. } else {
  373. $order = [$order_field, 'desc'];
  374. }
  375. if ($order_seq == 'asc') {
  376. $order = [$order_field, 'asc'];
  377. }
  378. if ($order_seq == 'desc') {
  379. $order = [$order_field, 'desc'];
  380. }
  381. }
  382. // 审核状态默认值
  383. $package = $request->header('x-package', '');
  384. $brand = $request->header('x-nbrand', '');
  385. $codeVersion = $request->header('x-codeversion', '');
  386. if ($order_field === 'recommend_index' && Utils::checkIsAudit($package, $brand, $codeVersion)) {
  387. $order = ['book_configs.bid', 'desc'];
  388. }
  389. // 是否只使用原创书殿的书
  390. $isAuth = check_qapp_auth($package ,0);
  391. if (!$isAuth){
  392. $where['cp_source'] = "ycsd";
  393. }
  394. $status = $request->input('status');
  395. if ($status != '') {
  396. $where['status'] = $status;
  397. }
  398. // 搜索关键词的情况下,屏蔽书籍完本状态
  399. if ($key && isset($where['status'])) {
  400. unset($where['status']);
  401. }
  402. $page_size = $request->input('page_size', 15);
  403. $where['channel_id'] = $request->input('distribution_channel_id',0);
  404. $books = BookConfigService::getBooks($where, $order, $page_size);
  405. return response()->pagination(new BookTransformer, $books);
  406. }
  407. public function hotWords(Request $request)
  408. {
  409. $result = BookConfigService::findBookKeywords();
  410. return response()->pagination(new KeywordTransformer, $result);
  411. }
  412. public function similarRecom(Request $request)
  413. {
  414. $package = $request->header('x-package', '');
  415. $category_id = $request->input('category_id');
  416. $bid = $request->input('bid');
  417. $package = $request->header('x-package', '');
  418. if (empty($bid) || (empty($category_id) && $category_id != 0)) {
  419. return response()->error('PARAM_ERROR');
  420. }
  421. $isAuth = check_qapp_auth($package ,0);
  422. $bid = BookService::decodeBidStatic($bid);
  423. $where = ['category_id' => $category_id, 'is_on_shelf' => [2]];
  424. if (!$isAuth){
  425. $where['cp_source'] = "ycsd";
  426. }
  427. $where['channel_id'] = $request->input('distribution_channel_id',0);
  428. $books = BookConfigService::getBooks($where, [], 4);
  429. $data = [];
  430. foreach ($books as $v) {
  431. if ($v->bid != $bid && count($data) < 3) {
  432. $data[] = $v;
  433. }
  434. }
  435. return response()->collection(new BookTransformer(), $data);
  436. }
  437. public function readOverRecommend(Request $request)
  438. {
  439. $bid = $request->input('bid');
  440. if (empty($bid)) {
  441. return response()->error('PARAM_ERROR');
  442. }
  443. $bid = BookService::decodeBidStatic($bid);
  444. $book_info = BookConfigService::getBookById($bid);
  445. $res = BookConfigService::getRecommendBooks($bid, $book_info->channel_name);
  446. $urge_status = 0;
  447. if ($book_info->status == 0 && !BookUrgeUpdateService::isHadUrged($this->uid, $bid)) {
  448. $urge_status = 1;
  449. }
  450. $recommend_result = collectionTransform(new BookTransformer(), $res);
  451. $book_status = [
  452. 'status' => $book_info->status,
  453. 'urge_status' => $urge_status
  454. ];
  455. $data = [
  456. 'recommend_result' => $recommend_result,
  457. 'book_status' => $book_status
  458. ];
  459. return response()->success($data);
  460. }
  461. public function rank(Request $request)
  462. {
  463. // 1:男频,2:女频
  464. $sex = (int)$request->input('sex');
  465. if (!in_array($sex, [1, 2], true)) {
  466. return response()->error('PARAM_ERROR');
  467. }
  468. // 默认
  469. $bids = [11529, 11941, 12720, 11990, 11988, 11976, 11977, 4183, 12717, 11833,
  470. 7287,14297,12716,14312,14000,13577,16712,13002,12717,15103,13928,14793,
  471. 12708,13286];
  472. if ($sex === 2) {
  473. $bids = [8469, 11660, 9117, 7891, 12281, 12470, 8167, 11661, 11670, 8476, 8557, 11662,
  474. 11680, 11926, 12462, 7836, 11681, 11664, 11928, 8631];
  475. }
  476. /**
  477. * pid:1为男频 2为女频
  478. SELECT
  479. CONCAT( books.id, ',' )
  480. FROM
  481. books
  482. LEFT JOIN book_configs ON books.id = book_configs.bid
  483. WHERE
  484. book_configs.is_on_shelf = 2
  485. AND books.category_id IN ( SELECT id FROM book_categories WHERE pid = 2 )
  486. ORDER BY
  487. book_configs.recommend_index DESC
  488. LIMIT 10;
  489. */
  490. // 根据包名、平台、版本号判断是否审核
  491. $package = $request->header('x-package', '');
  492. $brand = $request->header('x-nbrand', '');
  493. $codeVersion = $request->header('x-codeversion', '');
  494. if (Utils::checkIsAudit($package, $brand, $codeVersion)) {
  495. $bids = [2266, 3838, 9700, 10175, 10301, 3422, 1166, 4546, 9163, 2509,
  496. 7287,14297,12716,14312,14000,13577,16712,13002,12717,15103,13928,
  497. 14793,12708,13286,13336,13275,13073,15121,13929,12693,13254,3526,
  498. 10313,3483,13278,14004,4098,10378,14072,21376,21139,21757,19449];
  499. if ($sex === 2) {
  500. $bids = [159, 2439, 6276, 10074, 5409, 9379, 10323, 9078, 3603, 487];
  501. }
  502. }
  503. $isAuth = check_qapp_auth($package,0);
  504. if (!$isAuth){
  505. $rank = config('home.rank');
  506. $bids = $rank['male'];
  507. if ($sex === 2) {
  508. $bids = $rank['female'];;
  509. }
  510. }
  511. $channel_id = $request->input('distribution_channel_id',0);
  512. $books = collectionTransform(new BookTransformer, BookConfigService::getBookLists(compact('bids','channel_id')));
  513. return response()->success($books);
  514. }
  515. /**
  516. * 推荐书
  517. */
  518. public function recommen()
  519. {
  520. $books = $this->getDefaultBanner();
  521. return response()->success($books);
  522. }
  523. /**
  524. * 阅爱小说任务轮播图
  525. */
  526. public function recommenYueAi()
  527. {
  528. $user = (new QappUserService)->getGolableUser();
  529. if(isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  530. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  531. $data = config('home.yueai');
  532. $books = $data['task_banner'];
  533. $bids = BookConfigService::getAvailableBIdsbyBids(array_column($books,'bid'),$this->distribution_channel_id,false);
  534. if($orderRecord && !empty($bids)){
  535. foreach ($books as &$value){
  536. $value['bid'] =Hashids::encode($value['bid']);
  537. $value['redirect_url '] = empty($value['cid']) ? "views/Detail" : "views/Reader";
  538. }
  539. unset($value);
  540. return response()->success($books);
  541. }
  542. }
  543. $books = $this->getDefaultBanner();
  544. return response()->success($books);
  545. }
  546. /**
  547. * 新获取各种广告列表
  548. * @param Request $request
  549. * @return mixed
  550. */
  551. public function getRecommendBanners(Request $request)
  552. {
  553. $release_type = $request->get('release_type','');
  554. $distribution_id = $this->distribution_channel_id;
  555. if(empty($release_type)){
  556. //默认原banner
  557. $banner = $this->getDefaultBanner();
  558. return response()->success($banner);
  559. }
  560. if($release_type == '4' || $release_type == '5'){
  561. //弹窗和充值页返回需要先判断频率跟权限
  562. $advert = ChannelAdvert::select('id','photo as banner_url','activity_id','type','content','person','frequency')
  563. ->where('distribution_id',$distribution_id)
  564. ->where('release_type',$release_type)
  565. ->where('status',1)
  566. ->first();
  567. if(!$advert){
  568. return response()->success([]);
  569. }
  570. $advert = $advert->toArray();
  571. $advert['ids'] = Hashids::encode($advert['id']);
  572. if($advert['type'] == 1){
  573. $advert['redirect_url'] = 'views/Reader';
  574. $content = explode(';',$advert['content']);
  575. $advert['bid'] = isset($content[2]) ? $content[2] : '';
  576. $advert['cid'] = isset($content[3]) ? $content[3] : '';
  577. }else{
  578. $advert['redirect_url'] = 'views/Detail';
  579. }
  580. if($release_type == '4'){
  581. //弹窗需要判断频率
  582. if($advert['frequency'] == 'always'){
  583. $advert = self::getBackFormat($advert);
  584. return response()->success($advert);
  585. }
  586. $day = strtotime(date('Y-m-d H:i:s'));
  587. $nextDay = strtotime( date('Y-m-d'). ' +1 day');
  588. $nextWeek = strtotime(date('Y-m-d',strtotime('+1 week last monday')));
  589. if($advert['frequency'] == 'day'){
  590. if(!Redis::exists('banner:'.$distribution_id.':'.$this->uid)){
  591. Redis::setex('banner:'.$distribution_id.':'.$this->uid,($nextDay-$day),1);
  592. $advert = self::getBackFormat($advert);
  593. return response()->success($advert);
  594. }
  595. }
  596. if($advert['frequency'] == 'week'){
  597. if(!Redis::exists('banner:'.$distribution_id.':'.$this->uid)){
  598. Redis::setex('banner:'.$distribution_id.':'.$this->uid,($nextWeek-$day),1);
  599. $advert = self::getBackFormat($advert);
  600. return response()->success($advert);
  601. }
  602. }
  603. return response()->success([]);
  604. }
  605. if($release_type == '5'){
  606. //充值页返回需要判断用户权限
  607. $check_user = $this->checkUsers($advert['person']);
  608. if(!$check_user){
  609. return response()->success([]);
  610. }
  611. $activity = ActivityService::getById($advert['activity_id'] ?? 0);
  612. if ($activity){
  613. if ($activity['permanent'] == 1 || ($activity['start_time'] < date("Y-m-d H:i:s") && $activity['end_time'] > date("Y-m-d H:i:s") )){
  614. $advert['redirect_url'] = "/views/Activity";
  615. $advert = self::getBackFormat($advert);
  616. $advert['param'] = ['token' => $activity['token']];
  617. return response()->success($advert);
  618. }else{
  619. return response()->success([]);
  620. }
  621. }else{
  622. return response()->success([]);
  623. }
  624. }
  625. }
  626. //男女频,书架列表
  627. $banner = ChannelAdvertService::getAdvertList($distribution_id,$release_type);
  628. if($banner->isEmpty()){
  629. $banner = $this->getDefaultBanner();
  630. return response()->success($banner);
  631. }
  632. $banner->transform(function ($item) {
  633. $item->ids = Hashids::encode($item->id);
  634. if($item->type == 1){
  635. $content = explode(';',$item->content);
  636. $item->bid = isset($content[2]) ? $content[2] : '';
  637. $item->cid = isset($content[3]) ? $content[3] : '';
  638. if ($item->cid){
  639. $item->redirect_url = "views/Reader";
  640. }else{
  641. $item->redirect_url = "views/Detail";
  642. }
  643. $item->redirect_type = "book";
  644. }else{
  645. $activity = ActivityService::getById($item->activity_id);
  646. $item->redirect_url = "/views/Activity";
  647. $item->redirect_type = "activity";
  648. if($activity && !empty($activity['token'])){
  649. $item['param'] = ['token' => $activity['token']];
  650. }else{
  651. $item->redirect_url = "#";
  652. }
  653. }
  654. self::getBackFormat($item);
  655. return $item;
  656. });
  657. return response()->success($banner);
  658. }
  659. static function getBackFormat($data)
  660. {
  661. if(isset($data['id']) || $data->id) unset($data['id'],$data->id);
  662. if(isset($data['type']) || $data->type) unset($data['type'],$data->type);
  663. if(isset($data['person']) || $data->person) unset($data['person'],$data->person);
  664. if(isset($data['frequency']) || $data->frequency) unset($data['frequency'],$data->frequency);
  665. return $data;
  666. }
  667. /**
  668. * 默认获取banner
  669. * @return mixed
  670. */
  671. protected function getDefaultBanner()
  672. {
  673. $reco_banner_type = ['FEMALE', 'PUBLIC'];
  674. $banner = (new RecoBannerService)->getByType($reco_banner_type, 2);
  675. $banner->transform(function ($item) {
  676. $result = $this->getBidCidFromUrl($item->redirect_url);
  677. $item->bid = $result['bid'];
  678. $item->cid = $result['cid'];
  679. $item->ids = Hashids::encode($item->id);
  680. $item->type = 'default';
  681. if ($result['cid']) {
  682. $item->redirect_url = "views/Reader";
  683. } else {
  684. $item->redirect_url = "views/Detail";
  685. }
  686. $item->redirect_type = "book";
  687. unset($item->id);
  688. return $item;
  689. });
  690. return $banner;
  691. }
  692. /**
  693. * 限免
  694. */
  695. public function free(int $sex)
  696. {
  697. $result = BookConfigService::findFreeBooks($sex);
  698. return response()->success($result);
  699. }
  700. public function yueaiBackRecom(Request $request)
  701. {
  702. $package = $request->header('x-package', '');
  703. if (empty($package) || $package != 'com.beidao.kuaiying.yueai') {
  704. return response()->success([]);
  705. }
  706. $user = (new QappUserService)->getGolableUser();
  707. if(isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  708. $bid = BookConfigService::getAvailableBIdsbyBids([58238,60534,63220,14500,13254,63221,63548,14022,59334,58888,63417,61701],$this->distribution_channel_id,false);
  709. if (!empty($bid)){
  710. $bid = array_random($bid,4);
  711. }
  712. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  713. if($orderRecord && count($bid) >= 4){
  714. $where = ['is_on_shelf' => [1,2],'bids' => $bid];
  715. // $books = BookConfigService::getBooksByIds($bid,[],false);
  716. $books = BookConfigService::getBookLists($where,[],false);
  717. return response()->collection(new BookTransformer(), $books);
  718. }
  719. }
  720. return response()->success([]);
  721. $where = ['is_on_shelf' => [2]];
  722. $where['channel_id'] = $request->input('distribution_channel_id',0);
  723. $books = BookConfigService::getBooks($where, [], 4);
  724. return response()->collection(new BookTransformer(), $books);
  725. }
  726. public function shelfRecom(Request $request)
  727. {
  728. $category_id = $request->input('category_id');
  729. $bid = $request->input('bid');
  730. $package = $request->header('x-package', '');
  731. if (empty($package) || $package != 'com.beidao.kuaiying.yueai') {
  732. return response()->success([]);
  733. }
  734. return response()->success([]);
  735. $user = (new QappUserService)->getGolableUser();
  736. if(isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  737. $bid = BookConfigService::getAvailableBIdsbyBids([58238,60534,63220,14500,13254,63221,63548,14022,59334,58888,63417,61701],$this->distribution_channel_id,false);
  738. if (!empty($bid)){
  739. $bid = array_random($bid,4);
  740. }
  741. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  742. if($orderRecord && count($bid) > 1){
  743. $where = ['is_on_shelf' => [1,2],'bids' => $bid];
  744. // $books = BookConfigService::getBooksByIds($bid,[],false);
  745. $books = BookConfigService::getBookLists($where,[],false);
  746. return response()->collection(new BookTransformer(), $books);
  747. }
  748. }
  749. return response()->success([]);
  750. $where = ['is_on_shelf' => [2]];
  751. $where['channel_id'] = $request->input('distribution_channel_id',0);;
  752. $books = BookConfigService::getBooks($where, [], 4);
  753. return response()->collection(new BookTransformer(), $books);
  754. }
  755. /**
  756. * 新推荐书单
  757. * @param Request $request
  758. * @return mixed
  759. */
  760. public function recommendBooks(Request $request)
  761. {
  762. $distribution_id = $this->distribution_channel_id;
  763. $bid = $request->get('bid',0);
  764. if(empty($distribution_id)){
  765. \Log::info('recommendBooks:1');
  766. return response()->success([]);
  767. }
  768. if(!empty($bid)){
  769. \Log::info('recommendBooks:2');
  770. $bid = str_decode($bid);
  771. }
  772. //判断包是否存在
  773. $package_info = QappPackage::getPackage($distribution_id);
  774. if(empty($package_info) || !isset($package_info->channel_id)){
  775. \Log::info('recommendBooks:3');
  776. return response()->success([]);
  777. }
  778. //包对应有没有配置开启推荐书单
  779. $config = ChannelRecommendBookConfigService::getRecommendConfigs($distribution_id);
  780. if(empty($config) || !isset($config->status) || $config->status == 0){
  781. \Log::info('recommendBooks:4');
  782. return response()->success([]);
  783. }
  784. //根据频率和用户属性决定是否需要返回
  785. $res = $this->checkUsersAuth($config);
  786. if(!$res){
  787. \Log::info('recommendBooks:5');
  788. return response()->success([]);
  789. }
  790. $list = ChannelRecommendBooksService::getRecommendBooks($distribution_id,$bid);
  791. if(!$list->isEmpty()){
  792. foreach($list as $key => $item){
  793. $this->incrRecommendNum($distribution_id,$item->bid);
  794. }
  795. \Log::info('recommendBooks:6');
  796. return response()->collection(new BookTransformer(), $list);
  797. }
  798. \Log::info('recommendBooks:7');
  799. return response()->success([]);
  800. }
  801. /**
  802. * 点击推荐书籍记录点击次数
  803. * @param Request $request
  804. * @return mixed
  805. */
  806. public function clickRecommendBooks(Request $request)
  807. {
  808. $distribution_id = $this->distribution_channel_id;
  809. $bid = $request->get('bid','');
  810. if(empty($bid)){
  811. return response()->success();
  812. }
  813. //判断包是否存在
  814. $package_info = QappPackage::getPackage($distribution_id);
  815. if(empty($package_info) || !isset($package_info->channel_id)){
  816. return response()->success([]);
  817. }
  818. $date = date('Ymd');
  819. $bid = str_decode($bid);
  820. $cacheKey = 'recommend:click:'.$date.':'.$distribution_id.$bid;
  821. $this->incrRedisKey($cacheKey);
  822. return response()->success();
  823. }
  824. /**
  825. * 判断用户是否需要推荐
  826. * @param $config
  827. * @return bool
  828. */
  829. protected function checkUsersAuth($config)
  830. {
  831. \Log::info($config);
  832. \Log::info('$config->person:'.$config->person);
  833. \Log::info($this->uid);
  834. $res = $this->checkUsers($config->person);
  835. if($res === false){
  836. return false;
  837. }
  838. //频率判断
  839. if($config->frequency == 'back'){
  840. //返回即推送
  841. return true;
  842. }
  843. $day = strtotime(date('Y-m-d H:i:s'));
  844. $nextDay = strtotime( date('Y-m-d'). ' +1 day');
  845. $nextWeek = strtotime(date('Y-m-d',strtotime('+1 week last monday')));
  846. if($config->frequency == 'day'){
  847. //每日推送
  848. if(!Redis::exists('recommend:'.$config->channel_id.':'.$this->uid)){
  849. Redis::setex('recommend:'.$config->channel_id.':'.$this->uid,($nextDay-$day),1);
  850. return true;
  851. }
  852. \Log::info('当天已经推送过了');
  853. return false;
  854. }
  855. if($config->frequency == 'week'){
  856. //每周推送
  857. if(!Redis::exists('recommend:'.$config->channel_id.':'.$this->uid)){
  858. Redis::setex('recommend:'.$config->channel_id.':'.$this->uid,($nextWeek-$day),1);
  859. return true;
  860. }
  861. \Log::info('该周已经推送过了');
  862. return false;
  863. }
  864. }
  865. /**
  866. * 判断用户是否有权限
  867. * @param $type
  868. * @return bool
  869. */
  870. protected function checkUsers($type)
  871. {
  872. $res = false;
  873. switch($type)
  874. {
  875. case 'pay':
  876. //付费用户
  877. $orders = OrderService::getUserLastestOrder($this->uid);
  878. if($orders){
  879. $res = true;
  880. }
  881. \Log::info('用户是否付费:');
  882. \Log::info($orders);
  883. break;
  884. case 'send_order':
  885. //派单用户
  886. if($this->send_order_id != 0){
  887. $res = true;
  888. }
  889. \Log::info('用户是否是派单用户:$this->send_order_id:'.$this->send_order_id);
  890. break;
  891. case 'pay_send_order':
  892. //付费派单用户
  893. $orders = OrderService::getUserLastestOrder($this->uid);
  894. if($orders && $this->send_order_id != 0){
  895. $res = true;
  896. }
  897. \Log::info('用户是否是付费派单用户:$this->send_order_id:'.$this->send_order_id);
  898. \Log::info($orders);
  899. break;
  900. case 'unpaid':
  901. $orders = OrderService::getUserLastestOrder($this->uid);
  902. if(!$orders){
  903. $res = true;
  904. }
  905. break;
  906. case 'all':
  907. $res = true;
  908. \Log::info('所有用户返回');
  909. break;
  910. }
  911. return $res;
  912. }
  913. /**
  914. * 推广书籍推荐次数
  915. * @param $channel_id
  916. * @param $bid
  917. */
  918. protected function incrRecommendNum($channel_id,$bid)
  919. {
  920. $date = date('Ymd');
  921. $cacheKey = 'recommend:sum:'.$date.':'.$channel_id.$bid;
  922. $this->incrRedisKey($cacheKey);
  923. }
  924. /**
  925. * 点击广告统计
  926. * @param Request $request
  927. * @return mixed
  928. */
  929. public function getCheckAdvertisement(Request $request)
  930. {
  931. $type = $request->get('type','');
  932. $id = $request->get('ids','');
  933. $distribution_id = $this->distribution_channel_id;
  934. \Log::info('getCheckAdvertisement:type:'.$type.' id:'.$id.' $distribution_id:'.$distribution_id);
  935. if(empty($id) || empty($distribution_id)){
  936. return response()->success();
  937. }
  938. $id = str_decode($id);
  939. if(!$id){
  940. return response()->success();
  941. }
  942. if($type == 'default'){
  943. //默认原表reco_banners广告,区分跟新表channel_advert的id
  944. $id = -$id;
  945. }else{
  946. $advert = ChannelAdvert::find($id);
  947. if(!$advert){
  948. \Log::info('getCheckAdvertisement:error:不存在该广告');
  949. \Log::info(json_encode($request->all()));
  950. return response()->success();
  951. }
  952. }
  953. $where = ['channel_ad_id' => $id, 'uid' => $this->uid, 'distribution_id' => $distribution_id];
  954. \Log::info('insert_where:');
  955. \Log::info(json_encode($where));
  956. ChannelAdUser::firstOrCreate($where);
  957. $date = date('Ymd');
  958. $cacheKey = 'advertisement:pv:'.$date.':'.$distribution_id.$id;
  959. $this->incrRedisKey($cacheKey);
  960. //设置当前用户的所属广告有效期一周
  961. $key = 'advertisement:uid:'.$this->uid.':id';
  962. Redis::set($key,$id);
  963. Redis::expire($key,BaseConst::ONE_WEEK_SECONDS);
  964. return response()->success();
  965. }
  966. /**
  967. * redis新增
  968. * @param $cacheKey
  969. */
  970. protected function incrRedisKey($cacheKey)
  971. {
  972. if(!Redis::exists($cacheKey)){
  973. Redis::set($cacheKey,1);
  974. }else{
  975. Redis::incrBy($cacheKey, 1);
  976. }
  977. }
  978. /**
  979. * 绑定广告和订单
  980. * @param Request $request
  981. * @return mixed
  982. */
  983. public function getAdvertOrders(Request $request)
  984. {
  985. $order_id = $request->get('trade_no','');
  986. $uid = $this->uid;
  987. $distribution_id = $this->distribution_channel_id;
  988. $cacheKey = 'advertisement:uid:'.$uid.':id';
  989. if(empty($order_id)){
  990. return response()->success();
  991. }
  992. $channel_ad_id = 0;
  993. \Log::info('getAdvertOrders:trade_no'.$order_id.' uid:'.$uid);
  994. if(Redis::exists($cacheKey)){
  995. try {
  996. //获取广告id
  997. $channel_ad_id = Redis::get($cacheKey);
  998. //判断订单跟广告是否有关系
  999. $order = OrderService::getByTradeNo($order_id);
  1000. if(!$order){
  1001. return response()->success();
  1002. }
  1003. if($channel_ad_id > 0){
  1004. //新版
  1005. $type = 1;
  1006. $advert = ChannelAdvert::find($channel_ad_id);
  1007. if(!$advert){
  1008. return response()->success();
  1009. }
  1010. if($advert->type == '2' && $advert->activity_id != 0){
  1011. //广告类型为活动
  1012. if($order->activity_id != $advert->activity_id){
  1013. return response()->success();
  1014. }
  1015. }else{
  1016. //广告类型为书籍
  1017. $content = explode(';',$advert->content);
  1018. if(!isset($content[2])){
  1019. return response()->success();
  1020. }
  1021. if($order->from_bid == 0 || $order->from_bid != str_decode($content[2])){
  1022. return response()->success();
  1023. }
  1024. }
  1025. }else{
  1026. //旧版
  1027. $type = 0;
  1028. $advert = RecoBanner::find(abs($channel_ad_id));
  1029. if(!$advert){
  1030. return response()->success();
  1031. }
  1032. $result = $this->getBidCidFromUrl($advert->redirect_url);
  1033. $bid = $result['bid'];
  1034. $cid = $result['cid'];
  1035. if($cid){
  1036. if($order->from_bid == 0 || $order->from_bid != str_decode($bid)){
  1037. return response()->success();
  1038. }
  1039. }else{
  1040. if($order->activity_id == 0 || $order->from_bid != str_decode($bid)){
  1041. return response()->success();
  1042. }
  1043. }
  1044. }
  1045. $created_at = $updated_at = date('Y-m-d H:i:s');
  1046. DB::table('channel_advert_orders')->insert(compact('order_id','uid','distribution_id','channel_ad_id','type','created_at','updated_at'));
  1047. } catch (\Exception $e) {
  1048. \Log::info('绑定广告和订单失败'.$e->getMessage());
  1049. \Log::info('order_id:'.$order_id.' uid:'.$uid.' distribution_id:'.$distribution_id.' channel_ad_id:'.$channel_ad_id);
  1050. }
  1051. }
  1052. return response()->success();
  1053. }
  1054. private function getSpecialLibrary(Request $request)
  1055. {
  1056. $where = [];
  1057. $order = [];
  1058. $where['is_on_shelf'] = [2,4];
  1059. $category_id = $request->input('category_id');
  1060. if ($category_id) {
  1061. if ($category_id == 1) {
  1062. $where['channel_name'] = '男频';
  1063. } elseif ($category_id == 2) {
  1064. $where['channel_name'] = '女频';
  1065. } else {
  1066. $where['category_id'] = $category_id;
  1067. }
  1068. }
  1069. $key = $request->input('key');
  1070. $uid = $request->input('uid', 0);
  1071. if ($key && $uid && is_numeric($uid)) {
  1072. BookConfigService::saveUserSearchLog($key, $uid);
  1073. }
  1074. $where['key'] = $key;
  1075. $order_field = $request->input('order_field');
  1076. $order_seq = $request->input('order_seq');
  1077. if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
  1078. if ($order_field == 'update') {
  1079. $order = ['book_configs.updated_at', 'desc'];
  1080. } elseif ($order_field == 'create') {
  1081. $order = ['book_configs.created_at', 'desc'];
  1082. } else {
  1083. $order = [$order_field, 'desc'];
  1084. }
  1085. if ($order_seq == 'asc') {
  1086. $order = [$order_field, 'asc'];
  1087. }
  1088. if ($order_seq == 'desc') {
  1089. $order = [$order_field, 'desc'];
  1090. }
  1091. }
  1092. // 审核状态默认值
  1093. $package = $request->header('x-package', '');
  1094. $brand = $request->header('x-nbrand', '');
  1095. $codeVersion = $request->header('x-codeversion', '');
  1096. if ($order_field === 'recommend_index' && Utils::checkIsAudit($package, $brand, $codeVersion)) {
  1097. $order = ['book_configs.bid', 'desc'];
  1098. }
  1099. $status = $request->input('status');
  1100. if ($status != '') {
  1101. $where['status'] = $status;
  1102. }
  1103. // 搜索关键词的情况下,屏蔽书籍完本状态
  1104. if ($key && isset($where['status'])) {
  1105. unset($where['status']);
  1106. }
  1107. $page_size = $request->input('page_size', 15);
  1108. $where['channel_id'] = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
  1109. $books = BookConfigService::getBooks($where, $order, $page_size);
  1110. $special = get_special_bid();
  1111. $list = [];
  1112. foreach ($books as $ke => $val){
  1113. if ($val->is_on_shelf != 2 && !in_array($val->bid,$special)){
  1114. unset($books[$ke]);
  1115. }
  1116. }
  1117. return response()->pagination(new BookTransformer,$books);
  1118. }
  1119. }