1.优化拉取公告列表接口/api/notice/noticeList

2.移除强弹窗确认已读接口/api/notice/noticeConfirm
This commit is contained in:
2026-05-21 11:18:22 +08:00
parent 1b8d947f97
commit d1dceb44d8
10 changed files with 84 additions and 142 deletions

View File

@@ -25,23 +25,28 @@ class Notice extends MobileBase
'list_rows' => $pageSize,
]);
$noticeIds = [];
$popoutNoticeIds = [];
foreach ($paginate->items() as $row) {
$noticeIds[] = $row->id;
if ($this->intValue($row->notice_type, 0) === 1) {
$popoutNoticeIds[] = $row->id;
}
}
$readRows = [];
if ($noticeIds !== []) {
$readRows = UserNoticeRead::where('user_id', $this->auth->id)->whereIn('notice_id', $noticeIds)->column('notice_id');
$readMap = [];
if ($popoutNoticeIds !== []) {
$readRows = UserNoticeRead::where('user_id', $this->auth->id)->whereIn('notice_id', $popoutNoticeIds)->column('notice_id');
$readMap = array_flip($readRows);
}
$readMap = array_flip($readRows);
$list = [];
foreach ($paginate->items() as $row) {
$isPopout = $this->intValue($row->notice_type, 0) === 1;
$list[] = [
'notice_id' => $row->id,
'title' => $row->title,
'notice_type' => $this->intValue($row->notice_type, 0) === 1 ? 'popout' : 'silent',
'is_read' => isset($readMap[$row->id]),
'content' => $row->content,
'notice_type' => $isPopout ? 'popout' : 'silent',
'must_confirm' => $isPopout,
'is_read' => $isPopout && isset($readMap[$row->id]),
'publish_time' => $row->publish_at,
];
}
@@ -49,30 +54,6 @@ class Notice extends MobileBase
return $this->mobileSuccess(['list' => $list]);
}
public function noticeDetail(Request $request): Response
{
$response = $this->initializeMobile($request);
if ($response !== null) {
return $response;
}
$id = $this->intValue($request->input('notice_id', 0), 0);
if ($id < 1) {
return $this->mobileError(1001, 'Missing parameters');
}
$notice = OperationNotice::where('id', $id)->where('status', 1)->find();
if (!$notice) {
return $this->mobileError(2004, 'Notice does not exist');
}
return $this->mobileSuccess([
'notice_id' => $notice->id,
'title' => $notice->title,
'content' => $notice->content,
'notice_type' => $this->intValue($notice->notice_type, 0) === 1 ? 'popout' : 'silent',
'must_confirm' => $this->intValue($notice->notice_type, 0) === 1,
'publish_time' => $notice->publish_at,
]);
}
public function noticeConfirm(Request $request): Response
{
$response = $this->initializeMobile($request);
@@ -87,14 +68,18 @@ class Notice extends MobileBase
if (!$notice) {
return $this->mobileError(2004, 'Notice does not exist');
}
if ($this->intValue($notice->notice_type, 0) !== 1) {
return $this->mobileError(2004, 'Notice does not require confirmation');
}
$exists = UserNoticeRead::where('user_id', $this->auth->id)->where('notice_id', $noticeId)->find();
$readRow = UserNoticeRead::where('user_id', $this->auth->id)->where('notice_id', $noticeId)->find();
$now = time();
if ($exists) {
$exists->save([
'confirmed' => 1,
'read_at' => $now,
]);
if ($readRow) {
$readRow->read_at = $now;
if ($this->intValue($readRow->confirmed, 0) !== 1) {
$readRow->confirmed = 1;
}
$readRow->save();
} else {
UserNoticeRead::create([
'user_id' => $this->auth->id,