拆分接单平台共享服务
This commit is contained in:
@@ -98,7 +98,8 @@ import {
|
||||
resolveWorkerPermissions,
|
||||
resolveWorkOrderOperationalStatus,
|
||||
} from './mappers.js'
|
||||
import { ensureWorkerPlatformDefaults, normalizeWorkOrderTimeoutPolicy } from './worker-service.js'
|
||||
import { ensureWorkerPlatformDefaults } from './worker-platform-defaults.js'
|
||||
import { normalizeWorkOrderTimeoutPolicy } from './work-order-timeout-policy.js'
|
||||
import { getRequiredWorkOrder, getRequiredWorker } from './worker-session-context-service.js'
|
||||
import { resolveSharingQuantity } from './admin-worker-catalog-service.js'
|
||||
import {
|
||||
|
||||
@@ -49,7 +49,8 @@ import {
|
||||
resolveSkuNameQuantity,
|
||||
resolveWorkOrderRulePricing,
|
||||
} from './mappers.js'
|
||||
import { ensureWorkerPlatformDefaults, normalizeWorkOrderTimeoutPolicy } from './worker-service.js'
|
||||
import { ensureWorkerPlatformDefaults } from './worker-platform-defaults.js'
|
||||
import { normalizeWorkOrderTimeoutPolicy } from './work-order-timeout-policy.js'
|
||||
|
||||
export async function listAdminWorkerLevels() {
|
||||
await ensureWorkerPlatformDefaults()
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
export * from './mappers.js'
|
||||
export * from './worker-session-context-service.js'
|
||||
export * from './worker-service.js'
|
||||
export * from './worker-platform-defaults.js'
|
||||
export * from './work-order-timeout-policy.js'
|
||||
export * from './after-sales-service.js'
|
||||
export * from './admin-service.js'
|
||||
export * from './admin-worker-finance-service.js'
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
export const WORK_ORDER_TIMEOUT_POLICIES = ['reopen', 'cancel_release', 'cancel_deduct'] as const
|
||||
|
||||
export type WorkOrderTimeoutPolicy = (typeof WORK_ORDER_TIMEOUT_POLICIES)[number]
|
||||
|
||||
export function isWorkOrderTimeoutPolicy(value: unknown): value is WorkOrderTimeoutPolicy {
|
||||
return WORK_ORDER_TIMEOUT_POLICIES.includes(value as WorkOrderTimeoutPolicy)
|
||||
}
|
||||
|
||||
export function normalizeWorkOrderTimeoutPolicy(value: unknown): WorkOrderTimeoutPolicy {
|
||||
return isWorkOrderTimeoutPolicy(value) ? value : 'reopen'
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
getWorkCategoryByKey,
|
||||
getWorkerLevelByKey,
|
||||
upsertWorkCategory,
|
||||
upsertWorkerLevel,
|
||||
} from '../../repositories/worker-platform/index.js'
|
||||
import { nowIso } from '../../utils/time.js'
|
||||
import { DEFAULT_CATEGORY_KEY, DEFAULT_LEVEL_KEY, DEFAULT_LEVEL_NAME } from './mappers.js'
|
||||
|
||||
export async function ensureWorkerPlatformDefaults() {
|
||||
const now = nowIso()
|
||||
const existingLevel = await getWorkerLevelByKey(DEFAULT_LEVEL_KEY)
|
||||
const level =
|
||||
existingLevel ||
|
||||
(await upsertWorkerLevel({
|
||||
levelKey: DEFAULT_LEVEL_KEY,
|
||||
name: DEFAULT_LEVEL_NAME,
|
||||
sortOrder: 10,
|
||||
status: 'active',
|
||||
permissionJson: JSON.stringify({
|
||||
depositFreeAmount: 0,
|
||||
maxActiveOrders: 1,
|
||||
upgradeThreshold: 0,
|
||||
}),
|
||||
now,
|
||||
}))
|
||||
const existingCategory = await getWorkCategoryByKey(DEFAULT_CATEGORY_KEY)
|
||||
const category =
|
||||
existingCategory ||
|
||||
(await upsertWorkCategory({
|
||||
categoryKey: DEFAULT_CATEGORY_KEY,
|
||||
name: '默认分类',
|
||||
sortOrder: 100,
|
||||
status: 'active',
|
||||
now,
|
||||
}))
|
||||
return { level, category }
|
||||
}
|
||||
@@ -20,8 +20,6 @@ import {
|
||||
createWorkerUser,
|
||||
createWorkerWithdrawalAccount as createWorkerWithdrawalAccountRecord,
|
||||
getWorkerFinanceRequestSummary,
|
||||
getWorkCategoryByKey,
|
||||
getWorkerLevelByKey,
|
||||
getLatestWorkerSmsCode,
|
||||
recordWorkerSmsCodeFailure,
|
||||
getWorkerUserByInviteCode,
|
||||
@@ -72,8 +70,6 @@ import {
|
||||
upsertWorkerWorkOrderNote,
|
||||
markWorkerWorkOrderViewed,
|
||||
updateWorkerPassword,
|
||||
upsertWorkCategory,
|
||||
upsertWorkerLevel,
|
||||
type WorkOrderRow,
|
||||
type WorkOrderShareRow,
|
||||
type WorkerSessionRow,
|
||||
@@ -110,9 +106,6 @@ import {
|
||||
} from '../realtime/realtime-event-service.js'
|
||||
|
||||
import {
|
||||
DEFAULT_CATEGORY_KEY,
|
||||
DEFAULT_LEVEL_KEY,
|
||||
DEFAULT_LEVEL_NAME,
|
||||
INVITE_CODE_LENGTH,
|
||||
INVITE_CODE_RETRY_LIMIT,
|
||||
createWorkerSession,
|
||||
@@ -159,6 +152,8 @@ import {
|
||||
isWorkerPasswordStrong,
|
||||
verifyWorkerPassword,
|
||||
} from './mappers.js'
|
||||
import { ensureWorkerPlatformDefaults } from './worker-platform-defaults.js'
|
||||
import { normalizeWorkOrderTimeoutPolicy } from './work-order-timeout-policy.js'
|
||||
|
||||
const WORKER_DAILY_WITHDRAW_LIMIT = 3
|
||||
const VIP_AUTO_ACCEPT_EVIDENCE_WINDOW_HOURS = 24
|
||||
@@ -170,39 +165,16 @@ export {
|
||||
requireActiveWorkerSession,
|
||||
} from './worker-session-context-service.js'
|
||||
export type { WorkerSession } from './worker-session-context-service.js'
|
||||
export { ensureWorkerPlatformDefaults } from './worker-platform-defaults.js'
|
||||
export {
|
||||
isWorkOrderTimeoutPolicy,
|
||||
normalizeWorkOrderTimeoutPolicy,
|
||||
WORK_ORDER_TIMEOUT_POLICIES,
|
||||
} from './work-order-timeout-policy.js'
|
||||
export type { WorkOrderTimeoutPolicy } from './work-order-timeout-policy.js'
|
||||
|
||||
const WORKER_MAX_DEVICES = 3
|
||||
|
||||
export async function ensureWorkerPlatformDefaults() {
|
||||
const now = nowIso()
|
||||
const existingLevel = await getWorkerLevelByKey(DEFAULT_LEVEL_KEY)
|
||||
const level =
|
||||
existingLevel ||
|
||||
(await upsertWorkerLevel({
|
||||
levelKey: DEFAULT_LEVEL_KEY,
|
||||
name: DEFAULT_LEVEL_NAME,
|
||||
sortOrder: 10,
|
||||
status: 'active',
|
||||
permissionJson: JSON.stringify({
|
||||
depositFreeAmount: 0,
|
||||
maxActiveOrders: 1,
|
||||
upgradeThreshold: 0,
|
||||
}),
|
||||
now,
|
||||
}))
|
||||
const existingCategory = await getWorkCategoryByKey(DEFAULT_CATEGORY_KEY)
|
||||
const category =
|
||||
existingCategory ||
|
||||
(await upsertWorkCategory({
|
||||
categoryKey: DEFAULT_CATEGORY_KEY,
|
||||
name: '默认分类',
|
||||
sortOrder: 100,
|
||||
status: 'active',
|
||||
now,
|
||||
}))
|
||||
return { level, category }
|
||||
}
|
||||
|
||||
export async function sendWorkerSmsCode(payload: JsonObject = {}) {
|
||||
const phone = normalizeWorkerPhone(payload.phone)
|
||||
const config = runtimeConfig.worker.sms
|
||||
@@ -1646,18 +1618,6 @@ function resolveWorkOrderDeadlineAt(workOrder: WorkOrderRow, now: string): strin
|
||||
return new Date(new Date(now).getTime() + timeoutMinutes * 60 * 1000).toISOString()
|
||||
}
|
||||
|
||||
export const WORK_ORDER_TIMEOUT_POLICIES = ['reopen', 'cancel_release', 'cancel_deduct'] as const
|
||||
|
||||
export type WorkOrderTimeoutPolicy = (typeof WORK_ORDER_TIMEOUT_POLICIES)[number]
|
||||
|
||||
export function isWorkOrderTimeoutPolicy(value: unknown): value is WorkOrderTimeoutPolicy {
|
||||
return WORK_ORDER_TIMEOUT_POLICIES.includes(value as WorkOrderTimeoutPolicy)
|
||||
}
|
||||
|
||||
export function normalizeWorkOrderTimeoutPolicy(value: unknown): WorkOrderTimeoutPolicy {
|
||||
return isWorkOrderTimeoutPolicy(value) ? value : 'reopen'
|
||||
}
|
||||
|
||||
export async function settleDueDepositUnfreezes(
|
||||
options: { limit?: number; workerId?: number } = {},
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user