Lessonpackage.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 getIsShowTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
  47. $list = $this->getIsShowList();
  48. return isset($list[$value]) ? $list[$value] : '';
  49. }
  50. public function getBuytimesTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['buytimes']) ? $data['buytimes'] : '');
  53. $list = $this->getBuytimesList();
  54. return isset($list[$value]) ? $list[$value] : '';
  55. }
  56. public function getNewuserTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['newuser']) ? $data['newuser'] : '');
  59. $list = $this->getNewuserList();
  60. return isset($list[$value]) ? $list[$value] : '';
  61. }
  62. public function getOlduserTextAttr($value, $data)
  63. {
  64. $value = $value ? $value : (isset($data['olduser']) ? $data['olduser'] : '');
  65. $list = $this->getOlduserList();
  66. return isset($list[$value]) ? $list[$value] : '';
  67. }
  68. /*public function lessona()
  69. {
  70. return $this->belongsTo('Lesson', 'lesson_ids', 'id', [], 'LEFT')->setEagerlyType(0);
  71. }*/
  72. public function lessonb()
  73. {
  74. return $this->belongsTo('Lesson', 'gift_lesson_id', 'id', [], 'LEFT')->setEagerlyType(0);
  75. }
  76. }