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

@@ -7,7 +7,7 @@ use support\Response;
use Webman\Http\Request as WebmanRequest;
/**
* 用户公告阅读记录
* 用户公告阅读记录(只读,由客户端确认已读写入)
*/
class UserNoticeRead extends Backend
{
@@ -33,6 +33,42 @@ class UserNoticeRead extends Backend
return null;
}
public function add(WebmanRequest $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
return $this->error(__('User notice read records are client-generated; manual creation is not allowed'));
}
public function edit(WebmanRequest $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
return $this->error(__('User notice read record cannot be edited'));
}
public function del(WebmanRequest $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
return $this->error(__('User notice read record cannot be deleted'));
}
public function sortable(WebmanRequest $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
return $this->error(__('Sorting is not supported'));
}
protected function _index(): Response
{
if ($this->request && $this->request->get('select')) {

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,

View File

@@ -43,6 +43,7 @@ return [
'Current process does not allow this operation' => 'Current process does not allow this operation',
'Order does not exist' => 'Order does not exist',
'Notice does not exist' => 'Notice does not exist',
'Notice does not require confirmation' => 'This notice does not require confirmation',
// Deposit / Withdraw
'Idempotency key is too long' => 'Idempotency key is too long',
'Idempotency key conflict' => 'Idempotency key conflict, please do not submit repeatedly',

View File

@@ -75,6 +75,7 @@ return [
'Current process does not allow this operation' => '当前流程不允许该操作',
'Order does not exist' => '订单不存在',
'Notice does not exist' => '公告不存在',
'Notice does not require confirmation' => '该公告无需确认已读',
// 充值 / 提现
'Idempotency key is too long' => '幂等键过长',
'Idempotency key conflict' => '幂等键冲突(请勿重复提交)',

View File

@@ -38,6 +38,10 @@ return [
'Wallet record cannot be edited' => 'Wallet record cannot be edited',
'Wallet record cannot be deleted' => 'Wallet record cannot be deleted',
'User notice read records are client-generated; manual creation is not allowed' => 'User notice read records are client-generated; manual creation is not allowed',
'User notice read record cannot be edited' => 'User notice read record cannot be edited',
'User notice read record cannot be deleted' => 'User notice read record cannot be deleted',
'Admin wallet does not allow manual creation' => 'Admin wallet does not allow manual creation',
'Admin wallet does not allow manual editing' => 'Admin wallet does not allow manual editing',
'Admin wallet does not allow deletion' => 'Admin wallet does not allow deletion',

View File

@@ -38,6 +38,10 @@ return [
'Wallet record cannot be edited' => '钱包流水不可编辑',
'Wallet record cannot be deleted' => '钱包流水不可删除',
'User notice read records are client-generated; manual creation is not allowed' => '用户阅读记录由客户端确认已读写入,禁止后台手工新增',
'User notice read record cannot be edited' => '用户阅读记录不可编辑',
'User notice read record cannot be deleted' => '用户阅读记录不可删除',
'Admin wallet does not allow manual creation' => '管理员钱包不允许手动新增',
'Admin wallet does not allow manual editing' => '管理员钱包不允许手动编辑',
'Admin wallet does not allow deletion' => '管理员钱包不允许删除',