UploadService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. dump($res);
  19. $data = [
  20. 'fileName'=>$res[0]['origin_name'],
  21. 'url' => getenv("STORAGE_DOMAIN").$config['uri'] . date('Ymd') . '/thumb/' . $res[0]['save_name'],
  22. 'path' => $config['uri'] . date('Ymd') . '/' . $res[0]['save_name'],
  23. 'size' => $res[0]['size'],
  24. 'mime_type' => $res[0]['mime_type'],
  25. 'src' => getenv("STORAGE_DOMAIN").$config['uri'] . date('Ymd') . '/thumb/' . $res[0]['save_name'],
  26. ];
  27. $insertData = [
  28. 'upload_status' => 'ACTIVED',
  29. 'upload_name' => $res[0]['origin_name'],
  30. 'upload_ext_name' => $res[0]['extension'],
  31. 'upload_file_path' => $data['path'],
  32. 'upload_file_name' => $res[0]['save_name'],
  33. 'upload_file_size' => round($data['size'] / 1024, 2),
  34. 'upload_addtimes' => time()
  35. ];
  36. SysUpload::insert($insertData);
  37. } catch (\Exception $e) {
  38. return json_fail('上传失败:' . $e->getMessage());
  39. }
  40. return json_success('上传成功', $data);
  41. }
  42. /**
  43. * @Desc 修改文件状态
  44. * @Author Gorden
  45. * @Date 2024/3/7 9:29
  46. *
  47. * @param $id
  48. * @param $params
  49. * @return \support\Response
  50. */
  51. public static function updateStatus($id, $params)
  52. {
  53. try {
  54. SysUpload::where('upload_id', $id)->update(['upload_status' => $params['upload_status']]);
  55. return json_success('状态修改成功~');
  56. } catch (\Exception $e) {
  57. return json_fail('状态修改失败~');
  58. }
  59. }
  60. }