BookController.php 45 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($reco_banner_type);
  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 = BookConfigService::getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id),$channel,$package,$isAuthor);
  238. $liveBids = BookConfigService::getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id),$channel,$package,$isAuthor);
  239. $recomBids = BookConfigService::getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel,$package,$isAuthor);
  240. $newBids = BookConfigService::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. ->where('book_categories.pid',$channel)
  283. ->count();
  284. if($count == $book_count){
  285. return $bid_list;
  286. }
  287. //获取需要补充的书籍数量
  288. $supplement_count = (($count - $book_count) > 0) ? $count - $book_count : 0;
  289. if($supplement_count <= 0){
  290. return $bid_list;
  291. }
  292. //获取书籍交集bid,过滤掉不符合要求的书
  293. $bids = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  294. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  295. ->whereIn('book_configs.bid',$bid_list)
  296. ->where('book_configs.is_on_shelf',2)
  297. ->where($where)
  298. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  299. ->where('book_categories.pid',$channel)
  300. ->pluck('book_configs.bid')->all();
  301. $bid_list = array_intersect($bid_list,$bids);
  302. //获取随机的有效的书籍bid
  303. $rand_bid = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  304. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  305. ->where('book_configs.is_on_shelf',2)
  306. // ->where('book_configs.charge_type','!=','BOOK')
  307. ->where($where)
  308. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  309. ->where('book_categories.pid',$channel)
  310. ->inRandomOrder()
  311. ->limit($supplement_count)
  312. ->get()->pluck('bid')->toArray();
  313. return array_filter(array_merge($bid_list,$rand_bid));
  314. }
  315. private function getBidCidFromUrl(string $url)
  316. {
  317. if (preg_match('/\?bid=(\w+)\S+cid=(\w+)/', $url, $matches) || preg_match('/\?id=(\w+)/', $url, $matches)) {
  318. return [
  319. 'bid' => $matches[1],
  320. 'cid' => isset($matches[2]) ? $matches[2] : 0,
  321. ];
  322. } else {
  323. return [
  324. 'bid' => '',
  325. 'cid' => 0,
  326. ];
  327. }
  328. }
  329. public function library(Request $request)
  330. {
  331. $package = $request->header('x-package', '');
  332. if (in_array($package ,["com.app.kyy.dmzyd","com.app.kyy.tths"])){
  333. // return $this->getSpecialLibrary($request);
  334. }
  335. $where = [];
  336. $order = [];
  337. $where['is_on_shelf'] = [2];
  338. $category_id = $request->input('category_id');
  339. if ($category_id) {
  340. if ($category_id == 1) {
  341. $where['channel_name'] = '男频';
  342. } elseif ($category_id == 2) {
  343. $where['channel_name'] = '女频';
  344. } else {
  345. $where['category_id'] = $category_id;
  346. }
  347. }
  348. $key = $request->input('key');
  349. $uid = $request->input('uid', 0);
  350. if ($key && $uid && is_numeric($uid)) {
  351. BookConfigService::saveUserSearchLog($key, $uid);
  352. }
  353. $where['key'] = $key;
  354. $order_field = $request->input('order_field');
  355. $order_seq = $request->input('order_seq');
  356. if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
  357. if ($order_field == 'update') {
  358. $order = ['book_configs.updated_at', 'desc'];
  359. } elseif ($order_field == 'create') {
  360. $order = ['book_configs.created_at', 'desc'];
  361. } else {
  362. $order = [$order_field, 'desc'];
  363. }
  364. if ($order_seq == 'asc') {
  365. $order = [$order_field, 'asc'];
  366. }
  367. if ($order_seq == 'desc') {
  368. $order = [$order_field, 'desc'];
  369. }
  370. }
  371. // 审核状态默认值
  372. $package = $request->header('x-package', '');
  373. $brand = $request->header('x-nbrand', '');
  374. $codeVersion = $request->header('x-codeversion', '');
  375. if ($order_field === 'recommend_index' && Utils::checkIsAudit($package, $brand, $codeVersion)) {
  376. $order = ['book_configs.bid', 'desc'];
  377. }
  378. // 是否只使用原创书殿的书
  379. $isAuth = check_qapp_auth($package ,0);
  380. if (!$isAuth){
  381. $where['cp_source'] = "ycsd";
  382. }
  383. $status = $request->input('status');
  384. if ($status != '') {
  385. $where['status'] = $status;
  386. }
  387. // 搜索关键词的情况下,屏蔽书籍完本状态
  388. if ($key && isset($where['status'])) {
  389. unset($where['status']);
  390. }
  391. $page_size = $request->input('page_size', 15);
  392. $where['channel_id'] = $request->input('distribution_channel_id',0);
  393. $books = BookConfigService::getBooks($where, $order, $page_size);
  394. return response()->pagination(new BookTransformer, $books);
  395. }
  396. public function hotWords(Request $request)
  397. {
  398. $result = BookConfigService::findBookKeywords();
  399. return response()->pagination(new KeywordTransformer, $result);
  400. }
  401. public function similarRecom(Request $request)
  402. {
  403. $package = $request->header('x-package', '');
  404. $category_id = $request->input('category_id');
  405. $bid = $request->input('bid');
  406. $package = $request->header('x-package', '');
  407. if (empty($bid) || (empty($category_id) && $category_id != 0)) {
  408. return response()->error('PARAM_ERROR');
  409. }
  410. $isAuth = check_qapp_auth($package ,0);
  411. $bid = BookService::decodeBidStatic($bid);
  412. $where = ['category_id' => $category_id, 'is_on_shelf' => [2]];
  413. if (!$isAuth){
  414. $where['cp_source'] = "ycsd";
  415. }
  416. $where['channel_id'] = $request->input('distribution_channel_id',0);
  417. $books = BookConfigService::getBooks($where, [], 4);
  418. $data = [];
  419. foreach ($books as $v) {
  420. if ($v->bid != $bid && count($data) < 3) {
  421. $data[] = $v;
  422. }
  423. }
  424. return response()->collection(new BookTransformer(), $data);
  425. }
  426. public function readOverRecommend(Request $request)
  427. {
  428. $bid = $request->input('bid');
  429. if (empty($bid)) {
  430. return response()->error('PARAM_ERROR');
  431. }
  432. $bid = BookService::decodeBidStatic($bid);
  433. $book_info = BookConfigService::getBookById($bid);
  434. $res = BookConfigService::getRecommendBooks($bid, $book_info->channel_name);
  435. $urge_status = 0;
  436. if ($book_info->status == 0 && !BookUrgeUpdateService::isHadUrged($this->uid, $bid)) {
  437. $urge_status = 1;
  438. }
  439. $recommend_result = collectionTransform(new BookTransformer(), $res);
  440. $book_status = [
  441. 'status' => $book_info->status,
  442. 'urge_status' => $urge_status
  443. ];
  444. $data = [
  445. 'recommend_result' => $recommend_result,
  446. 'book_status' => $book_status
  447. ];
  448. return response()->success($data);
  449. }
  450. public function rank(Request $request)
  451. {
  452. // 1:男频,2:女频
  453. $sex = (int)$request->input('sex');
  454. if (!in_array($sex, [1, 2], true)) {
  455. return response()->error('PARAM_ERROR');
  456. }
  457. // 默认
  458. $bids = [11529, 11941, 12720, 11990, 11988, 11976, 11977, 4183, 12717, 11833,
  459. 7287,14297,12716,14312,14000,13577,16712,13002,12717,15103,13928,14793,
  460. 12708,13286];
  461. if ($sex === 2) {
  462. $bids = [8469, 11660, 9117, 7891, 12281, 12470, 8167, 11661, 11670, 8476, 8557, 11662,
  463. 11680, 11926, 12462, 7836, 11681, 11664, 11928, 8631];
  464. }
  465. /**
  466. * pid:1为男频 2为女频
  467. SELECT
  468. CONCAT( books.id, ',' )
  469. FROM
  470. books
  471. LEFT JOIN book_configs ON books.id = book_configs.bid
  472. WHERE
  473. book_configs.is_on_shelf = 2
  474. AND books.category_id IN ( SELECT id FROM book_categories WHERE pid = 2 )
  475. ORDER BY
  476. book_configs.recommend_index DESC
  477. LIMIT 10;
  478. */
  479. // 根据包名、平台、版本号判断是否审核
  480. $package = $request->header('x-package', '');
  481. $brand = $request->header('x-nbrand', '');
  482. $codeVersion = $request->header('x-codeversion', '');
  483. if (Utils::checkIsAudit($package, $brand, $codeVersion)) {
  484. $bids = [2266, 3838, 9700, 10175, 10301, 3422, 1166, 4546, 9163, 2509,
  485. 7287,14297,12716,14312,14000,13577,16712,13002,12717,15103,13928,
  486. 14793,12708,13286,13336,13275,13073,15121,13929,12693,13254,3526,
  487. 10313,3483,13278,14004,4098,10378,14072,21376,21139,21757,19449];
  488. if ($sex === 2) {
  489. $bids = [159, 2439, 6276, 10074, 5409, 9379, 10323, 9078, 3603, 487];
  490. }
  491. }
  492. $isAuth = check_qapp_auth($package,0);
  493. if (!$isAuth){
  494. $rank = config('home.rank');
  495. $bids = $rank['male'];
  496. if ($sex === 2) {
  497. $bids = $rank['female'];;
  498. }
  499. }
  500. $channel_id = $request->input('distribution_channel_id',0);
  501. $books = collectionTransform(new BookTransformer, BookConfigService::getBookLists(compact('bids','channel_id')));
  502. return response()->success($books);
  503. }
  504. /**
  505. * 推荐书
  506. */
  507. public function recommen()
  508. {
  509. $books = $this->getDefaultBanner();
  510. return response()->success($books);
  511. }
  512. /**
  513. * 阅爱小说任务轮播图
  514. */
  515. public function recommenYueAi()
  516. {
  517. $user = (new QappUserService)->getGolableUser();
  518. if(isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  519. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  520. $data = config('home.yueai');
  521. $books = $data['task_banner'];
  522. $bids = BookConfigService::getAvailableBIdsbyBids(array_column($books,'bid'),$this->distribution_channel_id,false);
  523. if($orderRecord && !empty($bids)){
  524. foreach ($books as &$value){
  525. $value['bid'] =Hashids::encode($value['bid']);
  526. $value['redirect_url '] = empty($value['cid']) ? "views/Detail" : "views/Reader";
  527. }
  528. unset($value);
  529. return response()->success($books);
  530. }
  531. }
  532. $books = $this->getDefaultBanner( ['FEMALE', 'PUBLIC']);
  533. return response()->success($books);
  534. }
  535. /**
  536. * 新获取各种广告列表
  537. * @param Request $request
  538. * @return mixed
  539. */
  540. public function getRecommendBanners(Request $request)
  541. {
  542. $release_type = $request->get('release_type','');
  543. $distribution_id = $this->distribution_channel_id;
  544. if(empty($release_type)){
  545. //默认原banner
  546. // $recom_banner_type = ['FEMALE', 'PUBLIC'] : ['FEMALE', 'PUBLIC'];
  547. $banner = $this->getDefaultBanner(['FEMALE','PUBLIC']);
  548. return response()->success($banner);
  549. }
  550. if($release_type == '4' || $release_type == '5'){
  551. //弹窗和充值页返回需要先判断频率跟权限
  552. $advert = ChannelAdvert::select('id','photo as banner_url','activity_id','type','content','person','frequency')
  553. ->where('distribution_id',$distribution_id)
  554. ->where('release_type',$release_type)
  555. ->where('status',1)
  556. ->first();
  557. if(!$advert){
  558. return response()->success([]);
  559. }
  560. $advert = $advert->toArray();
  561. $advert['ids'] = Hashids::encode($advert['id']);
  562. if($advert['type'] == 1){
  563. $advert['redirect_url'] = 'views/Reader';
  564. $content = explode(';',$advert['content']);
  565. $advert['bid'] = isset($content[2]) ? $content[2] : '';
  566. $advert['cid'] = isset($content[3]) ? $content[3] : '';
  567. }else{
  568. $advert['redirect_url'] = 'views/Detail';
  569. }
  570. if($release_type == '4'){
  571. //弹窗需要判断频率
  572. if($advert['frequency'] == 'always'){
  573. $advert = self::getBackFormat($advert);
  574. return response()->success($advert);
  575. }
  576. $day = strtotime(date('Y-m-d H:i:s'));
  577. $nextDay = strtotime( date('Y-m-d'). ' +1 day');
  578. $nextWeek = strtotime(date('Y-m-d',strtotime('+1 week last monday')));
  579. if($advert['frequency'] == 'day'){
  580. if(!Redis::exists('banner:'.$distribution_id.':'.$this->uid)){
  581. Redis::setex('banner:'.$distribution_id.':'.$this->uid,($nextDay-$day),1);
  582. $advert = self::getBackFormat($advert);
  583. return response()->success($advert);
  584. }
  585. }
  586. if($advert['frequency'] == 'week'){
  587. if(!Redis::exists('banner:'.$distribution_id.':'.$this->uid)){
  588. Redis::setex('banner:'.$distribution_id.':'.$this->uid,($nextWeek-$day),1);
  589. $advert = self::getBackFormat($advert);
  590. return response()->success($advert);
  591. }
  592. }
  593. return response()->success([]);
  594. }
  595. if($release_type == '5'){
  596. //充值页返回需要判断用户权限
  597. $check_user = $this->checkUsers($advert['person']);
  598. if(!$check_user){
  599. return response()->success([]);
  600. }
  601. $activity = ActivityService::getById($advert['activity_id'] ?? 0);
  602. if ($activity){
  603. if ($activity['permanent'] == 1 || ($activity['start_time'] < date("Y-m-d H:i:s") && $activity['end_time'] > date("Y-m-d H:i:s") )){
  604. $advert['redirect_url'] = "/views/Activity";
  605. $advert = self::getBackFormat($advert);
  606. $advert['param'] = ['token' => $activity['token']];
  607. return response()->success($advert);
  608. }else{
  609. return response()->success([]);
  610. }
  611. }else{
  612. return response()->success([]);
  613. }
  614. }
  615. }
  616. //男女频,书架列表
  617. $banner = ChannelAdvertService::getAdvertList($distribution_id,$release_type);
  618. if($banner->isEmpty()){
  619. $recom_banner_type = ["PUBLIC",$release_type ==1 ? "MALE" : "FEMALE"];
  620. $banner = $this->getDefaultBanner($recom_banner_type);
  621. return response()->success($banner);
  622. }
  623. $banner->transform(function ($item) {
  624. $item->ids = Hashids::encode($item->id);
  625. if($item->type == 1){
  626. $content = explode(';',$item->content);
  627. $item->bid = isset($content[2]) ? $content[2] : '';
  628. $item->cid = isset($content[3]) ? $content[3] : '';
  629. if ($item->cid){
  630. $item->redirect_url = "views/Reader";
  631. }else{
  632. $item->redirect_url = "views/Detail";
  633. }
  634. $item->redirect_type = "book";
  635. }else{
  636. $activity = ActivityService::getById($item->activity_id);
  637. $item->redirect_url = "/views/Activity";
  638. $item->redirect_type = "activity";
  639. if($activity && !empty($activity['token'])){
  640. $item['param'] = ['token' => $activity['token']];
  641. }else{
  642. $item->redirect_url = "#";
  643. }
  644. }
  645. self::getBackFormat($item);
  646. return $item;
  647. });
  648. return response()->success($banner);
  649. }
  650. static function getBackFormat($data)
  651. {
  652. if(isset($data['id']) || $data->id) unset($data['id'],$data->id);
  653. if(isset($data['type']) || $data->type) unset($data['type'],$data->type);
  654. if(isset($data['person']) || $data->person) unset($data['person'],$data->person);
  655. if(isset($data['frequency']) || $data->frequency) unset($data['frequency'],$data->frequency);
  656. return $data;
  657. }
  658. /**
  659. * 默认获取banner
  660. * @return mixed
  661. */
  662. protected function getDefaultBanner( $reco_banner_type = ['FEMALE', 'PUBLIC'])
  663. {
  664. $banner = (new RecoBannerService)->getByType($reco_banner_type, 2);
  665. $banner->transform(function ($item) {
  666. $result = $this->getBidCidFromUrl($item->redirect_url);
  667. $item->bid = $result['bid'];
  668. $item->cid = $result['cid'];
  669. $item->ids = Hashids::encode($item->id);
  670. $item->type = 'default';
  671. if ($result['cid']) {
  672. $item->redirect_url = "views/Reader";
  673. } else {
  674. $item->redirect_url = "views/Detail";
  675. }
  676. $item->redirect_type = "book";
  677. unset($item->id);
  678. return $item;
  679. });
  680. return $banner;
  681. }
  682. /**
  683. * 限免
  684. */
  685. public function free(int $sex)
  686. {
  687. $result = BookConfigService::findFreeBooks($sex);
  688. return response()->success($result);
  689. }
  690. public function yueaiBackRecom(Request $request)
  691. {
  692. $package = $request->header('x-package', '');
  693. if (empty($package) || $package != 'com.beidao.kuaiying.yueai') {
  694. return response()->success([]);
  695. }
  696. $user = (new QappUserService)->getGolableUser();
  697. if(isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  698. $bid = BookConfigService::getAvailableBIdsbyBids([58238,60534,63220,14500,13254,63221,63548,14022,59334,58888,63417,61701],$this->distribution_channel_id,false);
  699. if (!empty($bid)){
  700. $bid = array_random($bid,4);
  701. }
  702. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  703. if($orderRecord && count($bid) >= 4){
  704. $where = ['is_on_shelf' => [1,2],'bids' => $bid];
  705. // $books = BookConfigService::getBooksByIds($bid,[],false);
  706. $books = BookConfigService::getBookLists($where,[],false);
  707. return response()->collection(new BookTransformer(), $books);
  708. }
  709. }
  710. return response()->success([]);
  711. $where = ['is_on_shelf' => [2]];
  712. $where['channel_id'] = $request->input('distribution_channel_id',0);
  713. $books = BookConfigService::getBooks($where, [], 4);
  714. return response()->collection(new BookTransformer(), $books);
  715. }
  716. public function shelfRecom(Request $request)
  717. {
  718. $package = $request->header('x-package', '');
  719. $user = (new QappUserService)->getGolableUser();
  720. if (!empty($package) && $package == 'com.beidao.kuaiying.yueai') {
  721. if(isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  722. $bid = BookConfigService::getAvailableBIdsbyBids([58238,60534,63220,14500,13254,63221,63548,14022,59334,58888,63417,61701],$this->distribution_channel_id,false);
  723. if (!empty($bid)){
  724. $bid = array_random($bid,4);
  725. }
  726. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  727. if($orderRecord && count($bid) > 1){
  728. $where = ['is_on_shelf' => [1,2],'bids' => $bid];
  729. // $books = BookConfigService::getBooksByIds($bid,[],false);
  730. $books = BookConfigService::getBookLists($where,[],false);
  731. return response()->collection(new BookTransformer(), $books);
  732. }
  733. }
  734. return response()->success([]);
  735. }
  736. $where = ['is_on_shelf' => [2],'channel_id' => $this->distribution_channel_id,'is_high_quality' => 1];
  737. if (isset($user->uid) && $user->user->sex == 1){
  738. $where['channel_name'] = "男频";
  739. }else{
  740. $where['channel_name'] = "女频";
  741. }
  742. $books = BookConfigService::getBooks($where, [], 3);
  743. return response()->collection(new BookTransformer(), $books);
  744. }
  745. /**
  746. * 新推荐书单
  747. * @param Request $request
  748. * @return mixed
  749. */
  750. public function recommendBooks(Request $request)
  751. {
  752. $distribution_id = $this->distribution_channel_id;
  753. $bid = $request->get('bid',0);
  754. if(empty($distribution_id)){
  755. \Log::info('recommendBooks:1');
  756. return response()->success([]);
  757. }
  758. if(!empty($bid)){
  759. \Log::info('recommendBooks:2');
  760. $bid = str_decode($bid);
  761. }
  762. //判断包是否存在
  763. $package_info = QappPackage::getPackage($distribution_id);
  764. if(empty($package_info) || !isset($package_info->channel_id)){
  765. \Log::info('recommendBooks:3');
  766. return response()->success([]);
  767. }
  768. //包对应有没有配置开启推荐书单
  769. $config = ChannelRecommendBookConfigService::getRecommendConfigs($distribution_id);
  770. if(empty($config) || !isset($config->status) || $config->status == 0){
  771. \Log::info('recommendBooks:4');
  772. return response()->success([]);
  773. }
  774. //根据频率和用户属性决定是否需要返回
  775. $res = $this->checkUsersAuth($config);
  776. if(!$res){
  777. \Log::info('recommendBooks:5');
  778. return response()->success([]);
  779. }
  780. $list = ChannelRecommendBooksService::getRecommendBooks($distribution_id,$bid);
  781. if(!$list->isEmpty()){
  782. foreach($list as $key => $item){
  783. $this->incrRecommendNum($distribution_id,$item->bid);
  784. }
  785. \Log::info('recommendBooks:6');
  786. return response()->collection(new BookTransformer(), $list);
  787. }
  788. \Log::info('recommendBooks:7');
  789. return response()->success([]);
  790. }
  791. /**
  792. * 点击推荐书籍记录点击次数
  793. * @param Request $request
  794. * @return mixed
  795. */
  796. public function clickRecommendBooks(Request $request)
  797. {
  798. $distribution_id = $this->distribution_channel_id;
  799. $bid = $request->get('bid','');
  800. if(empty($bid)){
  801. return response()->success();
  802. }
  803. //判断包是否存在
  804. $package_info = QappPackage::getPackage($distribution_id);
  805. if(empty($package_info) || !isset($package_info->channel_id)){
  806. return response()->success([]);
  807. }
  808. $date = date('Ymd');
  809. $bid = str_decode($bid);
  810. $cacheKey = 'recommend:click:'.$date.':'.$distribution_id.$bid;
  811. $this->incrRedisKey($cacheKey);
  812. return response()->success();
  813. }
  814. /**
  815. * 判断用户是否需要推荐
  816. * @param $config
  817. * @return bool
  818. */
  819. protected function checkUsersAuth($config)
  820. {
  821. \Log::info($config);
  822. \Log::info('$config->person:'.$config->person);
  823. \Log::info($this->uid);
  824. $res = $this->checkUsers($config->person);
  825. if($res === false){
  826. return false;
  827. }
  828. //频率判断
  829. if($config->frequency == 'back'){
  830. //返回即推送
  831. return true;
  832. }
  833. $day = strtotime(date('Y-m-d H:i:s'));
  834. $nextDay = strtotime( date('Y-m-d'). ' +1 day');
  835. $nextWeek = strtotime(date('Y-m-d',strtotime('+1 week last monday')));
  836. if($config->frequency == 'day'){
  837. //每日推送
  838. if(!Redis::exists('recommend:'.$config->channel_id.':'.$this->uid)){
  839. Redis::setex('recommend:'.$config->channel_id.':'.$this->uid,($nextDay-$day),1);
  840. return true;
  841. }
  842. \Log::info('当天已经推送过了');
  843. return false;
  844. }
  845. if($config->frequency == 'week'){
  846. //每周推送
  847. if(!Redis::exists('recommend:'.$config->channel_id.':'.$this->uid)){
  848. Redis::setex('recommend:'.$config->channel_id.':'.$this->uid,($nextWeek-$day),1);
  849. return true;
  850. }
  851. \Log::info('该周已经推送过了');
  852. return false;
  853. }
  854. }
  855. /**
  856. * 判断用户是否有权限
  857. * @param $type
  858. * @return bool
  859. */
  860. protected function checkUsers($type)
  861. {
  862. $res = false;
  863. switch($type)
  864. {
  865. case 'pay':
  866. //付费用户
  867. $orders = OrderService::getUserLastestOrder($this->uid);
  868. if($orders){
  869. $res = true;
  870. }
  871. \Log::info('用户是否付费:');
  872. \Log::info($orders);
  873. break;
  874. case 'send_order':
  875. //派单用户
  876. if($this->send_order_id != 0){
  877. $res = true;
  878. }
  879. \Log::info('用户是否是派单用户:$this->send_order_id:'.$this->send_order_id);
  880. break;
  881. case 'pay_send_order':
  882. //付费派单用户
  883. $orders = OrderService::getUserLastestOrder($this->uid);
  884. if($orders && $this->send_order_id != 0){
  885. $res = true;
  886. }
  887. \Log::info('用户是否是付费派单用户:$this->send_order_id:'.$this->send_order_id);
  888. \Log::info($orders);
  889. break;
  890. case 'unpaid':
  891. $orders = OrderService::getUserLastestOrder($this->uid);
  892. if(!$orders){
  893. $res = true;
  894. }
  895. break;
  896. case 'all':
  897. $res = true;
  898. \Log::info('所有用户返回');
  899. break;
  900. }
  901. return $res;
  902. }
  903. /**
  904. * 推广书籍推荐次数
  905. * @param $channel_id
  906. * @param $bid
  907. */
  908. protected function incrRecommendNum($channel_id,$bid)
  909. {
  910. $date = date('Ymd');
  911. $cacheKey = 'recommend:sum:'.$date.':'.$channel_id.$bid;
  912. $this->incrRedisKey($cacheKey);
  913. }
  914. /**
  915. * 点击广告统计
  916. * @param Request $request
  917. * @return mixed
  918. */
  919. public function getCheckAdvertisement(Request $request)
  920. {
  921. $type = $request->get('type','');
  922. $id = $request->get('ids','');
  923. $distribution_id = $this->distribution_channel_id;
  924. \Log::info('getCheckAdvertisement:type:'.$type.' id:'.$id.' $distribution_id:'.$distribution_id);
  925. if(empty($id) || empty($distribution_id)){
  926. return response()->success();
  927. }
  928. $id = str_decode($id);
  929. if(!$id){
  930. return response()->success();
  931. }
  932. if($type == 'default'){
  933. //默认原表reco_banners广告,区分跟新表channel_advert的id
  934. $id = -$id;
  935. }else{
  936. $advert = ChannelAdvert::find($id);
  937. if(!$advert){
  938. \Log::info('getCheckAdvertisement:error:不存在该广告');
  939. \Log::info(json_encode($request->all()));
  940. return response()->success();
  941. }
  942. }
  943. $where = ['channel_ad_id' => $id, 'uid' => $this->uid, 'distribution_id' => $distribution_id];
  944. \Log::info('insert_where:');
  945. \Log::info(json_encode($where));
  946. ChannelAdUser::firstOrCreate($where);
  947. $date = date('Ymd');
  948. $cacheKey = 'advertisement:pv:'.$date.':'.$distribution_id.$id;
  949. $this->incrRedisKey($cacheKey);
  950. //设置当前用户的所属广告有效期一周
  951. $key = 'advertisement:uid:'.$this->uid.':id';
  952. Redis::set($key,$id);
  953. Redis::expire($key,BaseConst::ONE_WEEK_SECONDS);
  954. return response()->success();
  955. }
  956. /**
  957. * redis新增
  958. * @param $cacheKey
  959. */
  960. protected function incrRedisKey($cacheKey)
  961. {
  962. if(!Redis::exists($cacheKey)){
  963. Redis::set($cacheKey,1);
  964. }else{
  965. Redis::incrBy($cacheKey, 1);
  966. }
  967. }
  968. /**
  969. * 绑定广告和订单
  970. * @param Request $request
  971. * @return mixed
  972. */
  973. public function getAdvertOrders(Request $request)
  974. {
  975. $order_id = $request->get('trade_no','');
  976. $uid = $this->uid;
  977. $distribution_id = $this->distribution_channel_id;
  978. $cacheKey = 'advertisement:uid:'.$uid.':id';
  979. if(empty($order_id)){
  980. return response()->success();
  981. }
  982. $channel_ad_id = 0;
  983. \Log::info('getAdvertOrders:trade_no'.$order_id.' uid:'.$uid);
  984. if(Redis::exists($cacheKey)){
  985. try {
  986. //获取广告id
  987. $channel_ad_id = Redis::get($cacheKey);
  988. //判断订单跟广告是否有关系
  989. $order = OrderService::getByTradeNo($order_id);
  990. if(!$order){
  991. return response()->success();
  992. }
  993. if($channel_ad_id > 0){
  994. //新版
  995. $type = 1;
  996. $advert = ChannelAdvert::find($channel_ad_id);
  997. if(!$advert){
  998. return response()->success();
  999. }
  1000. if($advert->type == '2' && $advert->activity_id != 0){
  1001. //广告类型为活动
  1002. if($order->activity_id != $advert->activity_id){
  1003. return response()->success();
  1004. }
  1005. }else{
  1006. //广告类型为书籍
  1007. $content = explode(';',$advert->content);
  1008. if(!isset($content[2])){
  1009. return response()->success();
  1010. }
  1011. if($order->from_bid == 0 || $order->from_bid != str_decode($content[2])){
  1012. return response()->success();
  1013. }
  1014. }
  1015. }else{
  1016. //旧版
  1017. $type = 0;
  1018. $advert = RecoBanner::find(abs($channel_ad_id));
  1019. if(!$advert){
  1020. return response()->success();
  1021. }
  1022. $result = $this->getBidCidFromUrl($advert->redirect_url);
  1023. $bid = $result['bid'];
  1024. $cid = $result['cid'];
  1025. if($cid){
  1026. if($order->from_bid == 0 || $order->from_bid != str_decode($bid)){
  1027. return response()->success();
  1028. }
  1029. }else{
  1030. if($order->activity_id == 0 || $order->from_bid != str_decode($bid)){
  1031. return response()->success();
  1032. }
  1033. }
  1034. }
  1035. $created_at = $updated_at = date('Y-m-d H:i:s');
  1036. DB::table('channel_advert_orders')->insert(compact('order_id','uid','distribution_id','channel_ad_id','type','created_at','updated_at'));
  1037. } catch (\Exception $e) {
  1038. \Log::info('绑定广告和订单失败'.$e->getMessage());
  1039. \Log::info('order_id:'.$order_id.' uid:'.$uid.' distribution_id:'.$distribution_id.' channel_ad_id:'.$channel_ad_id);
  1040. }
  1041. }
  1042. return response()->success();
  1043. }
  1044. private function getSpecialLibrary(Request $request)
  1045. {
  1046. $where = [];
  1047. $order = [];
  1048. $where['is_on_shelf'] = [2,4];
  1049. $category_id = $request->input('category_id');
  1050. if ($category_id) {
  1051. if ($category_id == 1) {
  1052. $where['channel_name'] = '男频';
  1053. } elseif ($category_id == 2) {
  1054. $where['channel_name'] = '女频';
  1055. } else {
  1056. $where['category_id'] = $category_id;
  1057. }
  1058. }
  1059. $key = $request->input('key');
  1060. $uid = $request->input('uid', 0);
  1061. if ($key && $uid && is_numeric($uid)) {
  1062. BookConfigService::saveUserSearchLog($key, $uid);
  1063. }
  1064. $where['key'] = $key;
  1065. $order_field = $request->input('order_field');
  1066. $order_seq = $request->input('order_seq');
  1067. if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
  1068. if ($order_field == 'update') {
  1069. $order = ['book_configs.updated_at', 'desc'];
  1070. } elseif ($order_field == 'create') {
  1071. $order = ['book_configs.created_at', 'desc'];
  1072. } else {
  1073. $order = [$order_field, 'desc'];
  1074. }
  1075. if ($order_seq == 'asc') {
  1076. $order = [$order_field, 'asc'];
  1077. }
  1078. if ($order_seq == 'desc') {
  1079. $order = [$order_field, 'desc'];
  1080. }
  1081. }
  1082. // 审核状态默认值
  1083. $package = $request->header('x-package', '');
  1084. $brand = $request->header('x-nbrand', '');
  1085. $codeVersion = $request->header('x-codeversion', '');
  1086. if ($order_field === 'recommend_index' && Utils::checkIsAudit($package, $brand, $codeVersion)) {
  1087. $order = ['book_configs.bid', 'desc'];
  1088. }
  1089. $status = $request->input('status');
  1090. if ($status != '') {
  1091. $where['status'] = $status;
  1092. }
  1093. // 搜索关键词的情况下,屏蔽书籍完本状态
  1094. if ($key && isset($where['status'])) {
  1095. unset($where['status']);
  1096. }
  1097. $page_size = $request->input('page_size', 15);
  1098. $where['channel_id'] = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
  1099. $books = BookConfigService::getBooks($where, $order, $page_size);
  1100. $special = get_special_bid();
  1101. $list = [];
  1102. foreach ($books as $ke => $val){
  1103. if ($val->is_on_shelf != 2 && !in_array($val->bid,$special)){
  1104. unset($books[$ke]);
  1105. }
  1106. }
  1107. return response()->pagination(new BookTransformer,$books);
  1108. }
  1109. }