checkUid()){ return response()->error('XCX_NOT_LOGIN'); } $res = ReadRecordService::getReadRecord($this->uid); if($res){ $id_arr = []; foreach ($res as $key => $value) { $id_arr[] = $value['bid']; } $book = BookConfigService::getBooksByIds($id_arr); foreach ($res as $key => &$value) { foreach ($book as $val) { if($value['bid'] == $val->bid){ $value['cover'] = $val->cover; $value['last_chapter'] = $val->last_chapter; break; } } } $shelf = UserShelfBooksService::getUserShelfBooksListByUid($this->uid); foreach ($res as &$v){ $v['is_on_user_shelf'] = 0; foreach ($shelf as $val){ if($v['bid'] == $val->bid){ $v['is_on_user_shelf'] = 1; break; } } } } usort($res,function($a,$b){ if($a['time'] >= $b['time']) return -1; return 1; }); $res = json_encode($res); $res = json_decode($res); return response()->collection(new ReadRecordTransformer(),$res); } /** * @apiVersion 1.0.0 * @apiDescription 添加阅读记录 * @api {post} readrecord 添加阅读记录 * @apiGroup ReadRecord * @apiName addReadRecord * @apiParam {String} [token] token * @apiHeader {String} [Authorization] token 两个token任选其一 * @apiParam {Int} book_name 书名 * @apiParam {String} chapter_name 章节名 * @apiParam {Int} bid bid * @apiParam {Int} cid 章节id * @apiSuccess {int} code 状态码 * @apiSuccess {String} msg 信息 * @apiSuccess {object} data 结果集 * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * { * code: 0, * msg: "", * data:{} * */ public function addReadRecord(Request $request){ if(!$this->checkUid()){ return response()->error('XCX_NOT_LOGIN'); } $param = $request->except('_url'); if(checkParam($param,['bid','cid','chapter_name'])){ return response()->error('LACK_PARAM'); } //Redis::hset('book_read:' . $uid, $bid, "{$cid}_{$book_name}_{$chapter_name}_" . time()); $param['uid'] = $this->uid; $param['bid'] = Hashids::decode($param['bid'])[0]; $record_info = Redis::hget('book_read:'.$this->uid,$param['bid']); $param['book_name'] = 'unknown'; if($record_info){ $param['book_name'] = explode('_',$record_info)[1]; } ReadRecordService::addReadRecord($param); return response()->success(); } /** * @apiVersion 1.0.0 * @apiDescription 删除阅读记录 * @api {get} readrecord/delete 删除阅读记录 * @apiGroup ReadRecord * @apiParam {String} [token] token * @apiHeader {String} [Authorization] token 两个token任选其一 * @apiName delReadRecord * @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 delReadRecord(Request $request){ if(!$this->checkUid()){ return response()->error('XCX_NOT_LOGIN'); } $param = $request->except('_url'); if(checkParam($param,['bid'])){ return response()->error('LACK_PARAM'); } $param['bid'] = Hashids::decode($param['bid'])[0]; ReadRecordService::delReadRecord($this->uid,$param['bid']); return response()->success(); } }