Lessonpackage.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Lessonpackage extends Model
  5. {
  6. // 表名
  7. protected $table = 'lesson_package';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'is_show_text',
  17. 'buytimes_text',
  18. 'newuser_text',
  19. 'olduser_text'
  20. ];
  21. protected static function init()
  22. {
  23. self::afterInsert(function ($row) {
  24. $pk = $row->getPk();
  25. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  26. });
  27. }
  28. public function getIsShowList()
  29. {
  30. return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
  31. }
  32. public function getBuytimesList()
  33. {
  34. return ['0' => __('Buytimes 0'), '1' => __('Buytimes 1')];
  35. }
  36. public function getNewuserList()
  37. {
  38. return ['0' => __('Newuser 0'), '1' => __('Newuser 1')];
  39. }
  40. public function getOlduserList()
  41. {
  42. return ['0' => __('Olduser 0'), '1' => __('Olduser 1')];
  43. }
  44. public function getTypeList()
  45. {
  46. return ['1' => __('Type 1'), '2' => __('Type 2')];
  47. }
  48. public function getGiftTypeList()
  49. {
  50. return ['1' => __('Type 1'), '2' => __('Type 2')];
  51. }
  52. public function getIsShowTextAttr($value, $data)
  53. {
  54. $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
  55. $list = $this->getIsShowList();
  56. return isset($list[$value]) ? $list[$value] : '';
  57. }
  58. public function getBuytimesTextAttr($value, $data)
  59. {
  60. $value = $value ? $value : (isset($data['buytimes']) ? $data['buytimes'] : '');
  61. $list = $this->getBuytimesList();
  62. return isset($list[$value]) ? $list[$value] : '';
  63. }
  64. public function getNewuserTextAttr($value, $data)
  65. {
  66. $value = $value ? $value : (isset($data['newuser']) ? $data['newuser'] : '');
  67. $list = $this->getNewuserList();
  68. return isset($list[$value]) ? $list[$value] : '';
  69. }
  70. public function getOlduserTextAttr($value, $data)
  71. {
  72. $value = $value ? $value : (isset($data['olduser']) ? $data['olduser'] : '');
  73. $list = $this->getOlduserList();
  74. return isset($list[$value]) ? $list[$value] : '';
  75. }
  76. public function getTypeTextAttr($value, $data)
  77. {
  78. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  79. $list = $this->getTypeList();
  80. return isset($list[$value]) ? $list[$value] : '';
  81. }
  82. public function getGiftTypeTextAttr($value, $data)
  83. {
  84. $value = $value ? $value : (isset($data['gift_type']) ? $data['gift_type'] : '');
  85. $list = $this->getGiftTypeList();
  86. return isset($list[$value]) ? $list[$value] : '';
  87. }
  88. /*public function lessona()
  89. {
  90. return $this->belongsTo('Lesson', 'lesson_ids', 'id', [], 'LEFT')->setEagerlyType(0);
  91. }*/
  92. public function lessonb()
  93. {
  94. return $this->belongsTo('Lesson', 'gift_lesson_id', 'id', [], 'LEFT')->setEagerlyType(0);
  95. }
  96. }