GradeModel.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\admin\model\exam;
  3. use addons\exam\model\BaseModel;
  4. use app\admin\model\User;
  5. class GradeModel extends BaseModel
  6. {
  7. // 表名
  8. protected $name = 'exam_grade';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. protected $deleteTime = false;
  15. // 追加属性
  16. protected $append = [
  17. // 'grade_time_text'
  18. ];
  19. public function getGradeTimeTextAttr($value, $data)
  20. {
  21. $value = $value ? $value : ($data['grade_time'] ?? '');
  22. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  23. }
  24. protected function setGradeTimeAttr($value)
  25. {
  26. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  27. }
  28. public function user()
  29. {
  30. return $this->belongsTo(User::class, 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  31. }
  32. public function cate()
  33. {
  34. return $this->belongsTo(CateModel::class, 'cate_id', 'id', [], 'LEFT')->setEagerlyType(0);
  35. }
  36. public function paper()
  37. {
  38. return $this->belongsTo(PaperModel::class, 'paper_id', 'id', [], 'LEFT')->setEagerlyType(0);
  39. }
  40. }