Attachment.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. protected $append = [
  15. 'thumb_style'
  16. ];
  17. public function setUploadtimeAttr($value)
  18. {
  19. return is_numeric($value) ? $value : strtotime($value);
  20. }
  21. /**
  22. * 获取云储存的缩略图样式字符
  23. */
  24. public function getThumbStyleAttr($value, $data)
  25. {
  26. if (!isset($data['storage']) || $data['storage'] == 'local') {
  27. return '';
  28. } else {
  29. $config = get_addon_config($data['storage']);
  30. if ($config && isset($config['thumbstyle'])) {
  31. return $config['thumbstyle'];
  32. }
  33. }
  34. return '';
  35. }
  36. public static function getMimetypeList()
  37. {
  38. $data = [
  39. "image/*" => __("Image"),
  40. "audio/*" => __("Audio"),
  41. "video/*" => __("Video"),
  42. "text/*" => __("Text"),
  43. "application/*" => __("Application"),
  44. "zip,rar,7z,tar" => __("Zip"),
  45. ];
  46. return $data;
  47. }
  48. protected static function init()
  49. {
  50. // 如果已经上传该资源,则不再记录
  51. self::beforeInsert(function ($model) {
  52. if (self::where('url', '=', $model['url'])->where('storage', $model['storage'])->find()) {
  53. return false;
  54. }
  55. });
  56. }
  57. }