123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace app\common\model;
- use app\common\library\Redis;
- use app\main\constants\CacheConstants;
- use app\main\constants\ExportFansConstants;
- use think\Model;
- class ExportFans extends Model
- {
- // 表名
- protected $table = 'export_fans';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- 'status_text',
- 'pay_status_text',
- 'limittime_text'
- ];
-
-
- public function getStatusList()
- {
- return ['1' => __('Status 1'),'2' => __('Status 2')];
- }
- public function getPayStatusList()
- {
- return ['1' => __('Pay_status 1'),'2' => __('Pay_status 2')];
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['status'];
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getPayStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['pay_status'];
- $list = $this->getPayStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getLimittimeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['limittime'];
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setLimittimeAttr($value)
- {
- return $value && !is_numeric($value) ? strtotime($value) : $value;
- }
- public function getStarttimeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['starttime'];
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setStarttimeAttr($value)
- {
- return $value && !is_numeric($value) ? strtotime($value) : $value;
- }
- public function getOne($id)
- {
- $cacheKey = CacheConstants::getExportFansRow($id);
- if (!$data = Redis::instance()->hGetAll($cacheKey)) {
- $data = $this->where('id', $id)->where('status', ExportFansConstants::STATUS_YES)->find();
- if ($data) {
- $data = $data->getData();
- Redis::instance()->hMSet($cacheKey, $data);
- } else {
- $data = ['id' => 0];
- Redis::instance()->hMSet($cacheKey, $data);
- }
- Redis::instance()->expire($cacheKey, 1800);
- }
- if (!$data['id']) {
- $data = false;
- }
- return $data;
- }
- }
|