作者 郭盛
1 个管道 的构建 通过 耗费 2 秒

修改平台消息

... ... @@ -30,6 +30,40 @@ class Message extends Backend
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where($where)
->where('user_id','null')
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->where('user_id','null')
->order($sort, $order)
->limit($offset, $limit)
->select();
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}
... ...
... ... @@ -49,14 +49,27 @@ class Message extends Api
->whereOr('user_id','null')
->order('is_read desc,createtime desc')
->select();
$data['num'] = Db::name('message')
//查询出所有的平台信息
$read = Db::name('message')->where('user_id','null')->select();
//循环判断平台消息是否已读
$nums = 0;
foreach ($read as $val){
$info = Db::name('read')->where('user_id',$user_id)->where('message_id',$val['id'])->find();
if(empty($info)){
$nums += 1;
}
}
$num = Db::name('message')
->where('is_read',0)
->where(function ($query)use($user_id){
$query->where('user_id',$user_id)
->whereOr('user_id','null');
})
->order('is_read desc,createtime desc')
->where('user_id',$user_id)
// ->where(function ($query)use($user_id){
// $query->where('user_id',$user_id)
// ->whereOr('user_id','null');
// })
->count();
$data['num'] = $num + $nums;
//通知数量
$data['total'] = Db::name('message')
->where('user_id',$user_id)
->whereOr('user_id','null')
... ... @@ -103,16 +116,22 @@ class Message extends Api
$read['user_id'] = $user_id;
$read['message_id'] = $id;
$read['createtime'] = time();
Db::name('read')->insertGetId($read);
//判断该记录是否已经添加过了
$have = Db::name('read')->where('user_id',$read['user_id'])->where('message_id',$read['message_id'])->find();
if(empty($have)){
//没有添加过情况
Db::name('read')->insertGetId($read);
}
$data = Db::name('message')
->where('id',$id)
->field('id,title,content,createtime')
->find();
Db::name('message')->where('id',$id)->update(['is_read'=>1]);
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
}else{
//不是
$data = Db::name('message')
->where('id',$id)
->field('id,title,content,createtime')
->find();
Db::name('message')->where('id',$id)->update(['is_read'=>1]);
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
... ...