Usertrainevaluate.php 1.2 KB

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