mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-29 22:10:49 +00:00
74 lines
2.4 KiB
PHP
74 lines
2.4 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||
// +----------------------------------------------------------------------
|
||
// | Author: CRMEB Team <admin@crmeb.com>
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\adminapi\controller;
|
||
|
||
|
||
use app\Request;
|
||
use app\services\system\attachment\SystemAttachmentServices;
|
||
use crmeb\services\CacheService;
|
||
use think\Response;
|
||
|
||
class PublicController
|
||
{
|
||
|
||
/**
|
||
* 下载文件
|
||
* @param string $key
|
||
* @return Response|\think\response\File
|
||
*/
|
||
public function download(string $key = '')
|
||
{
|
||
if (!$key) {
|
||
return Response::create()->code(500);
|
||
}
|
||
$fileName = CacheService::get($key);
|
||
if (is_array($fileName) && isset($fileName['path']) && isset($fileName['fileName']) && $fileName['path'] && $fileName['fileName'] && file_exists($fileName['path'])) {
|
||
CacheService::delete($key);
|
||
return download($fileName['path'], $fileName['fileName']);
|
||
}
|
||
return Response::create()->code(500);
|
||
}
|
||
|
||
/**
|
||
* 获取workerman请求域名
|
||
* @return mixed
|
||
*/
|
||
public function getWorkerManUrl()
|
||
{
|
||
return app('json')->success(getWorkerManUrl());
|
||
}
|
||
|
||
/**
|
||
* 扫码上传
|
||
* @param Request $request
|
||
* @param int $upload_type
|
||
* @param int $type
|
||
* @return Response
|
||
* @author 吴汐
|
||
* @email 442384644@qq.com
|
||
* @date 2023/06/13
|
||
*/
|
||
public function scanUpload(Request $request, $upload_type = 0, $type = 0)
|
||
{
|
||
[$file, $uploadToken] = $request->postMore([
|
||
['file', 'file'],
|
||
['uploadToken', '']
|
||
], true);
|
||
$service = app()->make(SystemAttachmentServices::class);
|
||
if ($service->cacheDriver()->get('scan_upload') != $uploadToken) {
|
||
return app('json')->fail(410086);
|
||
}
|
||
$service->upload(0, $file, $upload_type, $type, '', $uploadToken);
|
||
return app('json')->success(100032);
|
||
}
|
||
}
|