You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.6 KiB
58 lines
2.6 KiB
/** |
|
* 客户字段归一化(新接口全小写 / 旧 camelCase) |
|
*/ |
|
import { CustomerDto, CustomerBalanceListItem } from '../types/login' |
|
import { pickField, toNumber } from '../utils/apiNormalize' |
|
|
|
export const normalizeCustomer = (raw: Record<string, any> | null | undefined): CustomerDto => { |
|
const src = raw || {} |
|
return { |
|
id: toNumber(pickField(src, 'id')), |
|
sn: String(pickField(src, 'sn') ?? ''), |
|
wxOpenId: String(pickField(src, 'wxOpenId', 'wxopenid') ?? ''), |
|
name: String(pickField(src, 'name') ?? ''), |
|
type: toNumber(pickField(src, 'type')), |
|
typeName: String(pickField(src, 'typeName', 'typename') ?? ''), |
|
amount: toNumber(pickField(src, 'amount')), |
|
wchart: String(pickField(src, 'wchart') ?? ''), |
|
phone: String(pickField(src, 'phone') ?? ''), |
|
bpSn: String(pickField(src, 'bpSn', 'bpsn') ?? ''), |
|
bpInfoName: String(pickField(src, 'bpInfoName', 'bpinfoname', 'bpname') ?? ''), |
|
instSn: String(pickField(src, 'instSn', 'instsn') ?? ''), |
|
ownerName: String(pickField(src, 'ownerName', 'ownername') ?? ''), |
|
createTime: String(pickField(src, 'createTime', 'createtime') ?? ''), |
|
lastLoginTime: String(pickField(src, 'lastLoginTime', 'lastlogintime') ?? ''), |
|
wxNickName: String(pickField(src, 'wxNickName', 'wxnickname', 'name') ?? ''), |
|
wxAvatarUrl: String(pickField(src, 'wxAvatarUrl', 'wxavatarurl') ?? ''), |
|
birthday: pickField<string>(src, 'birthday'), |
|
} |
|
} |
|
|
|
/** 归一化单条门店余额(balancelist 数组项) */ |
|
export const normalizeBalanceListItem = (raw: Record<string, any>): CustomerBalanceListItem => ({ |
|
bpSn: String(pickField(raw, 'bpSn', 'bpsn') ?? ''), |
|
bpName: String(pickField(raw, 'bpName', 'bpname') ?? ''), |
|
amount: toNumber(pickField(raw, 'amount')), |
|
points: toNumber(pickField(raw, 'points')), |
|
lockerCount: toNumber(pickField(raw, 'lockerCount', 'lockercount')), |
|
vipEndTime: pickField<string | null>(raw, 'vipEndTime', 'vipendtime') ?? null, |
|
}) |
|
|
|
/** 归一化客户跨店余额列表 */ |
|
export const normalizeBalanceList = ( |
|
raw: Record<string, any>[] | null | undefined |
|
): CustomerBalanceListItem[] => { |
|
if (!Array.isArray(raw)) return [] |
|
return raw.map(normalizeBalanceListItem) |
|
} |
|
|
|
/** 登录 data:扁平(Word)或嵌套 customer(旧) */ |
|
export const normalizeLoginData = (data: Record<string, any> | null | undefined) => { |
|
const src = data || {} |
|
const nested = pickField<Record<string, any>>(src, 'customer') |
|
const customer = normalizeCustomer(nested || src) |
|
const isNewCustomer = Boolean( |
|
pickField(src, 'isNewCustomer', 'isnewcustomer') ?? false |
|
) |
|
return { customer, isNewCustomer, message: String(pickField(src, 'message') ?? '') } |
|
}
|
|
|