Productchufabanci.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\Db;
  5. class Productchufabanci extends Model
  6. {
  7. // 表名
  8. protected $table = 'product_chufabanci';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = false;
  11. // 定义时间戳字段名
  12. protected $createTime = false;
  13. protected $updateTime = false;
  14. protected $deleteTime = false;
  15. // 追加属性
  16. protected $append = [
  17. 'chufatime_text',
  18. 'chufatype_text',
  19. 'fache_status_text',
  20. 'fache_time_text',
  21. 'daozhan_time_text'
  22. ];
  23. protected static function init()
  24. {
  25. self::beforeUpdate(function ($row) {
  26. $road_info = Db::name('product_road')->where('id',$row->road_id)->find();
  27. $row->chufatype = $road_info['roadtype'];
  28. });
  29. self::beforeInsert(function ($row) {
  30. $road_info = Db::name('product_road')->where('id',$row->road_id)->find();
  31. $row->chufatype = $road_info['roadtype'];
  32. });
  33. }
  34. public function getChufatypeList()
  35. {
  36. return ['1' => __('Chufatype 1'), '2' => __('Chufatype 2')];
  37. }
  38. public function getFacheStatusList()
  39. {
  40. return ['0' => __('Fache_status 0'), '1' => __('Fache_status 1'), '2' => __('Fache_status 2')];
  41. }
  42. public function getChufatimeTextAttr($value, $data)
  43. {
  44. $value = $value ? $value : (isset($data['chufatime']) ? $data['chufatime'] : '');
  45. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  46. }
  47. public function getChufatypeTextAttr($value, $data)
  48. {
  49. $value = $value ? $value : (isset($data['chufatype']) ? $data['chufatype'] : '');
  50. $list = $this->getChufatypeList();
  51. return isset($list[$value]) ? $list[$value] : '';
  52. }
  53. public function getFacheStatusTextAttr($value, $data)
  54. {
  55. $value = $value ? $value : (isset($data['fache_status']) ? $data['fache_status'] : '');
  56. $list = $this->getFacheStatusList();
  57. return isset($list[$value]) ? $list[$value] : '';
  58. }
  59. public function getFacheTimeTextAttr($value, $data)
  60. {
  61. $value = $value ? $value : (isset($data['fache_time']) ? $data['fache_time'] : '');
  62. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  63. }
  64. public function getDaozhanTimeTextAttr($value, $data)
  65. {
  66. $value = $value ? $value : (isset($data['daozhan_time']) ? $data['daozhan_time'] : '');
  67. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  68. }
  69. protected function setChufatimeAttr($value)
  70. {
  71. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  72. }
  73. protected function setFacheTimeAttr($value)
  74. {
  75. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  76. }
  77. protected function setDaozhanTimeAttr($value)
  78. {
  79. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  80. }
  81. public function product()
  82. {
  83. return $this->belongsTo('Product', 'product_id', 'id', [], 'LEFT')->setEagerlyType(0);
  84. }
  85. public function road()
  86. {
  87. return $this->belongsTo('app\admin\model\Productroad', 'road_id', 'id', [], 'LEFT')->setEagerlyType(0);
  88. }
  89. public function car()
  90. {
  91. return $this->belongsTo('Car', 'car_id', 'id', [], 'LEFT')->setEagerlyType(0);
  92. }
  93. public function coach()
  94. {
  95. return $this->belongsTo('Coach', 'coach_id', 'id', [], 'LEFT')->setEagerlyType(0);
  96. }
  97. }