uid); 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 添加书架 * @apiParam {String} [token] token * @apiHeader {String} [Authorization] token 两个token任选其一 * @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){ $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'); } /** * @apiVersion 1.0.0 * @apiDescription 删除书架 * @api {get} userShelfBooks/delete 删除书架 * @apiParam {String} [token] token * @apiHeader {String} [Authorization] token 两个token任选其一 * @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){ $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'); } /** * @apiVersion 1.0.0 * @apiDescription 是否在书架上 * @api {get} userShelfBooks/isonshelf 是否在书架上 * @apiParam {String} [token] token * @apiHeader {String} [Authorization] token 两个token任选其一 * @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){ $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); } }