提交 06945529 编写于 作者: G gongfuxiang

附件优化

上级 27105bc9
......@@ -11,6 +11,7 @@
namespace app\api\controller;
use think\facade\Hook;
use app\service\ResourcesService;
/**
* 百度编辑器控制器入口
......@@ -227,16 +228,6 @@ class Ueditor extends Common
$attachment_type = "file";
}
// 附件上传前处理钩子
$hook_name = 'plugins_controller_attachment_upload_handle_begin';
Hook::listen($hook_name, [
'hook_name' => $hook_name,
'is_backend' => true,
'attachment_type' => $attachment_type,
'field_name' => $field_name,
'temp_config' => &$temp_config,
]);
/* 生成上传实例对象并完成上传 */
$up = new \base\Uploader($field_name, $temp_config, $attachment_type);
......@@ -245,28 +236,27 @@ class Ueditor extends Common
* array(
* "state" => "", //上传状态,上传成功时必须返回"SUCCESS"
* "url" => "", //返回的地址
* "path" => "", //绝对地址
* "title" => "", //新文件名
* "original" => "", //原始文件名
* "type" => "" //文件类型
* "size" => "", //文件大小
* "hash" => "", //sha256值
* )
*/
$data = $up->getFileInfo();
print_r($data);die;
// 附件上传成功后处理钩子
$hook_name = 'plugins_controller_attachment_upload_handle_end';
Hook::listen($hook_name, [
'hook_name' => $hook_name,
'is_backend' => true,
'attachment_type' => $attachment_type,
'field_name' => $field_name,
'temp_config' => $temp_config,
'data' => &$data,
]);
// 返回数据
$this->current_result = json_encode($data);
if(isset($data['state']) && $data['state'] == 'SUCCESS')
{
$ret = ResourcesService::AttachmentAdd($data);
if($ret['code'] == 0)
{
$this->current_result = json_encode($ret['data']);
} else {
$this->current_result = json_encode(['state'=>$ret['msg']]);
}
} else {
$this->current_result = json_encode($data);
}
}
/**
......
......@@ -11,6 +11,7 @@
namespace app\service;
use think\Db;
use think\facade\Hook;
/**
* 资源服务层
......@@ -105,5 +106,59 @@ class ResourcesService
}
return '';
}
/**
* 附件添加
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-06-25T00:13:33+0800
* @param [array] $params [输入参数]
*/
public static function AttachmentAdd($params = [])
{
if(!empty($params['title']))
{
// 数据组装
$data = [
'path_type' => input('path_type', 'other'),
'original' => empty($params['original']) ? '' : mb_substr($params['original'], -160, null, 'utf-8'),
'title' => $params['title'],
'size' => $params['size'],
'type' => $params['type'],
'hash' => $params['hash'],
'path' => self::AttachmentPathHandle($params['url']),
'add_time' => time(),
];
// 附件上传前处理钩子
$hook_name = 'plugins_service_attachment_handle_begin';
Hook::listen($hook_name, [
'hook_name' => $hook_name,
'is_backend' => true,
'params' => $params,
'data' => &$data,
]);
// 添加到数据库
$attachment_id = Db::name('Attachment')->insertGetId($data);
if($attachment_id > 0)
{
// 附件上传后处理钩子
$hook_name = 'plugins_service_attachment_handle_end';
$ret = Hook::listen($hook_name, [
'hook_name' => $hook_name,
'is_backend' => true,
'params' => &$params,
'data' => &$data,
'attachment_id' => $attachment_id,
]);
return DataReturn('添加成功', 0, $params);
}
return DataReturn('添加失败', 0);
}
return DataReturn('附件不能为空', -1);
}
}
?>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册