Attachment.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class Attachment extends Model
  5. {
  6. // 开启自动写入时间戳字段
  7. protected $autoWriteTimestamp = 'int';
  8. // 定义时间戳字段名
  9. protected $createTime = 'createtime';
  10. protected $updateTime = 'updatetime';
  11. // 定义字段类型
  12. protected $type = [
  13. ];
  14. public function setUploadtimeAttr($value)
  15. {
  16. return is_numeric($value) ? $value : strtotime($value);
  17. }
  18. public static function getMimetypeList()
  19. {
  20. $data = [
  21. "image/*" => "图片",
  22. "audio/*" => "音频",
  23. "video/*" => "视频",
  24. "text/*" => "文档",
  25. "application/*" => "应用",
  26. "zip,rar,7z,tar" => "压缩包",
  27. ];
  28. return $data;
  29. }
  30. protected static function init()
  31. {
  32. // 如果已经上传该资源,则不再记录
  33. self::beforeInsert(function ($model) {
  34. if (self::where('url', '=', $model['url'])->find()) {
  35. return false;
  36. }
  37. });
  38. }
  39. }