Browse Source

修改开台逻辑,以及接口

master
DU 1 month ago
parent
commit
9df77e6ed2
  1. 34
      src/api/startDevice.ts
  2. 11
      src/pageScan/closeTable/components/FooterButtons.tsx
  3. 2
      src/pageScan/closeTable/index.tsx
  4. 19
      src/pageScan/renewFee/index.tsx
  5. 19
      src/pageScan/selfStart/index.tsx
  6. 11
      src/pageScan/turnOffRestart/index.tsx
  7. 47
      src/types/startDevice.ts

34
src/api/startDevice.ts

@ -1,6 +1,7 @@
/** /**
* API * API
* /api/v2/TablesDev/start_device * /api/v2/TablesDev/start_device
* ///api/v2/TablesDev/stop
*/ */
import { get, post } from '../services/request' import { get, post } from '../services/request'
import { import {
@ -11,6 +12,8 @@ import {
TableScanResponseDto, TableScanResponseDto,
CtrlType, CtrlType,
PayType, PayType,
StopGroupDevRequestDto,
StopGroupDevResponseDto,
} from '../types/startDevice' } from '../types/startDevice'
/** 小程序 JSAPI 支付固定交易类型 */ /** 小程序 JSAPI 支付固定交易类型 */
@ -132,13 +135,27 @@ export const couponStart = (grpSn: string, openId: string, couponCode: string) =
}) })
} }
/**
* /api/v2/TablesDev/stop
*
*/
export const stopDevice = (data: StopGroupDevRequestDto) => {
return post<StopGroupDevResponseDto>('/TablesDev/stop', {
tradeType: MINI_PROGRAM_TRADE_TYPE,
...data,
}, {
showLoading: true,
loadingText: '处理中...',
})
}
/** /**
* *
* @param grpSn * @param grpSn
* @param openId OpenId * @param openId OpenId
*/ */
export const immediateClose = (grpSn: string, openId: string) => { export const immediateClose = (grpSn: string, openId: string) => {
return startDevice({ return stopDevice({
grpSn, grpSn,
openId, openId,
ctrlType: CtrlType.ImmediateClose, ctrlType: CtrlType.ImmediateClose,
@ -149,21 +166,21 @@ export const immediateClose = (grpSn: string, openId: string) => {
* *
* @param grpSn * @param grpSn
* @param openId OpenId * @param openId OpenId
* @param amount * @param renewalAmount
* @param payType * @param payType
*/ */
export const renewFee = ( export const renewFee = (
grpSn: string, grpSn: string,
openId: string, openId: string,
amount: number, renewalAmount: number,
payType: PayType = PayType.WechatPay payType: PayType = PayType.WechatPay
) => { ) => {
return startDevice({ return stopDevice({
grpSn, grpSn,
openId, openId,
ctrlType: CtrlType.Renew, ctrlType: CtrlType.Renew,
amount,
payType, payType,
renewalAmount,
}) })
} }
@ -173,7 +190,7 @@ export const renewFee = (
* @param openId OpenId * @param openId OpenId
*/ */
export const turnOffRestart = (grpSn: string, openId: string) => { export const turnOffRestart = (grpSn: string, openId: string) => {
return startDevice({ return stopDevice({
grpSn, grpSn,
openId, openId,
ctrlType: CtrlType.TurnOffRestart, ctrlType: CtrlType.TurnOffRestart,
@ -207,6 +224,7 @@ export { CtrlType, PayType }
// 导出所有方法和类型 // 导出所有方法和类型
export default { export default {
startDevice, startDevice,
stopDevice,
invokeWechatPay, invokeWechatPay,
depositStart, depositStart,
balanceStart, balanceStart,

11
src/pageScan/closeTable/components/FooterButtons.tsx

@ -64,18 +64,17 @@ const FooterButtons = ({ type, grpSn, operationId }: FooterButtonsProps) => {
console.log('关台接口返回:', result) console.log('关台接口返回:', result)
const consumptionId = result.data.consumptionId const { operationId: responseOperationId, outTradeNo, needPay, payParameters } = result.data
const outTradeNo = result.data.paymentResponseDto?.outTradeNo
// 判断是否需要支付(可能需要补差价) // 判断是否需要支付(可能需要补差价)
if (result.data.paymentResponseDto?.payParameters) { if (needPay && payParameters) {
// 调起微信支付 // 调起微信支付
try { try {
await invokeWechatPay(result.data.paymentResponseDto.payParameters) await invokeWechatPay(payParameters)
// 轮询服务端确认支付结果 // 轮询服务端确认支付结果(responseOperationId 对应后端 operationId,需确认与 consumptionId 语义一致)
Taro.showLoading({ title: '确认支付中...', mask: true }) Taro.showLoading({ title: '确认支付中...', mask: true })
const paid = await pollTablePaymentStatus(consumptionId) const paid = await pollTablePaymentStatus(responseOperationId)
Taro.hideLoading() Taro.hideLoading()
if (paid) { if (paid) {

2
src/pageScan/closeTable/index.tsx

@ -142,7 +142,7 @@ const CloseTable = observer(() => {
<View className="info-row"> <View className="info-row">
<Text className="info-label"></Text> <Text className="info-label"></Text>
<Text className="info-value">{opInfo ? `${opInfo.deposit.toFixed(2)}元(${opInfo.depositStatus}` : '--'}</Text> <Text className="info-value">{opInfo ? `${opInfo.deposit.toFixed(2)}${opInfo.depositStatus ? `${opInfo.depositStatus}` : ''}` : '--'}</Text>
</View> </View>
<View className="info-row"> <View className="info-row">

19
src/pageScan/renewFee/index.tsx

@ -20,9 +20,11 @@ const RenewFee = observer(() => {
const scanInfo = tableStore.scanInfo const scanInfo = tableStore.scanInfo
const opInfo = scanInfo?.opInfo const opInfo = scanInfo?.opInfo
const priceInfo = scanInfo?.price const priceInfo = scanInfo?.price
const pricePerHour = priceInfo?.currentPrice || 0 const pricePerHour = priceInfo?.standard || 0
const [renewAmount, setRenewAmount] = useState(priceInfo?.deposit || 100) // 续费金额,默认押金额 // 续费最小金额:优先用 opInfo.deposit(close 状态下 price.deposit 可能为0)
const minDeposit = opInfo?.deposit || priceInfo?.deposit || 100
const [renewAmount, setRenewAmount] = useState(minDeposit)
const [paymentMethod] = useState('微信支付') // 支付方式 const [paymentMethod] = useState('微信支付') // 支付方式
const [loading, setLoading] = useState(false) // 加载状态 const [loading, setLoading] = useState(false) // 加载状态
@ -101,18 +103,17 @@ const RenewFee = observer(() => {
console.log('续费接口返回:', result) console.log('续费接口返回:', result)
const consumptionId = result.data.consumptionId const { operationId: responseOperationId, outTradeNo, needPay, payParameters } = result.data
const outTradeNo = result.data.paymentResponseDto?.outTradeNo
// 判断是否需要支付 // 判断是否需要支付
if (result.data.paymentResponseDto?.payParameters) { if (needPay && payParameters) {
// 调起微信支付 // 调起微信支付
try { try {
await invokeWechatPay(result.data.paymentResponseDto.payParameters) await invokeWechatPay(payParameters)
// 轮询服务端确认支付结果 // 轮询服务端确认支付结果(responseOperationId 对应后端 operationId,需确认与 consumptionId 语义一致)
Taro.showLoading({ title: '确认支付中...', mask: true }) Taro.showLoading({ title: '确认支付中...', mask: true })
const paid = await pollTablePaymentStatus(consumptionId) const paid = await pollTablePaymentStatus(responseOperationId)
Taro.hideLoading() Taro.hideLoading()
if (paid) { if (paid) {
@ -228,7 +229,7 @@ const RenewFee = observer(() => {
<Text className="renew-label">()</Text> <Text className="renew-label">()</Text>
<Stepper <Stepper
value={renewAmount} value={renewAmount}
min={priceInfo?.deposit || 100} min={minDeposit}
step={10} step={10}
onChange={handleRenewAmountChange} onChange={handleRenewAmountChange}
shape="circular" shape="circular"

19
src/pageScan/selfStart/index.tsx

@ -6,7 +6,7 @@ import Taro, { useLoad, useRouter } from '@tarojs/taro'
import { useState } from 'react' import { useState } from 'react'
import { observer } from 'mobx-react' import { observer } from 'mobx-react'
import { Stepper } from '@taroify/core' import { Stepper } from '@taroify/core'
import { depositStart, balanceStart, invokeWechatPay, PayType } from '../../api/startDevice' import { depositStart, balanceStart, invokeWechatPay, PayType, getTableInfo } from '../../api/startDevice'
import { closeOrder, pollTablePaymentStatus } from '../../api/order' import { closeOrder, pollTablePaymentStatus } from '../../api/order'
import { userStore, tableStore } from '../../store' import { userStore, tableStore } from '../../store'
import './index.scss' import './index.scss'
@ -54,7 +54,7 @@ const SelfStart = observer(() => {
setDeposit(value) setDeposit(value)
} }
const pricePerHour = priceInfo?.currentPrice || 0 const pricePerHour = priceInfo?.currentPrice || priceInfo?.standard || 0
// 根据押金和实际价格计算预计时长 // 根据押金和实际价格计算预计时长
const calculateDuration = () => { const calculateDuration = () => {
@ -158,6 +158,14 @@ const SelfStart = observer(() => {
Taro.hideLoading() Taro.hideLoading()
if (paid) { if (paid) {
// 支付成功后重新拉取台桌信息,更新 scanInfo(opInfo 会有完整数据)
try {
const openId2 = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId')
const freshInfo = await getTableInfo(grpSn, openId2)
tableStore.setScanInfo(freshInfo.data)
} catch (_) {
// 刷新失败不阻断流程,关台页会显示 '--' 但功能正常
}
Taro.showToast({ title: '开台成功', icon: 'success', duration: 2000 }) Taro.showToast({ title: '开台成功', icon: 'success', duration: 2000 })
setTimeout(() => { setTimeout(() => {
Taro.redirectTo({ Taro.redirectTo({
@ -184,6 +192,13 @@ const SelfStart = observer(() => {
} }
} else { } else {
// 无需支付(余额支付等场景) // 无需支付(余额支付等场景)
try {
const openId2 = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId')
const freshInfo = await getTableInfo(grpSn, openId2)
tableStore.setScanInfo(freshInfo.data)
} catch (_) {
// 刷新失败不阻断流程
}
Taro.showToast({ title: '开台成功', icon: 'success', duration: 2000 }) Taro.showToast({ title: '开台成功', icon: 'success', duration: 2000 })
setTimeout(() => { setTimeout(() => {
Taro.redirectTo({ Taro.redirectTo({

11
src/pageScan/turnOffRestart/index.tsx

@ -87,18 +87,17 @@ const TurnOffRestart = observer(() => {
console.log('关灯重开接口返回:', result) console.log('关灯重开接口返回:', result)
const consumptionId = result.data.consumptionId const { operationId: responseOperationId, outTradeNo, needPay, payParameters } = result.data
const outTradeNo = result.data.paymentResponseDto?.outTradeNo
// 判断是否需要支付 // 判断是否需要支付
if (result.data.paymentResponseDto?.payParameters) { if (needPay && payParameters) {
// 调起微信支付 // 调起微信支付
try { try {
await invokeWechatPay(result.data.paymentResponseDto.payParameters) await invokeWechatPay(payParameters)
// 轮询服务端确认支付结果 // 轮询服务端确认支付结果(responseOperationId 对应后端 operationId,需确认与 consumptionId 语义一致)
Taro.showLoading({ title: '确认支付中...', mask: true }) Taro.showLoading({ title: '确认支付中...', mask: true })
const paid = await pollTablePaymentStatus(consumptionId) const paid = await pollTablePaymentStatus(responseOperationId)
Taro.hideLoading() Taro.hideLoading()
if (paid) { if (paid) {

47
src/types/startDevice.ts

@ -286,3 +286,50 @@ export interface TableScanResponseDto {
/** 已开台时有值,可开台时为 null */ /** 已开台时有值,可开台时为 null */
opInfo: OpInfoDto | null opInfo: OpInfoDto | null
} }
// ─── 关台接口(/api/v2/TablesDev/stop)相关类型 ───────────────────────────────
/**
* /api/v2/TablesDev/stop
* ctrlType 使 CtrlType 5-6-7-8-
*/
export interface StopGroupDevRequestDto {
/** 设备序列号(必填) */
grpSn: string
/** 用户 OpenId(必填) */
openId: string
/** 操作类型:5-立即关台、6-续费、7-关灯重开、8-替人付费关台 */
ctrlType?: CtrlType
/** 支付方式:1-微信支付、2-支付宝、3-银联支付、4-余额支付、5-银行卡支付(可选) */
payType?: PayType
/** 交易类型:1-JSAPI小程序、2-Native扫码、3-APP、4-付款码、5-H5(可选) */
tradeType?: number
/** 续费金额(单位:元),仅 ctrlType=6(续费) 时需要 */
renewalAmount?: number
}
/**
* /api/v2/TablesDev/stop data
*/
export interface StopGroupDevResponseDto {
/** 设备序列号 */
grpSn: string
/** 操作 ID(用于支付轮询) */
operationId: number
/** 关台时间 */
stopTime: string
/** 最终消费金额 */
finalAmount: number
/** 退款金额 */
refundAmount: number
/** 操作类型(对应 CtrlType:5-立即关台、6-续费、7-关灯重开) */
stopType: CtrlType
/** 续费时返回新的结束时间 */
newStopTime: string
/** 微信支付参数(needPay=true 时有值,否则为 null) */
payParameters: WechatPayParameters | null
/** 是否需要前端调起支付 */
needPay: boolean
/** 商户订单号,前端轮询用 */
outTradeNo: string
}

Loading…
Cancel
Save