PublicController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller;
  12. use app\Request;
  13. use app\services\system\attachment\SystemAttachmentServices;
  14. use crmeb\services\CacheService;
  15. use think\Response;
  16. class PublicController
  17. {
  18. /**
  19. * 下载文件
  20. * @param string $key
  21. * @return Response|\think\response\File
  22. */
  23. public function download(string $key = '')
  24. {
  25. if (!$key) {
  26. return Response::create()->code(500);
  27. }
  28. $fileName = CacheService::get($key);
  29. if (is_array($fileName) && isset($fileName['path']) && isset($fileName['fileName']) && $fileName['path'] && $fileName['fileName'] && file_exists($fileName['path'])) {
  30. CacheService::delete($key);
  31. return download($fileName['path'], $fileName['fileName']);
  32. }
  33. return Response::create()->code(500);
  34. }
  35. /**
  36. * 获取workerman请求域名
  37. * @return mixed
  38. */
  39. public function getWorkerManUrl()
  40. {
  41. return app('json')->success(getWorkerManUrl());
  42. }
  43. /**
  44. * 扫码上传
  45. * @param Request $request
  46. * @param int $upload_type
  47. * @param int $type
  48. * @return Response
  49. * @author 吴汐
  50. * @email 442384644@qq.com
  51. * @date 2023/06/13
  52. */
  53. public function scanUpload(Request $request, $upload_type = 0, $type = 0)
  54. {
  55. [$file, $uploadToken, $pid] = $request->postMore([
  56. ['file', 'file'],
  57. ['uploadToken', ''],
  58. ['pid', 0]
  59. ], true);
  60. $service = app()->make(SystemAttachmentServices::class);
  61. if ($service->cacheDriver()->get('scan_upload') != $uploadToken) {
  62. return app('json')->fail(410086);
  63. }
  64. $service->upload((int)$pid, $file, $upload_type, $type, '', $uploadToken);
  65. return app('json')->success(100032);
  66. }
  67. }