Gift.php 2.5 KB

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