Gift.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\model\gift;
  3. use think\Model;
  4. class Gift extends Model
  5. {
  6. // 表名
  7. protected $name = 'gift';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_text',
  17. 'complex_text',
  18. 'timelimit_text'
  19. ];
  20. public function getTypeList()
  21. {
  22. return ['0' => __('Type 0'), '1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')];
  23. }
  24. public function getComplexList()
  25. {
  26. return ['1' => __('Complex 1'), '0' => __('Complex 0')];
  27. }
  28. public function getBoxtypeList()
  29. {
  30. return ['0' => __('非宝箱礼物'), '1' => __('青铜宝箱'), '2' => __('黄金宝箱'), '3' => __('荣耀黄金宝箱'), '4' => __('荣耀紫金宝箱')];
  31. }
  32. public function getTimelimitList()
  33. {
  34. return ['1' => __('Timelimit 1'), '0' => __('Timelimit 0')];
  35. }
  36. public function getTypeTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  39. $list = $this->getTypeList();
  40. return isset($list[$value]) ? $list[$value] : '';
  41. }
  42. public function getComplexTextAttr($value, $data)
  43. {
  44. $value = $value ? $value : (isset($data['complex']) ? $data['complex'] : '');
  45. $list = $this->getComplexList();
  46. return isset($list[$value]) ? $list[$value] : '';
  47. }
  48. public function getTimelimitTextAttr($value, $data)
  49. {
  50. $value = $value ? $value : (isset($data['timelimit']) ? $data['timelimit'] : '');
  51. $list = $this->getTimelimitList();
  52. return isset($list[$value]) ? $list[$value] : '';
  53. }
  54. public function gifttype()
  55. {
  56. return $this->belongsTo('app\admin\model\gift\Type', 'type', 'id', [], 'LEFT')->setEagerlyType(0);
  57. }
  58. }