完善接单平台通知配置
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
import {
|
||||
bumpAdminNotificationReminder,
|
||||
countPendingAdminNotifications,
|
||||
createAdminNotification,
|
||||
getPendingAdminNotificationByDedupeKey,
|
||||
listPendingAdminNotifications,
|
||||
resolveAdminNotificationsByEntity,
|
||||
type AdminNotificationRow,
|
||||
} from '../../repositories/admin-notification-repo.js'
|
||||
import { notifyInternalSafely } from '../notification/domain-notifications.js'
|
||||
import {
|
||||
getWorkerPlatformNotificationConfig,
|
||||
type WorkerPlatformNotificationEventKey,
|
||||
} from '../worker-platform/worker-platform-notification-config-service.js'
|
||||
|
||||
const ADMIN_WORKER_PLATFORM_PATH = '/admin/worker-platform'
|
||||
|
||||
export async function createWorkerWithdrawAdminNotification(input: {
|
||||
requestId: number
|
||||
workerName: string
|
||||
amountFen: number
|
||||
channel: string
|
||||
}) {
|
||||
return createConfiguredWorkerPlatformNotification('withdraw_requested', {
|
||||
notificationType: 'worker_withdraw_requested',
|
||||
priority: 'high',
|
||||
entityType: 'worker_finance_request',
|
||||
entityId: input.requestId,
|
||||
dedupeKey: `worker_withdraw_request:${input.requestId}`,
|
||||
title: '有新的提现申请',
|
||||
body: `打手:${input.workerName || '-'};金额:${formatAmount(input.amountFen)};渠道:${formatChannel(input.channel)}`,
|
||||
actionPath: `${ADMIN_WORKER_PLATFORM_PATH}?tab=finance`,
|
||||
now: new Date().toISOString(),
|
||||
})
|
||||
}
|
||||
|
||||
export async function createWorkerRechargeAdminNotification(input: {
|
||||
requestId: number
|
||||
workerName: string
|
||||
amountFen: number
|
||||
}) {
|
||||
return createConfiguredWorkerPlatformNotification('recharge_requested', {
|
||||
notificationType: 'worker_recharge_requested',
|
||||
priority: 'normal',
|
||||
entityType: 'worker_finance_request',
|
||||
entityId: input.requestId,
|
||||
dedupeKey: `worker_recharge_request:${input.requestId}`,
|
||||
title: '有新的充值申请',
|
||||
body: `打手:${input.workerName || '-'};金额:${formatAmount(input.amountFen)}`,
|
||||
actionPath: `${ADMIN_WORKER_PLATFORM_PATH}?tab=finance`,
|
||||
now: new Date().toISOString(),
|
||||
})
|
||||
}
|
||||
|
||||
export async function createWorkOrderMaterialAdminNotification(input: {
|
||||
workOrderId: number
|
||||
workOrderNo: string
|
||||
productName: string
|
||||
}) {
|
||||
return createConfiguredWorkerPlatformNotification('material_required', {
|
||||
notificationType: 'work_order_material_required',
|
||||
priority: 'normal',
|
||||
entityType: 'work_order',
|
||||
entityId: input.workOrderId,
|
||||
dedupeKey: `work_order_material:${input.workOrderId}`,
|
||||
title: '有工单待补资料',
|
||||
body: `订单:${input.workOrderNo || input.workOrderId};商品:${input.productName || '-'}`,
|
||||
actionPath: `${ADMIN_WORKER_PLATFORM_PATH}?tab=orders`,
|
||||
now: new Date().toISOString(),
|
||||
})
|
||||
}
|
||||
|
||||
export async function createWorkerAcceptanceAdminNotification(input: {
|
||||
workOrderId: number
|
||||
workOrderNo: string
|
||||
productName: string
|
||||
workerName: string
|
||||
imageCount: number
|
||||
}) {
|
||||
return createConfiguredWorkerPlatformNotification('acceptance_submitted', {
|
||||
notificationType: 'worker_acceptance_submitted',
|
||||
priority: 'normal',
|
||||
entityType: 'work_order',
|
||||
entityId: input.workOrderId,
|
||||
dedupeKey: acceptanceNotificationKey(input.workOrderId),
|
||||
title: '有订单待验收',
|
||||
body: [
|
||||
`订单:${input.workOrderNo || input.workOrderId}`,
|
||||
`商品:${input.productName || '-'}`,
|
||||
`打手:${input.workerName || '-'}`,
|
||||
`验收图片:${input.imageCount} 张`,
|
||||
].join(';'),
|
||||
actionPath: `${ADMIN_WORKER_PLATFORM_PATH}?tab=orders`,
|
||||
now: new Date().toISOString(),
|
||||
})
|
||||
}
|
||||
|
||||
export async function remindWorkerAcceptanceAdminNotification(workOrderId: number) {
|
||||
const now = new Date().toISOString()
|
||||
const eventConfig = getWorkerPlatformNotificationConfig().events.acceptance_reminded
|
||||
const notification = await bumpAdminNotificationReminder({
|
||||
dedupeKey: acceptanceNotificationKey(workOrderId),
|
||||
notificationType: 'worker_acceptance_reminded',
|
||||
title: '有打手催验收',
|
||||
visible: eventConfig.todoEnabled,
|
||||
soundEnabled: eventConfig.todoEnabled && eventConfig.soundEnabled,
|
||||
now,
|
||||
})
|
||||
if (notification && eventConfig.externalPushEnabled) {
|
||||
void notifyInternalSafely({
|
||||
title: '打手催促验收',
|
||||
body: `${notification.body};第 ${notification.reminder_count} 次催验收`,
|
||||
category: 'worker_acceptance_reminded',
|
||||
url: notification.action_path,
|
||||
cooldownKey: `worker_acceptance_reminded:${workOrderId}:${notification.reminder_count}`,
|
||||
cooldownMs: 30 * 60 * 1000,
|
||||
})
|
||||
}
|
||||
return notification
|
||||
}
|
||||
|
||||
export async function getWorkerAcceptanceReminder(workOrderId: number) {
|
||||
return getPendingAdminNotificationByDedupeKey(acceptanceNotificationKey(workOrderId))
|
||||
}
|
||||
|
||||
export async function resolveAdminNotificationEntity(
|
||||
entityType: string,
|
||||
entityId: number,
|
||||
reason: string,
|
||||
) {
|
||||
await resolveAdminNotificationsByEntity({
|
||||
entityType,
|
||||
entityId,
|
||||
reason,
|
||||
now: new Date().toISOString(),
|
||||
})
|
||||
}
|
||||
|
||||
export async function listAdminPendingNotifications(limit = 20) {
|
||||
const normalizedLimit = Math.min(50, Math.max(1, Math.floor(Number(limit) || 20)))
|
||||
const [items, pendingCount] = await Promise.all([
|
||||
listPendingAdminNotifications(normalizedLimit),
|
||||
countPendingAdminNotifications(),
|
||||
])
|
||||
return {
|
||||
pendingCount,
|
||||
items: items.map(mapAdminNotification),
|
||||
}
|
||||
}
|
||||
|
||||
function mapAdminNotification(row: AdminNotificationRow) {
|
||||
return {
|
||||
notificationId: Number(row.id),
|
||||
notificationType: row.notification_type,
|
||||
priority: row.priority,
|
||||
entityType: row.entity_type,
|
||||
entityId: Number(row.entity_id),
|
||||
title: row.title,
|
||||
body: row.body,
|
||||
actionPath: row.action_path,
|
||||
reminderCount: Number(row.reminder_count || 0),
|
||||
soundEnabled: row.sound_enabled !== false,
|
||||
lastRemindedAt: row.last_reminded_at,
|
||||
createdAt: row.created_at,
|
||||
updatedAt: row.updated_at,
|
||||
}
|
||||
}
|
||||
|
||||
async function createConfiguredWorkerPlatformNotification(
|
||||
eventKey: WorkerPlatformNotificationEventKey,
|
||||
input: {
|
||||
notificationType: string
|
||||
priority: string
|
||||
entityType: string
|
||||
entityId: number
|
||||
dedupeKey: string
|
||||
title: string
|
||||
body: string
|
||||
actionPath: string
|
||||
now: string
|
||||
},
|
||||
) {
|
||||
const eventConfig = getWorkerPlatformNotificationConfig().events[eventKey]
|
||||
const notification = await createAdminNotification({
|
||||
...input,
|
||||
visible: eventConfig.todoEnabled,
|
||||
soundEnabled: eventConfig.todoEnabled && eventConfig.soundEnabled,
|
||||
})
|
||||
if (notification && eventConfig.externalPushEnabled) {
|
||||
void notifyInternalSafely({
|
||||
title: notification.title,
|
||||
body: notification.body,
|
||||
category: notification.notification_type,
|
||||
url: notification.action_path,
|
||||
cooldownKey: notification.dedupe_key,
|
||||
})
|
||||
}
|
||||
return notification
|
||||
}
|
||||
|
||||
function acceptanceNotificationKey(workOrderId: number) {
|
||||
return `work_order_acceptance:${workOrderId}`
|
||||
}
|
||||
|
||||
function formatAmount(amountFen: number) {
|
||||
return `¥${(Math.max(0, Number(amountFen) || 0) / 100).toFixed(2)}`
|
||||
}
|
||||
|
||||
function formatChannel(channel: string) {
|
||||
return channel === 'wechat' ? '微信' : channel === 'alipay' ? '支付宝' : channel || '-'
|
||||
}
|
||||
@@ -56,7 +56,15 @@ import { randomId } from '../../utils/random.js'
|
||||
import { nowIso } from '../../utils/time.js'
|
||||
import { normalizePage, normalizePageSize, safeParseJson } from '../admin/admin-query-utils.js'
|
||||
import { getWorkerFinanceConfig, saveWorkerFinanceConfig } from './worker-finance-config-service.js'
|
||||
import {
|
||||
getWorkerPlatformNotificationConfig,
|
||||
saveWorkerPlatformNotificationConfig,
|
||||
} from './worker-platform-notification-config-service.js'
|
||||
import { refreshUploadedFileUrls } from '../file-storage/file-storage-service.js'
|
||||
import {
|
||||
createWorkOrderMaterialAdminNotification,
|
||||
resolveAdminNotificationEntity,
|
||||
} from '../admin/admin-notification-service.js'
|
||||
import {
|
||||
consumeIndustryVouchersBeforeWorkOrderAssign,
|
||||
consumeIndustryVouchersBeforeWorkOrderPublish,
|
||||
@@ -609,15 +617,25 @@ export async function saveAdminWorkerFinanceConfig(payload: JsonObject = {}) {
|
||||
return config
|
||||
}
|
||||
|
||||
export async function getAdminWorkerPlatformNotificationConfig() {
|
||||
return getWorkerPlatformNotificationConfig()
|
||||
}
|
||||
|
||||
export async function saveAdminWorkerPlatformNotificationConfig(payload: JsonObject = {}) {
|
||||
return saveWorkerPlatformNotificationConfig(payload)
|
||||
}
|
||||
|
||||
export async function listAdminWorkerFinanceRequests(query: JsonObject = {}) {
|
||||
const page = normalizePage(query.page)
|
||||
const pageSize = normalizePageSize(query.pageSize)
|
||||
const requestId = normalizeOptionalId(query.requestId ?? query.request_id) || 0
|
||||
const status = normalizeFinanceRequestStatus(query.status)
|
||||
const requestType = normalizeFinanceRequestType(query.requestType)
|
||||
const keyword = String(query.keyword || '').trim()
|
||||
const { items, total } = await listWorkerFinanceRequests({
|
||||
page,
|
||||
pageSize,
|
||||
requestId,
|
||||
status,
|
||||
requestType,
|
||||
keyword,
|
||||
@@ -670,6 +688,12 @@ export async function reviewAdminWorkerFinanceRequest(
|
||||
})
|
||||
}
|
||||
|
||||
await resolveAdminNotificationEntity(
|
||||
'worker_finance_request',
|
||||
Number(reviewed.request.id),
|
||||
'finance_request_reviewed',
|
||||
)
|
||||
|
||||
return {
|
||||
request: mapFinanceRequest(reviewed.request),
|
||||
}
|
||||
@@ -695,6 +719,7 @@ export async function getAdminWorkOrderEvents(workOrderId: number | string) {
|
||||
export async function listAdminWorkOrders(query: JsonObject = {}) {
|
||||
const page = normalizePage(query.page)
|
||||
const pageSize = normalizePageSize(query.pageSize)
|
||||
const workOrderId = normalizeOptionalId(query.workOrderId ?? query.work_order_id) || 0
|
||||
const workerId = normalizeOptionalId(query.workerId ?? query.worker_id) || 0
|
||||
const statuses = normalizeStatuses(query.status)
|
||||
const vipEvidencePending = normalizeBoolean(query.vipEvidencePending, false)
|
||||
@@ -702,6 +727,7 @@ export async function listAdminWorkOrders(query: JsonObject = {}) {
|
||||
page,
|
||||
pageSize,
|
||||
statuses,
|
||||
workOrderId,
|
||||
keyword: String(query.keyword || '').trim(),
|
||||
workerSharingId: workerId,
|
||||
vipEvidencePending,
|
||||
@@ -954,6 +980,9 @@ export async function submitAdminWorkOrderMaterial(
|
||||
payloadJson: JSON.stringify({ fields: submittedFields, complete, rewardAmount }),
|
||||
now,
|
||||
})
|
||||
if (nextStatus !== WORK_ORDER_STATUS.PENDING_MATERIAL) {
|
||||
await resolveAdminNotificationEntity('work_order', Number(workOrder.id), 'material_completed')
|
||||
}
|
||||
return { order: mapWorkOrderAdmin(updated || workOrder), complete }
|
||||
}
|
||||
|
||||
@@ -1319,6 +1348,9 @@ export async function markAdminWorkOrderProblem(
|
||||
payloadJson: JSON.stringify({ note }),
|
||||
now,
|
||||
})
|
||||
if (workOrder.status === WORK_ORDER_STATUS.PENDING_ACCEPTANCE) {
|
||||
await resolveAdminNotificationEntity('work_order', Number(workOrder.id), 'marked_problem')
|
||||
}
|
||||
return { order: mapWorkOrderAdmin(updated || workOrder) }
|
||||
}
|
||||
|
||||
@@ -1388,6 +1420,7 @@ export async function acceptAdminWorkOrder(workOrderId: number | string, actorNa
|
||||
errorCode: 'work_order_accept_conflict',
|
||||
})
|
||||
}
|
||||
await resolveAdminNotificationEntity('work_order', Number(workOrder.id), 'accepted')
|
||||
return { order: mapWorkOrderAdmin(updated || workOrder) }
|
||||
}
|
||||
|
||||
@@ -1633,6 +1666,13 @@ export async function syncWorkerOrdersForSourceOrder(
|
||||
}),
|
||||
now,
|
||||
})
|
||||
if (workOrder.status === WORK_ORDER_STATUS.PENDING_MATERIAL) {
|
||||
await createWorkOrderMaterialAdminNotification({
|
||||
workOrderId: Number(workOrder.id),
|
||||
workOrderNo: workOrder.work_order_no,
|
||||
productName: workOrder.product_name,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
import { APP_CONFIG_KEYS } from '../../config/app-config-keys.js'
|
||||
import type { JsonObject } from '../../types/json.js'
|
||||
import { readAppConfigEntry, saveAppConfigEntry } from '../config/app-config-store.js'
|
||||
|
||||
export const WORKER_PLATFORM_NOTIFICATION_EVENT_KEYS = [
|
||||
'withdraw_requested',
|
||||
'recharge_requested',
|
||||
'acceptance_submitted',
|
||||
'acceptance_reminded',
|
||||
'material_required',
|
||||
] as const
|
||||
|
||||
export type WorkerPlatformNotificationEventKey =
|
||||
(typeof WORKER_PLATFORM_NOTIFICATION_EVENT_KEYS)[number]
|
||||
|
||||
export type WorkerPlatformNotificationEventConfig = {
|
||||
todoEnabled: boolean
|
||||
soundEnabled: boolean
|
||||
externalPushEnabled: boolean
|
||||
}
|
||||
|
||||
export type WorkerPlatformNotificationConfig = {
|
||||
events: Record<WorkerPlatformNotificationEventKey, WorkerPlatformNotificationEventConfig>
|
||||
}
|
||||
|
||||
export function getWorkerPlatformNotificationConfig(): WorkerPlatformNotificationConfig {
|
||||
return readAppConfigEntry({
|
||||
configKey: APP_CONFIG_KEYS.workerPlatformNotifications,
|
||||
fallback: createDefaultWorkerPlatformNotificationConfig,
|
||||
normalize: normalizeWorkerPlatformNotificationConfig,
|
||||
})
|
||||
}
|
||||
|
||||
export async function saveWorkerPlatformNotificationConfig(rawValue: unknown) {
|
||||
return saveAppConfigEntry({
|
||||
configKey: APP_CONFIG_KEYS.workerPlatformNotifications,
|
||||
value: rawValue,
|
||||
normalize: normalizeWorkerPlatformNotificationConfig,
|
||||
})
|
||||
}
|
||||
|
||||
export function createDefaultWorkerPlatformNotificationConfig(): WorkerPlatformNotificationConfig {
|
||||
return {
|
||||
events: {
|
||||
withdraw_requested: createEnabledEventConfig(),
|
||||
recharge_requested: createEnabledEventConfig(),
|
||||
acceptance_submitted: createEnabledEventConfig(),
|
||||
acceptance_reminded: createEnabledEventConfig(),
|
||||
material_required: {
|
||||
todoEnabled: false,
|
||||
soundEnabled: false,
|
||||
externalPushEnabled: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeWorkerPlatformNotificationConfig(
|
||||
rawValue: unknown,
|
||||
): WorkerPlatformNotificationConfig {
|
||||
const source = isPlainObject(rawValue) ? rawValue : {}
|
||||
const rawEvents = isPlainObject(source.events) ? source.events : {}
|
||||
const defaults = createDefaultWorkerPlatformNotificationConfig()
|
||||
|
||||
return {
|
||||
events: Object.fromEntries(
|
||||
WORKER_PLATFORM_NOTIFICATION_EVENT_KEYS.map((key) => [
|
||||
key,
|
||||
normalizeEventConfig(rawEvents[key], defaults.events[key]),
|
||||
]),
|
||||
) as WorkerPlatformNotificationConfig['events'],
|
||||
}
|
||||
}
|
||||
|
||||
function createEnabledEventConfig(): WorkerPlatformNotificationEventConfig {
|
||||
return { todoEnabled: true, soundEnabled: true, externalPushEnabled: true }
|
||||
}
|
||||
|
||||
function normalizeEventConfig(
|
||||
value: unknown,
|
||||
fallback: WorkerPlatformNotificationEventConfig,
|
||||
): WorkerPlatformNotificationEventConfig {
|
||||
const source = isPlainObject(value) ? value : {}
|
||||
const todoEnabled =
|
||||
typeof source.todoEnabled === 'boolean' ? source.todoEnabled : fallback.todoEnabled
|
||||
return {
|
||||
todoEnabled,
|
||||
soundEnabled:
|
||||
todoEnabled &&
|
||||
(typeof source.soundEnabled === 'boolean' ? source.soundEnabled : fallback.soundEnabled),
|
||||
externalPushEnabled:
|
||||
typeof source.externalPushEnabled === 'boolean'
|
||||
? source.externalPushEnabled
|
||||
: fallback.externalPushEnabled,
|
||||
}
|
||||
}
|
||||
|
||||
function isPlainObject(value: unknown): value is JsonObject {
|
||||
return Object.prototype.toString.call(value) === '[object Object]'
|
||||
}
|
||||
@@ -68,6 +68,13 @@ import { normalizePage, normalizePageSize, safeParseJson } from '../admin/admin-
|
||||
import { getSmsProvider } from '../sms/index.js'
|
||||
import { getWorkerFinanceConfig } from './worker-finance-config-service.js'
|
||||
import { refreshUploadedFileUrls } from '../file-storage/file-storage-service.js'
|
||||
import {
|
||||
createWorkerAcceptanceAdminNotification,
|
||||
createWorkerRechargeAdminNotification,
|
||||
createWorkerWithdrawAdminNotification,
|
||||
getWorkerAcceptanceReminder,
|
||||
remindWorkerAcceptanceAdminNotification,
|
||||
} from '../admin/admin-notification-service.js'
|
||||
|
||||
import {
|
||||
DEFAULT_CATEGORY_KEY,
|
||||
@@ -689,6 +696,11 @@ export async function createWorkerRechargeRequest(
|
||||
errorCode: 'worker_recharge_request_create_failed',
|
||||
})
|
||||
}
|
||||
await createWorkerRechargeAdminNotification({
|
||||
requestId: Number(created.id),
|
||||
workerName: worker.display_name || worker.username,
|
||||
amountFen: Number(created.amount || amount),
|
||||
})
|
||||
return {
|
||||
request: mapFinanceRequest(created),
|
||||
}
|
||||
@@ -779,6 +791,12 @@ export async function createWorkerWithdrawRequest(
|
||||
errorCode: 'worker_withdraw_request_create_failed',
|
||||
})
|
||||
}
|
||||
await createWorkerWithdrawAdminNotification({
|
||||
requestId: Number(created.id),
|
||||
workerName: worker.display_name || worker.username,
|
||||
amountFen: Number(created.amount || amount),
|
||||
channel: created.account_channel,
|
||||
})
|
||||
return {
|
||||
request: mapFinanceRequest(created),
|
||||
availableForWithdraw,
|
||||
@@ -1426,11 +1444,107 @@ export async function submitWorkerOrderAcceptance(
|
||||
order: mapWorkOrderForWorker(acceptedOrder, resolveWorkerPermissions(worker)),
|
||||
}
|
||||
}
|
||||
await createWorkerAcceptanceAdminNotification({
|
||||
workOrderId: Number(workOrder.id),
|
||||
workOrderNo: workOrder.work_order_no,
|
||||
productName: workOrder.product_name,
|
||||
workerName: worker.display_name || worker.username,
|
||||
imageCount: imageUrls.length,
|
||||
})
|
||||
return {
|
||||
order: mapWorkOrderForWorker(updated || workOrder, resolveWorkerPermissions(worker)),
|
||||
}
|
||||
}
|
||||
|
||||
/** 打手在提交验收后催促后台处理;频率和次数均由服务端控制。 */
|
||||
export async function remindWorkerOrderAcceptance(
|
||||
workOrderId: number | string,
|
||||
session: WorkerSession,
|
||||
) {
|
||||
requireActiveWorkerSession(session)
|
||||
const workOrder = await getRequiredWorkOrder(workOrderId)
|
||||
if (
|
||||
workOrder.sharing_enabled ||
|
||||
Number(workOrder.assigned_worker_id || 0) !== Number(session.workerId)
|
||||
) {
|
||||
throw createHttpError('只能催促自己提交的整单验收', {
|
||||
statusCode: 403,
|
||||
errorCode: 'work_order_acceptance_reminder_owner_required',
|
||||
})
|
||||
}
|
||||
if (workOrder.status !== WORK_ORDER_STATUS.PENDING_ACCEPTANCE) {
|
||||
throw createHttpError('当前订单无需催验收', {
|
||||
statusCode: 409,
|
||||
errorCode: 'work_order_acceptance_reminder_status_invalid',
|
||||
})
|
||||
}
|
||||
const submittedAt = Date.parse(String(workOrder.submitted_at || ''))
|
||||
const now = Date.now()
|
||||
const firstReminderAt = submittedAt + 10 * 60 * 1000
|
||||
if (!Number.isFinite(submittedAt) || now < firstReminderAt) {
|
||||
throw createHttpError('提交验收满 10 分钟后才可催验收', {
|
||||
statusCode: 409,
|
||||
errorCode: 'work_order_acceptance_reminder_too_early',
|
||||
})
|
||||
}
|
||||
|
||||
let notification = await getWorkerAcceptanceReminder(Number(workOrder.id))
|
||||
if (!notification) {
|
||||
const worker = await getRequiredWorker(session.workerId)
|
||||
await createWorkerAcceptanceAdminNotification({
|
||||
workOrderId: Number(workOrder.id),
|
||||
workOrderNo: workOrder.work_order_no,
|
||||
productName: workOrder.product_name,
|
||||
workerName: worker.display_name || worker.username,
|
||||
imageCount: normalizeStringArray(safeParseJson(workOrder.acceptance_json).imageUrls).length,
|
||||
})
|
||||
notification = await getWorkerAcceptanceReminder(Number(workOrder.id))
|
||||
}
|
||||
if (!notification) {
|
||||
throw createHttpError('催验收待办创建失败,请稍后重试', {
|
||||
statusCode: 409,
|
||||
errorCode: 'work_order_acceptance_reminder_notification_missing',
|
||||
})
|
||||
}
|
||||
if (Number(notification.reminder_count || 0) >= 3) {
|
||||
throw createHttpError('该订单最多催验收 3 次', {
|
||||
statusCode: 409,
|
||||
errorCode: 'work_order_acceptance_reminder_limit_reached',
|
||||
})
|
||||
}
|
||||
const lastRemindedAt = Date.parse(String(notification.last_reminded_at || ''))
|
||||
const nextRemindAt = lastRemindedAt + 30 * 60 * 1000
|
||||
if (Number.isFinite(lastRemindedAt) && now < nextRemindAt) {
|
||||
throw createHttpError('每 30 分钟可催验收一次,请稍后再试', {
|
||||
statusCode: 409,
|
||||
errorCode: 'work_order_acceptance_reminder_cooldown',
|
||||
})
|
||||
}
|
||||
|
||||
const reminded = await remindWorkerAcceptanceAdminNotification(Number(workOrder.id))
|
||||
if (!reminded) {
|
||||
throw createHttpError('订单状态已变化,请刷新后重试', {
|
||||
statusCode: 409,
|
||||
errorCode: 'work_order_acceptance_reminder_conflict',
|
||||
})
|
||||
}
|
||||
const remindedAt = new Date(reminded.last_reminded_at || new Date().toISOString()).getTime()
|
||||
await createWorkOrderEvent({
|
||||
workOrderId: Number(workOrder.id),
|
||||
actorType: 'worker',
|
||||
actorId: String(session.workerId),
|
||||
eventType: 'acceptance_reminded',
|
||||
fromStatus: WORK_ORDER_STATUS.PENDING_ACCEPTANCE,
|
||||
toStatus: WORK_ORDER_STATUS.PENDING_ACCEPTANCE,
|
||||
payloadJson: JSON.stringify({ reminderCount: reminded.reminder_count }),
|
||||
now: new Date(reminded.last_reminded_at || new Date().toISOString()).toISOString(),
|
||||
})
|
||||
return {
|
||||
reminderCount: Number(reminded.reminder_count || 0),
|
||||
nextRemindAt: new Date(remindedAt + 30 * 60 * 1000).toISOString(),
|
||||
}
|
||||
}
|
||||
|
||||
/** VIP 自动验收订单在 24 小时内追加验收图片,不改变订单状态和结算结果。 */
|
||||
export async function supplementWorkerAcceptedOrderEvidence(
|
||||
workOrderId: number | string,
|
||||
|
||||
Reference in New Issue
Block a user