This commit is contained in:
xman 2025-04-21 14:18:11 +08:00
parent d7046959aa
commit ca133f4153
4 changed files with 60 additions and 13 deletions

View File

@ -58,22 +58,25 @@ class Message extends Backend
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$list = $this->model
->auth($this->auth)
->where($where)
->where('type',1)
->auth($this->auth)
->order($sort, $order)
->paginate($limit);
$result = ['total' => $list->total(), 'rows' => $list->items()];
$update = [];
foreach ($list as $item){
$readUids = explode(',',$item->read_uid);
foreach ($list as &$item){
$readUids = explode(',',$item->read_uid??'');
$item->status = 1;
if(!in_array($this->auth->id,$readUids)){
$readUids[] = $this->auth->id;
$update[] = [
'id' => $item->id,
'read_uid' => implode(',',$readUids)
'read_uid' => implode(',',$readUids),
'update_time' => date('Y-m-d H:i:s')
];
$item->status = 0;
}
}
if($update){
@ -124,11 +127,20 @@ class Message extends Backend
public function getNoreadCount()
{
return $this->model
->where('type',1)
->auth($this->auth)
->whereRaw("FIND_IN_SET(?, read_uid) = 0 OR read_uid IS NULL OR read_uid = ''", [$this->auth->id])
->count();
$count = 0;
if(!$this->auth->isSuperAdmin()){
$count = $this->model
->where('type',1)
->auth($this->auth)
//->whereRaw("FIND_IN_SET(?, read_uid) = 0 OR read_uid IS NULL OR read_uid = ''", [$this->auth->id])
->whereRaw("FIND_IN_SET({$this->auth->id}, read_uid) = 0 OR read_uid = '' or read_uid is null")
->count();
}
return [
'count' => $count
];
}
}

View File

@ -27,7 +27,7 @@
<li class="hidden-xs">
<!-- <a href="__PUBLIC__" target="_blank"><i class="fa fa-home" style="font-size:14px;"></i> {:__('Home')}</a>-->
<a href="message/index" class="addtabsit my-message">
消息(<span class="my-message-count text-danger text-bold">0</span>)
消息(<span class="my-message-count text-danger text-bold">0</span>)
</a>
</li>
@ -91,8 +91,8 @@
</div>-->
<div class="pull-left">
<a href="message/index" class="addtabsit my-message">
消息(<span class="my-message-count text-danger text-bold">0</span>)
<a href="/admin/message/index" class="addtabsit my-message">
消息(<span class="my-message-count text-danger text-bold">0</span>)
</a>
</div>

View File

@ -419,5 +419,31 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'adminlte', 'form'], functi
}
};
window.setInterval(function(){
// window.location.reload();
$.ajax({
type: "get",
url: 'message/getNoreadCount',
async : true,
dataType:"json",//返回整个HTML
success: function (data) {
var noread = data.count;
$(".my-message-count").html(noread);
if(noread>0){
Toastr.info('未读消息',"有 "+noread+" 条未读消息",{
timeOut:"30000",
onclick:function(){
//window.location.href='/admin/message/index';
Backend.api.addtabs('/admin/message/index','消息列表')
}
});
}
},
});
},60*1000);
return Controller;
});

View File

@ -33,7 +33,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
//{field: 'to_id', title: __('To_id')},
//{field: 'area_id', title: __('Area_id')},
{field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
{field: 'title', title: __('Title'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
//{field: 'status', title: __('状态'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
{field: 'title', title: __('Title'), operate: false, table: table, class: 'autocontent', formatter: function (val,row){
if(row.status == 0){
val = '<span class="label label-danger">new</span> '+ val;
}
return val;
}
},
{field: 'content', title: __('Content'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
// {field: 'uri', title: __('Uri'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},