RoomModel.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\admin\model\exam;
  3. use addons\exam\model\BaseModel;
  4. use traits\model\SoftDelete;
  5. class RoomModel extends BaseModel
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $name = 'exam_room';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. 'start_time_text',
  19. 'end_time_text',
  20. 'status_text',
  21. 'signup_mode_text',
  22. 'is_makeup_text'
  23. ];
  24. protected static function init()
  25. {
  26. self::afterInsert(function ($row) {
  27. $pk = $row->getPk();
  28. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  29. });
  30. }
  31. public function getStatusList()
  32. {
  33. return ['NORMAL' => __('Normal'), 'HIDDEN' => __('Hidden')];
  34. }
  35. public function getSignupModeList()
  36. {
  37. return ['NORMAL' => __('Signup_mode normal'), 'PASSWORD' => __('Signup_mode password'), 'AUDIT' => __('Signup_mode audit')];
  38. }
  39. public function getIsMakeupList()
  40. {
  41. return ['0' => __('Is_makeup 0'), '1' => __('Is_makeup 1')];
  42. }
  43. public function getStartTimeTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');
  46. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  47. }
  48. public function getEndTimeTextAttr($value, $data)
  49. {
  50. $value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : '');
  51. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  52. }
  53. public function getStatusTextAttr($value, $data)
  54. {
  55. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  56. $list = $this->getStatusList();
  57. return isset($list[$value]) ? $list[$value] : '';
  58. }
  59. public function getSignupModeTextAttr($value, $data)
  60. {
  61. $value = $value ? $value : (isset($data['signup_mode']) ? $data['signup_mode'] : '');
  62. $list = $this->getSignupModeList();
  63. return isset($list[$value]) ? $list[$value] : '';
  64. }
  65. public function getIsMakeupTextAttr($value, $data)
  66. {
  67. $value = $value ? $value : (isset($data['is_makeup']) ? $data['is_makeup'] : '');
  68. $list = $this->getIsMakeupList();
  69. return isset($list[$value]) ? $list[$value] : '';
  70. }
  71. protected function setStartTimeAttr($value)
  72. {
  73. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  74. }
  75. protected function setEndTimeAttr($value)
  76. {
  77. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  78. }
  79. public function paper()
  80. {
  81. return $this->belongsTo(PaperModel::class, 'paper_id', 'id', [], 'LEFT')->setEagerlyType(0);
  82. }
  83. public function cate()
  84. {
  85. return $this->belongsTo(CateModel::class, 'cate_id', 'id', [], 'LEFT')->setEagerlyType(0);
  86. }
  87. public function cates()
  88. {
  89. return $this->belongsTo(CateModel::class, 'cate_id', 'id');
  90. }
  91. }