123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace app\common\model;
- use app\common\library\Redis;
- use think\Model;
- class ClientConfig extends Model
- {
- // 表名
- protected $table = 'client_config';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- 'fun_type_text',
- 'type_text',
- 'user_pay_type_text',
- 'status_text',
- 'position_text',
- ];
-
-
- public function getFunTypeList()
- {
- return ['1' => __('Fun_type 1'),'2' => __('Fun_type 2'),'3' => __('Fun_type 3')];
- }
- public function getTypeList()
- {
- return ['1' => __('Type 1'),'2' => __('Type 2'),'3' => __('Type 3'),'4' => __('Type 4')];
- }
- public function getUserPayTypeList()
- {
- return ['0' => __('User_pay_type 0'),'1' => __('User_pay_type 1'),'2' => __('User_pay_type 2')];
- }
- public function getStatusList()
- {
- return ['1' => __('Status 1'),'0' => __('Status 0')];
- }
- public function getPositionList()
- {
- return ['1' => __('书架'),'2' => __('个人中心'), '3' => __('书城首页')];
- }
- public function getPositionTextAttr($value, $data)
- {
- $value = $value ? $value : $data['position'];
- $arr = array_filter(explode(',', $value));
- if (!empty($arr)) {
- $list = $this->getPositionList();
- $str = '';
- foreach ($arr as $row) {
- $str .= $list[$row]. ',';
- }
- $str = trim($str, ',');
- }
- return isset($str) ? $str : '';
- }
- public function getFunTypeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['fun_type'];
- $list = $this->getFunTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getTypeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['type'];
- $list = $this->getTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getUserPayTypeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['user_pay_type'];
- $list = $this->getUserPayTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['status'];
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- /**
- * 获取配置的内容
- * @param null $id
- */
- public function getOne($id = null)
- {
- $row = [];
- $redisKey = 'CCP:'.$id;
- if (Redis::instance()->exists($redisKey)) {
- $row = Redis::instance()->hGetAll($redisKey);
- } else {
- $row = $this->where('id', 'eq', $id)->find();
- if ($row) {
- $row = $row->toArray();
- Redis::instance()->hMSet($redisKey, $row);
- Redis::instance()->expire($redisKey, 3600);
- }
- }
- return $row;
- }
- /**
- * 删除缓存
- * @param null $id
- */
- public function delCache($id = null)
- {
- $redisKey = 'CCP:'.$id;
- return Redis::instance()->del($redisKey);
- }
- }
|