Use unique contact identifiers for KOC claims
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
accountFromPublishLink,
|
||||
extractXhsPublishUrl,
|
||||
} from "../../../lib/partner-utils";
|
||||
import { parseClaimantIdentifier } from "../../../lib/claimant-identifier";
|
||||
import {
|
||||
partnerOptions,
|
||||
withPartnerCors,
|
||||
@@ -32,6 +33,7 @@ type PartnerBody = {
|
||||
distributionIds?: string[];
|
||||
delegationLabel?: string;
|
||||
delegationBundleId?: string;
|
||||
claimantIdentifier?: string;
|
||||
claimantName?: string;
|
||||
quantity?: number;
|
||||
accountNickname?: string;
|
||||
@@ -411,16 +413,25 @@ async function handlePost(request: Request) {
|
||||
const db = getRawDb();
|
||||
|
||||
if (body.action === "recover") {
|
||||
const claimantName = textValue(body.claimantName, 40);
|
||||
if (claimantName.length < 2) {
|
||||
const identifierInput = textValue(
|
||||
body.claimantIdentifier ?? body.claimantName,
|
||||
64,
|
||||
);
|
||||
const claimantIdentifier = parseClaimantIdentifier(identifierInput);
|
||||
if (!claimantIdentifier && identifierInput.length < 2) {
|
||||
return Response.json(
|
||||
{ error: "请填写领取时使用的企微昵称或联系人" },
|
||||
{ error: "请输入领取时使用的正确微信号或手机号" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
const partnerId = `partner-ext-${hashText(
|
||||
`${task.id}:${claimantName.toLowerCase()}`,
|
||||
const legacyPartnerId = `partner-ext-${hashText(
|
||||
`${task.id}:${identifierInput.toLowerCase()}`,
|
||||
)}`;
|
||||
const partnerId = claimantIdentifier
|
||||
? `partner-ext-${hashText(
|
||||
`claimant:${claimantIdentifier.canonical}`,
|
||||
)}`
|
||||
: legacyPartnerId;
|
||||
const recovered = await db
|
||||
.prepare(
|
||||
`SELECT
|
||||
@@ -433,12 +444,12 @@ async function handlePost(request: Request) {
|
||||
FROM claims c
|
||||
LEFT JOIN distributions d ON d.claim_id = c.id
|
||||
LEFT JOIN contents co ON co.id = d.content_id
|
||||
WHERE c.task_id = ? AND c.partner_id = ?
|
||||
WHERE c.task_id = ? AND c.partner_id IN (?, ?)
|
||||
GROUP BY c.id, c.claim_token, c.quantity, c.created_at
|
||||
ORDER BY c.created_at DESC, c.id DESC
|
||||
LIMIT 20`,
|
||||
)
|
||||
.bind(task.id, partnerId)
|
||||
.bind(task.id, partnerId, legacyPartnerId)
|
||||
.all<{
|
||||
claim_token: string;
|
||||
quantity: number;
|
||||
@@ -449,7 +460,7 @@ async function handlePost(request: Request) {
|
||||
}>();
|
||||
if (recovered.results.length === 0) {
|
||||
return Response.json(
|
||||
{ error: "没有找到领取记录,请确认昵称与领取时完全一致" },
|
||||
{ error: "没有找到领取记录,请确认微信号或手机号与领取时完全一致" },
|
||||
{ status: 404 },
|
||||
);
|
||||
}
|
||||
@@ -468,10 +479,17 @@ async function handlePost(request: Request) {
|
||||
if (task.status !== "active") {
|
||||
return Response.json({ error: "任务已结束,无法继续领取" }, { status: 409 });
|
||||
}
|
||||
const claimantName = textValue(body.claimantName, 40);
|
||||
const identifierInput = textValue(
|
||||
body.claimantIdentifier ?? body.claimantName,
|
||||
64,
|
||||
);
|
||||
const claimantIdentifier = parseClaimantIdentifier(identifierInput);
|
||||
const quantity = quantityValue(body.quantity);
|
||||
if (claimantName.length < 2) {
|
||||
return Response.json({ error: "请填写企微昵称或联系人" }, { status: 400 });
|
||||
if (!claimantIdentifier) {
|
||||
return Response.json(
|
||||
{ error: "请输入正确的微信号或手机号" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
const available = await db
|
||||
.prepare(
|
||||
@@ -486,8 +504,9 @@ async function handlePost(request: Request) {
|
||||
return Response.json({ error: "当前任务已领完" }, { status: 409 });
|
||||
}
|
||||
const partnerId = `partner-ext-${hashText(
|
||||
`${task.id}:${claimantName.toLowerCase()}`,
|
||||
`claimant:${claimantIdentifier.canonical}`,
|
||||
)}`;
|
||||
const claimantName = claimantIdentifier.display;
|
||||
const claimId = uid("claim");
|
||||
const claimToken = crypto.randomUUID().replaceAll("-", "");
|
||||
const statements: D1PreparedStatement[] = [
|
||||
|
||||
Reference in New Issue
Block a user