13 changed files with 569 additions and 639 deletions
@ -1,150 +0,0 @@
@@ -1,150 +0,0 @@
|
||||
/** |
||||
* 球台相关 API |
||||
* 包含开台、关台、续费等接口 |
||||
*/ |
||||
import { post } from './request' |
||||
|
||||
/** |
||||
* 开台操作类型 |
||||
*/ |
||||
export enum TableOperationType { |
||||
/** 押金开台 */ |
||||
SelfServiceDeposit = 1, |
||||
/** 余额开台 */ |
||||
SelfServiceBalance = 2, |
||||
/** 定时开台 */ |
||||
Timed = 3, |
||||
/** 信用开台 */ |
||||
Credit = 4, |
||||
/** 团购券开台 */ |
||||
GroupBuy = 5, |
||||
/** 立即关台 */ |
||||
ImmediateClose = 6, |
||||
/** 续费 */ |
||||
Renew = 7, |
||||
/** 关灯重开 */ |
||||
ReopenAfterClose = 8, |
||||
} |
||||
|
||||
/** |
||||
* 支付渠道 |
||||
*/ |
||||
export enum PaymentChannel { |
||||
/** 微信支付 */ |
||||
WechatPay = 1, |
||||
/** 支付宝 */ |
||||
Alipay = 2, |
||||
/** 银联支付 */ |
||||
UnionPay = 3, |
||||
/** 余额支付 */ |
||||
Balance = 4, |
||||
/** 银行卡支付 */ |
||||
BankCard = 5, |
||||
} |
||||
|
||||
/** |
||||
* 开台请求参数 |
||||
*/ |
||||
export interface StartTableRequest { |
||||
/** 设备编码 */ |
||||
grpSn: string |
||||
/** 用户 OpenId */ |
||||
openId: string |
||||
/** 开台操作类型 */ |
||||
ctrlType: TableOperationType |
||||
/** 消费金额 */ |
||||
amount?: number |
||||
/** 支付渠道 */ |
||||
payType?: PaymentChannel |
||||
/** 开台时长(小时),定时开台使用 */ |
||||
durationHours?: number |
||||
/** 团购券码,团购券开台使用 */ |
||||
couponCode?: string |
||||
} |
||||
|
||||
/** |
||||
* 开台响应数据 |
||||
*/ |
||||
export interface StartTableResponse { |
||||
/** 机构编码 */ |
||||
instSn: string |
||||
/** 店铺编码 */ |
||||
bpSn: string |
||||
/** 球台编码 */ |
||||
grpSn: string |
||||
/** 开台设备id */ |
||||
operationId: number |
||||
/** 开始时间 */ |
||||
startTime: string |
||||
/** 结束时间 */ |
||||
expectedEndTime: string |
||||
/** 开台操作详情id */ |
||||
detailIds: number[] |
||||
/** 控制id */ |
||||
controlMessageId: number |
||||
/** 商户订单号 */ |
||||
outTradeNo: string |
||||
/** 支付参数(用于调起微信支付) */ |
||||
payParameters: WechatPayParameters | null |
||||
/** 支付URL(用于扫码支付) */ |
||||
payUrl: string |
||||
} |
||||
|
||||
/** |
||||
* 微信支付参数 |
||||
*/ |
||||
export interface WechatPayParameters { |
||||
/** 时间戳 */ |
||||
timeStamp: string |
||||
/** 随机字符串 */ |
||||
nonceStr: string |
||||
/** 统一下单接口返回的 prepay_id */ |
||||
package: string |
||||
/** 签名方式 */ |
||||
signType: string |
||||
/** 签名 */ |
||||
paySign: string |
||||
} |
||||
|
||||
/** |
||||
* 开台 API |
||||
* @param data 开台请求参数 |
||||
* @returns 开台响应 |
||||
*/ |
||||
export const startTable = (data: StartTableRequest) => { |
||||
return post<StartTableResponse>('/Tables/start', data, { |
||||
showLoading: true, |
||||
loadingText: '开台中...', |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* 调起微信支付 |
||||
* @param payParams 支付参数 |
||||
* @returns Promise |
||||
*/ |
||||
export const invokeWechatPay = (payParams: WechatPayParameters): Promise<void> => { |
||||
return new Promise((resolve, reject) => { |
||||
// 使用 wx.requestPayment 调起微信支付
|
||||
wx.requestPayment({ |
||||
timeStamp: payParams.timeStamp, |
||||
nonceStr: payParams.nonceStr, |
||||
package: payParams.package, |
||||
signType: payParams.signType as 'MD5' | 'HMAC-SHA256' | 'RSA', |
||||
paySign: payParams.paySign, |
||||
success: () => { |
||||
resolve() |
||||
}, |
||||
fail: (err) => { |
||||
reject(err) |
||||
}, |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
export default { |
||||
startTable, |
||||
invokeWechatPay, |
||||
TableOperationType, |
||||
PaymentChannel, |
||||
} |
||||
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
/** |
||||
* 订单记录 / 订单详情 字段归一化 |
||||
* 对应接口:/api/v2/order/records、/api/v2/order/detail/{id} |
||||
*/ |
||||
import { pickField, toNumber } from './apiNormalize' |
||||
import { OrderRecordItem, OrderRecordPagedResult, OrderDetailDto } from '../types/order' |
||||
|
||||
/** 归一化单条订单记录(列表项) */ |
||||
export const normalizeOrderRecordItem = (raw: Record<string, any>): OrderRecordItem => ({ |
||||
id: toNumber(pickField(raw, 'id')), |
||||
title: String(pickField(raw, 'title') ?? ''), |
||||
statusText: String(pickField(raw, 'statusText', 'statustext') ?? ''), |
||||
bpName: String(pickField(raw, 'bpName', 'bpname') ?? ''), |
||||
startTime: String(pickField(raw, 'startTime', 'starttime') ?? ''), |
||||
durationText: String(pickField(raw, 'durationText', 'durationtext') ?? ''), |
||||
actualAmount: toNumber(pickField(raw, 'actualAmount', 'actualamount')), |
||||
}) |
||||
|
||||
/** 归一化订单记录分页响应 */ |
||||
export const normalizeOrderRecordPagedResult = ( |
||||
raw: Record<string, any> | null | undefined |
||||
): OrderRecordPagedResult => { |
||||
const src = raw || {} |
||||
const list = pickField<Record<string, any>[]>(src, 'data') || [] |
||||
return { |
||||
data: Array.isArray(list) ? list.map(normalizeOrderRecordItem) : [], |
||||
totalCount: toNumber(pickField(src, 'totalCount', 'totalcount')), |
||||
pageIndex: toNumber(pickField(src, 'pageIndex', 'pageindex'), 1), |
||||
pageSize: toNumber(pickField(src, 'pageSize', 'pagesize'), 10), |
||||
totalPages: toNumber(pickField(src, 'totalPages', 'totalpages')), |
||||
hasPrevious: Boolean(pickField(src, 'hasPrevious', 'hasprevious') ?? false), |
||||
hasNext: Boolean(pickField(src, 'hasNext', 'hasnext') ?? false), |
||||
} |
||||
} |
||||
|
||||
/** 归一化订单详情 */ |
||||
export const normalizeOrderDetail = ( |
||||
raw: Record<string, any> | null | undefined |
||||
): OrderDetailDto => { |
||||
const src = raw || {} |
||||
const memberPrice = pickField<number | null>(src, 'memberPrice', 'memberprice') |
||||
const couponDeduction = pickField<number | null>(src, 'couponDeduction', 'coupondeduction') |
||||
const couponDescription = pickField<string | null>(src, 'couponDescription', 'coupondescription') |
||||
const actualAmount = pickField<number | null>(src, 'actualAmount', 'actualamount') |
||||
return { |
||||
id: toNumber(pickField(src, 'id')), |
||||
projectName: String(pickField(src, 'projectName', 'projectname') ?? ''), |
||||
statusText: String(pickField(src, 'statusText', 'statustext') ?? ''), |
||||
storePhone: String(pickField(src, 'storePhone', 'storephone') ?? ''), |
||||
durationText: String(pickField(src, 'durationText', 'durationtext') ?? ''), |
||||
actualAmount: actualAmount === null || actualAmount === undefined ? null : toNumber(actualAmount), |
||||
pricePerHour: toNumber(pickField(src, 'pricePerHour', 'priceperhour')), |
||||
discountPricePerHour: toNumber(pickField(src, 'discountPricePerHour', 'discountpriceperhour')), |
||||
onlineTotalPayment: toNumber(pickField(src, 'onlineTotalPayment', 'onlinetotalpayment')), |
||||
deposit: toNumber(pickField(src, 'deposit')), |
||||
originalAmount: toNumber(pickField(src, 'originalAmount', 'originalamount')), |
||||
memberPrice: memberPrice === null || memberPrice === undefined ? null : toNumber(memberPrice), |
||||
couponDeduction: |
||||
couponDeduction === null || couponDeduction === undefined ? null : toNumber(couponDeduction), |
||||
couponDescription: couponDescription === null || couponDescription === undefined ? null : String(couponDescription), |
||||
bpName: String(pickField(src, 'bpName', 'bpname') ?? ''), |
||||
bpAddress: String(pickField(src, 'bpAddress', 'bpaddress') ?? ''), |
||||
tableName: String(pickField(src, 'tableName', 'tablename') ?? ''), |
||||
startTime: String(pickField(src, 'startTime', 'starttime') ?? ''), |
||||
stopTime: String(pickField(src, 'stopTime', 'stoptime') ?? ''), |
||||
outTradeNo: String(pickField(src, 'outTradeNo', 'outtradeno') ?? ''), |
||||
chargingStandard: String(pickField(src, 'chargingStandard', 'chargingstandard') ?? ''), |
||||
payTypeName: String(pickField(src, 'payTypeName', 'paytypename') ?? ''), |
||||
} |
||||
} |
||||
Loading…
Reference in new issue