99 lines
2.9 KiB
TypeScript
99 lines
2.9 KiB
TypeScript
// xuchao: 抖音核销接口层。接口契约依赖后端 /mp-api/douyin/*;后端尚未提供时由 DOUYIN_BACKEND_READY 控制直接返回模拟数据以便测试。
|
|
// xuchao: 后端就绪后只需将 DOUYIN_BACKEND_READY 置为 true,即可走真实请求(无需改其它代码)。
|
|
import { post } from '../../../api/request'
|
|
|
|
// xuchao: 后端 /mp-api/douyin/* 是否已就绪。false=用模拟数据测试;true=走真实后端。
|
|
const DOUYIN_BACKEND_READY = false
|
|
|
|
/** 券码实名信息(用于回填绑卡表单) */
|
|
export interface VoucherRealnameInfo {
|
|
voucher_id: string
|
|
realname: string
|
|
card_id: string
|
|
/** 证件类型文案,如「身份证」 */
|
|
card_type: string
|
|
mobile: string
|
|
}
|
|
|
|
/** 单张券码(对齐小泥人 voucher-list 的 ret 元素) */
|
|
export interface VoucherItem {
|
|
id: string
|
|
order_id: string
|
|
/** 券码,列表展示与提交均使用此值 */
|
|
code: string
|
|
/** 1=未使用 3=已使用 5=已取消 */
|
|
status: number
|
|
mobile: string
|
|
product_name: string
|
|
merchant_name: string
|
|
voucherRealnameInfo?: VoucherRealnameInfo[]
|
|
}
|
|
|
|
export interface QueryVoucherListParams {
|
|
mobile: string
|
|
/** 1=未使用,默认查未使用 */
|
|
status?: number
|
|
}
|
|
|
|
export interface ActivateAndBindParams {
|
|
voucherId: string
|
|
voucherCode: string
|
|
quantity: number
|
|
mobile: string
|
|
userName: string
|
|
idType: string
|
|
idNo: string
|
|
faceImg: string
|
|
}
|
|
|
|
const delay = (ms: number) => new Promise<void>((r) => setTimeout(r, ms))
|
|
|
|
// xuchao: 模拟券码数据(后端未就绪时使用),含一条带实名信息用于验证回填。
|
|
const MOCK_VOUCHERS: VoucherItem[] = [
|
|
{
|
|
id: '1001',
|
|
order_id: 'DY202607280001',
|
|
code: '20260728192093019',
|
|
status: 1,
|
|
mobile: '',
|
|
product_name: '赣湘全域旅游年卡',
|
|
merchant_name: '爱上萍乡',
|
|
voucherRealnameInfo: [
|
|
{ voucher_id: '1001', realname: '张三', card_id: '360302199001011234', card_type: '身份证', mobile: '' },
|
|
],
|
|
},
|
|
{
|
|
id: '1002',
|
|
order_id: 'DY202607280002',
|
|
code: '20260728192093011',
|
|
status: 1,
|
|
mobile: '',
|
|
product_name: '赣湘全域旅游年卡',
|
|
merchant_name: '爱上萍乡',
|
|
},
|
|
]
|
|
|
|
/**
|
|
* xuchao: 查询当前手机号可核销的券码列表。
|
|
* 后端接口:POST /mp-api/douyin/voucherList,入参 { mobile, status }。
|
|
*/
|
|
export async function queryVoucherList(params: QueryVoucherListParams): Promise<VoucherItem[]> {
|
|
if (!DOUYIN_BACKEND_READY) {
|
|
await delay(300)
|
|
return MOCK_VOUCHERS.map((v) => ({ ...v, mobile: params.mobile }))
|
|
}
|
|
return post<VoucherItem[]>('/douyin/voucherList', params)
|
|
}
|
|
|
|
/**
|
|
* xuchao: 激活且绑定(核销)。
|
|
* 后端接口:POST /mp-api/douyin/activateAndBind,入参见 ActivateAndBindParams。
|
|
*/
|
|
export async function activateAndBind(params: ActivateAndBindParams): Promise<void> {
|
|
if (!DOUYIN_BACKEND_READY) {
|
|
await delay(800)
|
|
return
|
|
}
|
|
await post<null>('/douyin/activateAndBind', params)
|
|
}
|