Merge branch 'main' of https://gitea.hao858.com/dachui/order_site
This commit is contained in:
@@ -0,0 +1,211 @@
|
|||||||
|
-- 180_douyu_customer_homepage_screenshot.sql
|
||||||
|
--
|
||||||
|
-- 斗鱼客户领取页增加必填用户主页截图:
|
||||||
|
-- 1. 截图对象和展示地址作为斗鱼任务正式字段保存;
|
||||||
|
-- 2. 客户资料变化继续通过订单项快照事务 Outbox 同步 live-hub;
|
||||||
|
-- 3. 快照升级到 contractVersion=3,携带客户资料和主页截图。
|
||||||
|
|
||||||
|
ALTER TABLE douyu_fulfillment_tasks
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_object_key TEXT NOT NULL DEFAULT '',
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_url TEXT NOT NULL DEFAULT '',
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_thumbnail_url TEXT NOT NULL DEFAULT '',
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_filename TEXT NOT NULL DEFAULT '',
|
||||||
|
ADD COLUMN IF NOT EXISTS customer_homepage_screenshot_uploaded_at TIMESTAMPTZ;
|
||||||
|
|
||||||
|
COMMENT ON COLUMN douyu_fulfillment_tasks.customer_homepage_screenshot_object_key IS
|
||||||
|
'客户上传的斗鱼个人主页截图对象 key;文件台账和归属校验以 file_assets 为准';
|
||||||
|
COMMENT ON COLUMN douyu_fulfillment_tasks.customer_homepage_screenshot_url IS
|
||||||
|
'客户主页截图稳定展示地址;供 order_site 和 live-hub 工作台读取';
|
||||||
|
COMMENT ON COLUMN douyu_fulfillment_tasks.customer_homepage_screenshot_thumbnail_url IS
|
||||||
|
'客户主页截图缩略图稳定展示地址';
|
||||||
|
COMMENT ON COLUMN douyu_fulfillment_tasks.customer_homepage_screenshot_uploaded_at IS
|
||||||
|
'客户主页截图随资料提交保存的时间';
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION enqueue_live_hub_platform_fulfillment_event(
|
||||||
|
p_order_id BIGINT,
|
||||||
|
p_order_item_id BIGINT,
|
||||||
|
p_fulfillment_id BIGINT,
|
||||||
|
p_reason TEXT
|
||||||
|
) RETURNS VOID
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
v_event_id UUID := gen_random_uuid();
|
||||||
|
v_snapshot JSONB;
|
||||||
|
v_dedupe_key TEXT;
|
||||||
|
BEGIN
|
||||||
|
SELECT jsonb_build_object(
|
||||||
|
'orderId', o.id,
|
||||||
|
'orderItemId', oi.id,
|
||||||
|
'fulfillmentId', f.id,
|
||||||
|
'sourceOrderId', o.id::text,
|
||||||
|
'sourceOrderItemId', oi.id::text,
|
||||||
|
'sourceFulfillmentId', f.id::text,
|
||||||
|
'platformOrderId', o.platform_order_id,
|
||||||
|
'provider', o.provider,
|
||||||
|
'platform', o.platform,
|
||||||
|
'shopId', o.shop_id,
|
||||||
|
'shopName', o.shop_name,
|
||||||
|
'orderStatus', o.order_status,
|
||||||
|
'payStatus', o.pay_status,
|
||||||
|
'totalAmountFen', o.total_amount,
|
||||||
|
'orderCreatedAt', to_char(
|
||||||
|
o.created_at AT TIME ZONE 'UTC',
|
||||||
|
'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
|
||||||
|
),
|
||||||
|
'paidAt', CASE
|
||||||
|
WHEN o.paid_at IS NULL THEN NULL
|
||||||
|
ELSE to_char(o.paid_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')
|
||||||
|
END,
|
||||||
|
'skuCode', oi.sku_code,
|
||||||
|
'skuName', oi.sku_name,
|
||||||
|
'internalSkuKey', cfg.sku_key,
|
||||||
|
'quantity', oi.quantity,
|
||||||
|
'revenueAmountFen', oi.revenue_amount_fen,
|
||||||
|
'itemUpdatedAt', to_char(
|
||||||
|
oi.updated_at AT TIME ZONE 'UTC',
|
||||||
|
'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
|
||||||
|
),
|
||||||
|
'fulfillmentStatus', f.status,
|
||||||
|
'fulfillmentChannel', f.channel,
|
||||||
|
'fulfillmentIssueCode', COALESCE(f.issue_code, ''),
|
||||||
|
'fulfillmentUpdatedAt', to_char(
|
||||||
|
f.updated_at AT TIME ZONE 'UTC',
|
||||||
|
'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
|
||||||
|
),
|
||||||
|
'configEnabled', cfg.enabled,
|
||||||
|
'douyuFulfillmentEnabled', cfg.douyu_fulfillment_enabled,
|
||||||
|
'customerRoleName', COALESCE(task.customer_role_name, ''),
|
||||||
|
'customerPlatform', COALESCE(task.customer_platform, ''),
|
||||||
|
'customerSystem', COALESCE(task.customer_system, ''),
|
||||||
|
'homeImages', CASE
|
||||||
|
WHEN COALESCE(task.customer_homepage_screenshot_object_key, '') = ''
|
||||||
|
AND COALESCE(task.customer_homepage_screenshot_url, '') = ''
|
||||||
|
THEN '[]'::jsonb
|
||||||
|
ELSE jsonb_build_array(jsonb_build_object(
|
||||||
|
'url', COALESCE(task.customer_homepage_screenshot_url, ''),
|
||||||
|
'thumbnailUrl', COALESCE(
|
||||||
|
NULLIF(task.customer_homepage_screenshot_thumbnail_url, ''),
|
||||||
|
task.customer_homepage_screenshot_url,
|
||||||
|
''
|
||||||
|
),
|
||||||
|
'objectKey', COALESCE(task.customer_homepage_screenshot_object_key, ''),
|
||||||
|
'filename', COALESCE(task.customer_homepage_screenshot_filename, '')
|
||||||
|
))
|
||||||
|
END,
|
||||||
|
'customerProfileUpdatedAt', CASE
|
||||||
|
WHEN task.customer_homepage_screenshot_uploaded_at IS NULL THEN NULL
|
||||||
|
ELSE to_char(
|
||||||
|
task.customer_homepage_screenshot_uploaded_at AT TIME ZONE 'UTC',
|
||||||
|
'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
|
||||||
|
)
|
||||||
|
END
|
||||||
|
)
|
||||||
|
INTO v_snapshot
|
||||||
|
FROM orders o
|
||||||
|
JOIN order_items oi ON oi.order_id = o.id
|
||||||
|
JOIN fulfillments f ON f.order_item_id = oi.id
|
||||||
|
JOIN manual_fulfillment_configs cfg ON cfg.id = f.fulfillment_config_id
|
||||||
|
LEFT JOIN douyu_fulfillment_tasks task ON task.order_item_id = oi.id
|
||||||
|
WHERE o.id = p_order_id
|
||||||
|
AND oi.id = p_order_item_id
|
||||||
|
AND f.id = p_fulfillment_id
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
IF v_snapshot IS NULL THEN
|
||||||
|
RETURN;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
v_dedupe_key := CONCAT(
|
||||||
|
'platform-fulfillment-order:',
|
||||||
|
p_order_item_id,
|
||||||
|
':',
|
||||||
|
md5(v_snapshot::text)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO integration_outbox (
|
||||||
|
event_id, destination, event_type, dedupe_key, payload_json, status, created_at
|
||||||
|
) VALUES (
|
||||||
|
v_event_id,
|
||||||
|
'live_hub',
|
||||||
|
'platform_fulfillment.order_snapshot',
|
||||||
|
v_dedupe_key,
|
||||||
|
jsonb_build_object(
|
||||||
|
'eventId', v_event_id::text,
|
||||||
|
'eventType', 'platform_fulfillment.order_snapshot',
|
||||||
|
'contractVersion', 3,
|
||||||
|
'occurredAt', to_char(
|
||||||
|
clock_timestamp() AT TIME ZONE 'UTC',
|
||||||
|
'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
|
||||||
|
),
|
||||||
|
'data', v_snapshot || jsonb_build_object(
|
||||||
|
'reason', COALESCE(p_reason, '')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'pending',
|
||||||
|
NOW()
|
||||||
|
)
|
||||||
|
ON CONFLICT (dedupe_key) DO NOTHING;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION enqueue_platform_fulfillment_from_douyu_task()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
IF NEW.fulfillment_id IS NOT NULL THEN
|
||||||
|
PERFORM enqueue_live_hub_platform_fulfillment_event(
|
||||||
|
NEW.order_id,
|
||||||
|
NEW.order_item_id,
|
||||||
|
NEW.fulfillment_id,
|
||||||
|
CONCAT('customer-profile:', NEW.status)
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS trg_platform_fulfillment_douyu_task_sync
|
||||||
|
ON douyu_fulfillment_tasks;
|
||||||
|
CREATE TRIGGER trg_platform_fulfillment_douyu_task_sync
|
||||||
|
AFTER INSERT OR UPDATE OF
|
||||||
|
customer_role_name,
|
||||||
|
customer_platform,
|
||||||
|
customer_system,
|
||||||
|
customer_homepage_screenshot_object_key,
|
||||||
|
customer_homepage_screenshot_url,
|
||||||
|
customer_homepage_screenshot_thumbnail_url,
|
||||||
|
customer_homepage_screenshot_filename,
|
||||||
|
customer_homepage_screenshot_uploaded_at
|
||||||
|
ON douyu_fulfillment_tasks
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION enqueue_platform_fulfillment_from_douyu_task();
|
||||||
|
|
||||||
|
-- 已有活动任务补一次 contractVersion=3 快照,让 live-hub 立即拿到当前客户资料。
|
||||||
|
DO $$
|
||||||
|
DECLARE
|
||||||
|
candidate RECORD;
|
||||||
|
BEGIN
|
||||||
|
FOR candidate IN
|
||||||
|
SELECT
|
||||||
|
task.order_id,
|
||||||
|
task.order_item_id,
|
||||||
|
task.fulfillment_id
|
||||||
|
FROM douyu_fulfillment_tasks task
|
||||||
|
JOIN fulfillments f ON f.id = task.fulfillment_id
|
||||||
|
JOIN manual_fulfillment_configs cfg ON cfg.id = f.fulfillment_config_id
|
||||||
|
WHERE cfg.enabled = TRUE
|
||||||
|
AND cfg.douyu_fulfillment_enabled = TRUE
|
||||||
|
AND f.channel = 'manual'
|
||||||
|
AND f.status IN ('assigned', 'processing', 'completed', 'archived')
|
||||||
|
LOOP
|
||||||
|
PERFORM enqueue_live_hub_platform_fulfillment_event(
|
||||||
|
candidate.order_id,
|
||||||
|
candidate.order_item_id,
|
||||||
|
candidate.fulfillment_id,
|
||||||
|
'migration_customer_profile_snapshot'
|
||||||
|
);
|
||||||
|
END LOOP;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
@@ -7,12 +7,28 @@ import {
|
|||||||
refreshDouyuCustomerBinding,
|
refreshDouyuCustomerBinding,
|
||||||
saveDouyuCustomerProfile,
|
saveDouyuCustomerProfile,
|
||||||
startDouyuCustomerBinding,
|
startDouyuCustomerBinding,
|
||||||
|
uploadDouyuCustomerHomepageScreenshot,
|
||||||
} from '../services/douyu-fulfillment/douyu-fulfillment-service.js'
|
} from '../services/douyu-fulfillment/douyu-fulfillment-service.js'
|
||||||
|
import { createRateLimitMiddleware, getParamRateLimitKey } from '../middleware/rate-limit.js'
|
||||||
|
import { uploadSingleFile } from './file-upload.js'
|
||||||
import { openCustomerOrderRealtimeStream } from '../services/realtime/realtime-event-service.js'
|
import { openCustomerOrderRealtimeStream } from '../services/realtime/realtime-event-service.js'
|
||||||
import { createRouteHandler } from '../utils/http.js'
|
import { createRouteHandler } from '../utils/http.js'
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
|
const homepageScreenshotOrderRateLimit = createRateLimitMiddleware({
|
||||||
|
scope: 'douyu-homepage-screenshot:order',
|
||||||
|
windowMs: 60_000,
|
||||||
|
max: 10,
|
||||||
|
key: getParamRateLimitKey('orderNo'),
|
||||||
|
})
|
||||||
|
|
||||||
|
const homepageScreenshotIpRateLimit = createRateLimitMiddleware({
|
||||||
|
scope: 'douyu-homepage-screenshot:ip',
|
||||||
|
windowMs: 60_000,
|
||||||
|
max: 30,
|
||||||
|
})
|
||||||
|
|
||||||
router.get('/:orderNo/realtime', (req, res) => {
|
router.get('/:orderNo/realtime', (req, res) => {
|
||||||
openCustomerOrderRealtimeStream(
|
openCustomerOrderRealtimeStream(
|
||||||
res,
|
res,
|
||||||
@@ -29,6 +45,21 @@ router.get(
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
router.post(
|
||||||
|
'/:orderNo/homepage-screenshot',
|
||||||
|
homepageScreenshotIpRateLimit,
|
||||||
|
homepageScreenshotOrderRateLimit,
|
||||||
|
uploadSingleFile,
|
||||||
|
createRouteHandler(
|
||||||
|
(req) => uploadDouyuCustomerHomepageScreenshot(String(req.params.orderNo || ''), req.file),
|
||||||
|
{
|
||||||
|
successMessage: '主页截图已上传',
|
||||||
|
errorMessage: '上传主页截图失败',
|
||||||
|
scope: '[douyu-fulfillment/:orderNo/homepage-screenshot]',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
'/:orderNo/profile',
|
'/:orderNo/profile',
|
||||||
createRouteHandler(
|
createRouteHandler(
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
import type { PoolClient } from 'pg'
|
import type { PoolClient } from 'pg'
|
||||||
|
|
||||||
|
import { runtimeConfig } from '../../config/runtime.js'
|
||||||
import { query, withTransaction } from '../../db/client.js'
|
import { query, withTransaction } from '../../db/client.js'
|
||||||
|
import { getFileAssetByObjectKey } from '../../repositories/file-asset-repo.js'
|
||||||
|
import {
|
||||||
|
ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES,
|
||||||
|
buildFileUrl,
|
||||||
|
uploadFileAsset,
|
||||||
|
} from '../file-storage/file-storage-service.js'
|
||||||
import {
|
import {
|
||||||
publishCustomerOrderRealtimeChange,
|
publishCustomerOrderRealtimeChange,
|
||||||
publishRealtimeEvent,
|
publishRealtimeEvent,
|
||||||
@@ -26,6 +33,11 @@ type DouyuTaskRow = {
|
|||||||
customer_role_name: string
|
customer_role_name: string
|
||||||
customer_platform: string
|
customer_platform: string
|
||||||
customer_system: string
|
customer_system: string
|
||||||
|
customer_homepage_screenshot_object_key: string
|
||||||
|
customer_homepage_screenshot_url: string
|
||||||
|
customer_homepage_screenshot_thumbnail_url: string
|
||||||
|
customer_homepage_screenshot_filename: string
|
||||||
|
customer_homepage_screenshot_uploaded_at: string | null
|
||||||
binding_phase: string
|
binding_phase: string
|
||||||
live_execution_status: string
|
live_execution_status: string
|
||||||
live_binding_status: string
|
live_binding_status: string
|
||||||
@@ -99,6 +111,8 @@ type DouyuFulfillmentSettingsRow = {
|
|||||||
const AUTO_DISCOVERY_INTERVAL_MS = 15_000
|
const AUTO_DISCOVERY_INTERVAL_MS = 15_000
|
||||||
const LIVE_STATE_SYNC_INTERVAL_MS = 60_000
|
const LIVE_STATE_SYNC_INTERVAL_MS = 60_000
|
||||||
const TERMINAL_TASK_STATUSES = new Set(['completed', 'cancelled'])
|
const TERMINAL_TASK_STATUSES = new Set(['completed', 'cancelled'])
|
||||||
|
const DOUYU_HOMEPAGE_SCREENSHOT_SCENE = 'douyu-homepage-screenshot'
|
||||||
|
const DOUYU_HOMEPAGE_UPLOADER_TYPE = 'douyu-customer'
|
||||||
|
|
||||||
let lastAutomaticDiscoveryAt = 0
|
let lastAutomaticDiscoveryAt = 0
|
||||||
let automaticDiscoveryInFlight: Promise<{ created: number; updated: number } | null> | null = null
|
let automaticDiscoveryInFlight: Promise<{ created: number; updated: number } | null> | null = null
|
||||||
@@ -124,6 +138,36 @@ function liveHubBaseUrl() {
|
|||||||
.replace(/\/+$/, '')
|
.replace(/\/+$/, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function douyuHomepageScreenshotUploaderId(taskId: number) {
|
||||||
|
return `douyu-task-${taskId}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function absoluteOrderSiteFileUrl(pathname: string) {
|
||||||
|
const normalizedPath = String(pathname || '').trim()
|
||||||
|
if (!normalizedPath) return ''
|
||||||
|
try {
|
||||||
|
return new URL(normalizedPath, new URL(runtimeConfig.orders.claimBaseUrl).origin).toString()
|
||||||
|
} catch {
|
||||||
|
return normalizedPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasDouyuCustomerProfile(input: {
|
||||||
|
customer_role_name?: string
|
||||||
|
customer_platform?: string
|
||||||
|
customer_system?: string
|
||||||
|
customer_homepage_screenshot_object_key?: string
|
||||||
|
customer_homepage_screenshot_url?: string
|
||||||
|
}) {
|
||||||
|
return Boolean(
|
||||||
|
String(input.customer_role_name || '').trim() &&
|
||||||
|
['wechat', 'qq'].includes(String(input.customer_platform || '').trim()) &&
|
||||||
|
['ios', 'android'].includes(String(input.customer_system || '').trim()) &&
|
||||||
|
String(input.customer_homepage_screenshot_object_key || '').trim() &&
|
||||||
|
String(input.customer_homepage_screenshot_url || '').trim(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export async function getDouyuFulfillmentSettings() {
|
export async function getDouyuFulfillmentSettings() {
|
||||||
const result = await query<DouyuFulfillmentSettingsRow>(
|
const result = await query<DouyuFulfillmentSettingsRow>(
|
||||||
`
|
`
|
||||||
@@ -417,7 +461,18 @@ export function statusForLive(live: LiveBindingState): string {
|
|||||||
if (live.customerProfileReset === true) return 'waiting_profile'
|
if (live.customerProfileReset === true) return 'waiting_profile'
|
||||||
if (live.executionStatus === 'completed') return 'completed'
|
if (live.executionStatus === 'completed') return 'completed'
|
||||||
if (live.executionStatus === 'cancelled') return 'cancelled'
|
if (live.executionStatus === 'cancelled') return 'cancelled'
|
||||||
if (live.bindingStatus === 'failed' || BINDING_FAILURE_ISSUES.has(live.issueCode)) {
|
const bindTaskFailed = ['failed', 'error', 'stopped'].includes(live.bindTaskStatus)
|
||||||
|
const bindingStarted =
|
||||||
|
live.bindingStatus !== 'not_started' ||
|
||||||
|
Boolean(live.bindTaskId) ||
|
||||||
|
Boolean(live.qrUrl) ||
|
||||||
|
live.bindReadyForConfirm ||
|
||||||
|
live.bindConfirmed
|
||||||
|
if (
|
||||||
|
live.bindingStatus === 'failed' ||
|
||||||
|
bindTaskFailed ||
|
||||||
|
(BINDING_FAILURE_ISSUES.has(live.issueCode) && bindingStarted)
|
||||||
|
) {
|
||||||
return 'failed'
|
return 'failed'
|
||||||
}
|
}
|
||||||
if (live.executionStatus === 'manual_required') return 'manual_required'
|
if (live.executionStatus === 'manual_required') return 'manual_required'
|
||||||
@@ -504,6 +559,26 @@ async function updateTaskFromLiveState(
|
|||||||
customer_role_name = CASE WHEN $19 THEN '' ELSE customer_role_name END,
|
customer_role_name = CASE WHEN $19 THEN '' ELSE customer_role_name END,
|
||||||
customer_platform = CASE WHEN $19 THEN '' ELSE customer_platform END,
|
customer_platform = CASE WHEN $19 THEN '' ELSE customer_platform END,
|
||||||
customer_system = CASE WHEN $19 THEN '' ELSE customer_system END,
|
customer_system = CASE WHEN $19 THEN '' ELSE customer_system END,
|
||||||
|
customer_homepage_screenshot_object_key = CASE
|
||||||
|
WHEN $19 THEN ''
|
||||||
|
ELSE customer_homepage_screenshot_object_key
|
||||||
|
END,
|
||||||
|
customer_homepage_screenshot_url = CASE
|
||||||
|
WHEN $19 THEN ''
|
||||||
|
ELSE customer_homepage_screenshot_url
|
||||||
|
END,
|
||||||
|
customer_homepage_screenshot_thumbnail_url = CASE
|
||||||
|
WHEN $19 THEN ''
|
||||||
|
ELSE customer_homepage_screenshot_thumbnail_url
|
||||||
|
END,
|
||||||
|
customer_homepage_screenshot_filename = CASE
|
||||||
|
WHEN $19 THEN ''
|
||||||
|
ELSE customer_homepage_screenshot_filename
|
||||||
|
END,
|
||||||
|
customer_homepage_screenshot_uploaded_at = CASE
|
||||||
|
WHEN $19 THEN NULL
|
||||||
|
ELSE customer_homepage_screenshot_uploaded_at
|
||||||
|
END,
|
||||||
qr_url = $15,
|
qr_url = $15,
|
||||||
qr_generated_at = NULLIF($16, '')::timestamptz,
|
qr_generated_at = NULLIF($16, '')::timestamptz,
|
||||||
qr_expires_at = NULLIF($17, '')::timestamptz,
|
qr_expires_at = NULLIF($17, '')::timestamptz,
|
||||||
@@ -787,9 +862,34 @@ export async function getCustomerDouyuFulfillment(orderNo: string) {
|
|||||||
return localCustomerFulfillment(task)
|
return localCustomerFulfillment(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function uploadDouyuCustomerHomepageScreenshot(
|
||||||
|
orderNo: string,
|
||||||
|
file: Express.Multer.File | null | undefined,
|
||||||
|
) {
|
||||||
|
const task = await loadTaskByOrderNo(orderNo)
|
||||||
|
if (task.status === 'completed' || task.status === 'cancelled') {
|
||||||
|
throw createHttpError('当前订单已结束,不能上传资料', {
|
||||||
|
statusCode: 409,
|
||||||
|
errorCode: 'douyu_fulfillment_closed',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return uploadFileAsset({
|
||||||
|
file,
|
||||||
|
scene: DOUYU_HOMEPAGE_SCREENSHOT_SCENE,
|
||||||
|
uploaderType: DOUYU_HOMEPAGE_UPLOADER_TYPE,
|
||||||
|
uploaderId: douyuHomepageScreenshotUploaderId(task.id),
|
||||||
|
allowedContentTypes: ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export async function saveDouyuCustomerProfile(
|
export async function saveDouyuCustomerProfile(
|
||||||
orderNo: string,
|
orderNo: string,
|
||||||
input: { roleName?: unknown; platform?: unknown; system?: unknown },
|
input: {
|
||||||
|
roleName?: unknown
|
||||||
|
platform?: unknown
|
||||||
|
system?: unknown
|
||||||
|
homepageScreenshotObjectKey?: unknown
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
const task = await loadTaskByOrderNo(orderNo)
|
const task = await loadTaskByOrderNo(orderNo)
|
||||||
if (task.status === 'completed' || task.status === 'cancelled') {
|
if (task.status === 'completed' || task.status === 'cancelled') {
|
||||||
@@ -807,29 +907,70 @@ export async function saveDouyuCustomerProfile(
|
|||||||
const system = String(input.system ?? '')
|
const system = String(input.system ?? '')
|
||||||
.trim()
|
.trim()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
|
const homepageScreenshotObjectKey = String(input.homepageScreenshotObjectKey ?? '')
|
||||||
|
.trim()
|
||||||
|
.slice(0, 512)
|
||||||
if (!roleName || !['wechat', 'qq'].includes(platform) || !['ios', 'android'].includes(system)) {
|
if (!roleName || !['wechat', 'qq'].includes(platform) || !['ios', 'android'].includes(system)) {
|
||||||
throw createHttpError('请完整填写角色名、微信/QQ 和苹果/安卓', {
|
throw createHttpError('请完整填写角色名、微信/QQ 和苹果/安卓', {
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
errorCode: 'douyu_customer_profile_invalid',
|
errorCode: 'douyu_customer_profile_invalid',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (!homepageScreenshotObjectKey) {
|
||||||
|
throw createHttpError('请上传游戏主页截图', {
|
||||||
|
statusCode: 400,
|
||||||
|
errorCode: 'douyu_customer_homepage_screenshot_required',
|
||||||
|
})
|
||||||
|
}
|
||||||
await withTransaction(async (client) => {
|
await withTransaction(async (client) => {
|
||||||
|
const asset = await getFileAssetByObjectKey(homepageScreenshotObjectKey, client)
|
||||||
|
if (
|
||||||
|
!asset ||
|
||||||
|
asset.uploader_type !== DOUYU_HOMEPAGE_UPLOADER_TYPE ||
|
||||||
|
asset.uploader_id !== douyuHomepageScreenshotUploaderId(task.id) ||
|
||||||
|
asset.scene !== DOUYU_HOMEPAGE_SCREENSHOT_SCENE ||
|
||||||
|
!ORDER_SERVICE_SCREENSHOT_CONTENT_TYPES.has(String(asset.content_type || '').trim())
|
||||||
|
) {
|
||||||
|
throw createHttpError('主页截图无效,请重新上传', {
|
||||||
|
statusCode: 400,
|
||||||
|
errorCode: 'douyu_customer_homepage_screenshot_invalid',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const screenshotUrl = absoluteOrderSiteFileUrl(buildFileUrl(asset.object_key))
|
||||||
|
const thumbnailUrl = absoluteOrderSiteFileUrl(
|
||||||
|
buildFileUrl(asset.thumbnail_object_key || asset.object_key),
|
||||||
|
)
|
||||||
await client.query(
|
await client.query(
|
||||||
`
|
`
|
||||||
UPDATE douyu_fulfillment_tasks
|
UPDATE douyu_fulfillment_tasks
|
||||||
SET customer_role_name = $2,
|
SET customer_role_name = $2,
|
||||||
customer_platform = $3,
|
customer_platform = $3,
|
||||||
customer_system = $4,
|
customer_system = $4,
|
||||||
|
customer_homepage_screenshot_object_key = $5,
|
||||||
|
customer_homepage_screenshot_url = $6,
|
||||||
|
customer_homepage_screenshot_thumbnail_url = $7,
|
||||||
|
customer_homepage_screenshot_filename = $8,
|
||||||
|
customer_homepage_screenshot_uploaded_at = NOW(),
|
||||||
status = CASE WHEN status = 'waiting_profile' THEN 'preparing' ELSE status END,
|
status = CASE WHEN status = 'waiting_profile' THEN 'preparing' ELSE status END,
|
||||||
updated_at = NOW()
|
updated_at = NOW()
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
[task.id, roleName, platform, system],
|
[
|
||||||
|
task.id,
|
||||||
|
roleName,
|
||||||
|
platform,
|
||||||
|
system,
|
||||||
|
asset.object_key,
|
||||||
|
screenshotUrl,
|
||||||
|
thumbnailUrl,
|
||||||
|
asset.original_filename,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
await appendEvent(client, task.id, 'customer_profile_saved', 'customer', {
|
await appendEvent(client, task.id, 'customer_profile_saved', 'customer', {
|
||||||
roleName,
|
roleName,
|
||||||
platform,
|
platform,
|
||||||
system,
|
system,
|
||||||
|
homepageScreenshotObjectKey: asset.object_key,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return getCustomerDouyuFulfillment(orderNo)
|
return getCustomerDouyuFulfillment(orderNo)
|
||||||
@@ -837,6 +978,12 @@ export async function saveDouyuCustomerProfile(
|
|||||||
|
|
||||||
export async function startDouyuCustomerBinding(orderNo: string, forceRefresh = false) {
|
export async function startDouyuCustomerBinding(orderNo: string, forceRefresh = false) {
|
||||||
let task = await loadTaskByOrderNo(orderNo)
|
let task = await loadTaskByOrderNo(orderNo)
|
||||||
|
if (!hasDouyuCustomerProfile(task)) {
|
||||||
|
throw createHttpError('请先提交游戏角色和游戏主页截图,再开始绑定', {
|
||||||
|
statusCode: 409,
|
||||||
|
errorCode: 'douyu_customer_profile_required',
|
||||||
|
})
|
||||||
|
}
|
||||||
if (!task.live_session_id) {
|
if (!task.live_session_id) {
|
||||||
const session = await ensureLiveSession(task)
|
const session = await ensureLiveSession(task)
|
||||||
task = session.task
|
task = session.task
|
||||||
|
|||||||
@@ -43,6 +43,20 @@ test('斗鱼客户资料角色名不一致时禁止确认', () => {
|
|||||||
assert.equal(result.roleMatched, false)
|
assert.equal(result.roleMatched, false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('账号换绑冷却但尚未开始绑定,不应显示角色绑定失败', () => {
|
||||||
|
const status = statusForLive({
|
||||||
|
executionStatus: 'ready',
|
||||||
|
bindingStatus: 'not_started',
|
||||||
|
issueCode: 'account_role_cooldown',
|
||||||
|
bindTaskId: null,
|
||||||
|
qrUrl: '',
|
||||||
|
bindReadyForConfirm: false,
|
||||||
|
bindConfirmed: false,
|
||||||
|
accountReady: false,
|
||||||
|
} as never)
|
||||||
|
assert.equal(status, 'preparing')
|
||||||
|
})
|
||||||
|
|
||||||
test('绑定失败优先于旧角色确认标记', () => {
|
test('绑定失败优先于旧角色确认标记', () => {
|
||||||
const status = statusForLive({
|
const status = statusForLive({
|
||||||
executionStatus: 'manual_required',
|
executionStatus: 'manual_required',
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 304 KiB |
@@ -10,13 +10,16 @@ import QRCode from 'qrcode'
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||||||
import { useParams } from 'react-router'
|
import { useParams } from 'react-router'
|
||||||
|
|
||||||
|
import ImageUpload from '@/components/files/ImageUpload'
|
||||||
import {
|
import {
|
||||||
confirmDouyuBinding,
|
confirmDouyuBinding,
|
||||||
fetchDouyuFulfillment,
|
fetchDouyuFulfillment,
|
||||||
refreshDouyuBinding,
|
refreshDouyuBinding,
|
||||||
saveDouyuProfile,
|
saveDouyuProfile,
|
||||||
startDouyuBinding,
|
startDouyuBinding,
|
||||||
|
uploadDouyuHomepageScreenshot,
|
||||||
} from '@/services/douyu-fulfillment'
|
} from '@/services/douyu-fulfillment'
|
||||||
|
import type { UploadedFile } from '@/types/worker-platform'
|
||||||
import type {
|
import type {
|
||||||
DouyuCustomerFulfillment,
|
DouyuCustomerFulfillment,
|
||||||
DouyuCustomerPlatform,
|
DouyuCustomerPlatform,
|
||||||
@@ -77,6 +80,7 @@ export default function DouyuFulfillmentPage() {
|
|||||||
const [roleName, setRoleName] = useState('')
|
const [roleName, setRoleName] = useState('')
|
||||||
const [platform, setPlatform] = useState<DouyuCustomerPlatform>('wechat')
|
const [platform, setPlatform] = useState<DouyuCustomerPlatform>('wechat')
|
||||||
const [system, setSystem] = useState<DouyuCustomerSystem>('android')
|
const [system, setSystem] = useState<DouyuCustomerSystem>('android')
|
||||||
|
const [homepageScreenshot, setHomepageScreenshot] = useState<UploadedFile[]>([])
|
||||||
const [qrImage, setQrImage] = useState('')
|
const [qrImage, setQrImage] = useState('')
|
||||||
const [bindingQrExpanded, setBindingQrExpanded] = useState(false)
|
const [bindingQrExpanded, setBindingQrExpanded] = useState(false)
|
||||||
const [nowMs, setNowMs] = useState(() => Date.now())
|
const [nowMs, setNowMs] = useState(() => Date.now())
|
||||||
@@ -151,7 +155,14 @@ export default function DouyuFulfillmentPage() {
|
|||||||
|
|
||||||
const task = data?.task
|
const task = data?.task
|
||||||
const live = data?.live
|
const live = data?.live
|
||||||
const needsProfile = Boolean(task && !task.customer_role_name)
|
const hasCustomerProfile = Boolean(
|
||||||
|
task?.customer_role_name?.trim() &&
|
||||||
|
['wechat', 'qq'].includes(task.customer_platform) &&
|
||||||
|
['ios', 'android'].includes(task.customer_system) &&
|
||||||
|
task.customer_homepage_screenshot_object_key?.trim() &&
|
||||||
|
task.customer_homepage_screenshot_url?.trim(),
|
||||||
|
)
|
||||||
|
const needsProfile = Boolean(task && !hasCustomerProfile)
|
||||||
const bindingFailed = Boolean(live && BINDING_FAILURE_ISSUES.has(live.issueCode))
|
const bindingFailed = Boolean(live && BINDING_FAILURE_ISSUES.has(live.issueCode))
|
||||||
const bindingFailureRetryable = Boolean(live?.issueCode === 'binding_failed' && live.accountReady)
|
const bindingFailureRetryable = Boolean(live?.issueCode === 'binding_failed' && live.accountReady)
|
||||||
|
|
||||||
@@ -239,12 +250,18 @@ export default function DouyuFulfillmentPage() {
|
|||||||
message.warning(roleNameIssue)
|
message.warning(roleNameIssue)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const screenshot = homepageScreenshot[0]
|
||||||
|
if (!screenshot?.objectKey) {
|
||||||
|
message.warning('请上传游戏主页截图')
|
||||||
|
return
|
||||||
|
}
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
try {
|
try {
|
||||||
const response = await saveDouyuProfile(orderNo, {
|
const response = await saveDouyuProfile(orderNo, {
|
||||||
roleName: roleName.trim(),
|
roleName: roleName.trim(),
|
||||||
platform,
|
platform,
|
||||||
system,
|
system,
|
||||||
|
homepageScreenshotObjectKey: screenshot.objectKey,
|
||||||
})
|
})
|
||||||
applyData(response.data)
|
applyData(response.data)
|
||||||
message.success('资料已提交,正在准备绑定二维码')
|
message.success('资料已提交,正在准备绑定二维码')
|
||||||
@@ -408,6 +425,37 @@ export default function DouyuFulfillmentPage() {
|
|||||||
{roleNameIssue ? <ExclamationCircleOutlined aria-hidden="true" /> : null}
|
{roleNameIssue ? <ExclamationCircleOutlined aria-hidden="true" /> : null}
|
||||||
<span>{roleNameIssue || DOUYU_ROLE_NAME_FORMAT_HINT}</span>
|
<span>{roleNameIssue || DOUYU_ROLE_NAME_FORMAT_HINT}</span>
|
||||||
</p>
|
</p>
|
||||||
|
<label className="customer-collect-label">游戏主页截图(必填)</label>
|
||||||
|
<div className="customer-douyu-screenshot-row">
|
||||||
|
<div className="customer-douyu-screenshot-upload">
|
||||||
|
<ImageUpload
|
||||||
|
scene="douyu-homepage-screenshot"
|
||||||
|
scope="collect"
|
||||||
|
maxCount={1}
|
||||||
|
showPasteHint
|
||||||
|
value={homepageScreenshot}
|
||||||
|
onChange={setHomepageScreenshot}
|
||||||
|
uploader={async (file) => {
|
||||||
|
const response = await uploadDouyuHomepageScreenshot(orderNo, file)
|
||||||
|
return response.data.file
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="customer-douyu-screenshot-example">
|
||||||
|
<Image
|
||||||
|
src="/images/game-home-example.webp"
|
||||||
|
alt="游戏主页截图示例"
|
||||||
|
width={150}
|
||||||
|
height={140}
|
||||||
|
style={{ objectFit: 'cover', borderRadius: 8, border: '1px solid #334155' }}
|
||||||
|
/>
|
||||||
|
<span>示例:需能看到游戏名字和游戏 UID</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="customer-douyu-role-name-help">
|
||||||
|
请上传游戏主页截图,需能看到游戏名字/昵称和游戏
|
||||||
|
UID(编号);用于客服核对绑定是否正确。
|
||||||
|
</p>
|
||||||
<div className="customer-douyu-submit-bar">
|
<div className="customer-douyu-submit-bar">
|
||||||
<Button
|
<Button
|
||||||
block
|
block
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { apiGet, apiPost } from '@/lib/http'
|
import { apiGet, apiPost, apiPostForm } from '@/lib/http'
|
||||||
|
import { optimizeImageForUpload } from '@/utils/image-upload'
|
||||||
|
import type { UploadedFile } from '@/types/worker-platform'
|
||||||
import type {
|
import type {
|
||||||
DouyuCustomerFulfillment,
|
DouyuCustomerFulfillment,
|
||||||
DouyuCustomerPlatform,
|
DouyuCustomerPlatform,
|
||||||
@@ -17,6 +19,7 @@ export function saveDouyuProfile(
|
|||||||
roleName: string
|
roleName: string
|
||||||
platform: DouyuCustomerPlatform
|
platform: DouyuCustomerPlatform
|
||||||
system: DouyuCustomerSystem
|
system: DouyuCustomerSystem
|
||||||
|
homepageScreenshotObjectKey: string
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
return apiPost<DouyuCustomerFulfillment>(
|
return apiPost<DouyuCustomerFulfillment>(
|
||||||
@@ -51,3 +54,13 @@ export function confirmDouyuBinding(orderNo: string) {
|
|||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function uploadDouyuHomepageScreenshot(orderNo: string, file: File) {
|
||||||
|
const optimized = await optimizeImageForUpload(file, 'douyu-homepage-screenshot')
|
||||||
|
const form = new FormData()
|
||||||
|
form.append('file', optimized)
|
||||||
|
return apiPostForm<{ file: UploadedFile }>(
|
||||||
|
`/api/v1/douyu-fulfillment/${encodeURIComponent(orderNo)}/homepage-screenshot`,
|
||||||
|
form,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -645,3 +645,58 @@
|
|||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.customer-douyu-screenshot-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 14px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-douyu-screenshot-upload {
|
||||||
|
flex: 0 0 150px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-douyu-screenshot-upload .ant-upload-select,
|
||||||
|
.customer-douyu-screenshot-upload .ant-upload-list-item-container {
|
||||||
|
width: 150px !important;
|
||||||
|
height: 140px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-douyu-screenshot-example img {
|
||||||
|
width: 100% !important;
|
||||||
|
height: 100% !important;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-douyu-screenshot-example {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
min-width: 0;
|
||||||
|
color: #94a3b8;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.45;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.customer-douyu-screenshot-row {
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-douyu-screenshot-upload {
|
||||||
|
flex-basis: 126px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-douyu-screenshot-upload .ant-upload-select,
|
||||||
|
.customer-douyu-screenshot-upload .ant-upload-list-item-container {
|
||||||
|
width: 126px !important;
|
||||||
|
height: 118px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-douyu-screenshot-example .ant-image {
|
||||||
|
width: 126px !important;
|
||||||
|
height: 118px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ export type DouyuFulfillmentTask = {
|
|||||||
customer_role_name: string
|
customer_role_name: string
|
||||||
customer_platform: string
|
customer_platform: string
|
||||||
customer_system: string
|
customer_system: string
|
||||||
|
customer_homepage_screenshot_object_key: string
|
||||||
|
customer_homepage_screenshot_url: string
|
||||||
|
customer_homepage_screenshot_thumbnail_url: string
|
||||||
|
customer_homepage_screenshot_filename: string
|
||||||
|
customer_homepage_screenshot_uploaded_at: string | null
|
||||||
binding_phase: string
|
binding_phase: string
|
||||||
live_execution_status: string
|
live_execution_status: string
|
||||||
live_binding_status: string
|
live_binding_status: string
|
||||||
|
|||||||
Reference in New Issue
Block a user