<?php

namespace App\Http\Controllers\Wap\Book;

use App\Http\Controllers\Wap\Book\Transformers\RedBookChapterListTransformer;
use App\Http\Controllers\Wap\Book\Transformers\RedBookTransformer;
use App\Modules\Book\Models\BookSearchStat;
use App\Modules\Book\Services\BookSearchStatService;
use App\Modules\Book\Services\BookUrgeUpdateService;
use App\Modules\RecommendBook\Services\RecommendService;
use Illuminate\Http\Request;
use App\Http\Controllers\Wap\BaseController;
use App\Http\Controllers\Wap\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;
use Illuminate\Support\Facades\Cache;
use Redis;
use DB;

class RedBookController extends BaseController
{

    public function getLoop() {
       $res =  DB::table('red_books')->get();
       return response()->collection(new RedBookTransformer(),$res);
    }

    public function getBookDetail(Request $request) {
        $id = $request->input('id','');
        if(empty($id)) {
            return response()->error('PARAM_ERROR');
        }

        $detail = DB::table('red_books')->where('id',$id)->first();
        return response()->success(json_decode(json_encode($detail),true));
    }

    public function getChapterList(Request $request) {
        $id = $request->input('id','');
        if(empty($id)) {
            return response()->error('PARAM_ERROR');
        }
        $catalogs = DB::table('red_book_catalogs')
            ->where('red_bid',$id)
            ->orderBy('sequence','asc')
            ->paginate();
        return response()->pagination(new RedBookChapterListTransformer,$catalogs);
    }
}
