| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // +----------------------------------------------------------------------
- // | 附件上传模型
- // +----------------------------------------------------------------------
- namespace app\common\model;
- use think\Model;
- class Attachment extends Model
- {
- // 自动写入时间戳
- protected $autoWriteTimestamp = true;
- public static function onBeforeInsert($row)
- {
- if (self::where('path', $row['path'])->where('driver', $row['driver'])->find()) {
- return false;
- }
- }
- public function getCategoryAttr($value): string
- {
- return $value == '' ? 'unclassed' : $value;
- }
- public function setCategoryAttr($value)
- {
- return $value == 'unclassed' ? '' : $value;
- }
- /**
- * 获取Mimetype列表
- * @return array
- */
- public static function getMimetypeList()
- {
- $data = [
- "image/*" => "图片",
- "audio/*" => "音频",
- "video/*" => "视频",
- "text/*" => "文档",
- "application/*" => "应用",
- "zip,rar,7z,tar" => "压缩包",
- ];
- return $data;
- }
- /**
- * 获取定义的附件类别列表
- * @return array
- */
- public static function getCategoryList(): array
- {
- $data = config('site.attachmentcategory') ?? [];
- // 添加未归类选项
- $data['unclassed'] = '未归类';
- return $data;
- }
- /**
- * 返回上传文件的相关信息
- */
- public function getBaseData()
- {
- $data = [
- 'url' => $this->path,
- 'fullurl' => cdnurl($this->path, true),
- 'category' => $this->category,
- 'filename' => $this->name,
- 'filesize' => $this->size,
- 'mimetype' => $this->mime,
- ];
- return $data;
- }
- }
|