Gift.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. 'is_show_text'
  20. ];
  21. protected static function init()
  22. {
  23. self::beforeInsert(function ($row) {
  24. //礼物价值=价格
  25. $row->value = $row->price;
  26. });
  27. self::beforeUpdate(function ($row) {
  28. //礼物价值=价格
  29. $row->value = $row->price;
  30. });
  31. }
  32. public function getIsBigList()
  33. {
  34. return ['0' => __('Is_big 0'), '1' => __('Is_big 1')];
  35. }
  36. public function getTypeList()
  37. {
  38. return ['0' => __('Type 0'), '1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')];
  39. }
  40. public function getComplexList()
  41. {
  42. return ['1' => __('Complex 1'), '0' => __('Complex 0')];
  43. }
  44. public function getBoxtypeList()
  45. {
  46. return ['0' => __('非宝箱礼物'), '1' => __('青铜宝箱'), '2' => __('黄金宝箱'), '3' => __('荣耀黄金宝箱'), '4' => __('荣耀紫金宝箱')];
  47. }
  48. public function getTimelimitList()
  49. {
  50. return ['1' => __('Timelimit 1'), '0' => __('Timelimit 0')];
  51. }
  52. public function getIsShowList()
  53. {
  54. return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
  55. }
  56. public function getTypeTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  59. $list = $this->getTypeList();
  60. return isset($list[$value]) ? $list[$value] : '';
  61. }
  62. public function getIsBigTextAttr($value, $data)
  63. {
  64. $value = $value ? $value : (isset($data['is_big']) ? $data['is_big'] : '');
  65. $list = $this->getIsBigList();
  66. return isset($list[$value]) ? $list[$value] : '';
  67. }
  68. public function getComplexTextAttr($value, $data)
  69. {
  70. $value = $value ? $value : (isset($data['complex']) ? $data['complex'] : '');
  71. $list = $this->getComplexList();
  72. return isset($list[$value]) ? $list[$value] : '';
  73. }
  74. public function getTimelimitTextAttr($value, $data)
  75. {
  76. $value = $value ? $value : (isset($data['timelimit']) ? $data['timelimit'] : '');
  77. $list = $this->getTimelimitList();
  78. return isset($list[$value]) ? $list[$value] : '';
  79. }
  80. public function gifttype()
  81. {
  82. return $this->belongsTo('app\admin\model\gift\Type', 'type', 'id', [], 'LEFT')->setEagerlyType(0);
  83. }
  84. public function getIsShowTextAttr($value, $data)
  85. {
  86. $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
  87. $list = $this->getIsShowList();
  88. return isset($list[$value]) ? $list[$value] : '';
  89. }
  90. }