BookController.php 48 KB

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