12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\common\model;
- use app\common\library\Redis;
- use think\Model;
- class BookListCh extends Model
- {
- // 表名
- protected $table = 'book_list_ch';
-
- // 自动写入时间戳字段
- 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 = 'BLPC:'. $id; //书单信息缓存
- if ($redis->exists($key)) {
- $result = $redis->hGetAll($key);
- } else {
- $row = $this->where('id', 'EQ', $id)->find();
- if (!empty($row)) {
- $data = $row->toArray();
- //如果是vip 可以存一下所有的子账号
- $createAdminId = $row['admin_id'];
- $bindRows = model("VipAdminBind")
- ->where('admin_id_master', 'eq', $createAdminId)
- ->select();
- if ($bindRows) {
- $adminIds = array_column($bindRows, 'admin_id_slave');
- $data['admin_ids'] = json_encode($adminIds);
- } else {
- $data['admin_ids'] = json_encode([$createAdminId]);
- }
- $redis->hMSet($key, $data);
- $redis->expire($key, 600);
- $result = $data;
- }
- }
- return $result;
- }
- public function rmCache($id)
- {
- if (!empty($id)) {
- $redis = Redis::instance();
- $key = 'BLPC:'. $id; //书单信息缓存
- if ($redis->exists($key)) {
- $redis->del($key);
- }
- }
- return true;
- }
- }
|