refactor(礼品卡): 优化礼品卡相关功能和界面

- 修改 API 基础 URL以适应开发环境
- 移除未使用的 StoreCell 组件- 在 ShopGift 模型中添加核销时间字段
-调整 GiftCard 组件样式和布局
- 更新 goodsDetail 页面中的规格选择逻辑
- 优化 gift 组件中的有效期和类型显示
- 在 redeemGift 中添加礼品卡核销时间
- 重构 storeVerification 组件逻辑,优化核销流程
This commit is contained in:
2025-08-17 20:16:29 +08:00
parent 591df84568
commit f73bfeb743
9 changed files with 71 additions and 246 deletions

View File

@@ -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: '核销成功',