|
@@ -19,11 +19,24 @@ use DB;
|
|
|
|
|
|
/**
|
|
|
* @method static delReadRecordStatic(int $uid, array $bids) 删除最近阅读记录
|
|
|
+ * @method static getBookReadRecordStatic(int $uid, int $bid) 获取单本书籍的最近阅读记录
|
|
|
*/
|
|
|
class ReadRecordService
|
|
|
{
|
|
|
#region 以后按照这种方式写静态方法
|
|
|
use BaseService;
|
|
|
+
|
|
|
+ public function getBookReadRecord(int $uid, int $bid)
|
|
|
+ {
|
|
|
+ $record = Redis::hGet('book_read:' . $uid, $bid);
|
|
|
+ if ($record) {
|
|
|
+ $cid = explode('_', $record)[1];
|
|
|
+ $name = self::cid2ChapterName($cid);
|
|
|
+ return ['record_chapter_id' => $cid, 'record_chapter_name' => $name];
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 删除最近阅读记录
|
|
|
* @param int $uid
|
|
@@ -165,7 +178,7 @@ class ReadRecordService
|
|
|
|
|
|
/**
|
|
|
* 添加阅读记录升级版
|
|
|
- * @param $param
|
|
|
+ * @param array $param
|
|
|
*/
|
|
|
public static function addReadRecord($param)
|
|
|
{
|
|
@@ -228,7 +241,6 @@ class ReadRecordService
|
|
|
public static function getFirstReadRecord($uid)
|
|
|
{
|
|
|
self::delBookBase($uid);
|
|
|
- //Redis::hget('book_base:' . $uid, 'last_read', "{$bid}_{$cid}_{$book_name}_{$chapter_name}_" . time());
|
|
|
$record = Redis::hget('book_read:' . $uid, 'last_read');
|
|
|
if ($record) {
|
|
|
$record_arr = explode('_', $record);
|
|
@@ -295,20 +307,16 @@ class ReadRecordService
|
|
|
*/
|
|
|
public static function bid2BookName($bid)
|
|
|
{
|
|
|
- $book_name = null;
|
|
|
- if (is_null($book_name)) {
|
|
|
- $book_key = 'wap:string:book:' . $bid;
|
|
|
- $book_name = Redis::get($book_key);
|
|
|
- Redis::EXPIRE($book_key, 3600);
|
|
|
- if (!$book_name) {
|
|
|
- $book_name = '';
|
|
|
- $book_info = BookConfigService::getBookById($bid);
|
|
|
- if ($book_info && isset($book_info->book_name)) {
|
|
|
- $book_name = $book_info->book_name;
|
|
|
- }
|
|
|
+ $book_key = 'wap:string:book:' . $bid;
|
|
|
+ $book_name = Redis::get($book_key);
|
|
|
+ Redis::EXPIRE($book_key, 3600);
|
|
|
+ if (!$book_name) {
|
|
|
+ $book_name = '';
|
|
|
+ $book_info = BookConfigService::getBookById($bid);
|
|
|
+ if ($book_info && isset($book_info->book_name)) {
|
|
|
+ $book_name = $book_info->book_name;
|
|
|
}
|
|
|
}
|
|
|
- return $book_name;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -318,17 +326,14 @@ class ReadRecordService
|
|
|
*/
|
|
|
public static function cid2ChapterName($cid)
|
|
|
{
|
|
|
- $chapter_name = null;
|
|
|
- if (is_null($chapter_name)) {
|
|
|
- $chapter_key = 'wap:string:chapter:' . $cid;
|
|
|
- $chapter_name = Redis::get($chapter_key);
|
|
|
- Redis::EXPIRE($chapter_key, 3600);
|
|
|
- if (!$chapter_name) {
|
|
|
- $chapter_name = '';
|
|
|
- $chapter_info = Chapter::getChapterNameById($cid);
|
|
|
- if ($chapter_info && isset($chapter_info->name)) {
|
|
|
- $chapter_name = $chapter_info->name;
|
|
|
- }
|
|
|
+ $chapter_key = 'wap:string:chapter:' . $cid;
|
|
|
+ $chapter_name = Redis::get($chapter_key);
|
|
|
+ Redis::EXPIRE($chapter_key, 3600);
|
|
|
+ if (!$chapter_name) {
|
|
|
+ $chapter_name = '';
|
|
|
+ $chapter_info = Chapter::getChapterNameById($cid);
|
|
|
+ if ($chapter_info && isset($chapter_info->name)) {
|
|
|
+ $chapter_name = $chapter_info->name;
|
|
|
}
|
|
|
}
|
|
|
return $chapter_name;
|
|
@@ -341,7 +346,6 @@ class ReadRecordService
|
|
|
*/
|
|
|
public static function delBookNameAndChapter($uid)
|
|
|
{
|
|
|
- //Redis::hset('book_base:' . $uid, 'last_read', "{$bid}_{$cid}_{$book_name}_{$chapter_name}_" . time()) ;
|
|
|
$base_record = Redis::hget('book_base:' . $uid, 'last_read');
|
|
|
if ($base_record) {
|
|
|
$record_arr = explode('_', $base_record);
|