123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace app\common\model;
- use app\common\library\Redis;
- use think\Model;
- class BookList extends Model
- {
- // 表名
- protected $table = 'book_list';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- 'status_text',
- ];
-
-
- public function getStatusList()
- {
- return ['normal' => __('Status normal'),'hidden' => __('Status hidden')];
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['status'];
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- /**
- * 返回详情
- * @param $id
- * @return array
- */
- public function getInfo($id)
- {
- $result = [];
- $redis = Redis::instance();
- $key = 'BLP:'. $id; //书单信息缓存
- if ($redis->exists($key)) {
- $result = $redis->hGetAll($key);
- } else {
- $result = $this->where('id', 'EQ', $id)->find();
- if (!empty($result)) {
- $redis->hMSet($key, $result->toArray());
- $redis->expire($key, 600);
- }
- }
- return $result;
- }
- public function rmCache($id)
- {
- if (!empty($id)) {
- $redis = Redis::instance();
- $key = 'BLP:'. $id; //书单信息缓存
- if ($redis->exists($key)) {
- $redis->del($key);
- }
- }
- return true;
- }
- }
|