2023-01-31 13:52:40 +08:00

79 lines
1.8 KiB
PHP

<?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){
$res['nickname'] = Db::table('fa_szxc_information_usermsg')->where('user_id',$res['user_id'])->value('name');
$res['create_time'] = date('Y-m-d H:i:s',$res['create_time']);
$data['is_read'] = 1;
$data['read_time'] = time();
Db::table('cms_notice')->where($where)->update($data);
$this->apiSuccess('获取成功',$res);
}else{
$this->apiError('未找到该数据');
}
}
}