diff --git a/app/admin/controller/Notice.php b/app/admin/controller/Notice.php new file mode 100644 index 0000000..a2032ec --- /dev/null +++ b/app/admin/controller/Notice.php @@ -0,0 +1,94 @@ +0,'delete_time'=>0])->select(); + $count = $notices->count(); + $res = []; + if($count){ + $res = ['code'=>0,'msg'=>'','count'=>$count]; + foreach($notices as $msg){ + $res['data'][] = ['id'=>$msg['id'],'type'=>$msg['type'],'title'=>$msg['title'],'user_id'=>$msg['user_id'],'content'=>$msg['content'],'ctime'=>$msg['create_time']]; + } + } else { + $res = ['code'=>-1,'msg'=>'还没有发布任何通知']; + } + return json($res); + } + return View::fetch(); + } + + //添加消息 + public function add() + { + $sendId = Session::get('user_id'); + $data = Request::only(['type','title','receve_id','content']); + if($data['type'] == 1){ + $receveId = $data['receve_id']; //个人通知 + } else { + $receveId = 0; //系统通知 + } + unset($data['receve_id']); //收信人移除 + $data['user_id'] = $sendId; //发信人入信息库 + //写入信息库 + $result = Message::sendMsg($sendId,$receveId,$data); + if($result){ + $res = ['code'=>0,'msg'=>'发布成功']; + } else { + $res = ['code'=>0,'msg'=>'发布失败']; + } + return json($res); + } + + //编辑VIP积分规则 + public function edit() + { + $id = input('id'); + if(Request::isAjax()){ + $data = Request::only(['id','title','type','content']); + $result = MessageModel::update($data); + if($result){ + $res = ['code'=>0,'msg'=>'编辑成功']; + }else{ + $res = ['code'=>-1,'msg'=>'编辑失败']; + } + return json($res); + } + $msg = Db::name('message')->find($id); + View::assign(['msg'=>$msg]); + return View::fetch(); + } + + //删除消息 + public function delete($id) + { + if(Request::isAjax()){ + $msg = MessageModel::find($id); + $result = $msg->delete(); + + if($result){ + return json(['code'=>0,'msg'=>'删除成功']); + }else{ + return json(['code'=>-1,'msg'=>'删除失败']); + } + } + } + + + +} \ No newline at end of file diff --git a/app/common/model/Message.php b/app/common/model/Message.php index 0a0f4c4..5793840 100644 --- a/app/common/model/Message.php +++ b/app/common/model/Message.php @@ -19,6 +19,10 @@ class Message extends Model return $this->hasMany('User','user_id','id'); } - + //发件箱关联收件箱 + public function messageto() + { + return $this->hasMany('MessageTo','message_id','id'); + } } \ No newline at end of file diff --git a/app/common/model/MessageTo.php b/app/common/model/MessageTo.php index 951e62a..1872a9e 100644 --- a/app/common/model/MessageTo.php +++ b/app/common/model/MessageTo.php @@ -18,6 +18,11 @@ class MessageTo extends Model return $this->hasMany('User','user_id','id'); } + public function messages() + { + //评论关联用户 + return $this->belongsTo('Message','message_id','id'); + } } \ No newline at end of file diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 9d719a1..c754c8c 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -167,7 +167,7 @@ class Article extends BaseController } else { $receveId = $article['user_id']; } - $data = ['title'=>$title,'link'=>$link,'user_id'=>$sendId]; + $data = ['title'=>$title,'content'=>'评论通知','link'=>$link,'user_id'=>$sendId,'type'=>1]; Message::sendMsg($sendId,$receveId,$data); $res = ['code'=>1, 'msg'=>'留言成功']; diff --git a/app/index/controller/Login.php b/app/index/controller/Login.php index 64d28c8..695c96b 100644 --- a/app/index/controller/Login.php +++ b/app/index/controller/Login.php @@ -11,6 +11,7 @@ use think\facade\Cookie; use think\facade\Cache; use think\facade\View; use app\common\model\User as userModel; +use taoler\com\Message; class Login extends BaseController { @@ -56,6 +57,9 @@ class Login extends BaseController $user = new \app\common\model\User(); $res = $user->login($data); if ($res == 1) { + //获取系统站内通知信息 + Message::insertMsg(session('user_id')); + return json(['code'=>0,'msg'=>'登陆成功','url'=>'/']); } else { return json(['code'=>-1,'msg'=>$res]); diff --git a/app/index/controller/Message.php b/app/index/controller/Message.php index fadf935..b0468a0 100644 --- a/app/index/controller/Message.php +++ b/app/index/controller/Message.php @@ -5,6 +5,8 @@ use app\common\controller\BaseController; use think\facade\Session; use think\facade\Request; use think\facade\Db; +use app\common\model\Message as MessageModel; +use app\common\model\MessageTo; use taoler\com\Message as MessageApi; class Message extends BaseController @@ -33,12 +35,13 @@ class Message extends BaseController if($count){ $res = ['status'=>0,'msg'=>'','count'=>$count]; foreach ($msg as $k => $v){ - $data = ['id'=>$v['id'],'name'=>$v['name'],'content'=>$v['title'],'time'=>date("Y-m-d H:i",$v['create_time']),'link'=>$v['link'],'read'=>$v['is_read'] ? '已读':'未读']; + $data = ['id'=>$v['id'],'name'=>$v['name'],'title'=>$v['title'],'content'=>$v['content'],'time'=>date("Y-m-d H:i",$v['create_time']),'link'=>$v['link'],'read'=>$v['is_read'] ? '已读':'未读','type'=>$v['message_type']]; $res['rows'][] = $data; } } else { $res = ['status'=>0,'msg'=>'','rows'=>''];; } + //var_dump($res); return json($res); } @@ -46,11 +49,17 @@ class Message extends BaseController public function read() { $id =input('id'); - $msg = Db::name('message_to')->where('id',$id)->save(['is_read'=>1]); + //$msg = Db::name('message_to')->where('id',$id)->save(['is_read'=>1]); - $res=['status' =>0]; - - return json($res); + $msg = MessageTo::field('id,message_id')->with(['messages' => function($query){ + $query->where('delete_time',0)->field('id,content'); + }])->where('id',$id)->find(); + //改变读状态 + $result = $msg->update(['id'=>$id,'is_read'=>1]); + if($result){ + $res=['status' =>0,'content'=>$msg['messages']['content']]; + return json($res); + } } diff --git a/app/install/data/taoler.sql b/app/install/data/taoler.sql index 4354bac..eb7f79c 100644 --- a/app/install/data/taoler.sql +++ b/app/install/data/taoler.sql @@ -173,7 +173,11 @@ INSERT INTO `tao_auth_rule` VALUES ('72', 'admin/Vip/add', '添加vip等级', '1 INSERT INTO `tao_auth_rule` VALUES ('73', 'admin/Vip/vipEdit', '编辑vip等级', '1', '1', '1', '1', '', '0', '21', '', '1585548029', '0', '0'); INSERT INTO `tao_auth_rule` VALUES ('74', 'admin/Vip/delete', '删除vip等级', '1', '1', '2', '1', '', '0', '22', '', '1585548077', '0', '0'); INSERT INTO `tao_auth_rule` VALUES ('75', 'admin/Set/email', '邮箱设置', '1', '1', '2', '1', '', '0', '23', '', '1585548143', '0', '0'); -INSERT INTO `tao_auth_rule` VALUES ('76', 'admin/User/auth', '设置超级用户', '1', '1', '1', '1', '', '0', '22', '', '1578984801', '0', '0'); +INSERT INTO `tao_auth_rule` VALUES ('76', 'admin/Notice/index', '发布通知', '1', '1', '4', '1', '', '1', '10', '', '1585618141', '0', '0'); +INSERT INTO `tao_auth_rule` VALUES ('77', 'admin/Notice/add', '添加通知', '1', '1', '4', '1', '', '0', '11', '', '1585663336', '0', '0'); +INSERT INTO `tao_auth_rule` VALUES ('78', 'admin/Notice/edit', '编辑通知', '1', '1', '4', '1', '', '0', '12', '', '1585663366', '1585663465', '0'); +INSERT INTO `tao_auth_rule` VALUES ('79', 'admin/Notice/delete', '删除通知', '1', '1', '4', '1', '', '0', '13', '', '1585663412', '0', '0'); +INSERT INTO `tao_auth_rule` VALUES ('83', 'admin/User/auth', '设置超级用户', '1', '1', '1', '1', '', '0', '22', '', '1578984801', '0', '0'); DROP TABLE IF EXISTS `tao_cate`; CREATE TABLE `tao_cate` ( @@ -243,9 +247,10 @@ DROP TABLE IF EXISTS `tao_message`; CREATE TABLE `tao_message` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '消息ID', `title` varchar(255) NOT NULL COMMENT '消息标题', - `content` tinytext COMMENT '消息内容', + `content` text COMMENT '消息内容', `user_id` int(11) NOT NULL COMMENT '发送人ID', `link` varchar(255) NOT NULL COMMENT '链接', + `type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '消息类型0系统消息1普通消息', `create_time` int(11) NOT NULL COMMENT '创建时间', `update_time` int(11) NOT NULL COMMENT '更新时间', `delete_time` int(11) NOT NULL COMMENT '删除时间', @@ -258,6 +263,7 @@ CREATE TABLE `tao_message_to` ( `send_id` int(11) NOT NULL COMMENT '发送人ID', `receve_id` int(11) NOT NULL COMMENT '接收人ID', `message_id` varchar(255) NOT NULL COMMENT '消息标题', + `message_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '消息类型0系统消息1普通消息', `is_read` tinyint(1) NOT NULL DEFAULT '0' COMMENT '消息状态', `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间', diff --git a/app/middleware/Auth.php b/app/middleware/Auth.php index 4488f96..c0499c7 100644 --- a/app/middleware/Auth.php +++ b/app/middleware/Auth.php @@ -39,7 +39,8 @@ class Auth if (!$auth->check($app . '/' . $controller . '/' . $action, $admin_id) && $admin_id != 1) { //return response(''); - return response('没有权限'); + //return response('没有权限'); + return json(['code'=>-1,'msg'=>'没有权限!']); } } } diff --git a/extend/taoler/com/Message.php b/extend/taoler/com/Message.php index 54d1b6d..61ba83d 100644 --- a/extend/taoler/com/Message.php +++ b/extend/taoler/com/Message.php @@ -11,11 +11,21 @@ class Message //send msg public static function sendMsg($sendId,$receveId,$data) { - $msg = MessageModel::create($data); + //写入消息库 + $msg = MessageModel::create($data); //写入消息库 $msgId = $msg->id; - $result = MessageTo::create(['send_id'=>$sendId,'receve_id'=>$receveId,'message_id'=>$msgId]); - if($result){ + + //类型1为用户,写入用户收件箱 + if($data['type'] == 1){ + $result = MessageTo::create(['send_id'=>$sendId,'receve_id'=>$receveId,'message_id'=>$msgId,'message_type'=>$data['type']]); + if(!$result){ + return false; + } + } + if($msg){ return true; + } else { + return false; } } @@ -26,12 +36,29 @@ class Message ->alias('t') ->join('message m','t.message_id = m.id' ) ->join('user u','t.send_id = u.id') - ->field('t.id as id,name,title,link,receve_id,t.create_time as create_time,is_read') + ->field('t.id as id,name,title,content,link,receve_id,t.create_time as create_time,message_type,is_read') ->where('t.receve_id',$uid) ->where(['t.delete_time'=>0]) ->order(['t.create_time'=>'desc']) ->select(); return $msg; } + + //登录后插入系统消息 + public static function insertMsg($uid) + { + //得到所有系统消息 + $sysmsg = MessageModel::where(['type'=>0,'delete_time'=>0])->select(); + foreach($sysmsg as $smg){ + //检验通知是否被写入个人收件箱 + $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']]); + } + } + if($result){ + return true; + } + } } \ No newline at end of file diff --git a/public/static/admin/modules/appset.js b/public/static/admin/modules/appset.js new file mode 100644 index 0000000..2cb05d0 --- /dev/null +++ b/public/static/admin/modules/appset.js @@ -0,0 +1,193 @@ +//网站后台综合设置 + +layui.define(['table', 'form', 'layedit'], function(exports){ + var $ = layui.$ + ,table = layui.table + ,form = layui.form + ,layedit = layui.layedit; + + + var index = layedit.build('L_content',{ + height: 180 //设置编辑器高度 + ,tool: [ + 'strong' //加粗 + ,'italic' //斜体 + ,'underline' //下划线 + ,'del' //删除线 + ,'|' //分割线 + ,'left' //左对齐 + ,'center' //居中对齐 + ,'right' //右对齐 + ,'link' //超链接 + ,'unlink' //清除链接 + ,'face' //表情 + ,'image' //插入图片 + ], + }); + + //得到编辑器内容异步到表单中 + form.verify({ + content: function(value){ + return layedit.sync(index); + } + }); + + //通知列表 + table.render({ + elem: '#notice-list', + url: '/admin/Notice/index', + limit: 5, + cols:[[ + {type: 'numbers', fixed: 'left'}, + {field: 'type',title: '类型'}, + {field: 'title',title: '标题'}, + {field: 'user_id',title: '发信ID'}, + {field: 'content',title: '内容'}, + {field: 'ctime',title: '时间'}, + {title: '操作', width: 150, align:'center', fixed: 'right', toolbar: '#notice-tool'} + ]] + ,page: true + ,limit: 10 + ,height: 'full-220' + ,text: '对不起,加载出现异常!' + }); + //发站内通知信息 + form.on('select(type)', function(data){ + var tpl = '
{{ d.rows[i].name}}回答了您的帖子{{ d.rows[i].content}} {{ d.rows[i].read}}\ + {{# if(d.rows[i].type == 1){ }}\ +
{{ d.rows[i].name}}回答了您的帖子{{ d.rows[i].title}} {{ d.rows[i].read}}\ + {{# } else { }}\ +
系统消息:{{ d.rows[i].title}} {{ d.rows[i].read}}\ + {{# } }}\
{{d.rows[i].time}}删除
\