Gift.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. 'is_big_text',
  17. 'complex_text',
  18. 'timelimit_text'
  19. ];
  20. public function getIsBigList()
  21. {
  22. return ['0' => __('Is_big 0'), '1' => __('Is_big 1')];
  23. }
  24. public function getTypeList()
  25. {
  26. return ['0' => __('Type 0'), '1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')];
  27. }
  28. public function getComplexList()
  29. {
  30. return ['1' => __('Complex 1'), '0' => __('Complex 0')];
  31. }
  32. public function getBoxtypeList()
  33. {
  34. return ['0' => __('非宝箱礼物'), '1' => __('青铜宝箱'), '2' => __('黄金宝箱'), '3' => __('荣耀黄金宝箱'), '4' => __('荣耀紫金宝箱')];
  35. }
  36. public function getTimelimitList()
  37. {
  38. return ['1' => __('Timelimit 1'), '0' => __('Timelimit 0')];
  39. }
  40. public function getTypeTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  43. $list = $this->getTypeList();
  44. return isset($list[$value]) ? $list[$value] : '';
  45. }
  46. public function getIsBigTextAttr($value, $data)
  47. {
  48. $value = $value ? $value : (isset($data['is_big']) ? $data['is_big'] : '');
  49. $list = $this->getIsBigList();
  50. return isset($list[$value]) ? $list[$value] : '';
  51. }
  52. public function getComplexTextAttr($value, $data)
  53. {
  54. $value = $value ? $value : (isset($data['complex']) ? $data['complex'] : '');
  55. $list = $this->getComplexList();
  56. return isset($list[$value]) ? $list[$value] : '';
  57. }
  58. public function getTimelimitTextAttr($value, $data)
  59. {
  60. $value = $value ? $value : (isset($data['timelimit']) ? $data['timelimit'] : '');
  61. $list = $this->getTimelimitList();
  62. return isset($list[$value]) ? $list[$value] : '';
  63. }
  64. public function gifttype()
  65. {
  66. return $this->belongsTo('app\admin\model\gift\Type', 'type', 'id', [], 'LEFT')->setEagerlyType(0);
  67. }
  68. }