| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 | <?phpnamespace App\Http\Controllers\Wap\User;use Illuminate\Http\Request;use App\Http\Controllers\Wap\BaseController;use Redis;use App\Modules\Book\Services\UserShelfBooksService;use App\Http\Controllers\Wap\User\Transformers\UserShelfBooksTransformer;use App\Modules\User\Services\ReadRecordService;use Hashids;use Log;class UserShelfBooksController extends BaseController{    /**     * @apiDefine UserShelfBooks 书架     */    /**     * @apiVersion 1.0.0     * @apiDescription 获取书架     * @api {get} userShelfBooks 获取书架     * @apiGroup UserShelfBooks     * @apiName getChapter     * @apiSuccess {int}         code 状态码     * @apiSuccess {String}      msg  信息     * @apiSuccess {object}      data 结果集     * @apiSuccess {Int}         data.id   编号     * @apiSuccess {String}      data.distribution_channel_id   分销     * @apiSuccess {Int}         data.uid   uid     * @apiSuccess {Int}         data.bid   bid     * @apiSuccess {Int}         data.book_name   书名     * @apiSuccess {Int}         data.cover   封面     * @apiSuccess {Int}         data.last_cid   章节id     * @apiSuccessExample {json} Success-Response:     *     HTTP/1.1 200 OK     *     {     *       code: 0,     *       msg: "",     *       data: {     *          [     *               {     *                   id: 6,     *                   uid: 4,     *                   distribution_channel_id: 1,     *                   bid: 1,     *                   book_name: "京华烟云",     *                   cover: "https://leyue-bucket.oss-cn-hangzhou.aliyuncs.com/ycsd_cover/covermiddle/0/1.jpg",     *                   updated_at: 1511783068,     *                   last_cid: 4     *               },     *               {     *                   id: 7,     *                   uid: 4,     *                   distribution_channel_id: 1,     *                   bid: 1,     *                   book_name: "我来好好爱你",     *                   cover: "https://leyue-bucket.oss-cn-hangzhou.aliyuncs.com/ycsd_cover/covermiddle/0/11.jpg",     *                   updated_at: 1511783068,     *                   last_cid: 4     *               }     *           ]     *       }     */    public function index(Request $request){        if(!$this->checkUid()){            return response()->error('WAP_NOT_LOGIN');        }        $res = UserShelfBooksService::getUserShelfBooksListByUid($this->uid,1,true);        if($res->isEmpty()){            return response()->success();        }        $record = ReadRecordService::getReadRecord($this->uid);        //if(empty($record))   return response()->success($res);        foreach ($res as &$v){            $v['last_cid'] = $v['first_cid'];            foreach ($record as $val){                if($v['bid'] == $val['bid']){                    $v['updated_at'] = $val['time'];                    $v['last_cid'] = $val['cid'];                    break;                }            }        }        /*        usort($res,function($a,$b){            if($a['updated_at'] >= $b['updated_at']) return -1;            return 1;        });*/        return response()->collection(new UserShelfBooksTransformer(),$res);    }    /**     * @apiVersion 1.0.0     * @apiDescription 添加书架     * @api {post} userShelfBooks 添加书架     * @apiGroup UserShelfBooks     * @apiName addShelf     * @apiParam   {int}         bid bid     * @apiSuccess {int}         code 状态码     * @apiSuccess {String}      msg  信息     * @apiSuccess {object}      data 结果集     * @apiSuccessExample {json} Success-Response:     *     HTTP/1.1 200 OK     *     {     *       code: 0,     *       msg: "",     *       data: {}     */    public function addShelf(Request $request){        if(!$this->checkUid()){            return response()->error('WAP_NOT_LOGIN');        }        $param = $request->except('_url');        if(checkParam($param,['bid'])){            return response()->error('WAP_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('WAP_HAD_ON_SHELF');        }        if($res){            return response()->success($res);        }        return response()->error('WAP_SYS_ERROR');    }    /**     * @apiVersion 1.0.0     * @apiDescription 删除书架     * @api {get} userShelfBooks/delete 删除书架     * @apiGroup UserShelfBooks     * @apiName delShelf     * @apiParam   {int}         bid bid     * @apiSuccess {int}         code 状态码     * @apiSuccess {String}      msg  信息     * @apiSuccess {object}      data 结果集     * @apiSuccessExample {json} Success-Response:     *     HTTP/1.1 200 OK     *     {     *       code: 0,     *       msg: "",     *       data: {}     */    public function delShelf(Request $request){        if(!$this->checkUid()){            return response()->error('WAP_NOT_LOGIN');        }        $bid = $request->input('bid');        if(empty($bid)) return response()->error('WAP_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('WAP_SYS_ERROR');    }        /**     * @apiVersion 1.0.0     * @apiDescription 是否在书架上     * @api {get} userShelfBooks/isonshelf 是否在书架上     * @apiGroup UserShelfBooks     * @apiName isOnshelf     * @apiParam   {int}         bid bid     * @apiSuccess {int}         code 状态码     * @apiSuccess {String}      msg  信息     * @apiSuccess {object}      data 结果集     * @apiSuccess {Int}         data.is_on 是否在书架上(0|1)     * @apiSuccessExample {json} Success-Response:     *     HTTP/1.1 200 OK     *     {     *       code: 0,     *       msg: "",     *       data: {     *               is_on:0     *           }     */    public function  isOnshelf(Request $request){        if(!$this->checkUid()){            return response()->error('NOT_LOGIN');        }        $bid = $request->input('bid');        if(!$bid) return response()->error('LACK_PARAM');        $bid = Hashids::decode($bid)[0];        //$param['uid'] = $this->uid;        //$res = $this->apiClient->get($this->joinUrl('Read/isonshelf'),$param);        $res = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid,$bid);        if($res){            $data['is_on'] = 1;        }else{            $data['is_on'] = 0;        }        return response()->success($data);    }}
 |