1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace app\common\model\base;
- use app\common\model\Common;
- class Upload extends Common
- {
- protected $name = 'system_upload';
- protected $pk = 'id';
- protected $createTime = 'create_at';
- protected $hidden=[];
- protected $schema = [
- 'id' => 'int',
- 'name' => 'varchar',
- 'savename' => 'varchar',
- 'size' => 'int',
- 'ext' => 'varchar',
- 'path' => 'varchar',
- 'fullpath' => 'varchar',
- 'md5' => 'varchar',
- 'create_at' => 'datetime',
- 'type' => 'int',
- 'uid' => 'int',
- ];
- protected $append = [
- 'url',
- 'type_txt',
- 'preview'
- ];
- // 处理大图路径
- public function getUrlAttr($value,$data)
- {
- return WEBURL.$data['path'];
- }
- // 预览图
- public function getPreviewAttr($value,$data)
- {
- $url = WEBURL.$data['path'];
- $prev = $url.'.prev.'.$data['ext'];
- $prevPath = public_path().$data['path'].'.prev.'.$data['ext'];
- return file_exists($prevPath)?$prev:$url;
- }
- // 类型列表
- static public function typeList()
- {
- return ['other'=>'文件','images'=>'图片','audio'=>'音频','video'=>'视频'];
- }
- // 上传文件类型文字
- public function getTypeTxtAttr($value,$data)
- {
- $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
- $typeList = self::typeList();
- return isset($typeList[$value]) ? $typeList[$value] : '';
- }
- }
|