From 1f6ecebc6a061d0bc441e926fcae3cc1797c4569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Mon, 18 Aug 2025 02:10:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(user):=20=E4=BC=98=E5=8C=96=E7=A4=BC?= =?UTF-8?q?=E5=93=81=E5=8D=A1=E6=A0=B8=E9=94=80=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 API基础 URL 为正式环境地址 - 移除礼品卡信息中的 useTime 字段 -优化礼品卡核销页面布局和功能 - 完善礼品卡信息展示,包括商品图片、描述等 - 优化手动输入核销码流程,支持直接验证- 调整礼品卡状态展示方式,增加过期状态- 优化代码结构,提高可读性和可维护性 --- config/env.ts | 2 +- src/api/shop/shopGift/model/index.ts | 2 - src/user/store/verification.tsx | 265 +++++++++++++++++---------- 3 files changed, 173 insertions(+), 96 deletions(-) diff --git a/config/env.ts b/config/env.ts index 44ddb26..c92883b 100644 --- a/config/env.ts +++ b/config/env.ts @@ -2,7 +2,7 @@ export const ENV_CONFIG = { // 开发环境 development: { - API_BASE_URL: 'http://127.0.0.1:9200/api', + API_BASE_URL: 'https://cms-api.websoft.top/api', APP_NAME: '开发环境', DEBUG: 'true', }, diff --git a/src/api/shop/shopGift/model/index.ts b/src/api/shop/shopGift/model/index.ts index 611b4c4..3b2d4e1 100644 --- a/src/api/shop/shopGift/model/index.ts +++ b/src/api/shop/shopGift/model/index.ts @@ -24,8 +24,6 @@ export interface ShopGift { type?: number; // 领取时间 takeTime?: string; - // 使用时间 - useTime?: string; // 过期时间 expireTime?: string; // 有效期天数 diff --git a/src/user/store/verification.tsx b/src/user/store/verification.tsx index 1ac913e..ab5e39f 100644 --- a/src/user/store/verification.tsx +++ b/src/user/store/verification.tsx @@ -1,22 +1,12 @@ import React, { useState } from 'react' -import { View, Text } from '@tarojs/components' -import { Button, Input, Tag, Divider } from '@nutui/nutui-react-taro' -import { Scan, Search } from '@nutui/icons-react-taro' +import {View, Text, Image} from '@tarojs/components' +import {Button, Input, Tag, Divider} from '@nutui/nutui-react-taro' +import {Scan, Search} from '@nutui/icons-react-taro' import Taro from '@tarojs/taro' import dayjs from 'dayjs' import {getShopGiftByCode, updateShopGift} from "@/api/shop/shopGift"; import {useUser} from "@/hooks/useUser"; - -interface GiftCardInfo { - id: number - name: string - goodsName?: string - faceValue: string - type: number - status: number - expireTime?: string - code: string -} +import type { ShopGift } from "@/api/shop/shopGift/model"; const StoreVerification: React.FC = () => { const { @@ -24,7 +14,7 @@ const StoreVerification: React.FC = () => { } = useUser(); const [scanResult, setScanResult] = useState('') const [verificationCode, setVerificationCode] = useState('') - const [giftInfo, setGiftInfo] = useState(null) + const [giftInfo, setGiftInfo] = useState(null) const [verificationResult, setVerificationResult] = useState<'success' | 'failed' | null>(null) const [loading, setLoading] = useState(false) @@ -32,9 +22,11 @@ const StoreVerification: React.FC = () => { const handleScan = () => { Taro.scanCode({ success: (res) => { - setScanResult(res.result) - setVerificationCode(res.result) - handleManualVerification().then() + if (res.result) { + setScanResult(res.result) + setVerificationCode(res.result) + handleManualVerification(res.result) + } }, fail: (err) => { console.error('扫码失败:', err) @@ -45,83 +37,78 @@ const StoreVerification: React.FC = () => { } }) } + + + // 手动输入核销码验证 - const handleManualVerification = async () => { + const handleManualVerification = async (code?: string) => { + const codeToVerify = code || verificationCode.trim() + if (!codeToVerify) { + return false; + } setLoading(true) try { // 这里应该调用后端API验证核销码 - const gift = await getShopGiftByCode(verificationCode.trim()) - if(!isAdmin()){ + const gift = await getShopGiftByCode(codeToVerify) + + // 设置礼品信息用于显示 + setGiftInfo(gift) + + if (!isAdmin()) { + setVerificationResult('failed') + setLoading(false) return Taro.showToast({ title: '您没有核销权限', icon: 'error' }) } - if(gift.status == 1){ + if (gift.status === 1) { + setVerificationResult('failed') + setLoading(false) return Taro.showToast({ title: '此礼品码已使用', icon: 'error' }) } - if(gift.status == 2){ + if (gift.status === 2) { + setVerificationResult('failed') + setLoading(false) return Taro.showToast({ title: '此礼品码已失效', icon: 'error' }) } - if(gift.userId == 0){ + if (gift.userId === 0) { + setVerificationResult('failed') + setLoading(false) return Taro.showToast({ title: '此礼品码未认领', icon: 'error' }) } - if (!verificationCode.trim()) { - Taro.showToast({ - title: '请输入核销码', - icon: 'none' - }) - return - } + + // 验证成功,设置状态 + setVerificationResult('success') await updateShopGift({ ...gift, status: 1, - 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: '核销成功', - icon: 'success' + operatorUserId: Number(Taro.getStorageSync('UserId')) || 0, + takeTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), + verificationTime: dayjs().format('YYYY-MM-DD HH:mm:ss') }) - } catch (error) { - console.error('验证失败:', error) - } finally { - setLoading(false) - } - } - - // 确认核销 - const handleConfirmVerification = async () => { - if (!giftInfo) return - - setLoading(true) - try { - // 这里应该调用后端API完成核销 - await mockCompleteVerification(giftInfo.id) - Taro.showToast({ title: '核销成功', icon: 'success' }) - // 重置状态 setTimeout(() => { resetForm() }, 2000) } catch (error) { - console.error('核销失败:', error) + console.error('验证失败:', error) + setVerificationResult('failed') Taro.showToast({ - title: '核销失败', + title: '验证失败', icon: 'error' }) } finally { @@ -129,12 +116,6 @@ const StoreVerification: React.FC = () => { } } - // 模拟完成核销 - const mockCompleteVerification = async (giftId: number) => { - await new Promise(resolve => setTimeout(resolve, 1000)) - console.log('核销礼品卡:', giftId) - } - // 重置表单 const resetForm = () => { setScanResult('') @@ -146,13 +127,21 @@ const StoreVerification: React.FC = () => { // 获取类型文本 const getTypeText = (type: number) => { switch (type) { - case 10: return '实物礼品卡' - case 20: return '虚拟礼品卡' - case 30: return '服务礼品卡' - default: return '礼品卡' + case 10: + return '实物礼品卡' + case 20: + return '虚拟礼品卡' + case 30: + return '服务礼品卡' + default: + return '礼品卡' } } + // useEffect(() => { + // handleManualVerification().then() + // },[verificationCode]) + return ( {/* 页面标题 */} @@ -173,14 +162,15 @@ const StoreVerification: React.FC = () => { - {scanResult && ( + {/* 扫码结果显示 */} + {scanResult && !giftInfo && ( 扫码结果: @@ -188,29 +178,118 @@ const StoreVerification: React.FC = () => { )} + + {/* 商品信息展示 */} + {giftInfo && ( + + + 商品信息 + + {giftInfo.status === 0 ? '未使用' : + giftInfo.status === 1 ? '已使用' : '已过期'} + + + + + {/* 商品图片 */} + {giftInfo.goodsImage && ( + + + + )} + + {/* 商品详情 */} + + + {giftInfo.goodsName || giftInfo.name} + + + {giftInfo.description && ( + + {giftInfo.description} + + )} + + + + ¥{giftInfo.faceValue} + + + {giftInfo.type === 10 ? '实物礼品' : + giftInfo.type === 20 ? '虚拟礼品' : '服务礼品'} + + + + + + {/* 附加信息 */} + + {giftInfo.useLocation && ( + + 使用门店: + {giftInfo.useLocation} + + )} + + {giftInfo.expireTime && ( + + 有效期至: + + {dayjs(giftInfo.expireTime).format('YYYY-MM-DD HH:mm')} + + + )} + + {giftInfo.contactInfo && ( + + 客服电话: + {giftInfo.contactInfo} + + )} + + + )} {/* 手动输入区域 */} - - 手动输入核销码 - - - - - + { + !giftInfo && ( + + 手动输入核销码 + + + + + + ) + } + {/* 礼品卡信息 */} {giftInfo && ( @@ -246,7 +325,7 @@ const StoreVerification: React.FC = () => { 类型 - {getTypeText(giftInfo.type)} + {getTypeText(giftInfo.type as number)} @@ -264,14 +343,14 @@ const StoreVerification: React.FC = () => { )} - + - {verificationResult === 'success' && ( + {giftInfo && (