ChapterEdited.php 947 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2019/5/14
  6. * Time: 上午9:40
  7. */
  8. namespace app\common\model;
  9. use app\common\library\Redis;
  10. use app\main\constants\CacheConstants;
  11. use think\Model;
  12. class ChapterEdited extends Model
  13. {
  14. protected $pk = 'chapter_id';
  15. // 表名
  16. protected $table = 'chapter_edited';
  17. // 自动写入时间戳字段
  18. protected $autoWriteTimestamp = 'int';
  19. // 定义时间戳字段名
  20. protected $createTime = 'create_time';
  21. protected $updateTime = 'update_time';
  22. public function getChapterFromDb($chapter_id)
  23. {
  24. $cacheKey = CacheConstants::BOOK_EDITED_CHAPTER . $chapter_id;
  25. if ($data = Redis::instance()->get($cacheKey)) {
  26. $decode = json_decode($data, true);
  27. $decode['content'] = str_replace(['<p>', '</p>'], ['', "\n"], $decode['content']);
  28. return $decode;
  29. } else {
  30. return false;
  31. }
  32. }
  33. }