BookController.php 48 KB

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