From 50114953fbbe2d133b47aa9ca2531b43aacafec2 Mon Sep 17 00:00:00 2001 From: 1099438829 <1099438829@qq.com> Date: Sat, 20 Feb 2021 12:57:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8F=8B=E9=93=BE=E5=92=8C?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Files.php | 185 ++++++++----------------- app/admin/controller/FriendLink.php | 76 +++++++--- app/admin/controller/Images.php | 4 +- app/admin/model/Attachment.php | 3 +- app/admin/model/AttachmentCategory.php | 2 +- app/admin/view/friendlink/index.html | 37 ++--- app/admin/view/images/index.html | 4 +- 7 files changed, 133 insertions(+), 178 deletions(-) diff --git a/app/admin/controller/Files.php b/app/admin/controller/Files.php index 939da12..77edded 100644 --- a/app/admin/controller/Files.php +++ b/app/admin/controller/Files.php @@ -6,7 +6,9 @@ namespace app\admin\controller; use app\admin\model\Attachment; use app\admin\services\storage\QcloudCoService; use app\admin\services\UtilService as Util; +use think\exception\ValidateException; use think\facade\Filesystem; +use think\Request; class Files extends AuthController { @@ -66,145 +68,74 @@ class Files extends AuthController return json_encode(['location'=>"/uploads/".$savename]); } - /** - * 上传多图片 - * @return mixed - */ - public function images() - { - return Filesystem::putFile( 'image', request()->file('file')) ? app("json")->code()->success("上传成功") : app("json")->fail("上传失败"); - } - - /** - * 证书上传 - * @return mixed - */ - public function cert() - { - $file = $this->request->file("file"); - $savename = Filesystem::putFile( 'file', $file); - $filePath = "/uploads/".$savename; - return $savename ? app("json")->code()->success("上传成功",['filePath'=>$filePath,"name"=>$savename]) : app("json")->fail("上传失败"); - } - - /** - * 上传文件到cid:0, - * 图片 视频 音频 - * @return mixed - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function file() - { - $file = $this->request->file("file"); - try { - $savename = Filesystem::putFile( 'file', $file); - $filePath = "/uploads/".$savename; - return $savename ? app("json")->code()->success("上传成功",['filePath'=>$filePath,"name"=>$savename]) : app("json")->fail("上传失败"); - } catch (\think\exception\ValidateException $e) { - return app("json")->fail($e->getMessage()); - } - } - - /** - * @文档上传 - * @return mixed - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function document() - { - // 获取表单上传文件 例如上传了001.jpg - $file = request()->file('file');//根据表单name替换imgFile - try { - // 使用验证器验证上传的文件 - validate(['file' => [ - // 限制文件大小(单位b),这里限制为5M - 'fileSize' => 5 * 1024 * 1024, - // 限制文件后缀,多个后缀以英文逗号分割 - 'fileExt' => 'pdf,doc,docx' - // 更多规则请看“上传验证”的规则,文档地址https://www.kancloud.cn/manual/thinkphp6_0/1037629#_444 - ]])->check(['file' => $file]); - $savename = Filesystem::putFile( 'file', $file); - $filePath = "/uploads/".$savename; - return $savename ? app("json")->code()->success("上传成功",['filePath'=>$filePath,"name"=>$savename]) : app("json")->fail("上传失败"); - } catch (\think\exception\ValidateException $e) { - return app("json")->fail($e->getMessage()); - } - } /** * @单文件上传 * @param string $type 类型 files images documents banners * @return mixed */ - public function upload() + public function upload(Request $request) { - if(Request::isPost()) { + if($request->isPost()) { // 获取表单上传文件 例如上传了001.jpg - $file = request()->file('file');//根据表单name替换imgFile + $file = $request->file('file');//根据表单name替换imgFile $type = $this->request->post("type"); $type = $type ?:'files'; - switch ($type) { - case 'files': - $fileSize = 10 * 1024 * 1024; - $fileExt = 'pdf,doc,docx'; + switch (system_config("storage_type")) + { + case 1: + switch ($type) { + case 'files': + $fileSize = 10 * 1024 * 1024; + $fileExt = 'pdf,doc,docx,png,jpeg,jpg,text,mp4'; + break; + case 'slides': + $fileSize = 10 * 1024 * 1024; + $fileExt = 'png,jpeg,jpg'; + break; + case 'documents': + $fileSize = 5 * 1024 * 1024; + $fileExt = 'pdf,doc,docx'; + break; + case 'images': + $fileSize = 5 * 1024 * 1024; + $fileExt = 'png,jpeg,jpg'; + break; + case 'avatar': + $fileSize = 4 * 1024 * 1024; + $fileExt = 'png,jpeg,jpg'; + break; + default: + $fileSize = 0 * 1024 * 1024; + $fileExt = 'pdf,doc,docx'; + break; + } + try { + // 使用验证器验证上传的文件 + validate(['file' => [ + // 限制文件大小(单位b),这里限制为5M + 'fileSize' => $fileSize, + // 限制文件后缀,多个后缀以英文逗号分割 + 'fileExt' => $fileExt + // 更多规则请看“上传验证”的规则,文档地址https://www.kancloud.cn/manual/thinkphp6_0/1037629#_444 + ]])->check(['file' => $file]); + $savename = Filesystem::putFile( $type, $file); + $filePath = "/uploads/".$savename; + $res = Attachment::addAttachment($this->request->param("cid",0),basename($savename),$filePath,$type,$file->getMime(),$file->getSize(),system_config("storage_type")); + return $res? app("json")->code()->success("上传成功",['filePath'=>$filePath,"name"=>basename($savename)]) : app("json")->fail("上传失败"); + } catch (ValidateException $e) { + return app("json")->fail($e->getMessage()); + } break; - case 'banner': - $fileSize = 5 * 1024 * 1024; - $fileExt = 'png,jpeg,jpg'; + case 2: + return app("json")->fail('上传失败'); + $savename = Filesystem::putFile( 'image', $file); + $ext = $file->getOriginalExtension(); + $key = '/image/'.date('Ymd')."/".substr(md5($file->getRealPath()) , 0, 5). date('YmdHis') . rand(0, 9999) . '.' . $ext; + $filePath = QcloudCoService::put($key, $file->getRealPath()); + $res = Attachment::addAttachment($this->request->param("cid",0),basename($savename),$filePath,$type,$file->getMime(),$file->getSize(),system_config("storage_type")); + return $res? app("json")->code()->success("上传成功",['filePath'=>$filePath,"name"=>basename($savename)]) : app("json")->fail("上传失败"); break; - case 'documents': - $fileSize = 5 * 1024 * 1024; - $fileExt = 'pdf,doc,docx'; - break; - case 'image': - $fileSize = 5 * 1024 * 1024; - $fileExt = 'png,jpeg,jpg'; - break; - case 'images': - $fileSize = 5 * 1024 * 1024; - $fileExt = 'png,jpeg,jpg'; - break; - case 'template': - $fileSize = 5 * 1024 * 1024; - $fileExt = 'pdf,doc,docx'; - break; - case 'talentpool': - $fileSize = 5 * 1024 * 1024; - $fileExt = 'pdf,doc,docx,png,jpeg,jpg'; - break; - case 'offer': - $fileSize = 5 * 1024 * 1024; - $fileExt = 'pdf,doc,docx,png,jpeg,jpg'; - break; - case 'contract': - $fileSize = 5 * 1024 * 1024; - $fileExt = 'pdf,doc,docx,png,jpeg,jpg'; - break; - default: - $fileSize = 0 * 1024 * 1024; - $fileExt = 'pdf,doc,docx'; - break; - } -// Log::record('yangzailu::'); -// Log::record($fileExt); - try { - // 使用验证器验证上传的文件 - validate(['file' => [ - // 限制文件大小(单位b),这里限制为5M - 'fileSize' => $fileSize, - // 限制文件后缀,多个后缀以英文逗号分割 - 'fileExt' => $fileExt - // 更多规则请看“上传验证”的规则,文档地址https://www.kancloud.cn/manual/thinkphp6_0/1037629#_444 - ]])->check(['file' => $file]); - $savename = Filesystem::putFile( $type, $file); - $filePath = "/uploads/".$savename; - return $savename ? app("json")->code()->success("上传成功",['filePath'=>$filePath,"name"=>basename($savename)]) : app("json")->fail("上传失败"); - } catch (ValidateException $e) { - return app("json")->fail($e->getMessage()); } }else{ return app("json")->fail('上传失败'); diff --git a/app/admin/controller/FriendLink.php b/app/admin/controller/FriendLink.php index c6c2a8f..977c3d0 100644 --- a/app/admin/controller/FriendLink.php +++ b/app/admin/controller/FriendLink.php @@ -3,8 +3,11 @@ namespace app\admin\controller; use app\admin\model\FriendLink as aModel; +use app\admin\services\FormBuilderService as Form; use app\Request; use app\admin\services\UtilService as Util; +use FormBuilder\Factory\Elm; +use think\facade\Route as Url; /** * Class Message @@ -48,16 +51,53 @@ class FriendLink extends AuthController } /** - * 更新 + * 添加账号 * @param Request $request - * @return mixed - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - * @author 李玉坤 - * @date 2021-02-16 21:15 + * @return string + * @throws \FormBuilder\Exception\FormBuilderException */ - public function update(Request $request) + public function add(Request $request) + { + $form = array(); + $form[] = Elm::input('title','链接名称')->col(10); + $form[] = Elm::input('url','链接地址')->col(10); + $form[] = Elm::frameImage('image','网站图标',Url::buildUrl('admin/images/index',array('fodder'=>'image','limit'=>1)))->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::input('sort','排序')->col(10); + $form[] = Elm::textarea('description','描述')->col(10); + $form[] = Elm::radio('status','状态',1)->options([['label'=>'启用','value'=>1],['label'=>'冻结','value'=>0]])->col(10); + $form = Form::make_post_form($form, url('save')->build()); + $this->assign(compact('form')); + return $this->fetch("public/form-builder"); + } + + /** + * 修改账号 + * @return string + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function edit($id="") + { + if (!$id) return app("json")->fail("数据id不能为空"); + $ainfo = aModel::get($id); + if (!$ainfo) return app("json")->fail("没有该数据"); + $form = array(); + $form[] = Elm::input('title','链接名称',$ainfo['title'])->col(10); + $form[] = Elm::input('url','链接地址',$ainfo['url'])->col(10); + $form[] = Elm::frameImage('image','网站图标',Url::buildUrl('admin/images/index',array('fodder'=>'image','limit'=>1)),$ainfo['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::input('sort','排序',$ainfo['sort'])->col(10); + $form[] = Elm::textarea('description','描述',$ainfo['description'])->col(10); + $form[] = Elm::radio('status','状态',$ainfo['status'])->options([['label'=>'启用','value'=>1],['label'=>'冻结','value'=>0]])->col(10); + $form = Form::make_post_form($form, url('save',['id'=>$id])->build()); + $this->assign(compact('form')); + return $this->fetch("public/form-builder"); + } + + /** + * 保存修改 + * @param string $id + * @return mixed + */ + public function save($id="") { $data = Util::postMore([ ['id',''], @@ -68,16 +108,20 @@ class FriendLink extends AuthController ['sort',''], ['status',1], ]); - if ($data['id'] == '') return app("json")->fail("参数有误,Id为空!"); - $id = $data['id']; - unset($data['id']); - $saveData = []; - foreach ($data as $key=>$value){ - if ($value !== ''){ - $saveData[$key] = $value; + if ($data['title'] == "") return app("json")->fail("链接名称不能为空"); + if ($data['url'] == "") return app("json")->fail("链接地址不能为空"); + if (is_array($data['image'])) $data['image'] = $data['avatar'][0]; + if ($id=="") { + //判断下用户是否存在 + $info = aModel::where('url',$data['url'])->find(); + if ($info){ + return app("json")->fail("链接已存在"); } + $res = aModel::create($data); + }else { + $res = aModel::update($data,['id'=>$id]); } - return aModel::update($saveData,['id'=>$id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); + return $res ? app("json")->success("操作成功",'code') : app("json")->fail("操作失败"); } /** diff --git a/app/admin/controller/Images.php b/app/admin/controller/Images.php index e2efb3c..8fffefc 100644 --- a/app/admin/controller/Images.php +++ b/app/admin/controller/Images.php @@ -36,7 +36,7 @@ class Images extends AuthController */ public function category() { - return app("json")->success(AttachmentCategory::buildNodes("image",0,$this->request->param("title",""))); + return app("json")->success(AttachmentCategory::buildNodes("images",0,$this->request->param("title",""))); } /** @@ -103,7 +103,7 @@ class Images extends AuthController if ($id == "") { $data['create_user'] = $this->adminId; - $res = AttachmentCategory::save($data); + $res = AttachmentCategory::create($data); } else { diff --git a/app/admin/model/Attachment.php b/app/admin/model/Attachment.php index df1e315..6ac27c6 100644 --- a/app/admin/model/Attachment.php +++ b/app/admin/model/Attachment.php @@ -33,9 +33,8 @@ class Attachment extends BaseModel 'mime' => $mime, 'size' => $size, 'storage' => $storage, - 'upload_time' => time() ]; - return self::insert($data); + return self::create($data); } /** diff --git a/app/admin/model/AttachmentCategory.php b/app/admin/model/AttachmentCategory.php index 5fd731a..30070e7 100644 --- a/app/admin/model/AttachmentCategory.php +++ b/app/admin/model/AttachmentCategory.php @@ -57,7 +57,7 @@ class AttachmentCategory extends BaseModel * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public static function buildNodes(string $type = "image", int $pid = 0, string $title = "") + public static function buildNodes(string $type = "images", int $pid = 0, string $title = "") { $model = new self; $model = $model->where("type",$type); diff --git a/app/admin/view/friendlink/index.html b/app/admin/view/friendlink/index.html index fe66d03..dca1e72 100644 --- a/app/admin/view/friendlink/index.html +++ b/app/admin/view/friendlink/index.html @@ -45,7 +45,7 @@
- 删除 @@ -133,12 +133,17 @@ let html = ' \n' + ''; return html; + }, + events: { + 'click .btn-edit': function (event, value, row, index) { + iframe.createIframe('修改友链','/admin/friendlink/edit?id='+row.id) + }, } }], onEditableSave: function (field, row) { $.ajax({ type: "post", - url: "/admin/friendlink/update", + url: "/admin/friendlink/save", data: row, success: function (res) { if (res.code == 200 || res.status == 200) { @@ -195,31 +200,7 @@ text: '确认', btnClass: 'btn-danger', action: function () { - $.post("/admin/admin_log/del",data={id:id},function (res) { - if (res.status == 200 || res.code == 200) lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); - else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center'); - location.reload(); - }) - } - }, - cancel: { - text: '取消', - btnClass: 'btn-primary' - } - } - }); - } - function delAll() { - $.confirm({ - title: '重要提醒!', - content: '清空后将不可恢复,请谨慎操作!', - backgroundDismiss: true, - buttons: { - ok: { - text: '确认', - btnClass: 'btn-danger', - action: function () { - $.post("/admin/admin_log/empty",data={},function (res) { + $.post("/admin/friendlink/del",data={id:id},function (res) { if (res.status == 200 || res.code == 200) lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center'); location.reload(); @@ -252,7 +233,7 @@ text: '确认', btnClass: 'btn-danger', action: function () { - $.post("/admin/admin_log/del",data={id:checkID},function (res) { + $.post("/admin/friendlink/del",data={id:checkID},function (res) { if (res.status == 200 || res.code == 200) { lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');location.reload();} else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center'); }) diff --git a/app/admin/view/images/index.html b/app/admin/view/images/index.html index 6084224..de0b284 100644 --- a/app/admin/view/images/index.html +++ b/app/admin/view/images/index.html @@ -229,7 +229,6 @@ }); // 选中节点 $('#tree').on('nodeSelected', function (event, data) { - console.log(data); id = data.id; pid = data.pid; that.getImageList(); @@ -300,10 +299,11 @@ if (!$("#fileUpload").val()) return; var formData = new FormData(); formData.append("file", $("#fileUpload")[0].files[0]); + formData.append("type",'images'); formData.append("cid",id); $.ajax({ type: "POST", - url: "/admin/files/image", + url: "/admin/files/upload", enctype: 'multipart/form-data', data: formData, processData: false,