Maintain.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Maintain extends Model
  5. {
  6. // 表名
  7. protected $table = 'maintain';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text',
  17. 'canceltime_text',
  18. 'finishtime_text',
  19. 'baojia_confirmtime_text',
  20. 'cailiao_time_text',
  21. 'lingqu_time_text',
  22. 'shangmen_time_text',
  23. 'wancheng_time_text',
  24. 'eva_time_text'
  25. ];
  26. public function getStatusList()
  27. {
  28. return ['0' => __('Status 0'), '2' => __('Status 2'), '20' => __('Status 20'), '22' => __('Status 22'), '30' => __('Status 30'), '40' => __('Status 40'), '50' => __('Status 50'), '60' => __('Status 60'), '70' => __('Status 70'), '80' => __('Status 80'), '90' => __('Status 90'), '92' => __('Status 92'), '100' => __('Status 100')];
  29. }
  30. public function getStatusTextAttr($value, $data)
  31. {
  32. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  33. $list = $this->getStatusList();
  34. return isset($list[$value]) ? $list[$value] : '';
  35. }
  36. public function getCanceltimeTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['canceltime']) ? $data['canceltime'] : '');
  39. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  40. }
  41. public function getFinishtimeTextAttr($value, $data)
  42. {
  43. $value = $value ? $value : (isset($data['finishtime']) ? $data['finishtime'] : '');
  44. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  45. }
  46. public function getBaojiaConfirmtimeTextAttr($value, $data)
  47. {
  48. $value = $value ? $value : (isset($data['baojia_confirmtime']) ? $data['baojia_confirmtime'] : '');
  49. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  50. }
  51. public function getCailiaoTimeTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['cailiao_time']) ? $data['cailiao_time'] : '');
  54. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  55. }
  56. public function getLingquTimeTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['lingqu_time']) ? $data['lingqu_time'] : '');
  59. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  60. }
  61. public function getShangmenTimeTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['shangmen_time']) ? $data['shangmen_time'] : '');
  64. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  65. }
  66. public function getWanchengTimeTextAttr($value, $data)
  67. {
  68. $value = $value ? $value : (isset($data['wancheng_time']) ? $data['wancheng_time'] : '');
  69. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  70. }
  71. public function getEvaTimeTextAttr($value, $data)
  72. {
  73. $value = $value ? $value : (isset($data['eva_time']) ? $data['eva_time'] : '');
  74. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  75. }
  76. protected function setCanceltimeAttr($value)
  77. {
  78. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  79. }
  80. protected function setFinishtimeAttr($value)
  81. {
  82. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  83. }
  84. protected function setBaojiaConfirmtimeAttr($value)
  85. {
  86. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  87. }
  88. protected function setCailiaoTimeAttr($value)
  89. {
  90. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  91. }
  92. protected function setLingquTimeAttr($value)
  93. {
  94. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  95. }
  96. protected function setShangmenTimeAttr($value)
  97. {
  98. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  99. }
  100. protected function setWanchengTimeAttr($value)
  101. {
  102. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  103. }
  104. protected function setEvaTimeAttr($value)
  105. {
  106. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  107. }
  108. public function company()
  109. {
  110. return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
  111. }
  112. public function user()
  113. {
  114. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  115. }
  116. public function usercompany()
  117. {
  118. return $this->belongsTo('Usercompany', 'uc_id', 'id', [], 'LEFT')->setEagerlyType(0);
  119. }
  120. public function worker()
  121. {
  122. return $this->belongsTo('Worker', 'worker_id', 'id', [], 'LEFT')->setEagerlyType(0);
  123. }
  124. }