Gift.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Gift extends Model
  5. {
  6. // 表名
  7. protected $name = 'gift';
  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. 'is_vip_text'
  18. ];
  19. protected static function init()
  20. {
  21. self::afterInsert(function ($row) {
  22. $pk = $row->getPk();
  23. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  24. });
  25. }
  26. public function getIsShowList()
  27. {
  28. return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
  29. }
  30. public function getIsVipList()
  31. {
  32. return ['1' => __('Is_vip 1'), '0' => __('Is_vip 0')];
  33. }
  34. public function getIsShowTextAttr($value, $data)
  35. {
  36. $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
  37. $list = $this->getIsShowList();
  38. return isset($list[$value]) ? $list[$value] : '';
  39. }
  40. public function getIsVipTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['is_vip']) ? $data['is_vip'] : '');
  43. $list = $this->getIsVipList();
  44. return isset($list[$value]) ? $list[$value] : '';
  45. }
  46. }