新增附件事件
This commit is contained in:
parent
39c0ec4c48
commit
fe6ea82014
17
catch/system/events/AttachmentEvent.php
Normal file
17
catch/system/events/AttachmentEvent.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace catchAdmin\system\events;
|
||||
|
||||
|
||||
use catchAdmin\system\model\Attachments;
|
||||
|
||||
class AttachmentEvent
|
||||
{
|
||||
public function handle($params)
|
||||
{
|
||||
$file = $params['file'];
|
||||
|
||||
unset($params['file']);
|
||||
|
||||
Attachments::store($params, $file);
|
||||
}
|
||||
}
|
@ -89,6 +89,10 @@ return [
|
||||
'operateLog' => [
|
||||
OperateLogEvent::class,
|
||||
],
|
||||
// 附件操作
|
||||
'attachment' => [
|
||||
\catchAdmin\system\events\AttachmentEvent::class,
|
||||
],
|
||||
// 路由加载
|
||||
'RouteLoaded' => [
|
||||
LoadModuleRoutes::class
|
||||
|
@ -63,10 +63,12 @@ class CatchUpload
|
||||
if ($path) {
|
||||
$url = self::getCloudDomain($this->getDriver()) . $path;
|
||||
|
||||
Attachments::create(array_merge([
|
||||
event('attachment', [
|
||||
'path' => $path,
|
||||
'url' => $url,
|
||||
], $this->data($file)));
|
||||
'url' => $url,
|
||||
'driver' => $this->getDriver(),
|
||||
'file' => $file,
|
||||
]);
|
||||
|
||||
return $url;
|
||||
}
|
||||
@ -215,7 +217,12 @@ class CatchUpload
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化配置
|
||||
*
|
||||
* @time 2020年06月01日
|
||||
* @return void
|
||||
*/
|
||||
protected function initUploadConfig()
|
||||
{
|
||||
$configModel = app(Config::class);
|
||||
@ -224,41 +231,44 @@ class CatchUpload
|
||||
|
||||
if ($upload) {
|
||||
$disk = app()->config->get('filesystem.disks');
|
||||
$uploadConfigs = $configModel->getConfig($upload->id);
|
||||
// 读取上传可配置数据
|
||||
foreach ($uploadConfigs as $key => &$config) {
|
||||
// $disk[$key]['type'] = $key;
|
||||
// 腾讯云配置处理
|
||||
if (strtolower($key) == 'qcloud') {
|
||||
$config['credentials'] = [
|
||||
'appId' => $config['app_id'] ?? '',
|
||||
'secretKey' => $config['secret_key'] ?? '',
|
||||
'secretId' => $config['secret_id'] ?? '',
|
||||
];
|
||||
$readFromCdn = $config['read_from_cdn'] ?? false;
|
||||
$config['read_from_cdn'] = $readFromCdn ? true : false;
|
||||
}
|
||||
// OSS 配置
|
||||
if (strtolower($key) == 'oss') {
|
||||
$isCname = $config['is_cname'] ?? false;
|
||||
$config['is_cname'] = $isCname ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
// 合并数组
|
||||
array_walk($disk, function (&$item, $key) use ($uploadConfigs){
|
||||
if (!in_array($key, ['public', 'local'])) {
|
||||
if ($uploadConfigs[$key] ?? false) {
|
||||
foreach ($uploadConfigs[$key] as $k => $value) {
|
||||
$item[$k] = $value;
|
||||
}
|
||||
$uploadConfigs = $configModel->getConfig($upload->id);
|
||||
if (!empty($uploadConfigs)) {
|
||||
// 读取上传可配置数据
|
||||
foreach ($uploadConfigs as $key => &$config) {
|
||||
// $disk[$key]['type'] = $key;
|
||||
// 腾讯云配置处理
|
||||
if (strtolower($key) == 'qcloud') {
|
||||
$config['credentials'] = [
|
||||
'appId' => $config['app_id'] ?? '',
|
||||
'secretKey' => $config['secret_key'] ?? '',
|
||||
'secretId' => $config['secret_id'] ?? '',
|
||||
];
|
||||
$readFromCdn = $config['read_from_cdn'] ?? false;
|
||||
$config['read_from_cdn'] = $readFromCdn ? true : false;
|
||||
}
|
||||
// OSS 配置
|
||||
if (strtolower($key) == 'oss') {
|
||||
$isCname = $config['is_cname'] ?? false;
|
||||
$config['is_cname'] = $isCname ? true : false;
|
||||
}
|
||||
}
|
||||
});
|
||||
// 重新分配配置
|
||||
app()->config->set([
|
||||
'disk' => $disk,
|
||||
], 'filesystem');
|
||||
|
||||
// 合并数组
|
||||
array_walk($disk, function (&$item, $key) use ($uploadConfigs) {
|
||||
if (!in_array($key, ['public', 'local'])) {
|
||||
if ($uploadConfigs[$key] ?? false) {
|
||||
foreach ($uploadConfigs[$key] as $k => $value) {
|
||||
$item[$k] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// 重新分配配置
|
||||
app()->config->set([
|
||||
'disk' => $disk,
|
||||
], 'filesystem');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user