File.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace addons\qingdongams\model;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. /**
  6. *附件表
  7. */
  8. class File Extends Model {
  9. use SoftDelete;
  10. // 表名,不含前缀
  11. protected $name = 'qingdongams_file';
  12. // 开启自动写入时间戳字段
  13. protected $autoWriteTimestamp = 'int';
  14. // 定义时间戳字段名
  15. protected $createTime = 'createtime';
  16. protected $updateTime = 'updatetime';
  17. protected $deleteTime = 'deletetime';
  18. public function staff() {
  19. return $this->hasOne(Staff::class, 'id', 'create_staff_id')->field('id,name,num,img');
  20. }
  21. public function getFilePathAttr($value) {
  22. return cdnurl($value, true);
  23. }
  24. public function getSizeAttr($value) {
  25. return format_bytes($value);
  26. }
  27. //获取路径
  28. public static function getUrl($id) {
  29. if(is_numeric($id)){
  30. return self::where(['id' => $id])->value('file_path');
  31. }else{
  32. return $id;
  33. }
  34. }
  35. //获取路径
  36. public static function getId($path) {
  37. $paths=explode(',',$path);
  38. $ids=[];
  39. foreach ($paths as $v){
  40. if( $id=self::where(['file_path' => $v])->value('id')){
  41. $ids[]= $id;
  42. }
  43. }
  44. return implode(',',$ids);
  45. }
  46. }