Messages.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class Messages extends Model
  5. {
  6. // 表名
  7. protected $name = 'messages';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. protected $dateFormat = 'Y-m-d H:i:s';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. protected $deleteTime = false;
  15. // 追加属性
  16. protected $append = [
  17. 'message_type_text',
  18. 'createtime_text'
  19. ];
  20. protected $type = [
  21. 'extra_json' => 'array',
  22. ];
  23. public function getMessageTypeList()
  24. {
  25. return ['0' => __('Message_type 0'), '1' => __('Message_type 1')];
  26. }
  27. public function getMessageTypeTextAttr($value, $data)
  28. {
  29. $value = $value ? $value : (isset($data['message_type']) ? $data['message_type'] : '');
  30. $list = $this->getMessageTypeList();
  31. return isset($list[$value]) ? $list[$value] : '';
  32. }
  33. public function getCreatetimeTextAttr($value, $data)
  34. {
  35. return date('m/d|H:i', $data['createtime'] ?? 0);
  36. }
  37. }