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' => '管理员钱包不允许删除',

View File

@@ -153,7 +153,6 @@ Route::add(['GET', 'POST'], '/api/finance/withdrawDetail', [\app\api\controller\
Route::add(['GET', 'POST'], '/api/finance/withdrawList', [\app\api\controller\Finance::class, 'withdrawList']);
Route::get('/api/notice/noticeList', [\app\api\controller\Notice::class, 'noticeList']);
Route::get('/api/notice/noticeDetail', [\app\api\controller\Notice::class, 'noticeDetail']);
Route::get('/api/notice/noticeConfirm', [\app\api\controller\Notice::class, 'noticeConfirm']);
// ==================== Admin 路由 ====================

View File

@@ -13,7 +13,7 @@
- **请求方法**:所有移动端业务接口(`/api/*`,不含 `/api/v1/authToken`)一律使用 `POST` 调用;查询类接口同时兼容 `GET`(便于浏览器/调试工具直接访问),客户端统一走 `POST`
- `POST` 时请求头 `Content-Type: application/json`,参数放在 JSON body
- `GET` 兼容模式下,参数走 URL query string
- **例外**:公告模块 `/api/notice/noticeList``/api/notice/noticeDetail``/api/notice/noticeConfirm` **仅支持 `GET`**,参数一律走 URL query string
- **例外**:公告模块 `/api/notice/noticeList``/api/notice/noticeConfirm` **仅支持 `GET`**,参数一律走 URL query string
- 鉴权类接口 `/api/v1/authToken` 仍为 `GET`
- 时间UTC 时间戳(秒) + 服务端时区配置
- 金额:数字传输(如 `"100.00"`),客户端展示统一保留两位小数(存储仍为 `decimal(18,2)`
@@ -723,30 +723,25 @@
- `list`array<object>
- `notice_id`int含义公告 ID
- `title`string含义公告标题
- `content`string含义公告正文原详情接口字段
- `notice_type`string`silent`/`popout`,含义:公告类型)
- `is_read`bool含义当前用户是否已读
- `must_confirm`bool含义是否必须手动确认强弹窗为 `true`
- `is_read`bool含义当前用户是否已确认**仅 `popout` 强弹窗有效**`silent` 恒为 `false`,不写入阅读记录)
- `publish_time`int含义发布时间
### 6.2 公告详情
- **GET** `/api/notice/noticeDetail`
> **阅读记录口径**`user_notice_read` 仅用于强弹窗(`notice_type=popout`)的确认已读;静默信箱(`silent`)不生成、不查询阅读记录。
请求参数query string
- `id`int必填含义公告 ID
返回参数:
- `notice_id`int含义公告 ID
- `title`string含义公告标题
- `content`string含义公告正文
- `notice_type`string含义公告类型
- `must_confirm`bool含义是否必须手动确认
- `publish_time`int含义发布时间
### 6.3 强弹窗确认已读
### 6.2 强弹窗确认已读
- **GET** `/api/notice/noticeConfirm`
请求参数query string
- `notice_id`int含义待确认公告 ID
行为说明:
- **仅强弹窗**`notice_type=popout`)可调用;静默公告调用返回业务错误
- 若当前用户对该公告已有阅读记录:仅更新 `read_at`;若尚未确认则同时将 `confirmed` 置为 `1`
- 若无阅读记录:创建一条已确认记录
返回参数:
- `notice_id`int含义已确认公告 ID
- `confirmed`bool含义确认结果
@@ -880,8 +875,8 @@
## 8.3 公告强触达流程
1. 客户端监听 `notice.popout`
2. 拉取详情 `GET /api/notice/noticeDetail`
3. 用户勾选确认 `GET /api/notice/noticeConfirm?notice_id=...`
2. 拉取列表 `GET /api/notice/noticeList`(列表项已含 `content``must_confirm`
3. 用户勾选确认 `GET /api/notice/noticeConfirm?notice_id=...`(若已有阅读记录则仅更新 `read_at`
4. 未确认前可由前端阻断下注入口
---

View File

@@ -3,21 +3,18 @@
<el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
<TableHeader
:buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
:buttons="['refresh', 'comSearch', 'quickSearch', 'columnDisplay']"
:quick-search-placeholder="t('Quick search placeholder', { fields: t('operation.userNoticeRead.quick Search Fields') })"
></TableHeader>
<Table ref="tableRef"></Table>
<PopupForm />
</div>
</template>
<script setup lang="ts">
import { onMounted, provide, useTemplateRef } from 'vue'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import { baTableApi } from '/@/api/common'
import { defaultOptButtons } from '/@/components/table'
import TableHeader from '/@/components/table/header/index.vue'
import Table from '/@/components/table/index.vue'
import baTableClass from '/@/utils/baTable'
@@ -28,14 +25,12 @@ defineOptions({
const { t } = useI18n()
const tableRef = useTemplateRef('tableRef')
const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])
const baTable = new baTableClass(
new baTableApi('/admin/operation.UserNoticeRead/'),
{
pk: 'id',
column: [
{ type: 'selection', align: 'center', operator: false },
{ label: t('operation.userNoticeRead.id'), prop: 'id', align: 'center', width: 100, operator: 'RANGE', sortable: 'custom' },
{ label: t('operation.userNoticeRead.user_id'), prop: 'user_id', align: 'center', width: 100, operator: 'RANGE', show: false },
{
@@ -93,11 +88,7 @@ const baTable = new baTableClass(
sortable: 'custom',
timeFormat: 'yyyy-mm-dd hh:MM:ss',
},
{ label: t('Operate'), align: 'center', minWidth: 80, render: 'buttons', buttons: optButtons, operator: false, fixed: 'right' },
],
},
{
defaultItems: { confirmed: 0 },
}
)

View File

@@ -1,74 +0,0 @@
<template>
<el-dialog class="ba-operate-dialog" :close-on-click-modal="false" :model-value="['Add', 'Edit'].includes(baTable.form.operate!)" @close="baTable.toggleForm">
<template #header>
<div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">{{ baTable.form.operate ? t(baTable.form.operate) : '' }}</div>
</template>
<el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
<div class="ba-operate-form" :class="'ba-' + baTable.form.operate + '-form'" :style="config.layout.shrink ? '' : 'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'">
<el-form v-if="!baTable.form.loading" ref="formRef" @submit.prevent="" @keyup.enter="baTable.onSubmit(formRef)" :model="baTable.form.items" :label-position="config.layout.shrink ? 'top' : 'right'" :label-width="baTable.form.labelWidth + 'px'" :rules="rules">
<FormItem
:label="t('operation.userNoticeRead.user_id')"
type="remoteSelect"
v-model="baTable.form.items!.user_id"
prop="user_id"
:key="'uid-' + (baTable.form.items!.id ?? 'new')"
:input-attr="{
pk: 'id',
field: 'username',
remoteUrl: '/admin/user.User/index',
placeholder: t('Click select'),
}"
/>
<FormItem
:label="t('operation.userNoticeRead.notice_id')"
type="remoteSelect"
v-model="baTable.form.items!.notice_id"
prop="notice_id"
:key="'nid-' + (baTable.form.items!.id ?? 'new')"
:input-attr="{
pk: 'id',
field: 'title',
remoteUrl: '/admin/operation.OperationNotice/index',
placeholder: t('Click select'),
}"
/>
<FormItem :label="t('operation.userNoticeRead.read_at')" type="datetime" v-model="baTable.form.items!.read_at" prop="read_at" />
<FormItem
:label="t('operation.userNoticeRead.confirmed')"
type="radio"
v-model="baTable.form.items!.confirmed"
prop="confirmed"
:input-attr="{ content: { '0': t('operation.userNoticeRead.confirmed 0'), '1': t('operation.userNoticeRead.confirmed 1') } }"
/>
</el-form>
</div>
</el-scrollbar>
<template #footer>
<div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
<el-button @click="baTable.toggleForm()">{{ t('Cancel') }}</el-button>
<el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">{{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}</el-button>
</div>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import type { FormItemRule } from 'element-plus'
import { inject, reactive, useTemplateRef } from 'vue'
import { useI18n } from 'vue-i18n'
import FormItem from '/@/components/formItem/index.vue'
import { useConfig } from '/@/stores/config'
import type baTableClass from '/@/utils/baTable'
const config = useConfig()
const formRef = useTemplateRef('formRef')
const baTable = inject('baTable') as baTableClass
const { t } = useI18n()
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
user_id: [{ required: true, message: t('Please input field', { field: t('operation.userNoticeRead.user_id') }) }],
notice_id: [{ required: true, message: t('Please input field', { field: t('operation.userNoticeRead.notice_id') }) }],
})
</script>
<style scoped lang="scss"></style>