123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662 |
- <?php
- namespace App\Http\Controllers\Xchengxu\Book;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Xchengxu\BaseController;
- use App\Http\Controllers\Xchengxu\Book\Transformers\BookTransformer;
- use App\Modules\Book\Services\BookConfigService;
- use App\Modules\Book\Services\UserShelfBooksService;
- use App\Modules\Book\Services\ChapterService;
- use Hashids;
- use App\Modules\Subscribe\Services\YearOrderService;
- use Log;
- class BookController extends BaseController
- {
-
-
- public function index(Request $request,$bid){
- if(!$this->checkUid()){
- return response()->error('XCX_NOT_LOGIN');
- }
-
-
- $bid = Hashids::decode($bid)[0];
- $book_info = BookConfigService::getBookById($bid);
- if(!$book_info){
- return response()->error('XCX_SYS_ERROR');
- }
- if(!in_array($book_info->is_on_shelf,[1,2])){
- return response()->error('XCX_OFF_SHELF');
- }
- $is_on_shelf = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid,$bid);
- $book_info['is_on_user_shelf'] = 0;
- if($is_on_shelf){
- $book_info['is_on_user_shelf'] = 1;
- }
- $last_chapter = ChapterService::getChapterNameById($book_info['last_cid'],$bid);
- $book_info['last_chapter_is_vip'] = $last_chapter['is_vip'];
- return response()->item(new BookTransformer(), $book_info);
- }
-
- public function getBookLists(Request $request,$sex){
- if(!$this->checkUid()){
-
- }
- if($sex == 'male'){
- $type = [
- 'BOOK_MALE_LOOP',
- 'BOOK_MALE_HOT',
- 'BOOK_MALE_ZHIBO',
- 'BOOK_MALE_RECOM',
- 'BOOK_MALE_NEW_RECOM'
- ];
- }else{
- $type = [
- 'BOOK_FEMALE_LOOP',
- 'BOOK_FEMALE_HOT',
- 'BOOK_FEMALE_ZHIBO',
- 'BOOK_FEMALE_RECOM',
- 'BOOK_FEMALE_NEW_RECOM'
- ];
- }
- $book = [
- ['type'=>'lunbo','lable'=>'','books'=>''],
- ['type'=>'hot','lable'=>'热门推荐','books'=>''],
- ['type'=>'zhibo','lable'=>'神书直播','books'=>''],
- ['type'=>'recom','lable'=>'编辑推荐','books'=>''],
- ['type'=>'new_recom','lable'=>'新书推荐','books'=>''],
- ];
- foreach ($type as $key=>$v){
- $book[$key]['books'] = collectionTransform(new BookTransformer,BookConfigService::getBooksByIds(explode(',',env($v))));
- }
- return response()->success($book);
- }
-
- public function library(Request $request){
- $where = [];
-
- $order = [];
- $where['is_on_shelf'] = [1,2];
- $category_id = $request->input('category_id');
- if($category_id){
- if($category_id == 1){
- $where['channel_name'] = '男频';
- }elseif($category_id == 2){
- $where['channel_name'] = '女频';
- }else{
- $where['category_id'] = $category_id;
- }
- }
- $key = $request->input('key');
- $where['key'] = $key;
- $order_field = $request->input('order_field');
- $order_seq = $request->input('order_seq');
- if($order_field != '' && in_array($order_field,['recommend_index','click_count','update','size','create'])){
- if($order_field == 'update'){
- $order = ['book_configs.updated_at','desc'];
- }elseif ($order_field == 'create') {
- $order = ['book_configs.created_at','desc'];
- }
- else{
- $order = [$order_field,'desc'];
- }
- if($order_seq == 'asc'){
- $order = [$order_field,'asc'];
- }
- if($order_seq == 'desc'){
- $order = [$order_field,'desc'];
- }
- }
- $status = $request->input('status');
- if($status != ''){
- $where['status'] = $status;
- }
- $page_size = $request->input('page_size',15);
- $books = BookConfigService::getBooks($where,$order,$page_size);
- return response()->pagination(new BookTransformer,$books);
- }
-
- public function similarRecom (Request $request){
- if(!$this->checkUid()){
-
- }
- $category_id = $request->input('category_id');
- $bid = $request->input('bid');
- if(empty($bid) || empty($category_id)){
- return response()->error('PARAM_ERROR');
- }
- $bid = Hashids::decode($bid)[0];
- $where = ['category_id'=>$category_id,'is_on_shelf'=>[1,2]];
- $books = BookConfigService::getBooks($where,[],4);
- $data = [];
- foreach ($books as $v){
- if($v->bid != $bid && count($data) <3){
- $data[] = $v;
- }
- }
- return response()->collection(new BookTransformer(),$data);
- }
-
- public function readOverRecommend(Request $request){
- if(!$this->checkUid()){
-
- }
- $bid = $request->input('bid');
- if(empty($bid)){
- return response()->error('PARAM_ERROR');
- }
- $bid = Hashids::decode($bid)[0];
- $book_info = BookConfigService::getBookById($bid);
- $res = BookConfigService::getRecommendBooks($bid,$book_info->category_id);
- return response()->collection(new BookTransformer(),$res);
- }
-
- public function rank(Request $request){
- if(!$this->checkUid()){
-
- }
- $type = $request->input('type');
- $time = $request->input('time');
- if($type == 1){
-
- if($time == 1){
-
- $midstr = env('CLICK_RANK_MALE_WEEK','677,694,638,642,641,673,635,639,637,4');
- $fidstr = env('CLICK_RANK_FEMALE_WEEK','614,636,587,48,1,6,354,99,159,355');
- }elseif($time == 2){
-
- $midstr = env('CLICK_RANK_MALE_MONTH','757,775,780,612,638,635,694,639,642,693');
- $fidstr = env('CLICK_RANK_FEMALE_MONTH','324,614,6,1,5,10,48,57,41,58');
- }else{
- $midstr = env('CLICK_RANK_MALE_TOTAL','757,775,780,612,634,677,694,638,642,635');
- $fidstr = env('CLICK_RANK_FEMALE_TOTAL','324,614,636,1,5,6,521,10,41,48');
- }
- $female = collectionTransform(new BookTransformer,BookConfigService::getBooksByIds(explode(',',$fidstr)));
- $male = collectionTransform(new BookTransformer,BookConfigService::getBooksByIds(explode(',',$midstr)));
- }elseif($type == 2){
-
- if($time == 1){
-
- $midstr = env('WORD_RANK_MALE_WEEK','638,673,635,637,680,642,86,774,764,736');
- $fidstr = env('WORD_RANK_FEMALE_WEEK','48,58,324,354,159,262,7,9,11,525');
- }elseif($time == 2){
-
- $midstr = env('WORD_RANK_MALE_MONTH','2,638,642,635,639,4,743,680,736,73');
- $fidstr = env('WORD_RANK_FEMALE_MONTH','1,10,48,58,324,354,159,442,355,464');
- }else{
- $midstr = env('WORD_RANK_MALE_TOTAL','638,677,694,635,612,693,634,642,775,780');
- $fidstr = env('WORD_RANK_FEMALE_TOTAL','57,636,614,1,10,48,58,324,354,99');
- }
- $female = collectionTransform(new BookTransformer,BookConfigService::getBooksByIds(explode(',',$fidstr)));
- $male = collectionTransform(new BookTransformer,BookConfigService::getBooksByIds(explode(',',$midstr)));
- }
- elseif ($type == 3) {
-
- if($time == 1){
-
- $midstr = env('NEW_RANK_MALE_WEEK','635,639,4,642,629,446,741,737,731,86');
- $fidstr = env('NEW_RANK_FEMALE_WEEK','135,587,617,625,627,467,213,233,529,357');
- }elseif($time == 2){
-
- $midstr = env('NEW_RANK_MALE_MONTH','757,775,780,612,634,677,694,638,642,635');
- $fidstr = env('NEW_RANK_FEMALE_MONTH','33,39,40,51,587,617,625,627,50,60');
- }else{
- $midstr = env('NEW_RANK_MALE_TOTAL','693,641,673,637,4,3,612,634,677,694');
- $fidstr = env('NEW_RANK_FEMALE_TOTAL','284,30,33,39,40,51,587,50,60,357');
- }
- $female = collectionTransform(new BookTransformer,BookConfigService::getBooksByIds(explode(',',$fidstr)));
- $male = collectionTransform(new BookTransformer,BookConfigService::getBooksByIds(explode(',',$midstr)));
- }else{
- return response()->error('PARAM_ERROR');
- }
- $data = ['male'=>$male,'female'=>$female];
- return response()->success($data);
- }
- }
|