master
parent
ad34536256
commit
268ea4e34d
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
namespace Base\Service;
|
||||
|
||||
use Base\Facade\Request;
|
||||
|
||||
class AdminNoticeService
|
||||
{
|
||||
public function accept($uid)
|
||||
{
|
||||
$notices = M('admin_notice','tab_')
|
||||
->where([
|
||||
'start_time' => ['elt', time()],
|
||||
'end_time' => ['egt', time()],
|
||||
'_string' => 'concat(",", admin_ids, ",") like "%,' . $uid . ',%"'
|
||||
])
|
||||
->getField('id', true);
|
||||
if (empty($notices) || count($notices) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$readNotices = M('admin_notice_read', 'tab_')->where(['admin_id' => $uid, 'notice_id' => ['in', $notices]])->getField('notice_id', true);
|
||||
$unreadNotices = $readNotices ? array_diff($notices, $readNotices) : $notices;
|
||||
|
||||
$records = [];
|
||||
foreach ($unreadNotices as $noticeId) {
|
||||
$records[] = [
|
||||
'notice_id' => $noticeId,
|
||||
'admin_id' => $uid,
|
||||
'create_time' => time(),
|
||||
'update_time' => time()
|
||||
];
|
||||
}
|
||||
M('admin_notice_read', 'tab_')->addAll($records);
|
||||
}
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
M('admin_notice_read', 'tab_')->where(['id' => $id])->save(['status' => 1, 'update_time' => time()]);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
M('admin_notice_read', 'tab_')->where(['id' => $id])->save(['status' => 2, 'update_time' => time()]);
|
||||
}
|
||||
|
||||
public function getAdminNotices($uid)
|
||||
{
|
||||
$items = M('admin_notice_read', 'tab_')->field(['notice_id', 'status'])->where(['admin_id' => $uid, 'status' => ['in', [0, 1]]])->order('create_time desc')->select();
|
||||
if (empty($items) || count($items) == 0) {
|
||||
return [];
|
||||
}
|
||||
$ids = array_column($items, 'notice_id');
|
||||
$notices = M('admin_notice','tab_')
|
||||
->where([
|
||||
'id' => ['in', $ids],
|
||||
'start_time' => ['elt', time()],
|
||||
'end_time' => ['egt', time()],
|
||||
])
|
||||
->select();
|
||||
|
||||
if ($notices) {
|
||||
$notices = index_by_column('id', $notices);
|
||||
}
|
||||
|
||||
$records = [];
|
||||
foreach ($items as $item) {
|
||||
$notice = $notices[$item['notice_id']] ?? null;
|
||||
if (is_null($notice)) {
|
||||
continue;
|
||||
}
|
||||
$records[] = [
|
||||
'id' => $item['notice_id'],
|
||||
'status' => $item['status'],
|
||||
'type' => $notice['type'],
|
||||
'content' => $notice['content'],
|
||||
'title' => $notice['title'],
|
||||
'target' => $notice['target'],
|
||||
];
|
||||
}
|
||||
return $records;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue