From 650e2cc720d66c52622bfc3240d6fbcd95bfb193 Mon Sep 17 00:00:00 2001 From: DU Date: Tue, 5 May 2026 12:38:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=94=A8=E6=88=B7=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=8F=B0=E7=90=83=E6=A1=8C=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/startDevice.ts | 13 +++++++++++++ src/pageScan/couponStart/index.tsx | 22 ++++++++++++++++----- src/pageScan/renewFee/index.tsx | 24 +++++++++++++++++++---- src/pageScan/selfStart/index.tsx | 29 ++++++++++++++++++++-------- src/pageScan/timedStart/index.tsx | 31 +++++++++++++++++++----------- src/types/startDevice.ts | 10 ++++++++++ 6 files changed, 101 insertions(+), 28 deletions(-) diff --git a/src/api/startDevice.ts b/src/api/startDevice.ts index 34b12fd..b46a803 100644 --- a/src/api/startDevice.ts +++ b/src/api/startDevice.ts @@ -7,6 +7,7 @@ import { StartGroupDevRequestDto, StartDeviceResponse, WechatPayParameters, + PriceRequestDto, CtrlType, PayType, } from '../types/startDevice' @@ -178,6 +179,17 @@ export const turnOffRestart = (grpSn: string, openId: string) => { }) } +/** + * 根据用户获取台球桌实际价格(VIP/普通用户价格不同) + * @param openId 用户 OpenId + * @param groupDevSn 设备序列号(即 grpSn) + * @returns 该用户对应的价格(元/小时) + */ +export const getTablePrice = (openId: string, groupDevSn: string) => { + const data: PriceRequestDto = { openId, groupDevSn } + return post('/TablesDev/get-price', data) +} + // 导出枚举类型 export { CtrlType, PayType } @@ -192,6 +204,7 @@ export default { immediateClose, renewFee, turnOffRestart, + getTablePrice, CtrlType, PayType, } diff --git a/src/pageScan/couponStart/index.tsx b/src/pageScan/couponStart/index.tsx index 34fb4d1..e3a86b0 100644 --- a/src/pageScan/couponStart/index.tsx +++ b/src/pageScan/couponStart/index.tsx @@ -5,7 +5,7 @@ import { View, Text, Image, Input } from '@tarojs/components' import Taro, { useLoad, useRouter } from '@tarojs/taro' import { useState } from 'react' import { observer } from 'mobx-react' -import { couponStart, invokeWechatPay } from '../../api/startDevice' +import { couponStart, invokeWechatPay, getTablePrice } from '../../api/startDevice' import { userStore, tableStore } from '../../store' import './index.scss' @@ -38,6 +38,7 @@ const CouponStart = observer(() => { const [selectedCouponType, setSelectedCouponType] = useState(CouponType.THIRD_PARTY) const [selectedCouponId, setSelectedCouponId] = useState(1) // 选中的券ID const [loading, setLoading] = useState(false) // 加载状态 + const [pricePerHour, setPricePerHour] = useState(0) // 每小时价格(从接口获取) // 从路由参数获取设备信息,如果没有则从 store 获取 const grpSn = tableStore.getGrpSn(router.params.grpSn) @@ -75,6 +76,20 @@ const CouponStart = observer(() => { if (grpSn) { tableStore.setCurrentGrpSn(grpSn) } + + // 获取该用户对应的台球桌价格 + const openId = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId') + if (openId && grpSn) { + getTablePrice(openId, grpSn) + .then((res) => { + if (res.data) { + setPricePerHour(res.data) + } + }) + .catch((err) => { + console.error('获取价格失败:', err) + }) + } }) // 拨打电话 @@ -253,16 +268,13 @@ const CouponStart = observer(() => { {/* 价格信息 */} - ¥28.80 + ¥{pricePerHour > 0 ? pricePerHour.toFixed(2) : '--'} /小时 押金 ¥100.00 - - VIP ¥20.00 - {/* 价格时段 */} diff --git a/src/pageScan/renewFee/index.tsx b/src/pageScan/renewFee/index.tsx index 995edbc..5cd058e 100644 --- a/src/pageScan/renewFee/index.tsx +++ b/src/pageScan/renewFee/index.tsx @@ -6,7 +6,7 @@ import Taro, { useLoad, useRouter } from '@tarojs/taro' import { useState } from 'react' import { observer } from 'mobx-react' import { Stepper } from '@taroify/core' -import { renewFee, invokeWechatPay, PayType } from '../../api/startDevice' +import { renewFee, invokeWechatPay, getTablePrice, PayType } from '../../api/startDevice' import { userStore, tableStore } from '../../store' import './index.scss' @@ -19,6 +19,7 @@ const RenewFee = observer(() => { const [renewAmount, setRenewAmount] = useState(100) // 续费金额(修改初始值为100) const [paymentMethod] = useState('微信支付') // 支付方式 const [loading, setLoading] = useState(false) // 加载状态 + const [pricePerHour, setPricePerHour] = useState(0) // 每小时价格(从接口获取) // 从路由参数获取设备信息和操作记录ID,如果没有则从 store 获取 const grpSn = tableStore.getGrpSn(router.params.grpSn) @@ -34,6 +35,20 @@ const RenewFee = observer(() => { if (operationId) { tableStore.setCurrentOperationId(operationId) } + + // 获取该用户对应的台球桌价格 + const openId = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId') + if (openId && grpSn) { + getTablePrice(openId, grpSn) + .then((res) => { + if (res.data) { + setPricePerHour(res.data) + } + }) + .catch((err) => { + console.error('获取价格失败:', err) + }) + } }) // 拨打电话 @@ -50,10 +65,11 @@ const RenewFee = observer(() => { setRenewAmount(value) } - // 计算续费时长(以小时为单位,假设 28.8元/小时) + // 根据实际价格计算续费时长 const calculateDuration = () => { - const hours = Math.floor(renewAmount / 28.8) - const minutes = Math.round((renewAmount / 28.8 - hours) * 60) + if (!pricePerHour) return '-' + const hours = Math.floor(renewAmount / pricePerHour) + const minutes = Math.round((renewAmount / pricePerHour - hours) * 60) return `约${hours}小时${minutes}分钟` } diff --git a/src/pageScan/selfStart/index.tsx b/src/pageScan/selfStart/index.tsx index 25319eb..cc29599 100644 --- a/src/pageScan/selfStart/index.tsx +++ b/src/pageScan/selfStart/index.tsx @@ -6,7 +6,7 @@ import Taro, { useLoad, useRouter } from '@tarojs/taro' import { useState } from 'react' import { observer } from 'mobx-react' import { Stepper } from '@taroify/core' -import { depositStart, balanceStart, invokeWechatPay, PayType } from '../../api/startDevice' +import { depositStart, balanceStart, invokeWechatPay, getTablePrice, PayType } from '../../api/startDevice' import { userStore, tableStore } from '../../store' import './index.scss' @@ -18,6 +18,7 @@ const SelfStart = observer(() => { const [deposit, setDeposit] = useState(100) // 押金金额 const [paymentMethod, setPaymentMethod] = useState<'微信支付' | '余额支付'>('微信支付') // 支付方式 const [loading, setLoading] = useState(false) // 加载状态 + const [pricePerHour, setPricePerHour] = useState(0) // 每小时价格(从接口获取) // 从路由参数获取设备信息,如果没有则从 store 获取 const grpSn = tableStore.getGrpSn(router.params.grpSn) @@ -32,6 +33,20 @@ const SelfStart = observer(() => { if (grpSn) { tableStore.setCurrentGrpSn(grpSn) } + + // 获取该用户对应的台球桌价格 + const openId = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId') + if (openId && grpSn) { + getTablePrice(openId, grpSn) + .then((res) => { + if (res.data) { + setPricePerHour(res.data) + } + }) + .catch((err) => { + console.error('获取价格失败:', err) + }) + } // 显示提示 Toast setTimeout(() => { @@ -57,10 +72,11 @@ const SelfStart = observer(() => { setDeposit(value) } - // 计算续费时长(以小时为单位,假设 28.8元/小时) + // 根据押金和实际价格计算预计时长 const calculateDuration = () => { - const hours = Math.floor(deposit / 28.8) - const minutes = Math.round((deposit / 28.8 - hours) * 60) + if (!pricePerHour) return '-' + const hours = Math.floor(deposit / pricePerHour) + const minutes = Math.round((deposit / pricePerHour - hours) * 60) return `约${hours}小时${minutes}分钟` } @@ -224,16 +240,13 @@ const SelfStart = observer(() => { {/* 价格信息 */} - ¥28.80 + ¥{pricePerHour > 0 ? pricePerHour.toFixed(2) : '--'} /小时 押金 ¥100.00 - - VIP ¥20.00 - {/* 价格时段 */} diff --git a/src/pageScan/timedStart/index.tsx b/src/pageScan/timedStart/index.tsx index 9f1d24a..ac12844 100644 --- a/src/pageScan/timedStart/index.tsx +++ b/src/pageScan/timedStart/index.tsx @@ -5,7 +5,7 @@ import { View, Text, Image } from '@tarojs/components' import Taro, { useLoad, useRouter } from '@tarojs/taro' import { useState } from 'react' import { observer } from 'mobx-react' -import { timedStart, invokeWechatPay, PayType } from '../../api/startDevice' +import { timedStart, invokeWechatPay, getTablePrice, PayType } from '../../api/startDevice' import { userStore, tableStore } from '../../store' import './index.scss' @@ -29,6 +29,7 @@ const TimedStart = observer(() => { const [selectedDuration, setSelectedDuration] = useState(1) // 选中的时长 const [paymentMethod] = useState('微信支付') // 支付方式 const [loading, setLoading] = useState(false) // 加载状态 + const [pricePerHour, setPricePerHour] = useState(0) // 每小时价格(从接口获取) // 从路由参数获取设备信息,如果没有则从 store 获取 const grpSn = tableStore.getGrpSn(router.params.grpSn) @@ -40,6 +41,20 @@ const TimedStart = observer(() => { if (grpSn) { tableStore.setCurrentGrpSn(grpSn) } + + // 获取该用户对应的台球桌价格 + const openId = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId') + if (openId && grpSn) { + getTablePrice(openId, grpSn) + .then((res) => { + if (res.data) { + setPricePerHour(res.data) + } + }) + .catch((err) => { + console.error('获取价格失败:', err) + }) + } }) // 拨打电话 @@ -65,9 +80,10 @@ const TimedStart = observer(() => { }) } - // 计算支付金额(28.8元/小时) + // 根据实际价格计算支付金额 const calculateAmount = () => { - return (selectedDuration * 28.8).toFixed(2) + if (!pricePerHour) return '0.00' + return (selectedDuration * pricePerHour).toFixed(2) } // 立即开台 @@ -191,16 +207,9 @@ const TimedStart = observer(() => { {/* 价格信息 */} - ¥28.80 + ¥{pricePerHour > 0 ? pricePerHour.toFixed(2) : '--'} /小时 - - 押金 - ¥100.00 - - - VIP ¥20.00 - {/* 价格时段 */} diff --git a/src/types/startDevice.ts b/src/types/startDevice.ts index aa22821..d5690a1 100644 --- a/src/types/startDevice.ts +++ b/src/types/startDevice.ts @@ -157,3 +157,13 @@ export interface OrderInfo { /** 收费标准 */ pricingRule: string } + +/** + * 获取台球桌价格请求参数 + */ +export interface PriceRequestDto { + /** 用户微信 OpenId */ + openId: string + /** 设备序列号 */ + groupDevSn: string +}