diff --git a/README.md b/README.md index 825a88a..62afb00 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ * 后台:http://adm.aieok.com * 账号:test * 密码:test123 - * 版本:TaoLer 1.7.15 - * 日期:2021.7.1 + * 版本:TaoLer 1.7.16 + * 日期:2021.7.15 #### 项目地址 diff --git a/app/admin/controller/Forum.php b/app/admin/controller/Forum.php index 1a0ebc8..06a2129 100644 --- a/app/admin/controller/Forum.php +++ b/app/admin/controller/Forum.php @@ -221,7 +221,7 @@ class Forum extends AdminController $where[] = ['a.content','like','%'.$map['content'].'%']; unset($map['content']); } - if(isset($data['status'])){ + if(isset($data['status']) && $data['status'] !== '' ){ $where[] = ['a.status','=',(int)$data['status']]; unset($map['status']); } diff --git a/app/admin/controller/Set.php b/app/admin/controller/Set.php index 8b4be21..9706cbb 100644 --- a/app/admin/controller/Set.php +++ b/app/admin/controller/Set.php @@ -106,26 +106,16 @@ class Set extends AdminController //上传logo public function upload() { - $file = request()->file('file'); - - try { - validate(['image'=>'filesize:2048|fileExt:jpg,png,gif|image:200,200,jpg']) - ->check(array($file)); - $savename = \think\facade\Filesystem::disk('public')->putFile('logo',$file); - } catch (think\exception\ValidateException $e) { - echo $e->getMessage(); - } - $upload = Config::get('filesystem.disks.public.url'); - - if($savename){ - $name_path =str_replace('\\',"/",$upload.'/'.$savename); - $result = Db::name('system')->where('id', 1)->update(['logo'=>$name_path]); + $uploads = new \app\common\lib\Uploads(); + $upRes = $uploads->put('file','logo',2000,'image','uniqid'); + $logoJson = $upRes->getData(); + if($logoJson['status'] == 0){ + $result = Db::name('system')->where('id', 1)->update(['logo'=>$logoJson['url']]); if($result){ $res = ['code'=>0,'msg'=>'上传logo成功']; } else { $res = ['code'=>1,'msg'=>'上传错误']; } - } return json($res); } diff --git a/app/admin/controller/Slider.php b/app/admin/controller/Slider.php index 12518f3..ff80124 100644 --- a/app/admin/controller/Slider.php +++ b/app/admin/controller/Slider.php @@ -12,9 +12,10 @@ use app\admin\model\Slider as SliderModel; class Slider extends AdminController { /** - * 显示资源列表 - * - * @return \think\Response + * @return string + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException */ public function index() { @@ -50,10 +51,11 @@ class Slider extends AdminController /** - * 编辑幻灯 - * - * @param int $id - * @return \think\Response + * @param $id + * @return string|\think\response\Json + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException */ public function edit($id) { @@ -78,27 +80,16 @@ class Slider extends AdminController } /** - * 保存更新的资源 - * - * @param - * @param int $id - * @return \think\Response + * @return \think\response\Json */ public function uploadImg() { - $id = Request::param(); - $file = request()->file('file'); - try { - validate(['image'=>'filesize:2048|fileExt:jpg,png,gif|image:200,200,jpg']) - ->check(array($file)); - $savename = \think\facade\Filesystem::disk('public')->putFile('slider',$file); - } catch (think\exception\ValidateException $e) { - echo $e->getMessage(); - } - $upload = Config::get('filesystem.disks.public.url'); - - if($savename){ - $name_path =str_replace('\\',"/",$upload.'/'.$savename); + $uploads = new \app\common\lib\Uploads(); + $upRes = $uploads->put('file','slider',1024,'image'); + $slires = $upRes->getData(); + + if($slires['status'] == 0){ + $name_path = $slires['url']; $res = ['code'=>0,'msg'=>'上传flash成功','src'=>$name_path]; } else { $res = ['code'=>1,'msg'=>'上传错误']; @@ -107,10 +98,11 @@ class Slider extends AdminController } /** - * 删除指定资源 - * - * @param int $id - * @return \think\Response + * @param $id + * @return \think\response\Json + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException */ public function delete($id) { diff --git a/app/admin/controller/Upgrade.php b/app/admin/controller/Upgrade.php index 1a06927..cbc9dd3 100644 --- a/app/admin/controller/Upgrade.php +++ b/app/admin/controller/Upgrade.php @@ -294,13 +294,17 @@ class Upgrade extends AdminController public function uploadZip() { $files = request()->file('file'); + $mime = $files->getMime(); + if($mime !== 'application/zip'){ + return json(['code'=>-1,'msg'=>'文件类型不对']); + } $name = $files->getOriginalName(); //校验后缀 $ext = pathinfo($name,PATHINFO_EXTENSION); //文件后缀 if($ext != 'zip') { - return json(['code'=>0,'msg'=>'请上传文件格式不对']); + return json(['code'=>-1,'msg'=>'上传文件格式不对']); } //对比版本号 $fname = pathinfo($name,PATHINFO_FILENAME); //无后缀文件名 diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index ad64f33..49bc05f 100644 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -4,14 +4,11 @@ namespace app\admin\controller; use app\common\controller\AdminController; use app\admin\validate\Admin; -use app\admin\model\Admin as adminModel; use think\facade\View; use think\facade\Request; -use think\facade\Config; use think\facade\Db; -use think\facade\Session; -use think\exception\ValidateException; use app\common\model\User as UserModel; +use app\common\lib\Uploads; class User extends AdminController { @@ -26,7 +23,7 @@ class User extends AdminController public function list() { if(Request::isAjax()){ - $datas = Request::only(['id','name','email','sex']); + $datas = Request::only(['id','name','email','sex','status']); $map = array_filter($datas,[$this,'filtrArr']); $user = Db::name('user')->where(['delete_time'=>0])->where($map)->order('id desc')->paginate(30); $count = $user->total(); @@ -100,31 +97,22 @@ class User extends AdminController //上传头像 public function uploadImg() { - $file = request()->file('file'); - try { - validate(['file'=>'fileSize:204800|fileExt:jpg,png,gif']) - ->check(['file'=>$file]); - $savename = \think\facade\Filesystem::disk('public')->putFile('head_pic',$file); - } catch (think\exception\ValidateException $e) { - echo $e->getMessage(); - } - $upload = Config::get('filesystem.disks.public.url'); - - if($savename){ - $name_path =str_replace('\\',"/",$upload.'/'.$savename); - $res = ['code'=>0,'msg'=>'上传头像成功','src'=>$name_path]; - } else { - $res = ['code'=>-1,'msg'=>'上传错误']; - } - return json($res); + $uploads = new Uploads(); + $upRes = $uploads->put('file','head_pic',2000,'image'); + $userJson = $upRes->getData(); + if($userJson['status'] == 0){ + $res = ['code'=>0,'msg'=>'上传头像成功','src'=>$userJson['url']]; + } else { + $res = ['code'=>1,'msg'=>'上传错误']; + } + return json($res); } //审核用户 public function check() { - $data = Request::param(); - + $data = Request::only(['id','status']); //获取状态 $res = Db::name('user')->where('id',$data['id'])->save(['status' => $data['status']]); if($res){ diff --git a/app/admin/view/set/system/website.html b/app/admin/view/set/system/website.html index 7f320ae..6d6d7fa 100644 --- a/app/admin/view/set/system/website.html +++ b/app/admin/view/set/system/website.html @@ -188,7 +188,8 @@ //LOGO选完文件后不自动上传 upload.render({ elem: '#logo-img' - ,url: '{:url('admin/set/upload')}' + ,url: "{:url('admin/set/upload')}" + ,data: {type:'image'} ,auto: false ,exts: 'jpg|png|gif|bmp|jpeg' ,size: 1000 diff --git a/app/admin/view/slider/add.html b/app/admin/view/slider/add.html index 64fef9a..b072360 100644 --- a/app/admin/view/slider/add.html +++ b/app/admin/view/slider/add.html @@ -104,21 +104,20 @@ ,btns: ['clear', 'now'] ,trigger: 'click' }); - + //上传图片 upload.render({ elem: '#layuiadmin-upload-slid-img' ,url: 'uploadImg' + ,data:{type:'image'} ,accept: 'images' ,acceptMime: 'image/*' ,auto: false ,choose: function (obj) { //选择文件后的回调 imgcom.uploads(obj); } - ,done: function(res){ //console.log(res) $(this.item).prev("div").children("input").val(res.src) - if(res.code == 0){ layer.msg(res.msg,{ icon:6, diff --git a/app/admin/view/slider/edit.html b/app/admin/view/slider/edit.html index 262056c..178617f 100644 --- a/app/admin/view/slider/edit.html +++ b/app/admin/view/slider/edit.html @@ -73,11 +73,12 @@ base: '/static/admin/' //静态资源所在路径 }).extend({ index: 'lib/index' //主入口模块 - }).use(['index', 'form', 'upload','laydate','colorpicker'], function(){ + }).use(['index', 'form', 'upload','laydate','colorpicker', 'imgcom'], function(){ var $ = layui.$ ,form = layui.form ,laydate = layui.laydate - ,upload = layui.upload ; + ,upload = layui.upload + ,imgcom = layui.imgcom; var colorpicker = layui.colorpicker; //颜色表单赋值 @@ -102,17 +103,22 @@ ,btns: ['clear', 'now'] ,trigger: 'click' }); - + + //上传图片 upload.render({ //var id = $('.layui-btn').(this).attr('dataid'); elem: '#layuiadmin-upload-slid-img' ,url: 'uploadImg' + ,data:{type:'image'} ,accept: 'images' ,method: 'get' ,acceptMime: 'image/*' + ,auto: false + ,choose: function (obj) { //选择文件后的回调 + imgcom.uploads(obj); + } ,done: function(res){ $(this.item).prev("div").children("input").val(res.src) - if(res.code == 0){ layer.msg(res.msg,{ icon:6, diff --git a/app/admin/view/upgrade/index.html b/app/admin/view/upgrade/index.html index 53da15f..2ee48c2 100644 --- a/app/admin/view/upgrade/index.html +++ b/app/admin/view/upgrade/index.html @@ -152,6 +152,7 @@ upload.render({ elem: '#select-file' ,url: "{:url('admin/upgrade/uploadzip')}" + ,data: {type:'zip'} ,accept: 'file' ,acceptMime: 'application/zip' ,field: 'file' diff --git a/app/admin/view/user/list.html b/app/admin/view/user/list.html index 7ac84cf..9da8191 100644 --- a/app/admin/view/user/list.html +++ b/app/admin/view/user/list.html @@ -33,6 +33,17 @@ + +