From 4f9c25ab3dcfbd7eb9525612573ed261beb4578b Mon Sep 17 00:00:00 2001 From: toogee Date: Mon, 19 Oct 2020 17:23:55 +0800 Subject: [PATCH] message --- app/admin/controller/Notice.php | 3 +- app/common/lib/UploadFile.php | 30 +++++++ app/event.php | 3 + app/event/Message.php | 11 +++ app/index/controller/Article.php | 5 +- app/index/controller/Error.php | 5 +- app/index/controller/Login.php | 2 +- app/index/controller/Message.php | 6 +- app/listener/CommMsg.php | 21 +++++ app/listener/Message.php | 21 +++++ config/app.php | 12 ++- extend/taoler/com/Files.php | 106 +++++++++++++--------- extend/taoler/com/Message.php | 33 +++++-- public/static/admin/modules/addons.js | 124 ++++++++++++++++++++++++++ public/static/admin/modules/notice.js | 8 +- view/404.html | 2 +- view/taoler/index/error/404.html | 46 ---------- view/taoler/index/public/404.html | 57 ------------ 18 files changed, 321 insertions(+), 174 deletions(-) create mode 100644 app/common/lib/UploadFile.php create mode 100644 app/event/Message.php create mode 100644 app/listener/CommMsg.php create mode 100644 app/listener/Message.php create mode 100644 public/static/admin/modules/addons.js delete mode 100644 view/taoler/index/error/404.html delete mode 100644 view/taoler/index/public/404.html diff --git a/app/admin/controller/Notice.php b/app/admin/controller/Notice.php index 25d2528..4f6fb28 100644 --- a/app/admin/controller/Notice.php +++ b/app/admin/controller/Notice.php @@ -37,7 +37,7 @@ class Notice extends AdminController public function add() { $sendId = Session::get('admin_id'); - var_dump($sendId); + $data = Request::only(['type','title','receve_id','content']); if($data['type'] == 1){ $receveId = $data['receve_id']; //个人通知 @@ -49,6 +49,7 @@ class Notice extends AdminController //写入信息库 $result = Message::sendMsg($sendId,$receveId,$data); if($result){ + event('Message'); $res = ['code'=>0,'msg'=>'发布成功']; } else { $res = ['code'=>0,'msg'=>'发布失败']; diff --git a/app/common/lib/UploadFile.php b/app/common/lib/UploadFile.php new file mode 100644 index 0000000..f213fa7 --- /dev/null +++ b/app/common/lib/UploadFile.php @@ -0,0 +1,30 @@ +path = $path; + } + + private function __clone() + { + // TODO: Implement __clone() method. + } + + static function getInstance() + { + if(!(self::$_instance)){ + self::$_instance = new self(); + } + return self::$_instance; + } + +} \ No newline at end of file diff --git a/app/event.php b/app/event.php index e9851bb..0a5c5d1 100644 --- a/app/event.php +++ b/app/event.php @@ -2,6 +2,7 @@ // 事件定义文件 return [ 'bind' => [ + 'Message' => 'app\event\Message', ], 'listen' => [ @@ -10,6 +11,8 @@ return [ 'HttpEnd' => [], 'LogLevel' => [], 'LogWrite' => [], + 'Message' => ['app\listener\Message'], + 'CommMsg' => ['app\listener\CommMsg'], ], 'subscribe' => [ diff --git a/app/event/Message.php b/app/event/Message.php new file mode 100644 index 0000000..a7e8102 --- /dev/null +++ b/app/event/Message.php @@ -0,0 +1,11 @@ +comments()->where('status',1)->order(['cai'=>'asc','create_time'=>'asc'])->paginate(10); $article->inc('pv')->update(); $pv = Db::name('article')->field('pv')->where('id',$id)->value('pv'); + $download = download($article->upzip,'file'); /* $nt = time(); @@ -193,7 +194,7 @@ class Article extends BaseController //通用右栏 $ad_comm = Db::name('slider')->where('slid_status',1)->where('delete_time',0)->where('slid_type',2)->whereTime('slid_over','>=',time())->select(); - View::assign(['article'=>$article,'pv'=>$pv,'comments'=>$comments,'artHot'=>$artHot,'ad_art'=>$ad_article,'ad_comm'=>$ad_comm]); + View::assign(['article'=>$article,'pv'=>$pv,'comments'=>$comments,'artHot'=>$artHot,'ad_art'=>$ad_article,'ad_comm'=>$ad_comm,$download]); return View::fetch(); } @@ -224,7 +225,7 @@ class Article extends BaseController } $data = ['title'=>$title,'content'=>'评论通知','link'=>$link,'user_id'=>$sendId,'type'=>1]; Message::sendMsg($sendId,$receveId,$data); - + //event('CommMsg'); $res = ['code'=>0, 'msg'=>'留言成功']; } else { $res = ['code'=>-1, 'msg'=>'留言失败']; diff --git a/app/index/controller/Error.php b/app/index/controller/Error.php index f643bd6..cb2d0fb 100644 --- a/app/index/controller/Error.php +++ b/app/index/controller/Error.php @@ -2,12 +2,11 @@ namespace app\index\controller; use think\facade\View; -use app\common\controller\BaseController; -class Error extends BaseController +class Error { public function __call($method, $args) { - return View::fetch('error/404'); + return View::fetch('../view/404'); } } \ No newline at end of file diff --git a/app/index/controller/Login.php b/app/index/controller/Login.php index 71de334..d3f1b93 100644 --- a/app/index/controller/Login.php +++ b/app/index/controller/Login.php @@ -66,7 +66,7 @@ class Login extends BaseController $res = $user->login($data); if ($res == 1) { //获取系统站内通知信息 - Message::insertMsg(session('user_id')); + //Message::insertMsg(session('user_id')); //跳转到登陆前页面 return json(['code'=>0,'msg'=>'登陆成功','url'=> Cookie::get('url')]); } else { diff --git a/app/index/controller/Message.php b/app/index/controller/Message.php index d92f783..af0d773 100644 --- a/app/index/controller/Message.php +++ b/app/index/controller/Message.php @@ -69,15 +69,15 @@ class Message extends BaseController //消息删除 public function remove() { - $uid = Session::get('user_id'); + $uid = $this->uid; $id = Request::only(['id']); if($id['id'] == 'true'){ //删除所有此用户消息 - $msg = Db::name('message_to')->where(['receve_id'=>$uid,'delete_time'=>0])->delete(); + $msg = Db::name('message_to')->where(['receve_id'=>$uid,'delete_time'=>0])->useSoftDelete('delete_time',time())->delete(); } else { //删除单条消息 - $msg = Db::name('message_to')->where('id',$id['id'])->delete(); + $msg = Db::name('message_to')->where('id',$id['id'])->useSoftDelete('delete_time',time())->delete(); } if($msg){ diff --git a/app/listener/CommMsg.php b/app/listener/CommMsg.php new file mode 100644 index 0000000..657827d --- /dev/null +++ b/app/listener/CommMsg.php @@ -0,0 +1,21 @@ + [], // 域名绑定(自动多应用模式有效) - 'domain_bind' => [], + 'domain_bind' => [ + //'www' => 'index', + //'admin' => 'admin' + ], // 禁止URL访问的应用列表(自动多应用模式有效) 'deny_app_list' => [], // 异常页面的模板文件 - 'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl', + 'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl', // 错误显示信息,非调试模式有效 'error_message' => '页面错误!请稍后再试~', // 显示错误信息 - 'show_error_msg' => false, + 'show_error_msg' => true, //异常页面模板 'http_exception_template' => [ - 404 => '../view/404.html' + 404 => '../view/404.html', + 500 => '../view/404.html' ] ]; diff --git a/extend/taoler/com/Files.php b/extend/taoler/com/Files.php index 6073673..ab73a6e 100644 --- a/extend/taoler/com/Files.php +++ b/extend/taoler/com/Files.php @@ -5,7 +5,11 @@ use RecursiveIteratorIterator; use RecursiveDirectoryIterator; class Files { - //ȡĿ¼Ŀ¼ + /** + * 获取目录下子目录名 + * @param $path 目录 + * @return array + */ public static function getDirName($path) { if (is_dir($path)) { @@ -19,8 +23,12 @@ class Files return array_merge(array_diff($arr, array('install'))); } } - - //ļмļ + + /** + * 创建文件夹及子文件夹 + * @param $path + * @return bool + */ public static function create_dirs($path) { if (!is_dir($path)) @@ -41,12 +49,13 @@ class Files } return true; } - - /** - * ɾļм - * @param $dirPath ɾĿ¼ - * @param $nowDir Ƿɾǰļ$dirPath true false - */ + + /** + * 删除文件夹及内容 + * @param $dirPath 所删除的目录 + * @param bool $nowDir 是否删除当前文件夹$dirPath true false + * @return bool + */ public static function delDirAndFile( $dirPath, $nowDir=false ) { if ( $handle = opendir($dirPath) ) { @@ -62,8 +71,8 @@ class Files } } } - closedir( $handle ); - //ɾǰļ + closedir( $handle ); + //删除当前文件夹 if($nowDir == true){ if(rmdir($dirPath)){ return true; @@ -77,12 +86,13 @@ class Files return true; } - /** - * ļ$sourceµļļµݵ$dest +ݴ - * @param $source - * @param $dest - * @param $ex ָֻ$sourceµĿ¼,Ĭȫ - */ + /** + * 复制文件夹$source下的文件和子文件夹下的内容到$dest下 升级+备份代码 + * @param $source + * @param $dest + * @param array $ex 指定只复制$source下的目录,默认全复制 + * @return bool + */ public function copyDirs($source, $dest, $ex=array()) { $count = count($ex); @@ -91,7 +101,7 @@ class Files while (($file = readdir($handle)) !== false) { if (( $file != '.' ) && ( $file != '..' )) { if ( is_dir($source . $file) ) { - //ָļ + //ָ���ļ��� if($count != 0){ if(in_array($file,$ex)){ self::copyDirs($source . $file.'/', $dest . $file.'/'); @@ -110,12 +120,11 @@ class Files } return true; } - - + /** - * Ŀ¼ѭĿ¼ - * - * @param $catalogue + * 检测目录并循环创建目录 + * @param $dir + * @return bool */ public static function mkdirs($dir) { @@ -125,14 +134,14 @@ class Files } return true; } - + /** + * 删除文件以及目录 * @param $dir * @return bool - * ɾļԼĿ¼ */ public static function delDir($dir) { - //ɾĿ¼µļ + //先删除目录下的文件: // var_dump(is_dir($dir)); // if(!is_dir($dir)){ // return true; @@ -149,7 +158,7 @@ class Files } } closedir($dh); - //ɾǰļУ + //删除当前文件夹 if(rmdir($dir)) { return true; } else { @@ -158,9 +167,10 @@ class Files } /** + * 复制文件到指定文件 * @param $source * @param $dest - * ļָļ + * @return bool */ public static function copyDir($source, $dest) { @@ -185,10 +195,13 @@ class Files return true; } - /*д - * @param string $type 1 Ϊɿ 2 ģ - */ - + /** + * 写入 + * @param $content + * @param $filepath + * @param $type $type 1 为生成控制器 2 模型 + * @throws \Exception + */ public static function filePutContents($content,$filepath,$type){ if($type==1){ $str = file_get_contents($filepath); @@ -212,11 +225,11 @@ class Files $File->write($filepath, $_cache); } } + /** - * ȡļдС - * - * @param string $dir ļ· - * @return int + * 获取文件夹大小 + * @param $dir 根文件夹路径 + * @return bool|int */ public static function getDirSize($dir) { @@ -240,9 +253,10 @@ class Files } /** - * ļ - * - * @param $files + * 创建文件 + * @param $file + * @param $content + * @return bool */ public static function createFile($file,$content) { @@ -252,9 +266,9 @@ class Files fclose($myfile); return true; } + /** - * 鴴Ŀ¼ - * + * 基于数组创建目录 * @param $files */ public static function createDirOrFiles($files) @@ -268,7 +282,12 @@ class Files } } - // жļĿ¼ǷдȨ + + /** + * 判断文件或目录是否有写的权限 + * @param $file + * @return bool + */ public static function isWritable($file) { if (DIRECTORY_SEPARATOR == '/' AND @ ini_get("safe_mode") == FALSE) { @@ -282,8 +301,7 @@ class Files } /** - * д־ - * + * 写入日志 * @param $path * @param $content * @return bool|int diff --git a/extend/taoler/com/Message.php b/extend/taoler/com/Message.php index be68c64..552adeb 100644 --- a/extend/taoler/com/Message.php +++ b/extend/taoler/com/Message.php @@ -7,8 +7,14 @@ use app\common\model\Message as MessageModel; use app\common\model\MessageTo; class Message -{ - //send msg +{ + /** + * 发送消息 + * @param $sendId 发送者 + * @param $receveId 接收者 + * @param $data 发送数据 + * @return bool + */ public static function sendMsg($sendId,$receveId,$data) { //写入消息库 @@ -28,8 +34,15 @@ class Message return false; } } - - //receve msg + + /** + * 接收消息 + * @param $uid 接收消息用户ID + * @return \think\Collection + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ public static function receveMsg($uid) { $msg = Db::name('message_to') @@ -43,14 +56,20 @@ class Message ->select(); return $msg; } - - //登录后插入系统消息 + + /** + * 登录用户把消息写入数据表 + * @param $uid 登陆用户ID + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ public static function insertMsg($uid) { //得到所有系统消息 $sysmsg = MessageModel::where(['type'=>0,'delete_time'=>0])->select(); foreach($sysmsg as $smg){ - //检验通知是否被写入个人收件箱 + //检验通知ID是否被写入个人收件箱 $msgId = Db::name('message_to')->where('message_id',$smg['id'])->find(); if(!$msgId){ $result = MessageTo::create(['send_id'=>$smg['user_id'],'receve_id'=>$uid,'message_id'=>$smg['id'],'message_type'=>$smg['type']]); diff --git a/public/static/admin/modules/addons.js b/public/static/admin/modules/addons.js new file mode 100644 index 0000000..9d19a4d --- /dev/null +++ b/public/static/admin/modules/addons.js @@ -0,0 +1,124 @@ +//网站app版本发布 + +layui.define(['table', 'form','upload'], function(exports){ + var $ = layui.$ + ,table = layui.table + ,form = layui.form + ,upload = layui.upload; + + //版本推送 + table.render({ + elem: '#addons-list', + url: addonsIndex, + limit: 5, + cols:[[ + {type: 'numbers', fixed: 'left'}, + {field: 'addons_name',title: '插件', width: 150}, + {field: 'addons_version',title: '版本', width: 100}, + {field: 'addons_auther',title: '作者', width: 100}, + {field: 'addons_resume',title: '简介', minWidth: 200}, + {field: 'addons_price',title: '价格(元)'}, + {field: 'addons_status',title: '状态', width: 100}, + {field: 'ctime',title: '时间', width: 150}, + {title: '操作', width: 150, align:'center', fixed: 'right', toolbar: '#addons-tool'} + ]] + ,page: true + ,limit: 10 + ,height: 'full-220' + ,text: '对不起,加载出现异常!' + }); + +//监听工具条 + table.on('tool(addons-list)', function(obj){ + var data = obj.data; + if(obj.event === 'del'){ + layer.prompt({ + formType: 1 + ,title: '敏感操作,请验证口令' + }, function(value, index){ + layer.close(index); + + layer.confirm('真的删除行么', function(index){ + //obj.del(); + $.ajax({ + type:'post', + url:addonsDelete, + data:{id:data.id}, + dataType:'json', + success:function(data){ + if(data.code == 0){ + layer.msg(data.msg,{ + icon:6, + time:2000 + }); + } else { + layer.open({ + title:'删除失败', + content:data.msg, + icon:5, + adim:6 + }) + } + } + }); + table.reload('addons-list'); + layer.close(index); + }); + }); + } else if(obj.event === 'edit'){ + var tr = $(obj.tr); + layer.open({ + type: 2 + ,title: '编辑插件' + ,content: addonsEdit + '?id='+ data.id + ,maxmin: true + ,area: ['400px', '620px'] + ,btn: ['确定', '取消'] + ,yes: function(index, layero){ + + var iframeWindow = window['layui-layer-iframe'+ index] + ,submitID = 'LAY-addons-submit' + ,submit = layero.find('iframe').contents().find('#'+ submitID); + + //监听提交 + iframeWindow.layui.form.on('submit('+ submitID +')', function(data){ + var field = data.field; //获取提交的字段 + + //提交 Ajax 成功后,静态更新表格中的数据 + $.ajax({ + type:"post", + url:addonsEdit, + data:field, + daType:"json", + success:function (res){ + if (res.code == 0) { + layer.msg(res.msg,{ + icon:6, + time:2000 + }); + } else { + layer.open({ + tiele:'修改失败', + content:res.msg, + icon:5, + anim:6 + }); + } + } + }); + + table.reload('addons-list'); //数据刷新 + layer.close(index); //关闭弹层 + }); + + submit.trigger('click'); + } + ,success: function(layero, index){ + + } + }); + } + }); + + exports('addons', {}) +}); \ No newline at end of file diff --git a/public/static/admin/modules/notice.js b/public/static/admin/modules/notice.js index 5040104..fa65123 100644 --- a/public/static/admin/modules/notice.js +++ b/public/static/admin/modules/notice.js @@ -78,10 +78,8 @@ layui.define(['table', 'form', 'layedit','upload'], function(exports){ dataType:"json", success:function (data){ if (data.code == 0) { - conosle.log('123'); - $('#L_title').text(''); - - $('#L_content').text(''); + //$('#L_title').text(''); + //$('#L_content').text(''); layer.msg(data.msg,{ icon:6, time:2000 @@ -97,7 +95,7 @@ layui.define(['table', 'form', 'layedit','upload'], function(exports){ }); $('#L_title').val(''); - $('#L_content').value = ''; + $('#L_content').val(''); table.reload('notice-list'); //数据刷新 return false; }); diff --git a/view/404.html b/view/404.html index 989b88f..aafec2c 100644 --- a/view/404.html +++ b/view/404.html @@ -9,7 +9,7 @@

-

页面或者数据被 纸飞机 运到火星了,啥都看不到了…

+

页面或者数据被 纸飞机运到火星了,啥都看不到了…

diff --git a/view/taoler/index/error/404.html b/view/taoler/index/error/404.html deleted file mode 100644 index 458c228..0000000 --- a/view/taoler/index/error/404.html +++ /dev/null @@ -1,46 +0,0 @@ -{extend name="public/base" /} - -{block name="title"}404 - {$sysInfo.webname}{/block} -{block name="keywords"}{$sysInfo.keywords}{/block} -{block name="description"}{$sysInfo.descript}{/block} -{block name="column"}{include file="public/column" /}{/block} -{block name="content"} -
-
-
-

-

页面或者数据被 纸飞机 运到火星了,啥都看不到了…

-
-
-
-{/block} - -{block name="script"} - -{/block} - - - - - - - - - - - diff --git a/view/taoler/index/public/404.html b/view/taoler/index/public/404.html deleted file mode 100644 index aa6ac55..0000000 --- a/view/taoler/index/public/404.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - 404 - TaoLer社区 - - - - - - - - - -
-
-
-

-

页面或者数据被 纸飞机 运到火星了,啥都看不到了…

-
-
-
- - - - - - - - - - - - - - - - - - - - -