Banner.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Banner extends Model
  5. {
  6. // 表名
  7. protected $name = 'banner';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'opentype_text',
  17. 'place_text',
  18. 'status_text'
  19. ];
  20. protected static function init()
  21. {
  22. self::afterInsert(function ($row) {
  23. $pk = $row->getPk();
  24. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  25. });
  26. }
  27. public function getOpentypeList()
  28. {
  29. return ['1' => __('Opentype 1'), '2' => __('Opentype 2')];
  30. }
  31. public function getPlaceList()
  32. {
  33. return ['1' => __('Place 1'), '2' => __('Place 2'), '3' => __('Place 3'), '4' => __('Place 4'), '5' => __('Place 5'), '6' => __('Place 6')];
  34. }
  35. public function getStatusList()
  36. {
  37. return ['1' => __('Status 1'), '0' => __('Status 0')];
  38. }
  39. public function getOpentypeTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['opentype']) ? $data['opentype'] : '');
  42. $list = $this->getOpentypeList();
  43. return isset($list[$value]) ? $list[$value] : '';
  44. }
  45. public function getPlaceTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['place']) ? $data['place'] : '');
  48. $list = $this->getPlaceList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. public function getStatusTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  54. $list = $this->getStatusList();
  55. return isset($list[$value]) ? $list[$value] : '';
  56. }
  57. }