Car.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Car extends Model
  5. {
  6. // 表名
  7. protected $table = 'car';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'chepaicolor_text',
  17. 'is_etc_text',
  18. 'power_text',
  19. 'zhucetime_text',
  20. 'leasetype_text'
  21. ];
  22. public function getChepaicolorList()
  23. {
  24. return ['5' => __('Chepaicolor 5'), '1' => __('Chepaicolor 1'), '2' => __('Chepaicolor 2'), '3' => __('Chepaicolor 3'), '4' => __('Chepaicolor 4'), '9' => __('Chepaicolor 9'), '91' => __('Chepaicolor 91'), '92' => __('Chepaicolor 92'), '94' => __('Chepaicolor 94'), '224' => __('Chepaicolor 224'), '225' => __('Chepaicolor 225')];
  25. }
  26. public function getIsEtcList()
  27. {
  28. return ['0' => __('Is_etc 0'), '1' => __('Is_etc 1')];
  29. }
  30. public function getPowerList()
  31. {
  32. return ['1' => __('Power 1'), '2' => __('Power 2')];
  33. }
  34. public function getLeasetypeList()
  35. {
  36. return ['1' => __('Leasetype 1'), '2' => __('Leasetype 2'), '3' => __('Leasetype 3')];
  37. }
  38. public function getChepaicolorTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['chepaicolor']) ? $data['chepaicolor'] : '');
  41. $list = $this->getChepaicolorList();
  42. return isset($list[$value]) ? $list[$value] : '';
  43. }
  44. public function getIsEtcTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['is_etc']) ? $data['is_etc'] : '');
  47. $list = $this->getIsEtcList();
  48. return isset($list[$value]) ? $list[$value] : '';
  49. }
  50. public function getPowerTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['power']) ? $data['power'] : '');
  53. $list = $this->getPowerList();
  54. return isset($list[$value]) ? $list[$value] : '';
  55. }
  56. public function getZhucetimeTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['zhucetime']) ? $data['zhucetime'] : '');
  59. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  60. }
  61. public function getLeasetypeTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['leasetype']) ? $data['leasetype'] : '');
  64. $list = $this->getLeasetypeList();
  65. return isset($list[$value]) ? $list[$value] : '';
  66. }
  67. protected function setZhucetimeAttr($value)
  68. {
  69. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  70. }
  71. }