BookController.php 24 KB

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