Upload.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\common\model\base;
  3. use app\common\model\Common;
  4. class Upload extends Common
  5. {
  6. protected $name = 'system_upload';
  7. protected $pk = 'id';
  8. protected $createTime = 'create_at';
  9. protected $hidden=[];
  10. protected $schema = [
  11. 'id' => 'int',
  12. 'name' => 'varchar',
  13. 'savename' => 'varchar',
  14. 'size' => 'int',
  15. 'ext' => 'varchar',
  16. 'path' => 'varchar',
  17. 'fullpath' => 'varchar',
  18. 'md5' => 'varchar',
  19. 'create_at' => 'datetime',
  20. 'type' => 'int',
  21. 'uid' => 'int',
  22. ];
  23. protected $append = [
  24. 'url',
  25. 'type_txt',
  26. 'preview'
  27. ];
  28. // 处理大图路径
  29. public function getUrlAttr($value,$data)
  30. {
  31. return WEBURL.$data['path'];
  32. }
  33. // 预览图
  34. public function getPreviewAttr($value,$data)
  35. {
  36. $url = WEBURL.$data['path'];
  37. $prev = $url.'.prev.'.$data['ext'];
  38. $prevPath = public_path().$data['path'].'.prev.'.$data['ext'];
  39. return file_exists($prevPath)?$prev:$url;
  40. }
  41. // 类型列表
  42. static public function typeList()
  43. {
  44. return ['other'=>'文件','images'=>'图片','audio'=>'音频','video'=>'视频'];
  45. }
  46. // 上传文件类型文字
  47. public function getTypeTxtAttr($value,$data)
  48. {
  49. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  50. $typeList = self::typeList();
  51. return isset($typeList[$value]) ? $typeList[$value] : '';
  52. }
  53. }