Gift.php 2.6 KB

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