Orderroad.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Orderroad extends Model
  5. {
  6. // 表名
  7. protected $table = 'order_road';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'roadtype_text',
  17. 'chufatime_text',
  18. 'hexiao_status_text',
  19. 'hexiao_time_text'
  20. ];
  21. public function getRoadtypeList()
  22. {
  23. return ['1' => __('Roadtype 1'), '2' => __('Roadtype 2')];
  24. }
  25. public function getHexiaoStatusList()
  26. {
  27. return ['0' => __('Hexiao_status 0'), '1' => __('Hexiao_status 1')];
  28. }
  29. public function getRoadtypeTextAttr($value, $data)
  30. {
  31. $value = $value ? $value : (isset($data['roadtype']) ? $data['roadtype'] : '');
  32. $list = $this->getRoadtypeList();
  33. return isset($list[$value]) ? $list[$value] : '';
  34. }
  35. public function getChufatimeTextAttr($value, $data)
  36. {
  37. $value = $value ? $value : (isset($data['chufatime']) ? $data['chufatime'] : '');
  38. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  39. }
  40. public function getHexiaoStatusTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['hexiao_status']) ? $data['hexiao_status'] : '');
  43. $list = $this->getHexiaoStatusList();
  44. return isset($list[$value]) ? $list[$value] : '';
  45. }
  46. public function getHexiaoTimeTextAttr($value, $data)
  47. {
  48. $value = $value ? $value : (isset($data['hexiao_time']) ? $data['hexiao_time'] : '');
  49. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  50. }
  51. protected function setChufatimeAttr($value)
  52. {
  53. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  54. }
  55. protected function setHexiaoTimeAttr($value)
  56. {
  57. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  58. }
  59. public function order()
  60. {
  61. return $this->belongsTo('Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
  62. }
  63. public function user()
  64. {
  65. return $this->belongsTo('User', 'hexiao_uid', 'id', [], 'LEFT')->setEagerlyType(0);
  66. }
  67. public function coach()
  68. {
  69. return $this->belongsTo('Coach', 'hexiao_coachid', 'id', [], 'LEFT')->setEagerlyType(0);
  70. }
  71. }