123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- namespace App\Http\Controllers\QuickApp\User;
- use Illuminate\Http\Request;
- use App\Http\Controllers\QuickApp\BaseController;
- use Redis;
- use App\Modules\Book\Services\UserShelfBooksService;
- use App\Modules\Book\Services\ChapterService;
- use App\Http\Controllers\QuickApp\User\Transformers\UserShelfBooksTransformer;
- use App\Modules\User\Services\ReadRecordService;
- use Hashids;
- use Log;
- class UserShelfBooksController extends BaseController
- {
-
-
- public function index(Request $request){
- $res = UserShelfBooksService::getUserShelfBooksListByUid($this->uid);
- if($res->isEmpty()){
- return response()->success();
- }
- $record = ReadRecordService::getReadRecord($this->uid);
- foreach ($res as &$v){
- $bid=$v['bid'];
- $last_cid = $v['last_cid'];
- $last_chapter = ChapterService::getChapterNameByID($last_cid,$bid);
- $v['last_chapter']="最后章节:{$last_chapter['name']}";
- foreach ($record as $val){
- if($v['bid'] == $val['bid']){
- $v['updated_at'] = $val['time'];
- $recent_reading_cid = $val['cid'];
- $v['recent_cid'] = $recent_reading_cid;
- $recent_reading_chapter = ChapterService::getChapterNameById($recent_reading_cid,$bid);
- $v['recent_reading_chapter'] = "最近阅读:{$recent_reading_chapter['name']}";
- break;
- }
- }
- }
- return response()->collection(new UserShelfBooksTransformer(),$res);
- }
-
- public function addShelf(Request $request){
- $param = $request->except('_url');
- if(checkParam($param,['bid'])){
- return response()->error('LACK_PARAM');
- }
- $param['uid'] = $this->uid;
- $param['bid'] = Hashids::decode($param['bid'])[0];
- $param['distribution_channel_id'] = $this->distribution_channel_id;
- $res = null;
- try{
- $res = UserShelfBooksService::create($param);
- }catch (\Exception $e){
- return response()->error('QAPP_PARAM_ERROR');
- }
- if($res){
- return response()->success($res);
- }
- return response()->error('QAPP_SYS_ERROR');
- }
-
- public function delShelf(Request $request){
- $bid = $request->input('bid');
- if(empty($bid)) return response()->error('LACK_PARAM');
- $param['uid'] = $this->uid;
- $param['bid'] = Hashids::decode($bid)[0];
- $res = UserShelfBooksService::del($this->uid,$param['bid']);
- if($res){
- return response()->success();
- }
- return response()->error('QAPP_SYS_ERROR');
- }
-
-
- public function isOnshelf(Request $request){
- $bid = $request->input('bid');
- if(!$bid) return response()->error('LACK_PARAM');
- $bid = Hashids::decode($bid)[0];
- $res = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid,$bid);
- if($res){
- $data['is_on'] = 1;
- }else{
- $data['is_on'] = 0;
- }
- return response()->success($data);
- }
- }
|