message send
This commit is contained in:
parent
6455e9f7ef
commit
a2bf02e7c8
24
app/common/model/Message.php
Normal file
24
app/common/model/Message.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
use think\Db;
|
||||
|
||||
|
||||
class Message extends Model
|
||||
{
|
||||
protected $pk = 'id'; //主键
|
||||
protected $autoWriteTimestamp = true; //开启自动时间戳
|
||||
protected $createTime = 'create_time';
|
||||
protected $updateTime = 'update_time';
|
||||
|
||||
//用户关联评论
|
||||
public function user()
|
||||
{
|
||||
return $this->hasMany('User','user_id','id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
23
app/common/model/MessageTo.php
Normal file
23
app/common/model/MessageTo.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
use think\Db;
|
||||
|
||||
class MessageTo extends Model
|
||||
{
|
||||
protected $pk = 'id'; //主键
|
||||
protected $autoWriteTimestamp = true; //开启自动时间戳
|
||||
protected $createTime = 'create_time';
|
||||
protected $updateTime = 'update_time';
|
||||
|
||||
//用户关联评论
|
||||
public function user()
|
||||
{
|
||||
return $this->hasMany('User','user_id','id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
13
app/facade/Jump.php
Normal file
13
app/facade/Jump.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace app\facade;
|
||||
|
||||
use think\Facade;
|
||||
|
||||
class Jump extends Facade
|
||||
{
|
||||
protected static function getFacadeClass()
|
||||
{
|
||||
return 'app\api\controller\Jump';
|
||||
}
|
||||
|
||||
}
|
15
app/facade/Message.php
Normal file
15
app/facade/Message.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace app\facade;
|
||||
|
||||
use think\Facade;
|
||||
|
||||
class Message extends Facade
|
||||
{
|
||||
protected static function getFacadeClass()
|
||||
{
|
||||
return 'app\api\controller\Message';
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -11,9 +11,11 @@ use app\common\model\User;
|
||||
use app\common\model\Comment;
|
||||
use app\common\model\Collection;
|
||||
use app\common\model\Article as ArticleModel;
|
||||
use app\facade\Message;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Config;
|
||||
|
||||
|
||||
class Article extends BaseController
|
||||
{
|
||||
protected $middleware = [
|
||||
@ -150,11 +152,27 @@ class Article extends BaseController
|
||||
//if (Request::isAjax()){
|
||||
//获取评论
|
||||
$data = Request::only(['content','article_id','user_id']);
|
||||
$sendId = $data['user_id'];
|
||||
|
||||
//用户留言存入数据库
|
||||
if (Comment::create($data)) {
|
||||
//站内信
|
||||
$article = Db::name('article')->field('id,title,user_id')->where('id',$data['article_id'])->find();
|
||||
$title = $article['title'];
|
||||
$link = '/index/jie/'.$data['article_id'].'.html';
|
||||
//@user comment
|
||||
$preg = "/@([^@\s]*)\s/";
|
||||
preg_match($preg,$data['content'],$username);
|
||||
if(isset($username[1])){
|
||||
$receveId = Db::name('user')->whereOr('nickname', $username[1])->whereOr('name', $username[1])->value('id');
|
||||
} else {
|
||||
$receveId = $article['user_id'];
|
||||
}
|
||||
$data = ['title'=>$title,'link'=>$link,'user_id'=>$sendId];
|
||||
Message::sendMsg($sendId,$receveId,$data);
|
||||
|
||||
$res = ['code'=>1, 'msg'=>'留言成功'];
|
||||
} else{
|
||||
} else {
|
||||
$res = ['code'=>0, 'msg'=>'留言失败'];
|
||||
}
|
||||
return json($res);
|
||||
|
@ -53,7 +53,7 @@ class Index extends BaseController
|
||||
}
|
||||
|
||||
//热议文章
|
||||
$artHot = Article::field('id,title')->withCount('comments')->where(['status'=>1,'delete_time'=>0])->whereTime('create_time', 'year')->order('comments_count','desc')->limit(10)->select();
|
||||
$artHot = Article::field('id,title')->withCount('comments')->where(['status'=>1,'delete_time'=>0])->whereTime('create_time', 'year')->order('comments_count','desc')->limit(10)->withCache(60)->select();
|
||||
|
||||
//首页赞助
|
||||
$ad_index = Cache::get('adindex');
|
||||
@ -94,7 +94,7 @@ class Index extends BaseController
|
||||
//回帖榜
|
||||
public function reply()
|
||||
{
|
||||
$user = User::withCount('comments')->order('comments_count','desc')->limit(20)->select();
|
||||
$user = User::withCount('comments')->order(['comments_count'=>'desc','last_login_time'=>'desc'])->limit(20)->select();
|
||||
if($user)
|
||||
{
|
||||
$res['status'] = 0;
|
||||
|
@ -4,17 +4,72 @@ namespace app\index\controller;
|
||||
use app\common\controller\BaseController;
|
||||
use think\facade\Session;
|
||||
use think\facade\Request;
|
||||
use think\Db;
|
||||
use think\facade\Db;
|
||||
use app\facade\Message as MessageApi;
|
||||
|
||||
class Message extends BaseController
|
||||
{
|
||||
//消息
|
||||
public function nums(){
|
||||
//消息数目
|
||||
public function nums()
|
||||
{
|
||||
$msg = Db::name('message_to')->where('receve_id',Session::get('user_id'))->where(['is_read'=>0,'delete_time'=>0])->select();
|
||||
|
||||
//$res['status'] = 0;
|
||||
$res=['status' =>0,'count' => 0, 'msg' => 'nums'];
|
||||
$count = $msg->count();
|
||||
if($count){
|
||||
$res=['status' =>0,'count' => $count, 'msg' => 'nums'];
|
||||
} else {
|
||||
$res=['status' =>0,'count' => 0, 'msg' => $count];
|
||||
}
|
||||
return json($res);
|
||||
}
|
||||
|
||||
//消息查询
|
||||
public function find()
|
||||
{
|
||||
$uid = Session::get('user_id');
|
||||
$msg = MessageApi::receveMsg($uid);
|
||||
$count = $msg->count();
|
||||
$res = [];
|
||||
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']];
|
||||
$res['rows'][] = $data;
|
||||
}
|
||||
} else {
|
||||
$res = ['status'=>0,'msg'=>'','rows'=>''];;
|
||||
}
|
||||
return json($res);
|
||||
}
|
||||
|
||||
//读消息
|
||||
public function read()
|
||||
{
|
||||
$id =input('id');
|
||||
$msg = Db::name('message_to')->where('id',$id)->save(['is_read'=>1]);
|
||||
|
||||
$res=['status' =>0];
|
||||
|
||||
return json($res);
|
||||
|
||||
}
|
||||
|
||||
//消息删除
|
||||
public function remove()
|
||||
{
|
||||
$uid = Session::get('user_id');
|
||||
$id = Request::only(['id']);
|
||||
if($id['id'] == 'true'){
|
||||
$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'])->useSoftDelete('delete_time',time())->delete();
|
||||
}
|
||||
|
||||
if($msg){
|
||||
$res = ['status'=>0];
|
||||
}
|
||||
return $res;
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
@ -13,6 +13,7 @@ use app\common\model\Article;
|
||||
use app\common\model\Collection;
|
||||
use app\common\model\User as userModel;
|
||||
use think\facade\Config;
|
||||
use app\facade\Message;
|
||||
|
||||
class User extends BaseController
|
||||
{
|
||||
@ -127,7 +128,11 @@ class User extends BaseController
|
||||
|
||||
public function message()
|
||||
{
|
||||
return view();
|
||||
$uid = Session::get('user_id');
|
||||
$msg = Message::receveMsg($uid);
|
||||
|
||||
View::assign('msg',$msg);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
//个人页
|
||||
|
@ -225,6 +225,32 @@ CREATE TABLE `tao_mail_server` (
|
||||
|
||||
INSERT INTO `tao_mail_server` VALUES ('1', 'xxxx@aliyun.com', 'smtp.aliyun.com', '25', 'user', '123456', '0');
|
||||
|
||||
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 NOT NULL COMMENT '消息内容',
|
||||
`user_id` int(11) NOT NULL COMMENT '发送人ID',
|
||||
`link` varchar(255) NOT NULL COMMENT '链接',
|
||||
`create_time` int(11) NOT NULL COMMENT '创建时间',
|
||||
`update_time` int(11) NOT NULL COMMENT '更新时间',
|
||||
`delete_time` int(11) NOT NULL COMMENT '删除时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
|
||||
|
||||
DROP TABLE IF EXISTS `tao_message_to`;
|
||||
CREATE TABLE `tao_message_to` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '消息ID',
|
||||
`send_id` int(11) NOT NULL COMMENT '发送人ID',
|
||||
`receve_id` int(11) NOT NULL COMMENT '接收人ID',
|
||||
`message_id` varchar(255) NOT NULL COMMENT '消息标题',
|
||||
`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 '更新时间',
|
||||
`delete_time` int(11) NOT NULL DEFAULT '0' COMMENT '删除时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `tao_slider`;
|
||||
CREATE TABLE `tao_slider` (
|
||||
|
Loading…
Reference in New Issue
Block a user