forked from gxwebsoft/mp-10550
refactor(礼品卡): 优化礼品卡相关功能和界面
- 修改 API 基础 URL以适应开发环境 - 移除未使用的 StoreCell 组件- 在 ShopGift 模型中添加核销时间字段 -调整 GiftCard 组件样式和布局 - 更新 goodsDetail 页面中的规格选择逻辑 - 优化 gift 组件中的有效期和类型显示 - 在 redeemGift 中添加礼品卡核销时间 - 重构 storeVerification 组件逻辑,优化核销流程
This commit is contained in:
@@ -165,7 +165,7 @@ const GiftCardDetail = () => {
|
||||
return (
|
||||
<ConfigProvider>
|
||||
{/* 礼品卡卡片 */}
|
||||
<View className="m-4 p-6 rounded-2xl text-white" style={{backgroundColor: '#fbbf24'}}>
|
||||
<View className="m-4 p-6 rounded-2xl text-white" style={{background: 'linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%)'}}>
|
||||
<View className="flex items-center justify-between mb-4">
|
||||
<View className="w-full">
|
||||
<Text className="text-4xl font-bold">{getGiftValueDisplay()}</Text>
|
||||
@@ -212,8 +212,8 @@ const GiftCardDetail = () => {
|
||||
<View className="flex items-center mb-3">
|
||||
<Clock size="16" className="text-gray-400 mr-3" />
|
||||
<View>
|
||||
<Text className="text-gray-600 text-sm">有效期</Text>
|
||||
<Text className="text-gray-900 px-1">{getValidityText()}</Text>
|
||||
<Text className="text-gray-400 text-sm">有效期</Text>
|
||||
<Text className="text-blue-500 text-sm px-1">{getValidityText()}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -222,8 +222,8 @@ const GiftCardDetail = () => {
|
||||
<View className="flex items-center mb-3">
|
||||
<Gift size="16" className="text-gray-400 mr-3" />
|
||||
<View>
|
||||
<Text className="text-gray-600 text-sm">礼品卡类型</Text>
|
||||
<Text className="text-gray-900 px-1">{getGiftTypeText(gift.type)}</Text>
|
||||
<Text className="text-gray-400 text-sm">类型</Text>
|
||||
<Text className="text-blue-500 text-sm px-1">{getGiftTypeText(gift.type)}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -233,8 +233,8 @@ const GiftCardDetail = () => {
|
||||
<View className="flex items-center">
|
||||
<Location size="16" className="text-gray-400 mr-3" />
|
||||
<View>
|
||||
<Text className="text-gray-600 text-sm">使用地址</Text>
|
||||
<Text className="text-gray-900 px-1">{gift.useLocation}</Text>
|
||||
<Text className="text-gray-400 text-sm">使用地址</Text>
|
||||
<Text className="text-blue-500 text-sm px-1">{gift.useLocation}</Text>
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
|
||||
@@ -4,6 +4,7 @@ import {Button, ConfigProvider, Input, Divider} from '@nutui/nutui-react-taro'
|
||||
import {ArrowLeft, QrCode, Gift, Voucher} from '@nutui/icons-react-taro'
|
||||
import Taro from '@tarojs/taro'
|
||||
import {View, Text} from '@tarojs/components'
|
||||
import dayjs from 'dayjs'
|
||||
import {ShopGift} from "@/api/shop/shopGift/model";
|
||||
import {pageShopGift, updateShopGift} from "@/api/shop/shopGift";
|
||||
import GiftCard from "@/components/GiftCard";
|
||||
@@ -74,7 +75,8 @@ const GiftCardRedeem = () => {
|
||||
try {
|
||||
await updateShopGift({
|
||||
...validGift,
|
||||
userId: Taro.getStorageSync('UserId')
|
||||
userId: Taro.getStorageSync('UserId'),
|
||||
takeTime: dayjs.unix(Date.now() / 1000).format('YYYY-MM-DD HH:mm:ss')
|
||||
})
|
||||
|
||||
setRedeemSuccess(true)
|
||||
@@ -236,7 +238,7 @@ const GiftCardRedeem = () => {
|
||||
</View>
|
||||
|
||||
<Text className="text-2xl font-bold text-gray-900 mb-2">兑换成功!</Text>
|
||||
<Text className="text-gray-600 mb-6">礼品卡已添加到您的账户中</Text>
|
||||
<Text className="text-left text-gray-500 mb-6">礼品卡已添加到您的账户中</Text>
|
||||
|
||||
{validGift && (
|
||||
<View className="mb-6">
|
||||
|
||||
@@ -5,16 +5,7 @@ import { Scan, Search } from '@nutui/icons-react-taro'
|
||||
import Taro from '@tarojs/taro'
|
||||
import dayjs from 'dayjs'
|
||||
import {getShopGiftByCode, updateShopGift} from "@/api/shop/shopGift";
|
||||
|
||||
// interface VerificationData {
|
||||
// type: string
|
||||
// giftId: number
|
||||
// giftCode: string
|
||||
// verificationCode: string
|
||||
// faceValue: string
|
||||
// timestamp: number
|
||||
// expireTime?: string
|
||||
// }
|
||||
import {useUser} from "@/hooks/useUser";
|
||||
|
||||
interface GiftCardInfo {
|
||||
id: number
|
||||
@@ -28,6 +19,9 @@ interface GiftCardInfo {
|
||||
}
|
||||
|
||||
const StoreVerification: React.FC = () => {
|
||||
const {
|
||||
isAdmin
|
||||
} = useUser();
|
||||
const [scanResult, setScanResult] = useState<string>('')
|
||||
const [verificationCode, setVerificationCode] = useState<string>('')
|
||||
const [giftInfo, setGiftInfo] = useState<GiftCardInfo | null>(null)
|
||||
@@ -38,10 +32,9 @@ const StoreVerification: React.FC = () => {
|
||||
const handleScan = () => {
|
||||
Taro.scanCode({
|
||||
success: (res) => {
|
||||
console.log('扫码结果:', res.result)
|
||||
setScanResult(res.result)
|
||||
verificationQRCode(res.result)
|
||||
// parseQRCode(res.result)
|
||||
setVerificationCode(res.result)
|
||||
handleManualVerification().then()
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('扫码失败:', err)
|
||||
@@ -52,79 +45,49 @@ const StoreVerification: React.FC = () => {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 解析二维码数据
|
||||
// const parseQRCode = (qrData: string) => {
|
||||
// try {
|
||||
// const data: VerificationData = JSON.parse(qrData)
|
||||
//
|
||||
// if (data.type === 'gift_card_verification') {
|
||||
// setVerificationCode(data.verificationCode)
|
||||
// console.log(data.verificationCode,'...vaerrr')
|
||||
// } else {
|
||||
// throw new Error('无效的二维码格式')
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error('解析二维码失败:', error)
|
||||
// Taro.showToast({
|
||||
// title: '无效的二维码',
|
||||
// icon: 'error'
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
// 扫码核销操作
|
||||
const verificationQRCode = async (code:string) => {
|
||||
const gift = await getShopGiftByCode(code)
|
||||
|
||||
if(gift.status == 1){
|
||||
return Taro.showToast({
|
||||
title: '此礼品码已使用',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
if(gift.status == 2){
|
||||
return Taro.showToast({
|
||||
title: '此礼品码已失效',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
if(gift.userId == 0){
|
||||
return Taro.showToast({
|
||||
title: '此礼品码未认领',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
updateShopGift({
|
||||
...gift,
|
||||
status: 1,
|
||||
takeTime: dayjs.unix(Date.now() / 1000).format('YYYY-MM-DD HH:mm:ss')
|
||||
}).then(() => {
|
||||
Taro.showToast({
|
||||
title: '核销成功',
|
||||
icon: 'success'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 手动输入核销码验证
|
||||
const handleManualVerification = async () => {
|
||||
if (!verificationCode.trim()) {
|
||||
Taro.showToast({
|
||||
title: '请输入核销码',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
setLoading(true)
|
||||
try {
|
||||
// 这里应该调用后端API验证核销码
|
||||
const giftCard = await getShopGiftByCode(verificationCode.trim())
|
||||
const gift = await getShopGiftByCode(verificationCode.trim())
|
||||
if(!isAdmin()){
|
||||
return Taro.showToast({
|
||||
title: '您没有核销权限',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
if(gift.status == 1){
|
||||
return Taro.showToast({
|
||||
title: '此礼品码已使用',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
if(gift.status == 2){
|
||||
return Taro.showToast({
|
||||
title: '此礼品码已失效',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
if(gift.userId == 0){
|
||||
return Taro.showToast({
|
||||
title: '此礼品码未认领',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
if (!verificationCode.trim()) {
|
||||
Taro.showToast({
|
||||
title: '请输入核销码',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
await updateShopGift({
|
||||
...giftCard,
|
||||
...gift,
|
||||
status: 1,
|
||||
takeTime: dayjs.unix(Date.now() / 1000).format('YYYY-MM-DD HH:mm:ss')
|
||||
operatorUserId: Taro.getStorageSync('UserId'),
|
||||
takeTime: dayjs.unix(Date.now() / 1000).format('YYYY-MM-DD HH:mm:ss'),
|
||||
verificationTime: dayjs.unix(Date.now() / 1000).format('YYYY-MM-DD HH:mm:ss')
|
||||
})
|
||||
Taro.showToast({
|
||||
title: '核销成功',
|
||||
|
||||
Reference in New Issue
Block a user