更新了对对碰预订单的api

This commit is contained in:
tsui110 2025-12-19 23:48:47 +08:00
parent ad0232ad21
commit 9f7c98ddad
2 changed files with 66 additions and 5 deletions

View File

@ -209,6 +209,10 @@ export function getMatchingCardTypes() {
return authRequest({ url: '/api/app/matching/card_types', method: 'GET' }) return authRequest({ url: '/api/app/matching/card_types', method: 'GET' })
} }
export function createMatchingPreorder(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 } }) return authRequest({
url: '/api/app/matching/preorder',
method: 'POST',
data: { issue_id, position, coupon_id, item_card_id }
})
} }

View File

@ -158,7 +158,8 @@
v-model:visible="paymentVisible" v-model:visible="paymentVisible"
:amount="paymentAmount" :amount="paymentAmount"
:coupons="coupons" :coupons="coupons"
:showCards="false" :propCards="propCards"
:showCards="true"
@confirm="onPaymentConfirm" @confirm="onPaymentConfirm"
/> />
</template> </template>
@ -167,7 +168,7 @@
import { ref, computed } from 'vue' import { ref, computed } from 'vue'
import { onLoad } from '@dcloudio/uni-app' import { onLoad } from '@dcloudio/uni-app'
import PaymentPopup from '../../../components/PaymentPopup.vue' 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 detail = ref({})
const statusText = ref('') const statusText = ref('')
@ -181,6 +182,9 @@ const tabActive = ref('pool')
const winRecords = ref([]) const winRecords = ref([])
const paymentVisible = ref(false) const paymentVisible = ref(false)
const coupons = ref([]) 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 paymentAmount = computed(() => (((Number(detail.value.price_draw || 0) / 100) || 0)).toFixed(2))
const cardTypesLoading = ref(false) const cardTypesLoading = ref(false)
const cardTypes = ref([]) const cardTypes = ref([])
@ -426,7 +430,12 @@ async function onParticipate() {
return return
} }
coupons.value = [] coupons.value = []
propCards.value = []
selectedCoupon.value = null
selectedCard.value = null
paymentVisible.value = true paymentVisible.value = true
fetchCoupons()
fetchPropCards()
} }
function selectCardType(it) { function selectCardType(it) {
@ -448,6 +457,8 @@ async function fetchCardTypes() {
} }
async function onPaymentConfirm(data) { async function onPaymentConfirm(data) {
selectedCoupon.value = data?.coupon || null
selectedCard.value = data?.card || null
paymentVisible.value = false paymentVisible.value = false
await doDraw() await doDraw()
} }
@ -467,7 +478,12 @@ async function doDraw() {
return 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('预下单失败') if (!preRes) throw new Error('预下单失败')
const orderNo = preRes.order_no || preRes.data?.order_no || preRes.result?.order_no || preRes.orderNo const orderNo = preRes.order_no || preRes.data?.order_no || preRes.result?.order_no || preRes.orderNo
if (!orderNo) throw new Error('未获取到订单号') 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) => { onLoad((opts) => {
const id = (opts && opts.id) || '' const id = (opts && opts.id) || ''
if (id) { if (id) {