UploadService.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\admin\service\sys_manage;
  3. use app\model\SysUpload;
  4. use support\Storage;
  5. class UploadService
  6. {
  7. /**
  8. * @Desc 上传文件
  9. * @Author Gorden
  10. * @Date 2024/2/26 13:22
  11. *
  12. * @return \support\Response
  13. */
  14. public static function upload($config)
  15. {
  16. try {
  17. $res = Storage::uploadFile($config);
  18. $data = [
  19. 'fileName'=>$res[0]['origin_name'],
  20. 'url' => getenv("STORAGE_DOMAIN").$config['uri'] . date('Ymd') . '/thumb/' . $res[0]['save_name'],
  21. 'path' => $config['uri'] . date('Ymd') . '/' . $res[0]['save_name'],
  22. 'size' => $res[0]['size'],
  23. 'mime_type' => $res[0]['mime_type'],
  24. 'src' => getenv("STORAGE_DOMAIN").$config['uri'] . date('Ymd') . '/thumb/' . $res[0]['save_name'],
  25. ];
  26. $insertData = [
  27. 'upload_status' => 'ACTIVED',
  28. 'upload_name' => $res[0]['origin_name'],
  29. 'upload_ext_name' => $res[0]['extension'],
  30. 'upload_file_path' => $data['path'],
  31. 'upload_file_name' => $res[0]['save_name'],
  32. 'upload_file_size' => round($data['size'] / 1024, 2),
  33. 'upload_addtimes' => time()
  34. ];
  35. SysUpload::insert($insertData);
  36. } catch (\Exception $e) {
  37. return json_fail('上传失败:' . $e->getMessage());
  38. }
  39. return json_success('上传成功', $data);
  40. }
  41. /**
  42. * @Desc 修改文件状态
  43. * @Author Gorden
  44. * @Date 2024/3/7 9:29
  45. *
  46. * @param $id
  47. * @param $params
  48. * @return \support\Response
  49. */
  50. public static function updateStatus($id, $params)
  51. {
  52. try {
  53. SysUpload::where('upload_id', $id)->update(['upload_status' => $params['upload_status']]);
  54. return json_success('状态修改成功~');
  55. } catch (\Exception $e) {
  56. return json_fail('状态修改失败~');
  57. }
  58. }
  59. }