BookController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Book;
  3. use App\Libs\Utils;
  4. use App\Modules\Book\Services\BookAuditService;
  5. use App\Modules\RecommendBook\Services\QappRecommendService;
  6. use App\Modules\RecommendBook\Services\RecommendService;
  7. use App\Modules\Book\Services\RecoBannerService;
  8. use App\Modules\User\Models\QappPackage;
  9. use App\Modules\User\Services\QappUserService;
  10. use Illuminate\Http\Request;
  11. use App\Http\Controllers\QuickApp\BaseController;
  12. use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
  13. use App\Http\Controllers\QuickApp\Book\Transformers\KeywordTransformer;
  14. use App\Modules\Book\Models\BookConfig;
  15. use App\Modules\Book\Services\BookConfigService;
  16. use App\Modules\Book\Services\BookService;
  17. use App\Modules\Book\Services\BookUrgeUpdateService;
  18. use App\Modules\Book\Services\UserShelfBooksService;
  19. use App\Modules\Book\Services\ChapterService;
  20. use App\Modules\Subscribe\Services\BookOrderService;
  21. use App\Modules\Subscribe\Services\ChapterOrderService;
  22. use App\Modules\Subscribe\Services\YearOrderService;
  23. use App\Modules\User\Services\ReadRecordService;
  24. use Hashids;
  25. class BookController extends BaseController
  26. {
  27. public function index(Request $request, $bid)
  28. {
  29. $bid = BookService::decodeBidStatic($bid);
  30. $book_info = BookConfigService::getBookById($bid);
  31. if (!$book_info) {
  32. return response()->error('QAPP_SYS_ERROR');
  33. }
  34. //yuyuedu、xinghe 快应用这两个cp的书屏蔽下
  35. if(in_array($book_info->cp_source,getHiddenCp())){
  36. return response()->error('QAPP_SYS_ERROR');
  37. }
  38. if($this->distribution_channel_id == 7477 && $bid == 13765){
  39. $book_info->is_on_shelf = 2;
  40. }
  41. $special = get_special_bid();
  42. if (in_array($this->distribution_channel_id,[9487,9390]) && in_array($book_info->bid,$special)){
  43. $book_info->is_on_shelf = 2;
  44. }
  45. if($bid == 58886){
  46. $book_info->is_on_shelf = 0;
  47. }
  48. if (!in_array($book_info->is_on_shelf, [1,2])) {
  49. return response()->error('QAPP_OFF_SHELF');
  50. }
  51. $is_on_shelf = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid, $bid);
  52. $book_info['is_on_user_shelf'] = 0;
  53. if ($is_on_shelf) {
  54. $book_info['is_on_user_shelf'] = 1;
  55. }
  56. $last_chapter = ChapterService::getChapterNameById($book_info['last_cid'], $bid);
  57. $book_info->last_chapter = $last_chapter['name'];
  58. list($is_split,$is_change_chapter_name) = BookService::splitContent($bid);
  59. if($is_split && ($book_info->channel_name == '男频' || $is_change_chapter_name) ){
  60. $book_info->last_chapter = '第'.$book_info->chapter_count.'章';
  61. }
  62. $book_info['last_chapter_is_vip'] = $last_chapter['is_vip'];
  63. $book_info['is_need_charge'] = $this->isNeedCharge($bid, $last_chapter, $book_info);
  64. $record = ReadRecordService::getBookReadRecordStatic($this->uid, $bid);
  65. if ($record) {
  66. $book_info['record_chapter_id'] = $record['record_chapter_id'];
  67. $book_info['record_chapter_name'] = $record['record_chapter_name'];
  68. }
  69. return response()->item(new BookTransformer(), $book_info);
  70. }
  71. /**
  72. * 获取订购记录
  73. * @param $book_info
  74. * @param $chapter_id
  75. * @return bool
  76. */
  77. protected function getOrderRecord($bid, $chapter_id)
  78. {
  79. //包年记录
  80. $uid = $this->uid;
  81. $res = YearOrderService::getRecord($uid);
  82. if ($res) return true;
  83. $res = null;
  84. //单本订购记录
  85. $res = BookOrderService::getRecordByuidBid($uid, $bid);
  86. if ($res) return true;
  87. $res = null;
  88. //章节订购记录
  89. $chapterOrder = new ChapterOrderService();
  90. if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
  91. return false;
  92. }
  93. /**
  94. * 判断是否需要充值
  95. */
  96. private function isBookNeedCharge(int $bid, float $price)
  97. {
  98. $book_order = $this->getOrderRecord($bid, 0);
  99. if ($book_order) {
  100. return false;
  101. } else {
  102. $user_info = $this->user_info;
  103. return $user_info['balance'] < $price;
  104. }
  105. }
  106. /**
  107. * 判断章节是否需要充值
  108. */
  109. private function isChapterNeedCharge(int $bid, int $cid, float $price)
  110. {
  111. $book_order = $this->getOrderRecord($bid, $cid);
  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 isNeedCharge(int $bid, $last_chapter, $book_info)
  123. {
  124. $is_free = BookConfigService::judgeBookIsFree($bid);
  125. if ($is_free) {
  126. return false;
  127. }
  128. switch ($book_info->charge_type) {
  129. case 'BOOK':
  130. $price = $this->getPrice($book_info);
  131. return $this->isBookNeedCharge($bid, $price);
  132. default:
  133. $price = isset($last_chapter->is_vip) ? $this->getPrice($book_info, $last_chapter->size) : 0;
  134. return isset($last_chapter->is_vip) ? $this->isChapterNeedCharge($bid, $last_chapter->id, $price) : false;
  135. }
  136. }
  137. /**
  138. * 计算价格
  139. * @param $book_info
  140. * @param $chapter_size
  141. * @return float
  142. */
  143. protected function getPrice($book_info, $chapter_size = 0)
  144. {
  145. if ($book_info->charge_type == 'BOOK')
  146. return $book_info->price * 100;
  147. return ceil($chapter_size / 100);
  148. }
  149. /**
  150. * 首页
  151. */
  152. public function getBookLists(Request $request, $sex)
  153. {
  154. // 获取基本数据
  155. $package = $request->header('x-package', '');
  156. $brand = $request->header('x-nbrand', '');
  157. $codeVersion = $request->header('x-codeversion', '');
  158. $isAuth = check_qapp_auth($package ,0);
  159. // 根据包名、平台、版本号判断是否审核
  160. if (Utils::checkIsAudit($package, $brand, $codeVersion) || $isAuth == false) {
  161. $result = BookAuditService::getHomeBooksData($sex, $package,$isAuth);
  162. return response()->success($result);
  163. }
  164. $user = (new QappUserService)->getGolableUser();
  165. if($package == "com.beidao.kuaiying.yueai" && $sex == "male" && isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  166. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  167. if($orderRecord){
  168. $result = BookAuditService::getYueaiHomeBooksData($sex, $package,$isAuth,1);
  169. return response()->success($result);
  170. }
  171. }
  172. if ($sex == 'male') {
  173. $channel = 1;
  174. $reco_banner_type = ['MALE', 'PUBLIC'];
  175. } else {
  176. $reco_banner_type = ['FEMALE', 'PUBLIC'];
  177. $channel = 2;
  178. }
  179. if($isAuth){
  180. $books = (new RecoBannerService)->getByType($reco_banner_type, 2);
  181. $books->transform(function ($item) {
  182. $result = $this->getBidCidFromUrl($item->redirect_url);
  183. $item->bid = $result['bid'];
  184. $item->cid = $result['cid'];
  185. if ($result['cid']) {
  186. $item->redirect_url = "views/Reader";
  187. } else {
  188. $item->redirect_url = "views/Detail";
  189. }
  190. return $item;
  191. });
  192. }else{
  193. $home = config('home.ycsd');
  194. $banner = $home['reco_banner'];
  195. $books = $banner[$sex];
  196. }
  197. //新判断: 根据包名来获取对应所需的bid
  198. $qapp_package = QappPackage::getPackageByPackage($package);
  199. if($qapp_package){
  200. $package_id = $qapp_package->id;
  201. }else{
  202. $package_id = 0;
  203. }
  204. \Log::info('un_send_order_book:package_id1:'.$package_id.' $package:'.$package);
  205. if(isset($user->uid) && !empty($user->uid)){
  206. if(!$this->send_order_id || $this->send_order_id == 0 ){
  207. \Log::info('un_send_order_book:uid:'.$this->uid.' $package:'.$package);
  208. $result = $this->getCheckBids($channel,$books,$package_id,$package);
  209. if(isset($result[1]['books']) && count((array)$result[1]['books']) > 1){
  210. return response()->success($result);
  211. }
  212. $result = $this->getCheckBids($channel,$books,0,$package);
  213. return response()->success($result);
  214. }else{
  215. $package_id = 0;
  216. }
  217. \Log::info('un_send_order_book:package_id2:'.$package_id.' $package:'.$package);
  218. }else{
  219. $package_id = 0;
  220. }
  221. \Log::info('un_send_order_book:package_id3:'.$package_id.' $package:'.$package);
  222. $result = $this->getCheckBids($channel,$books,$package_id,$package);
  223. return response()->success($result);
  224. }
  225. /**
  226. * 根据包名
  227. * @param $channel
  228. * @param $books
  229. * @param $package_id
  230. * @return array
  231. */
  232. private function getCheckBids($channel,$books,$package_id,$package)
  233. {
  234. $isAuthor = check_qapp_auth($package_id,1);
  235. $hotBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id),$channel,$package,$isAuthor);
  236. $liveBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id),$channel,$package,$isAuthor);
  237. $recomBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel,$package,$isAuthor);
  238. $newBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id),$channel,$package,$isAuthor);
  239. return array_filter([
  240. ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
  241. ['type' => 'hot', 'lable' => '热门书单', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($hotBids))],
  242. ['type' => 'zhibo', 'lable' => '神书直播', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($liveBids))],
  243. ['type' => 'recom', 'lable' => '小编精选', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($recomBids))],
  244. ['type' => 'new_recom', 'lable' => '人气新书', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($newBids))]
  245. ]);
  246. }
  247. /**
  248. * 检测并补充不满足条件的书籍id
  249. * @param $bid_list
  250. * @param $channel : 频道
  251. * @param $package : 频道
  252. * @return array
  253. */
  254. private function getCheckBooks($bid_list,$channel,$package,$is_author)
  255. {
  256. $hidden_cp = getHiddenCp();
  257. if($package !== 'com.beidao.kuaiying.zsy'){
  258. $hidden_cp = array_merge($hidden_cp,['lianshang']);
  259. }
  260. //获取书本数量
  261. $count = count($bid_list);
  262. if (!$is_author){
  263. $where = [
  264. ['book_configs.charge_type','!=','BOOK'],
  265. ['book_configs.cp_source','=','ycsd'],
  266. ];
  267. }else{
  268. $where = [
  269. ['book_configs.charge_type','!=','BOOK'],
  270. ];
  271. }
  272. //获取当前有效书本数量
  273. $book_count = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  274. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  275. ->whereIn('book_configs.bid',$bid_list)
  276. ->where('book_configs.is_on_shelf',2)
  277. ->where('book_configs.charge_type','!=','BOOK')
  278. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  279. ->where($where)
  280. ->where('book_categories.pid',$channel)
  281. ->count();
  282. if($count == $book_count){
  283. return $bid_list;
  284. }
  285. //获取需要补充的书籍数量
  286. $supplement_count = (($count - $book_count) > 0) ? $count - $book_count : 0;
  287. if($supplement_count <= 0){
  288. return $bid_list;
  289. }
  290. //获取书籍交集bid,过滤掉不符合要求的书
  291. $bids = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  292. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  293. ->whereIn('book_configs.bid',$bid_list)
  294. ->where('book_configs.is_on_shelf',2)
  295. ->where($where)
  296. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  297. ->where('book_categories.pid',$channel)
  298. ->pluck('book_configs.bid')->all();
  299. $bid_list = array_intersect($bid_list,$bids);
  300. //获取随机的有效的书籍bid
  301. $rand_bid = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  302. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  303. ->where('book_configs.is_on_shelf',2)
  304. // ->where('book_configs.charge_type','!=','BOOK')
  305. ->where($where)
  306. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  307. ->where('book_categories.pid',$channel)
  308. ->inRandomOrder()
  309. ->limit($supplement_count)
  310. ->get()->pluck('bid')->toArray();
  311. return array_filter(array_merge($bid_list,$rand_bid));
  312. }
  313. private function getBidCidFromUrl(string $url)
  314. {
  315. if (preg_match('/\?bid=(\w+)\S+cid=(\w+)/', $url, $matches) || preg_match('/\?id=(\w+)/', $url, $matches)) {
  316. return [
  317. 'bid' => $matches[1],
  318. 'cid' => isset($matches[2]) ? $matches[2] : 0,
  319. ];
  320. } else {
  321. return [
  322. 'bid' => '',
  323. 'cid' => 0,
  324. ];
  325. }
  326. }
  327. public function library(Request $request)
  328. {
  329. $channel_id = $request->input('distribution_channel_id',0);
  330. if (in_array($channel_id,[9487,9390])){
  331. return $this->getSpecialLibrary($request);
  332. }
  333. $where = [];
  334. $order = [];
  335. $where['is_on_shelf'] = [2];
  336. $category_id = $request->input('category_id');
  337. if ($category_id) {
  338. if ($category_id == 1) {
  339. $where['channel_name'] = '男频';
  340. } elseif ($category_id == 2) {
  341. $where['channel_name'] = '女频';
  342. } else {
  343. $where['category_id'] = $category_id;
  344. }
  345. }
  346. $key = $request->input('key');
  347. $uid = $request->input('uid', 0);
  348. if ($key && $uid && is_numeric($uid)) {
  349. BookConfigService::saveUserSearchLog($key, $uid);
  350. }
  351. $where['key'] = $key;
  352. $order_field = $request->input('order_field');
  353. $order_seq = $request->input('order_seq');
  354. if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
  355. if ($order_field == 'update') {
  356. $order = ['book_configs.updated_at', 'desc'];
  357. } elseif ($order_field == 'create') {
  358. $order = ['book_configs.created_at', 'desc'];
  359. } else {
  360. $order = [$order_field, 'desc'];
  361. }
  362. if ($order_seq == 'asc') {
  363. $order = [$order_field, 'asc'];
  364. }
  365. if ($order_seq == 'desc') {
  366. $order = [$order_field, 'desc'];
  367. }
  368. }
  369. // 审核状态默认值
  370. $package = $request->header('x-package', '');
  371. $brand = $request->header('x-nbrand', '');
  372. $codeVersion = $request->header('x-codeversion', '');
  373. if ($order_field === 'recommend_index' && Utils::checkIsAudit($package, $brand, $codeVersion)) {
  374. $order = ['book_configs.bid', 'desc'];
  375. }
  376. // 是否只使用原创书殿的书
  377. $isAuth = check_qapp_auth($package ,0);
  378. if (!$isAuth){
  379. $where['cp_source'] = "ycsd";
  380. }
  381. $status = $request->input('status');
  382. if ($status != '') {
  383. $where['status'] = $status;
  384. }
  385. // 搜索关键词的情况下,屏蔽书籍完本状态
  386. if ($key && isset($where['status'])) {
  387. unset($where['status']);
  388. }
  389. $page_size = $request->input('page_size', 15);
  390. $where['channel_id'] = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
  391. $books = BookConfigService::getBooks($where, $order, $page_size);
  392. return response()->pagination(new BookTransformer, $books);
  393. }
  394. public function hotWords(Request $request)
  395. {
  396. $result = BookConfigService::findBookKeywords();
  397. return response()->pagination(new KeywordTransformer, $result);
  398. }
  399. public function similarRecom(Request $request)
  400. {
  401. $package = $request->header('x-package', '');
  402. $category_id = $request->input('category_id');
  403. $bid = $request->input('bid');
  404. $package = $request->header('x-package', '');
  405. if (empty($bid) || (empty($category_id) && $category_id != 0)) {
  406. return response()->error('PARAM_ERROR');
  407. }
  408. $isAuth = check_qapp_auth($package ,0);
  409. $bid = BookService::decodeBidStatic($bid);
  410. $where = ['category_id' => $category_id, 'is_on_shelf' => [2]];
  411. if (!$isAuth){
  412. $where['cp_source'] = "ycsd";
  413. }
  414. $where['channel_id'] = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
  415. $books = BookConfigService::getBooks($where, [], 4);
  416. $data = [];
  417. foreach ($books as $v) {
  418. if ($v->bid != $bid && count($data) < 3) {
  419. $data[] = $v;
  420. }
  421. }
  422. return response()->collection(new BookTransformer(), $data);
  423. }
  424. public function readOverRecommend(Request $request)
  425. {
  426. $bid = $request->input('bid');
  427. if (empty($bid)) {
  428. return response()->error('PARAM_ERROR');
  429. }
  430. $bid = BookService::decodeBidStatic($bid);
  431. $book_info = BookConfigService::getBookById($bid);
  432. $res = BookConfigService::getRecommendBooks($bid, $book_info->channel_name);
  433. $urge_status = 0;
  434. if ($book_info->status == 0 && !BookUrgeUpdateService::isHadUrged($this->uid, $bid)) {
  435. $urge_status = 1;
  436. }
  437. $recommend_result = collectionTransform(new BookTransformer(), $res);
  438. $book_status = [
  439. 'status' => $book_info->status,
  440. 'urge_status' => $urge_status
  441. ];
  442. $data = [
  443. 'recommend_result' => $recommend_result,
  444. 'book_status' => $book_status
  445. ];
  446. return response()->success($data);
  447. }
  448. public function rank(Request $request)
  449. {
  450. // 1:男频,2:女频
  451. $sex = (int)$request->input('sex');
  452. if (!in_array($sex, [1, 2], true)) {
  453. return response()->error('PARAM_ERROR');
  454. }
  455. // 默认
  456. $bids = [11529, 11941, 12720, 11990, 11988, 11976, 11977, 4183, 12717, 11833,
  457. 7287,14297,12716,14312,14000,13577,16712,13002,12717,15103,13928,14793,
  458. 12708,13286];
  459. if ($sex === 2) {
  460. $bids = [8469, 11660, 9117, 7891, 12281, 12470, 8167, 11661, 11670, 8476, 8557, 11662,
  461. 11680, 11926, 12462, 7836, 11681, 11664, 11928, 8631];
  462. }
  463. /**
  464. * pid:1为男频 2为女频
  465. SELECT
  466. CONCAT( books.id, ',' )
  467. FROM
  468. books
  469. LEFT JOIN book_configs ON books.id = book_configs.bid
  470. WHERE
  471. book_configs.is_on_shelf = 2
  472. AND books.category_id IN ( SELECT id FROM book_categories WHERE pid = 2 )
  473. ORDER BY
  474. book_configs.recommend_index DESC
  475. LIMIT 10;
  476. */
  477. // 根据包名、平台、版本号判断是否审核
  478. $package = $request->header('x-package', '');
  479. $brand = $request->header('x-nbrand', '');
  480. $codeVersion = $request->header('x-codeversion', '');
  481. if (Utils::checkIsAudit($package, $brand, $codeVersion)) {
  482. $bids = [2266, 3838, 9700, 10175, 10301, 3422, 1166, 4546, 9163, 2509,
  483. 7287,14297,12716,14312,14000,13577,16712,13002,12717,15103,13928,
  484. 14793,12708,13286,13336,13275,13073,15121,13929,12693,13254,3526,
  485. 10313,3483,13278,14004,4098,10378,14072,21376,21139,21757,19449];
  486. if ($sex === 2) {
  487. $bids = [159, 2439, 6276, 10074, 5409, 9379, 10323, 9078, 3603, 487];
  488. }
  489. }
  490. $isAuth = check_qapp_auth($package,0);
  491. if (!$isAuth){
  492. $rank = config('home.rank');
  493. $bids = $rank['male'];
  494. if ($sex === 2) {
  495. $bids = $rank['female'];;
  496. }
  497. }
  498. $channel_id = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
  499. $books = collectionTransform(new BookTransformer, BookConfigService::getBookLists(compact('bids','channel_id')));
  500. return response()->success($books);
  501. }
  502. /**
  503. * 推荐书
  504. */
  505. public function recommen()
  506. {
  507. $reco_banner_type = ['FEMALE', 'PUBLIC'];
  508. $books = (new RecoBannerService)->getByType($reco_banner_type, 2);
  509. $books->transform(function ($item) {
  510. $result = $this->getBidCidFromUrl($item->redirect_url);
  511. $item->bid = $result['bid'];
  512. $item->cid = $result['cid'];
  513. if ($result['cid']) {
  514. $item->redirect_url = "views/Reader";
  515. } else {
  516. $item->redirect_url = "views/Detail";
  517. }
  518. return $item;
  519. });
  520. return response()->success($books);
  521. }
  522. /**
  523. * 阅爱小说任务轮播图
  524. */
  525. public function recommenYueAi()
  526. {
  527. $user = (new QappUserService)->getGolableUser();
  528. if(isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  529. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  530. $data = config('home.yueai');
  531. $books = $data['task_banner'];
  532. $bids = BookConfigService::getAvailableBIdsbyBids(array_column($books,'bid'),$this->distribution_channel_id,false);
  533. if($orderRecord && !empty($bids)){
  534. foreach ($books as &$value){
  535. $value['bid'] =Hashids::encode($value['bid']);
  536. $value['redirect_url '] = empty($value['cid']) ? "views/Detail" : "views/Reader";
  537. }
  538. unset($value);
  539. return response()->success($books);
  540. }
  541. }
  542. $reco_banner_type = ['FEMALE', 'PUBLIC'];
  543. $books = (new RecoBannerService)->getByType($reco_banner_type, 2);
  544. $books->transform(function ($item) {
  545. $result = $this->getBidCidFromUrl($item->redirect_url);
  546. $item->bid = $result['bid'];
  547. $item->cid = $result['cid'];
  548. if ($result['cid']) {
  549. $item->redirect_url = "views/Reader";
  550. } else {
  551. $item->redirect_url = "views/Detail";
  552. }
  553. return $item;
  554. });
  555. return response()->success($books);
  556. }
  557. /**
  558. * 限免
  559. */
  560. public function free(int $sex)
  561. {
  562. $result = BookConfigService::findFreeBooks($sex);
  563. return response()->success($result);
  564. }
  565. public function yueaiBackRecom(Request $request)
  566. {
  567. $package = $request->header('x-package', '');
  568. if (empty($package) || $package != 'com.beidao.kuaiying.yueai') {
  569. return response()->success([]);
  570. }
  571. $user = (new QappUserService)->getGolableUser();
  572. if(isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  573. $bid = BookConfigService::getAvailableBIdsbyBids([58238,60534,63220,14500,13254,63221,63548,14022,59334,58888,63417,61701],$this->distribution_channel_id,false);
  574. if (!empty($bid)){
  575. $bid = array_random($bid,4);
  576. }
  577. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  578. if($orderRecord && count($bid) >= 4){
  579. $where = ['is_on_shelf' => [1,2],'bids' => $bid];
  580. // $books = BookConfigService::getBooksByIds($bid,[],false);
  581. $books = BookConfigService::getBookLists($where,[],false);
  582. return response()->collection(new BookTransformer(), $books);
  583. }
  584. }
  585. return response()->success([]);
  586. $where = ['is_on_shelf' => [2]];
  587. $where['channel_id'] = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
  588. $books = BookConfigService::getBooks($where, [], 4);
  589. return response()->collection(new BookTransformer(), $books);
  590. }
  591. public function shelfRecom(Request $request)
  592. {
  593. $category_id = $request->input('category_id');
  594. $bid = $request->input('bid');
  595. $package = $request->header('x-package', '');
  596. if (empty($package) || $package != 'com.beidao.kuaiying.yueai') {
  597. return response()->success([]);
  598. }
  599. return response()->success([]);
  600. $user = (new QappUserService)->getGolableUser();
  601. if(isset($user->uid) && !empty($user->uid) && $user->send_order_id > 0){
  602. $bid = BookConfigService::getAvailableBIdsbyBids([58238,60534,63220,14500,13254,63221,63548,14022,59334,58888,63417,61701],$this->distribution_channel_id,false);
  603. if (!empty($bid)){
  604. $bid = array_random($bid,4);
  605. }
  606. $orderRecord = ChapterOrderService::hasUserRecord($user->uid);
  607. if($orderRecord && count($bid) > 1){
  608. $where = ['is_on_shelf' => [1,2],'bids' => $bid];
  609. // $books = BookConfigService::getBooksByIds($bid,[],false);
  610. $books = BookConfigService::getBookLists($where,[],false);
  611. return response()->collection(new BookTransformer(), $books);
  612. }
  613. }
  614. return response()->success([]);
  615. $where = ['is_on_shelf' => [2]];
  616. $where['channel_id'] = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
  617. $books = BookConfigService::getBooks($where, [], 4);
  618. return response()->collection(new BookTransformer(), $books);
  619. }
  620. private function getSpecialLibrary(Request $request)
  621. {
  622. $where = [];
  623. $order = [];
  624. $where['is_on_shelf'] = [2,4,7];
  625. $category_id = $request->input('category_id');
  626. if ($category_id) {
  627. if ($category_id == 1) {
  628. $where['channel_name'] = '男频';
  629. } elseif ($category_id == 2) {
  630. $where['channel_name'] = '女频';
  631. } else {
  632. $where['category_id'] = $category_id;
  633. }
  634. }
  635. $key = $request->input('key');
  636. $uid = $request->input('uid', 0);
  637. if ($key && $uid && is_numeric($uid)) {
  638. BookConfigService::saveUserSearchLog($key, $uid);
  639. }
  640. $where['key'] = $key;
  641. $order_field = $request->input('order_field');
  642. $order_seq = $request->input('order_seq');
  643. if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
  644. if ($order_field == 'update') {
  645. $order = ['book_configs.updated_at', 'desc'];
  646. } elseif ($order_field == 'create') {
  647. $order = ['book_configs.created_at', 'desc'];
  648. } else {
  649. $order = [$order_field, 'desc'];
  650. }
  651. if ($order_seq == 'asc') {
  652. $order = [$order_field, 'asc'];
  653. }
  654. if ($order_seq == 'desc') {
  655. $order = [$order_field, 'desc'];
  656. }
  657. }
  658. // 审核状态默认值
  659. $package = $request->header('x-package', '');
  660. $brand = $request->header('x-nbrand', '');
  661. $codeVersion = $request->header('x-codeversion', '');
  662. if ($order_field === 'recommend_index' && Utils::checkIsAudit($package, $brand, $codeVersion)) {
  663. $order = ['book_configs.bid', 'desc'];
  664. }
  665. $status = $request->input('status');
  666. if ($status != '') {
  667. $where['status'] = $status;
  668. }
  669. // 搜索关键词的情况下,屏蔽书籍完本状态
  670. if ($key && isset($where['status'])) {
  671. unset($where['status']);
  672. }
  673. $page_size = $request->input('page_size', 15);
  674. $where['channel_id'] = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
  675. $books = BookConfigService::getBooks($where, $order, $page_size);
  676. return response()->pagination(new BookTransformer,$books);
  677. }
  678. }