TaoLer/app/index/controller/Message.php

75 lines
1.8 KiB
PHP
Raw Normal View History

2020-01-01 13:17:19 +08:00
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use think\facade\Session;
use think\facade\Request;
2020-03-28 21:41:07 +08:00
use think\facade\Db;
2020-03-29 19:57:18 +08:00
use taoler\com\Message as MessageApi;
2020-01-01 13:17:19 +08:00
class Message extends BaseController
{
2020-03-28 21:41:07 +08:00
//消息数目
public function nums()
{
$msg = Db::name('message_to')->where('receve_id',Session::get('user_id'))->where(['is_read'=>0,'delete_time'=>0])->select();
2020-01-01 13:17:19 +08:00
2020-03-28 21:41:07 +08:00
$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){
2020-03-29 19:57:18 +08:00
$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'] ? '已读':'未读'];
2020-03-28 21:41:07 +08:00
$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];
2020-01-01 13:17:19 +08:00
2020-03-28 21:41:07 +08:00
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;
2020-01-01 13:17:19 +08:00
}
}