PublicController.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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 crmeb\services\CacheService;
  13. use think\Response;
  14. class PublicController
  15. {
  16. /**
  17. * 下载文件
  18. * @param string $key
  19. * @return Response|\think\response\File
  20. */
  21. public function download(string $key = '')
  22. {
  23. if (!$key) {
  24. return Response::create()->code(500);
  25. }
  26. $fileName = CacheService::get($key);
  27. if (is_array($fileName) && isset($fileName['path']) && isset($fileName['fileName']) && $fileName['path'] && $fileName['fileName'] && file_exists($fileName['path'])) {
  28. CacheService::delete($key);
  29. return download($fileName['path'], $fileName['fileName']);
  30. }
  31. return Response::create()->code(500);
  32. }
  33. /**
  34. * 获取workerman请求域名
  35. * @return mixed
  36. */
  37. public function getWorkerManUrl()
  38. {
  39. return app('json')->success(getWorkerManUrl());
  40. }
  41. }