SpecialRechargeTpl.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\common\model;
  3. use app\common\library\Redis;
  4. use think\Model;
  5. class SpecialRechargeTpl extends Model
  6. {
  7. // 表名
  8. protected $table = 'special_recharge_tpl';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. // 追加属性
  15. protected $append = [
  16. 'status_text'
  17. ];
  18. public function getStatusList()
  19. {
  20. return ['normal' => __('Status normal'),'hidden' => __('Status hidden')];
  21. }
  22. public function getStatusTextAttr($value, $data)
  23. {
  24. $value = $value ? $value : $data['status'];
  25. $list = $this->getStatusList();
  26. return isset($list[$value]) ? $list[$value] : '';
  27. }
  28. public function getOne($id)
  29. {
  30. $redisKey = 'SUT:'.$id;
  31. if (Redis::instance()->exists($redisKey)) {
  32. return json_decode(Redis::instance()->get($redisKey), true);
  33. }
  34. $row = $this->get($id);
  35. $result = $row ? $row->toArray() : [];
  36. Redis::instance()->set($redisKey, json_encode($result), 86400);
  37. return $result;
  38. }
  39. }