feat(coupon): 优惠券中心(领取)+ 我的券 + 下单核销/回退
- 新表 user_coupons(快照面额/门槛/类目/有效期)+ orders.user_coupon_id - 仓储:getCouponsWithClaimed/claimCoupon/getUserCoupons/resolveUserCoupon/consumeUserCoupon/releaseUserCouponByOrder - 接口:POST /api/marketing/coupons/:id/claim(同券仅一次、受总量限制)、GET /api/marketing/my-coupons(自动标记过期)、券中心带 claimed 标识 - 下单:createOrder 支持 userCouponId(校验归属/门槛/类目/有效期,服务端算抵扣,与订单同事务占用) - 回退:买家取消/大神拒单/超时退款/仲裁退款 均把券退回为 UNUSED - 小程序:新增 pages/user/coupons(券中心+我的券)、个人中心入口(可用张数)、下单改为选择"我的券"并传 userCouponId - 回归 94 套件/666 用例全绿;冒烟 9/9(领取/重复领取409/不存在404/下单抵扣100-10=90/取消回退)
这个提交包含在:
@@ -239,7 +239,7 @@
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue';
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app';
|
||||
import { createOrder, payOrder as payOrderApi, requestWechatPayment, getCompanionDetail, getUserProfile, getMarketingCoupons } from '@/common/api.js';
|
||||
import { createOrder, payOrder as payOrderApi, requestWechatPayment, getCompanionDetail, getUserProfile, getMyCoupons } from '@/common/api.js';
|
||||
import { preloadSubscribeTemplates, requestSubscribeFor } from '@/common/subscribe.js';
|
||||
import { ICONS } from '@/common/icons.js';
|
||||
import { getCurrentThemeKey, applyThemeToNativeUI } from '@/common/theme.js';
|
||||
@@ -381,21 +381,20 @@ const currentCoupon = ref(availableCoupons.value[0]);
|
||||
|
||||
const loadLiveCoupons = async () => {
|
||||
try {
|
||||
const list = await getMarketingCoupons();
|
||||
if (Array.isArray(list) && list.length > 0) {
|
||||
const activeCoupons = list
|
||||
.filter(c => c.status === 1)
|
||||
.map(c => ({
|
||||
id: String(c.id),
|
||||
title: c.name,
|
||||
amount: Number(c.discountAmount || 0),
|
||||
minAmount: Number(c.minSpend || 0),
|
||||
tag: c.minSpend > 0 ? `满¥${c.minSpend}减¥${c.discountAmount}` : `立减¥${c.discountAmount}`
|
||||
}));
|
||||
activeCoupons.push({ id: 'c_none', title: '不使用优惠券', amount: 0, minAmount: 0, tag: '不使用' });
|
||||
availableCoupons.value = activeCoupons;
|
||||
autoSelectBestCoupon();
|
||||
}
|
||||
const uid = uni.getStorageSync('userId') || 0;
|
||||
const res = uid ? await getMyCoupons(uid, 'UNUSED') : null;
|
||||
const mine = Array.isArray(res?.list) ? res.list : [];
|
||||
const activeCoupons = mine.map(c => ({
|
||||
id: String(c.id),
|
||||
title: c.name,
|
||||
amount: Number(c.discountAmount || 0),
|
||||
minAmount: Number(c.minSpend || 0),
|
||||
categoryLimit: c.categoryLimit || 'ALL',
|
||||
tag: c.minSpend > 0 ? `满¥${c.minSpend}减¥${c.discountAmount}` : `立减¥${c.discountAmount}`
|
||||
}));
|
||||
activeCoupons.push({ id: 'c_none', title: '不使用优惠券', amount: 0, minAmount: 0, tag: '不使用', categoryLimit: 'ALL' });
|
||||
availableCoupons.value = activeCoupons;
|
||||
autoSelectBestCoupon();
|
||||
} catch (e) {
|
||||
console.warn('[OrderCreate] 加载优惠券异常:', e);
|
||||
}
|
||||
@@ -474,6 +473,7 @@ const handlePay = async () => {
|
||||
|
||||
const uid = Number(uni.getStorageSync('userId') || currentUserId.value || 1001);
|
||||
const serviceTitle = selectedService.value ? selectedService.value.title : `${expert.value.game}专属服务`;
|
||||
const usingUserCoupon = currentCoupon.value && currentCoupon.value.id && currentCoupon.value.id !== 'c_none';
|
||||
const basePayload = {
|
||||
buyerId: uid,
|
||||
clientName: currentUserName.value || '超能电竞玩家',
|
||||
@@ -485,7 +485,8 @@ const handlePay = async () => {
|
||||
hourlyRate: selectedService.value ? selectedService.value.price : (expert.value.price || 35),
|
||||
durationHours: hours.value,
|
||||
amount: finalTotal.value,
|
||||
couponDiscount: discount.value,
|
||||
couponDiscount: usingUserCoupon ? 0 : discount.value,
|
||||
userCouponId: usingUserCoupon ? String(currentCoupon.value.id) : '',
|
||||
payType: payMethod.value,
|
||||
location: isOffline.value ? meetVenue.value : (remark.value || '线上语音开黑'),
|
||||
expenseBurden: expenseBurden.value === 'AA' ? 'AA制各自付' : (expenseBurden.value === 'CLIENT' ? '客户全包' : '大神自理'),
|
||||
|
||||
在新工单中引用
屏蔽一个用户