From 9f7c98ddad09680b0801c495aa66233790097b31 Mon Sep 17 00:00:00 2001 From: tsui110 Date: Fri, 19 Dec 2025 23:48:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E5=AF=B9=E5=AF=B9?= =?UTF-8?q?=E7=A2=B0=E9=A2=84=E8=AE=A2=E5=8D=95=E7=9A=84api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/appUser.js | 8 +++- pages/activity/duiduipeng/index.vue | 63 +++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/api/appUser.js b/api/appUser.js index bc70938..1e6f17a 100644 --- a/api/appUser.js +++ b/api/appUser.js @@ -209,6 +209,10 @@ export function getMatchingCardTypes() { return authRequest({ url: '/api/app/matching/card_types', method: 'GET' }) } -export function createMatchingPreorder(issue_id) { - return authRequest({ url: '/api/app/matching/preorder', method: 'POST', data: { issue_id } }) +export function createMatchingPreorder({ issue_id, position, coupon_id = 0, item_card_id = 0 }) { + return authRequest({ + url: '/api/app/matching/preorder', + method: 'POST', + data: { issue_id, position, coupon_id, item_card_id } + }) } diff --git a/pages/activity/duiduipeng/index.vue b/pages/activity/duiduipeng/index.vue index 0801daa..ed4d5bf 100644 --- a/pages/activity/duiduipeng/index.vue +++ b/pages/activity/duiduipeng/index.vue @@ -158,7 +158,8 @@ v-model:visible="paymentVisible" :amount="paymentAmount" :coupons="coupons" - :showCards="false" + :propCards="propCards" + :showCards="true" @confirm="onPaymentConfirm" /> @@ -167,7 +168,7 @@ import { ref, computed } from 'vue' import { onLoad } from '@dcloudio/uni-app' import PaymentPopup from '../../../components/PaymentPopup.vue' -import { getActivityDetail, getActivityIssues, getActivityIssueRewards, getActivityWinRecords, createWechatOrder, getLotteryResult, getMatchingCardTypes, createMatchingPreorder } from '../../../api/appUser' +import { getActivityDetail, getActivityIssues, getActivityIssueRewards, getActivityWinRecords, getUserCoupons, getItemCards, createWechatOrder, getLotteryResult, getMatchingCardTypes, createMatchingPreorder } from '../../../api/appUser' const detail = ref({}) const statusText = ref('') @@ -181,6 +182,9 @@ const tabActive = ref('pool') const winRecords = ref([]) const paymentVisible = ref(false) const coupons = ref([]) +const propCards = ref([]) +const selectedCoupon = ref(null) +const selectedCard = ref(null) const paymentAmount = computed(() => (((Number(detail.value.price_draw || 0) / 100) || 0)).toFixed(2)) const cardTypesLoading = ref(false) const cardTypes = ref([]) @@ -426,7 +430,12 @@ async function onParticipate() { return } coupons.value = [] + propCards.value = [] + selectedCoupon.value = null + selectedCard.value = null paymentVisible.value = true + fetchCoupons() + fetchPropCards() } function selectCardType(it) { @@ -448,6 +457,8 @@ async function fetchCardTypes() { } async function onPaymentConfirm(data) { + selectedCoupon.value = data?.coupon || null + selectedCard.value = data?.card || null paymentVisible.value = false await doDraw() } @@ -467,7 +478,12 @@ async function doDraw() { return } - const preRes = await createMatchingPreorder(Number(iid)) + const preRes = await createMatchingPreorder({ + issue_id: Number(iid), + position: String(selectedCardType.value.code || ''), + coupon_id: selectedCoupon.value?.id ? Number(selectedCoupon.value.id) : 0, + item_card_id: selectedCard.value?.id ? Number(selectedCard.value.id) : 0 + }) if (!preRes) throw new Error('预下单失败') const orderNo = preRes.order_no || preRes.data?.order_no || preRes.result?.order_no || preRes.orderNo if (!orderNo) throw new Error('未获取到订单号') @@ -510,6 +526,47 @@ async function doDraw() { } } +async function fetchCoupons() { + const user_id = uni.getStorageSync('user_id') + if (!user_id) return + try { + const res = await getUserCoupons(user_id, 0, 1, 100) + let list = [] + if (Array.isArray(res)) list = res + else if (res && Array.isArray(res.list)) list = res.list + else if (res && Array.isArray(res.data)) list = res.data + coupons.value = list.map((i, idx) => { + const cents = (i.remaining !== undefined && i.remaining !== null) ? Number(i.remaining) : Number(i.amount ?? i.value ?? 0) + const yuan = isNaN(cents) ? 0 : (cents / 100) + return { + id: i.id ?? i.coupon_id ?? String(idx), + name: i.name ?? i.title ?? '优惠券', + amount: Number(yuan).toFixed(2) + } + }) + } catch (e) { + coupons.value = [] + } +} + +async function fetchPropCards() { + const user_id = uni.getStorageSync('user_id') + if (!user_id) return + try { + const res = await getItemCards(user_id, 0) + let list = [] + if (Array.isArray(res)) list = res + else if (res && Array.isArray(res.list)) list = res.list + else if (res && Array.isArray(res.data)) list = res.data + propCards.value = list.map((i, idx) => ({ + id: i.id ?? i.card_id ?? i.item_card_id ?? String(idx), + name: i.name ?? i.title ?? i.card_name ?? '道具卡' + })) + } catch (e) { + propCards.value = [] + } +} + onLoad((opts) => { const id = (opts && opts.id) || '' if (id) {