NoticeModel.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\admin\model\exam;
  3. use addons\exam\model\BaseModel;
  4. class NoticeModel extends BaseModel
  5. {
  6. // 表名
  7. protected $name = 'exam_notice';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text',
  17. 'create_time_text'
  18. ];
  19. protected static function init()
  20. {
  21. self::afterInsert(function ($row) {
  22. $pk = $row->getPk();
  23. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  24. });
  25. }
  26. public function getStatusList()
  27. {
  28. return ['NORMAL' => __('Normal'), 'HIDDEN' => __('Hidden')];
  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 getCreateTimeTextAttr($value, $data)
  37. {
  38. $value = $value ?: ($data['createtime'] ?? '');
  39. return is_numeric($value) ? date('Y-m-d H:i:s', $value) : $value;
  40. }
  41. }