PublicController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 app\services\system\SystemRouteServices;
  15. use crmeb\services\CacheService;
  16. use think\Response;
  17. class PublicController
  18. {
  19. /**
  20. * 下载文件
  21. * @param string $key
  22. * @return Response|\think\response\File
  23. */
  24. public function download(string $key = '')
  25. {
  26. if (!$key) {
  27. return Response::create()->code(500);
  28. }
  29. $fileName = CacheService::get($key);
  30. if (is_array($fileName) && isset($fileName['path']) && isset($fileName['fileName']) && $fileName['path'] && $fileName['fileName'] && file_exists($fileName['path'])) {
  31. CacheService::delete($key);
  32. return download($fileName['path'], $fileName['fileName']);
  33. }
  34. return Response::create()->code(500);
  35. }
  36. /**
  37. * 获取workerman请求域名
  38. * @return mixed
  39. */
  40. public function getWorkerManUrl()
  41. {
  42. return app('json')->success(getWorkerManUrl());
  43. }
  44. /**
  45. * 扫码上传
  46. * @param Request $request
  47. * @param int $upload_type
  48. * @param int $type
  49. * @return Response
  50. * @author 吴汐
  51. * @email 442384644@qq.com
  52. * @date 2023/06/13
  53. */
  54. public function scanUpload(Request $request, $upload_type = 0, $type = 0)
  55. {
  56. [$file, $uploadToken, $pid] = $request->postMore([
  57. ['file', 'file'],
  58. ['uploadToken', ''],
  59. ['pid', 0]
  60. ], true);
  61. $service = app()->make(SystemAttachmentServices::class);
  62. if (CacheService::get('scan_upload') != $uploadToken) {
  63. return app('json')->fail(410086);
  64. }
  65. $service->upload((int)$pid, $file, $upload_type, $type, '', $uploadToken);
  66. return app('json')->success(100032);
  67. }
  68. public function import(Request $request)
  69. {
  70. $filePath = $request->param('file_path', '');
  71. if (empty($filePath)) {
  72. return app('json')->fail(12894);
  73. }
  74. app()->make(SystemRouteServices::class)->import($filePath);
  75. return app('json')->success(100010);
  76. }
  77. }