diff --git a/config/env.ts b/config/env.ts index c92883b..44ddb26 100644 --- a/config/env.ts +++ b/config/env.ts @@ -2,7 +2,7 @@ export const ENV_CONFIG = { // 开发环境 development: { - API_BASE_URL: 'https://cms-api.websoft.top/api', + API_BASE_URL: 'http://127.0.0.1:9200/api', APP_NAME: '开发环境', DEBUG: 'true', }, diff --git a/src/admin/components/StoreCell.tsx b/src/admin/components/StoreCell.tsx deleted file mode 100644 index 9fd837e..0000000 --- a/src/admin/components/StoreCell.tsx +++ /dev/null @@ -1,150 +0,0 @@ -import {Cell} from '@nutui/nutui-react-taro' -import navTo from "@/utils/common"; -import Taro from '@tarojs/taro' -import {View, Text} from '@tarojs/components' -import {ArrowRight, ShieldCheck, LogisticsError, Location, Reward, Tips, Ask, Setting, Scan} from '@nutui/icons-react-taro' -import {useUser} from '@/hooks/useUser' - -const UserCell = () => { - const {logoutUser, isCertified, hasRole, isAdmin} = useUser(); - - const onLogout = () => { - Taro.showModal({ - title: '提示', - content: '确定要退出登录吗?', - success: function (res) { - if (res.confirm) { - // 使用 useUser hook 的 logoutUser 方法 - logoutUser(); - Taro.reLaunch({ - url: '/pages/index/index' - }) - } - } - }) - } - - return ( - <> - - - 我的服务 - - }> - - - 门店核销 - - } - align="center" - extra={} - onClick={() => { - navTo('/user/wallet/index', true) - }} - /> - - - 我的钱包 - - } - align="center" - extra={} - onClick={() => { - navTo('/user/wallet/index', true) - }} - /> - - - 收货地址 - - } - align="center" - extra={} - onClick={() => { - navTo('/user/address/index', true) - }} - /> - - - 实名认证 - {isCertified() && ( - 已认证 - )} - - } - align="center" - extra={} - onClick={() => { - navTo('/user/userVerify/index', true) - }} - /> - - - 常见问题 - - } - align="center" - extra={} - onClick={() => { - navTo('/user/help/index') - }} - /> - - - 关于我们 - - } - align="center" - extra={} - onClick={() => { - navTo('/user/about/index') - }} - /> - - - 账号管理 - - }> - } - onClick={() => navTo('/user/profile/profile', true)} - /> - } - onClick={onLogout} - /> - - - - ) -} -export default UserCell diff --git a/src/api/shop/shopGift/model/index.ts b/src/api/shop/shopGift/model/index.ts index ce2de42..611b4c4 100644 --- a/src/api/shop/shopGift/model/index.ts +++ b/src/api/shop/shopGift/model/index.ts @@ -1,4 +1,4 @@ -import type { PageParam } from '@/api/index'; +import type { PageParam } from '@/api'; /** * 礼品卡 @@ -64,6 +64,8 @@ export interface ShopGift { useLocation?: string; // 客服联系方式 contactInfo?: string; + // 核销时间 + verificationTime?: string; } /** diff --git a/src/components/GiftCard.scss b/src/components/GiftCard.scss index 8130a0f..dbacea0 100644 --- a/src/components/GiftCard.scss +++ b/src/components/GiftCard.scss @@ -460,7 +460,6 @@ margin-bottom: 6px; .time-text { - font-size: 12px; color: #666; margin-left: 6px; } diff --git a/src/components/GiftCard.tsx b/src/components/GiftCard.tsx index 57fe12f..5caf542 100644 --- a/src/components/GiftCard.tsx +++ b/src/components/GiftCard.tsx @@ -197,8 +197,8 @@ const GiftCard: React.FC = ({ - {getTypeText()} - {name} + {getTypeText()} + {name} {statusInfo.text} @@ -325,7 +325,7 @@ const GiftCard: React.FC = ({ {useLocation && ( - 使用地址:{useLocation} + 使用地址:{useLocation} )} diff --git a/src/shop/goodsDetail/index.tsx b/src/shop/goodsDetail/index.tsx index 5f07907..75f8279 100644 --- a/src/shop/goodsDetail/index.tsx +++ b/src/shop/goodsDetail/index.tsx @@ -82,7 +82,7 @@ const GoodsDetail = () => { }; // 规格选择确认回调 - const handleSpecConfirm = (sku: ShopGoodsSku, quantity: number, action: 'cart' | 'buy') => { + const handleSpecConfirm = (sku: ShopGoodsSku, quantity: number, action?: 'cart' | 'buy') => { // setSelectedSku(sku); setShowSpecSelector(false); @@ -96,7 +96,7 @@ const GoodsDetail = () => { image: goods!.image || '', specInfo: sku.sku, // sku字段包含规格信息 }, quantity); - } else { + } else if (action === 'buy') { // 立即购买 const orderData = { goodsId: goods!.goodsId!, @@ -105,6 +105,15 @@ const GoodsDetail = () => { price: sku.price || goods!.price || '0' }; navTo(`/shop/orderConfirm/index?orderData=${encodeURIComponent(JSON.stringify(orderData))}`, true); + } else { + // 默认情况:如果action未定义,默认为立即购买 + const orderData = { + goodsId: goods!.goodsId!, + skuId: sku.id, + quantity, + price: sku.price || goods!.price || '0' + }; + navTo(`/shop/orderConfirm/index?orderData=${encodeURIComponent(JSON.stringify(orderData))}`, true); } }; diff --git a/src/user/gift/detail.tsx b/src/user/gift/detail.tsx index 958c34f..b7ccd23 100644 --- a/src/user/gift/detail.tsx +++ b/src/user/gift/detail.tsx @@ -165,7 +165,7 @@ const GiftCardDetail = () => { return ( {/* 礼品卡卡片 */} - + {getGiftValueDisplay()} @@ -212,8 +212,8 @@ const GiftCardDetail = () => { - 有效期 - {getValidityText()} + 有效期 + {getValidityText()} @@ -222,8 +222,8 @@ const GiftCardDetail = () => { - 礼品卡类型 - {getGiftTypeText(gift.type)} + 类型 + {getGiftTypeText(gift.type)} @@ -233,8 +233,8 @@ const GiftCardDetail = () => { - 使用地址 - {gift.useLocation} + 使用地址 + {gift.useLocation} diff --git a/src/user/gift/redeem.tsx b/src/user/gift/redeem.tsx index 379badd..36667db 100644 --- a/src/user/gift/redeem.tsx +++ b/src/user/gift/redeem.tsx @@ -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 = () => { 兑换成功! - 礼品卡已添加到您的账户中 + 礼品卡已添加到您的账户中 {validGift && ( diff --git a/src/user/store/verification.tsx b/src/user/store/verification.tsx index dc96d0b..1ac913e 100644 --- a/src/user/store/verification.tsx +++ b/src/user/store/verification.tsx @@ -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('') const [verificationCode, setVerificationCode] = useState('') const [giftInfo, setGiftInfo] = useState(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: '核销成功',