AwardLists.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class AwardLists extends Model
  5. {
  6. // 表名
  7. protected $table = 'award_lists';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 追加属性
  14. protected $append = [
  15. 'type_text',
  16. 'state_text'
  17. ];
  18. public function getTypeList()
  19. {
  20. return ['1' => __(' 无奖励'),'2' => __('书籍'),'3' => __('Vip'),'4' => __('赠送书币'),'5' => __('抽奖次数')];
  21. }
  22. public function getStateList()
  23. {
  24. return ['1' => __('生效'),'2' => __('失效')];
  25. }
  26. public function getTypeTextAttr($value, $data)
  27. {
  28. $value = $value ? $value : $data['type'];
  29. $list = $this->getTypeList();
  30. return isset($list[$value]) ? $list[$value] : '';
  31. }
  32. public function getStateTextAttr($value, $data)
  33. {
  34. $value = $value ? $value : $data['state'];
  35. $list = $this->getStateList();
  36. return isset($list[$value]) ? $list[$value] : '';
  37. }
  38. }