PublicController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\controller\admin;
  12. use app\Request;
  13. use app\services\other\CacheServices;
  14. use app\services\system\attachment\SystemAttachmentServices;
  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. * 获取erp开关
  38. * @return mixed
  39. */
  40. public function getErpConfig()
  41. {
  42. return app('json')->success(['open_erp' => !!sys_config('erp_open')]);
  43. }
  44. /**扫码上传
  45. * @param Request $request
  46. * @param $upload_type
  47. * @return \think\Response
  48. */
  49. public function scanUpload(Request $request)
  50. {
  51. [$file, $upload_type, $cache, $uploadToken, $type, $relation_id, $pid] = $request->postMore([
  52. ['file', 'file'],
  53. ['upload_type', 0],
  54. ['cache', ''],
  55. ['uploadToken', ''],
  56. ['type', 0],
  57. ['relation_id', 0],
  58. ['pid', 0]
  59. ], true);
  60. if (!$cache || !$uploadToken) {
  61. return app('json')->fail('参数有误,无法上传!');
  62. }
  63. $cacheServices = app()->make(CacheServices::class);
  64. $service = app()->make(SystemAttachmentServices::class);
  65. if ($cacheServices->getDbCache($cache, '') == '' || $cacheServices->getDbCache($cache, '') != $uploadToken) {
  66. return app('json')->fail('请重新扫码上传!');
  67. }
  68. $service->storeUpload((int)$pid, $file, $relation_id, $type, $upload_type, $uploadToken);
  69. return app('json')->success('上传成功!');
  70. }
  71. }