Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jcy2004x
ShopXO
提交
06945529
ShopXO
项目概览
jcy2004x
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
06945529
编写于
6月 25, 2019
作者:
G
gongfuxiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
附件优化
上级
27105bc9
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
70 addition
and
25 deletion
+70
-25
application/api/controller/Ueditor.php
application/api/controller/Ueditor.php
+15
-25
application/service/ResourcesService.php
application/service/ResourcesService.php
+55
-0
未找到文件。
application/api/controller/Ueditor.php
浏览文件 @
06945529
...
...
@@ -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,29 +236,28 @@ 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
,
]);
// 返回数据
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
);
}
}
/**
* [ActionList 文件列表]
...
...
application/service/ResourcesService.php
浏览文件 @
06945529
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录