11 changed files with 1134 additions and 117 deletions
@ -0,0 +1,191 @@
@@ -0,0 +1,191 @@
|
||||
/** |
||||
* 开台操作相关 API |
||||
* 接口地址:/api/v2/TablesDev/start_device |
||||
*/ |
||||
import { post } from '../services/request' |
||||
import { |
||||
StartGroupDevRequestDto, |
||||
StartDeviceResponse, |
||||
WechatPayParameters, |
||||
CtrlType, |
||||
PayType, |
||||
} from '../types/startDevice' |
||||
|
||||
/** |
||||
* 开台操作接口 |
||||
* @param data 开台请求参数 |
||||
* @returns 开台响应 |
||||
*/ |
||||
export const startDevice = (data: StartGroupDevRequestDto) => { |
||||
return post<StartDeviceResponse>('/TablesDev/start_device', data, { |
||||
showLoading: true, |
||||
loadingText: '处理中...', |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* 调起微信支付 |
||||
* @param payParams 支付参数 |
||||
* @returns Promise |
||||
*/ |
||||
export const invokeWechatPay = (payParams: WechatPayParameters): Promise<void> => { |
||||
return new Promise((resolve, reject) => { |
||||
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) |
||||
}, |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* 押金开台 |
||||
* @param grpSn 设备编码 |
||||
* @param openId 用户OpenId |
||||
* @param amount 押金金额 |
||||
* @param payType 支付方式 |
||||
*/ |
||||
export const depositStart = ( |
||||
grpSn: string, |
||||
openId: string, |
||||
amount: number, |
||||
payType: PayType = PayType.WechatPay |
||||
) => { |
||||
return startDevice({ |
||||
grpSn, |
||||
openId, |
||||
ctrlType: CtrlType.DepositStart, |
||||
amount, |
||||
payType, |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* 余额开台 |
||||
* @param grpSn 设备编码 |
||||
* @param openId 用户OpenId |
||||
* @param amount 金额 |
||||
*/ |
||||
export const balanceStart = (grpSn: string, openId: string, amount: number) => { |
||||
return startDevice({ |
||||
grpSn, |
||||
openId, |
||||
ctrlType: CtrlType.BalanceStart, |
||||
amount, |
||||
payType: PayType.Balance, |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* 定时开台 |
||||
* @param grpSn 设备编码 |
||||
* @param openId 用户OpenId |
||||
* @param durationHours 开台时长(小时) |
||||
* @param amount 金额 |
||||
* @param payType 支付方式 |
||||
*/ |
||||
export const timedStart = ( |
||||
grpSn: string, |
||||
openId: string, |
||||
durationHours: number, |
||||
amount: number, |
||||
payType: PayType = PayType.WechatPay |
||||
) => { |
||||
return startDevice({ |
||||
grpSn, |
||||
openId, |
||||
ctrlType: CtrlType.TimedStart, |
||||
durationHours, |
||||
amount, |
||||
payType, |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* 团购券开台 |
||||
* @param grpSn 设备编码 |
||||
* @param openId 用户OpenId |
||||
* @param couponCode 团购券码 |
||||
*/ |
||||
export const couponStart = (grpSn: string, openId: string, couponCode: string) => { |
||||
return startDevice({ |
||||
grpSn, |
||||
openId, |
||||
ctrlType: CtrlType.CouponStart, |
||||
couponCode, |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* 立即关台 |
||||
* @param grpSn 设备编码 |
||||
* @param openId 用户OpenId |
||||
*/ |
||||
export const immediateClose = (grpSn: string, openId: string) => { |
||||
return startDevice({ |
||||
grpSn, |
||||
openId, |
||||
ctrlType: CtrlType.ImmediateClose, |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* 续费 |
||||
* @param grpSn 设备编码 |
||||
* @param openId 用户OpenId |
||||
* @param amount 续费金额 |
||||
* @param payType 支付方式 |
||||
*/ |
||||
export const renewFee = ( |
||||
grpSn: string, |
||||
openId: string, |
||||
amount: number, |
||||
payType: PayType = PayType.WechatPay |
||||
) => { |
||||
return startDevice({ |
||||
grpSn, |
||||
openId, |
||||
ctrlType: CtrlType.Renew, |
||||
amount, |
||||
payType, |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* 关灯重开 |
||||
* @param grpSn 设备编码 |
||||
* @param openId 用户OpenId |
||||
*/ |
||||
export const turnOffRestart = (grpSn: string, openId: string) => { |
||||
return startDevice({ |
||||
grpSn, |
||||
openId, |
||||
ctrlType: CtrlType.TurnOffRestart, |
||||
}) |
||||
} |
||||
|
||||
// 导出枚举类型
|
||||
export { CtrlType, PayType } |
||||
|
||||
// 导出所有方法和类型
|
||||
export default { |
||||
startDevice, |
||||
invokeWechatPay, |
||||
depositStart, |
||||
balanceStart, |
||||
timedStart, |
||||
couponStart, |
||||
immediateClose, |
||||
renewFee, |
||||
turnOffRestart, |
||||
CtrlType, |
||||
PayType, |
||||
} |
||||
@ -0,0 +1,125 @@
@@ -0,0 +1,125 @@
|
||||
/** |
||||
* 台球桌状态管理 - MobX |
||||
*/ |
||||
import { makeAutoObservable } from 'mobx' |
||||
import Taro from '@tarojs/taro' |
||||
import { TableInfo, OrderInfo } from '../types/startDevice' |
||||
|
||||
class TableStore { |
||||
/** 当前设备编码 */ |
||||
currentGrpSn: string = '123' |
||||
|
||||
/** 当前操作记录ID */ |
||||
currentOperationId: number = 0 |
||||
|
||||
/** 台球桌信息 */ |
||||
tableInfo: TableInfo | null = null |
||||
|
||||
/** 订单信息 */ |
||||
orderInfo: OrderInfo | null = null |
||||
|
||||
/** 加载状态 */ |
||||
isLoading: boolean = false |
||||
|
||||
constructor() { |
||||
makeAutoObservable(this) |
||||
this.initFromStorage() |
||||
} |
||||
|
||||
/** |
||||
* 从本地存储初始化数据 |
||||
*/ |
||||
initFromStorage = () => { |
||||
try { |
||||
const grpSn = Taro.getStorageSync('currentGrpSn') |
||||
const operationId = Taro.getStorageSync('currentOperationId') |
||||
const tableInfo = Taro.getStorageSync('tableInfo') |
||||
const orderInfo = Taro.getStorageSync('orderInfo') |
||||
|
||||
if (grpSn) this.currentGrpSn = grpSn |
||||
if (operationId) this.currentOperationId = operationId |
||||
if (tableInfo) this.tableInfo = tableInfo |
||||
if (orderInfo) this.orderInfo = orderInfo |
||||
} catch (error) { |
||||
console.error('读取台球桌信息失败:', error) |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 设置当前设备编码 |
||||
*/ |
||||
setCurrentGrpSn = (grpSn: string) => { |
||||
this.currentGrpSn = grpSn |
||||
Taro.setStorageSync('currentGrpSn', grpSn) |
||||
} |
||||
|
||||
/** |
||||
* 设置当前操作记录ID |
||||
*/ |
||||
setCurrentOperationId = (operationId: number) => { |
||||
this.currentOperationId = operationId |
||||
Taro.setStorageSync('currentOperationId', operationId) |
||||
} |
||||
|
||||
/** |
||||
* 设置台球桌信息 |
||||
*/ |
||||
setTableInfo = (info: TableInfo | null) => { |
||||
this.tableInfo = info |
||||
if (info) { |
||||
Taro.setStorageSync('tableInfo', info) |
||||
} else { |
||||
Taro.removeStorageSync('tableInfo') |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 设置订单信息 |
||||
*/ |
||||
setOrderInfo = (info: OrderInfo | null) => { |
||||
this.orderInfo = info |
||||
if (info) { |
||||
Taro.setStorageSync('orderInfo', info) |
||||
} else { |
||||
Taro.removeStorageSync('orderInfo') |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 设置加载状态 |
||||
*/ |
||||
setLoading = (loading: boolean) => { |
||||
this.isLoading = loading |
||||
} |
||||
|
||||
/** |
||||
* 清空所有台球桌相关数据 |
||||
*/ |
||||
clearAll = () => { |
||||
this.currentGrpSn = '' |
||||
this.currentOperationId = 0 |
||||
this.tableInfo = null |
||||
this.orderInfo = null |
||||
|
||||
Taro.removeStorageSync('currentGrpSn') |
||||
Taro.removeStorageSync('currentOperationId') |
||||
Taro.removeStorageSync('tableInfo') |
||||
Taro.removeStorageSync('orderInfo') |
||||
} |
||||
|
||||
/** |
||||
* 获取当前设备编码(优先从参数,其次从store) |
||||
*/ |
||||
getGrpSn = (paramGrpSn?: string): string => { |
||||
return paramGrpSn || this.currentGrpSn |
||||
} |
||||
|
||||
/** |
||||
* 获取当前操作记录ID(优先从参数,其次从store) |
||||
*/ |
||||
getOperationId = (paramOperationId?: number): number => { |
||||
return paramOperationId || this.currentOperationId |
||||
} |
||||
} |
||||
|
||||
export const tableStore = new TableStore() |
||||
@ -0,0 +1,150 @@
@@ -0,0 +1,150 @@
|
||||
/** |
||||
* 开台操作相关类型定义 |
||||
* 对应接口:/api/v2/TablesDev/start_device |
||||
*/ |
||||
|
||||
/** |
||||
* 操作类型枚举 |
||||
*/ |
||||
export enum CtrlType { |
||||
/** 押金开台 */ |
||||
DepositStart = 1, |
||||
/** 余额开台 */ |
||||
BalanceStart = 2, |
||||
/** 定时开台 */ |
||||
TimedStart = 3, |
||||
/** 信用开台 */ |
||||
CreditStart = 4, |
||||
/** 团购券开台 */ |
||||
CouponStart = 5, |
||||
/** 立即关台 */ |
||||
ImmediateClose = 6, |
||||
/** 续费 */ |
||||
Renew = 7, |
||||
/** 关灯重开 */ |
||||
TurnOffRestart = 8, |
||||
/** 替人付费关台 */ |
||||
PayForOthersClose = 9, |
||||
} |
||||
|
||||
/** |
||||
* 支付方式枚举 |
||||
*/ |
||||
export enum PayType { |
||||
/** 微信支付 */ |
||||
WechatPay = 1, |
||||
/** 支付宝 */ |
||||
Alipay = 2, |
||||
/** 银联支付 */ |
||||
UnionPay = 3, |
||||
/** 余额支付 */ |
||||
Balance = 4, |
||||
/** 银行卡支付 */ |
||||
BankCard = 5, |
||||
} |
||||
|
||||
/** |
||||
* 开台请求参数 |
||||
*/ |
||||
export interface StartGroupDevRequestDto { |
||||
/** 设备编码(必填) */ |
||||
grpSn: string |
||||
/** OpenId(必填) */ |
||||
openId: string |
||||
/** 操作类型:押金开台(1)、余额开台(2)、定时开台(3)、信用开台(4)、团购券开台(5)、立即关台(6)、续费(7)、关灯重开(8)、替人付费关台(9) */ |
||||
ctrlType?: CtrlType |
||||
/** 消费金额 */ |
||||
amount?: number |
||||
/** 支付方式:微信支付(1)、支付宝(2)、银联支付(3)、余额支付(4)、银行卡支付(5) */ |
||||
payType?: PayType |
||||
/** 开台时长(小时),定时开台使用 */ |
||||
durationHours?: number |
||||
/** 团购券码,团购券开台使用 */ |
||||
couponCode?: string |
||||
/** 备注 */ |
||||
remark?: string |
||||
/** 附加数据(JSON格式) */ |
||||
attach?: string |
||||
} |
||||
|
||||
/** |
||||
* 微信支付参数 |
||||
*/ |
||||
export interface WechatPayParameters { |
||||
/** 时间戳 */ |
||||
timeStamp: string |
||||
/** 随机字符串 */ |
||||
nonceStr: string |
||||
/** 统一下单接口返回的 prepay_id */ |
||||
package: string |
||||
/** 签名方式 */ |
||||
signType: string |
||||
/** 签名 */ |
||||
paySign: string |
||||
} |
||||
|
||||
/** |
||||
* 开台响应数据 |
||||
*/ |
||||
export interface StartDeviceResponse { |
||||
/** 消费记录ID */ |
||||
consumptionId: number |
||||
/** 商户订单号 */ |
||||
outTradeNo: string |
||||
/** 支付参数(用于调起微信支付) */ |
||||
payParameters: WechatPayParameters | null |
||||
/** H5支付URL */ |
||||
mwebUrl: string |
||||
/** 支付URL(用于扫码支付) */ |
||||
payUrl: string |
||||
/** 描述消息 */ |
||||
errorMessage: string |
||||
} |
||||
|
||||
/** |
||||
* 台球桌信息 |
||||
*/ |
||||
export interface TableInfo { |
||||
/** 设备编码 */ |
||||
grpSn: string |
||||
/** 台球桌名称 */ |
||||
tableName: string |
||||
/** 台球桌类型 */ |
||||
tableType: string |
||||
/** 门店名称 */ |
||||
storeName: string |
||||
/** 门店电话 */ |
||||
storePhone: string |
||||
/** 价格(元/小时) */ |
||||
price: number |
||||
/** VIP价格(元/小时) */ |
||||
vipPrice: number |
||||
/** 押金金额 */ |
||||
deposit: number |
||||
/** 价格时段 */ |
||||
pricePeriod: string |
||||
} |
||||
|
||||
/** |
||||
* 订单信息 |
||||
*/ |
||||
export interface OrderInfo { |
||||
/** 操作记录ID */ |
||||
operationId: number |
||||
/** 设备编码 */ |
||||
grpSn: string |
||||
/** 开始时间 */ |
||||
startTime: string |
||||
/** 已消费时长(分钟) */ |
||||
consumedMinutes: number |
||||
/** 已消费金额 */ |
||||
consumedAmount: number |
||||
/** 剩余时长(分钟) */ |
||||
remainingMinutes?: number |
||||
/** 订单编号 */ |
||||
orderNo: string |
||||
/** 开台方式 */ |
||||
startMethod: string |
||||
/** 收费标准 */ |
||||
pricingRule: string |
||||
} |
||||
Loading…
Reference in new issue