消息通知接口
This commit is contained in:
parent
940e97680b
commit
13fb77f8dd
76
app/api/controller/Notice.php
Normal file
76
app/api/controller/Notice.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\BaseController;
|
||||
use app\api\middleware\Auth;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 消息通知接口
|
||||
*/
|
||||
class Notice extends BaseController
|
||||
{
|
||||
/**
|
||||
* 控制器中间件 [不需要鉴权]
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
Auth::class => ['except' => [] ]
|
||||
];
|
||||
|
||||
/**
|
||||
* 消息通知列表
|
||||
*/
|
||||
public function list($page=1,$limit=10){
|
||||
$where['status'] = 1;
|
||||
$where['user_id'] = JWT_UID;
|
||||
$res = Db::table('cms_notice')
|
||||
->where($where)
|
||||
->field('id,user_id,title,content,create_time,is_read,read_time')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
$this->apiSuccess('获取成功',$res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 未读消息数
|
||||
*/
|
||||
public function count(){
|
||||
$where['status'] = 1;
|
||||
$where['is_read'] = 0;
|
||||
$where['user_id'] = JWT_UID;
|
||||
$res = Db::table('cms_notice')
|
||||
->where($where)
|
||||
->count();
|
||||
$this->apiSuccess('获取成功',$res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息详情
|
||||
*/
|
||||
public function info(){
|
||||
$id = get_params('id');
|
||||
if(empty($id)){
|
||||
$this->apiError('缺少参数');
|
||||
}
|
||||
$where['id'] = $id;
|
||||
$where['user_id'] = JWT_UID;
|
||||
$res = Db::table('cms_notice')
|
||||
->where($where)
|
||||
->find();
|
||||
if($res){
|
||||
$data['is_read'] = 1;
|
||||
$data['read_time'] = time();
|
||||
Db::table('cms_notice')->where($where)->update($data);
|
||||
$this->apiSuccess('获取成功',$res);
|
||||
}else{
|
||||
$this->apiError('未找到该数据');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user