BookController.php 48 KB

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