批量提交
This commit is contained in:
+201
-12
@@ -1,17 +1,206 @@
|
||||
<?php
|
||||
/**
|
||||
* 后台管理系统-首页
|
||||
*/
|
||||
namespace app\admin\controller;
|
||||
use app\admin\controller\Base;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\facade\Env;
|
||||
use think\facade\Config;
|
||||
|
||||
use app\BaseController;
|
||||
class Index extends Base{
|
||||
# 首页
|
||||
public function index(){
|
||||
$menus = [];
|
||||
$menu = [];
|
||||
$where = ['group_id'=>$this->aUser['group_id']];
|
||||
$role = Db::table('yz_admin_user_group')->where($where)->find();
|
||||
if($role){
|
||||
$role['rights'] = (isset($role['rights']) && $role['rights']) ? json_decode($role['rights'],true) : [];
|
||||
}
|
||||
if($role['rights']){
|
||||
$where = [
|
||||
['smid','in',implode(',',$role['rights']) ],
|
||||
['status','=',1]
|
||||
];
|
||||
// 获取所有菜单
|
||||
$menus = Db::table('yz_admin_sys_menu')->order('type,sort desc')->where($where)->select()->toArray();
|
||||
|
||||
// 构建树形结构菜单
|
||||
$menuTree = [];
|
||||
$menuMap = [];
|
||||
|
||||
// 先将所有菜单项映射到一个关联数组中
|
||||
foreach($menus as $item){
|
||||
$item['children'] = [];
|
||||
$menuMap[$item['smid']] = $item;
|
||||
}
|
||||
|
||||
// 构建树形结构
|
||||
foreach($menus as $item){
|
||||
if($item['parent_id'] == 0){
|
||||
// 顶级菜单
|
||||
$menuTree[$item['smid']] = &$menuMap[$item['smid']];
|
||||
}else{
|
||||
// 子菜单,添加到父菜单的children数组中
|
||||
if(isset($menuMap[$item['parent_id']])){
|
||||
$menuMap[$item['parent_id']]['children'][] = &$menuMap[$item['smid']];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$menu = $menuTree;
|
||||
}
|
||||
|
||||
View::assign([
|
||||
'role' => $role,
|
||||
'menu' => $menu
|
||||
]);
|
||||
return View::fetch();
|
||||
}
|
||||
# 欢迎页面
|
||||
public function welcome(){
|
||||
View::assign([
|
||||
'time' => date('Y-m-d',$_SERVER['REQUEST_TIME']),
|
||||
]);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
class Index extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">16载初心不改 - 你值得信赖的PHP框架 Admin模块</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
|
||||
}
|
||||
/**
|
||||
* 保存附件信息到数据库
|
||||
* @param string $name 文件名
|
||||
* @param int $type 附件类型
|
||||
* @param int $size 文件大小
|
||||
* @param string $src 文件路径
|
||||
* @return int 附件ID
|
||||
*/
|
||||
private function saveAttachment($name, $type, $size, $src) {
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'type' => $type,
|
||||
'size' => $size,
|
||||
'src' => $src,
|
||||
'create_time' => time(),
|
||||
'update_time' => time()
|
||||
];
|
||||
return Db::table('yz_attachments')->insertGetId($data);
|
||||
}
|
||||
|
||||
public function hello($name = 'ThinkPHP6')
|
||||
{
|
||||
return 'hello,' . $name;
|
||||
}
|
||||
}
|
||||
# 图片上传
|
||||
public function upload_img(){
|
||||
// 获取上传的文件
|
||||
$file = request()->file();
|
||||
$files = request()->file('file');
|
||||
|
||||
// 检查是否有文件上传
|
||||
if(empty($file)){
|
||||
return json(['code'=>1, 'msg'=>'没有文件上传'])->send();
|
||||
}
|
||||
|
||||
try {
|
||||
// 验证上传的文件
|
||||
validate([
|
||||
'image'=>'filesize:10240|fileExt:jpg,png,gif,jpeg'
|
||||
])->check($file);
|
||||
|
||||
// 存储文件到public磁盘的uploads目录
|
||||
$info = \think\facade\Filesystem::disk('public')->putFile('uploads', $files);
|
||||
|
||||
// 处理文件路径,统一使用正斜杠
|
||||
$info = str_replace("\\", "/", $info);
|
||||
$img = '/storage/'.$info;
|
||||
|
||||
// 保存附件信息
|
||||
$fileName = $files->getOriginalName();
|
||||
$fileSize = $files->getSize();
|
||||
$attachmentId = $this->saveAttachment($fileName, 1, $fileSize, $img);
|
||||
|
||||
// 返回成功信息
|
||||
return json([
|
||||
'code' => 0,
|
||||
'data' => $img,
|
||||
'url' => $this->config['admin_domain'].$img,
|
||||
'attachment_id' => $attachmentId
|
||||
])->send();
|
||||
|
||||
} catch (\think\exception\ValidateException $e) {
|
||||
// 捕获验证异常并返回错误信息
|
||||
return json(['code'=>1, 'msg'=>$e->getMessage()])->send();
|
||||
} catch (\Exception $e) {
|
||||
// 捕获其他异常
|
||||
return json(['code'=>1, 'msg'=>'上传失败:'.$e->getMessage()])->send();
|
||||
}
|
||||
}
|
||||
# 富文本图片上传
|
||||
public function upload_imgs(){
|
||||
$file = request()->file();
|
||||
$files = request()->file('file');
|
||||
if(empty($file)){
|
||||
return json(['code'=>1, 'msg'=>'没有文件上传'])->send();
|
||||
}
|
||||
try {
|
||||
validate(['image'=>'filesize:10240|fileExt:jpg,png,gif,jpeg'])->check($file);
|
||||
$info = \think\facade\Filesystem::disk('public')->putFile('uploads', $files);
|
||||
|
||||
// 处理文件路径
|
||||
$info = str_replace("\\", "/", $info);
|
||||
$img = '/storage/'.$info;
|
||||
|
||||
// 保存附件信息
|
||||
$fileName = $files->getOriginalName();
|
||||
$fileSize = $files->getSize();
|
||||
$attachmentId = $this->saveAttachment($fileName, 2, $fileSize, $img);
|
||||
|
||||
return json([
|
||||
'code' => 0,
|
||||
'data' => [
|
||||
'src' => $img,
|
||||
'attachment_id' => $attachmentId
|
||||
]
|
||||
])->send();
|
||||
} catch (\think\exception\ValidateException $e) {
|
||||
return json(['code'=>1, 'msg'=>$e->getMessage()])->send();
|
||||
}
|
||||
}
|
||||
# 富文本图片上传
|
||||
public function upload_imgs_kin(){
|
||||
$file = request()->file();
|
||||
$files = request()->file('imgFile');
|
||||
|
||||
if(empty($file)){
|
||||
return json(['error'=>1, 'message'=>'没有文件上传'])->send();
|
||||
}
|
||||
try {
|
||||
validate(['image'=>'filesize:10240|fileExt:jpg,png,gif,jpeg'])->check($file);
|
||||
$info = \think\facade\Filesystem::disk('public')->putFile('uploads', $files);
|
||||
|
||||
// 处理文件路径
|
||||
$info = str_replace("\\", "/", $info);
|
||||
$img = '/storage/'.$info;
|
||||
|
||||
// 保存附件信息
|
||||
$fileName = $files->getOriginalName();
|
||||
$fileSize = $files->getSize();
|
||||
$attachmentId = $this->saveAttachment($fileName, 3, $fileSize, $img);
|
||||
|
||||
return json([
|
||||
'error' => 0,
|
||||
'url' => $img,
|
||||
'attachment_id' => $attachmentId
|
||||
])->send();
|
||||
} catch (\think\exception\ValidateException $e) {
|
||||
return json(['error'=>1, 'message'=>$e->getMessage()])->send();
|
||||
}
|
||||
}
|
||||
# 清除缓存
|
||||
public function clear(){
|
||||
$a = delete_dir_file(Env::get('runtime_path').'cache/');
|
||||
$b = delete_dir_file(Env::get('runtime_path').'temp/');
|
||||
if ($a || $b) {
|
||||
$this->returnCode(0);
|
||||
} else {
|
||||
$this->returnCode('91000006');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user