Caraccident.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Caraccident extends Model
  5. {
  6. // 表名
  7. protected $table = 'car_accident';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'addtime_text'
  17. ];
  18. public function getAddtimeTextAttr($value, $data)
  19. {
  20. $value = $value ? $value : (isset($data['addtime']) ? $data['addtime'] : '');
  21. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  22. }
  23. protected function setAddtimeAttr($value)
  24. {
  25. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  26. }
  27. public function car()
  28. {
  29. return $this->belongsTo('Car', 'car_id', 'id', [], 'LEFT')->setEagerlyType(0);
  30. }
  31. public function coach()
  32. {
  33. return $this->belongsTo('Coach', 'coach_id', 'id', [], 'LEFT')->setEagerlyType(0);
  34. }
  35. }