From d9185f34ed36e0c64d530173f338ccaefbf607cf Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Fri, 4 Dec 2026 17:19:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E4=BB=98=E5=8F=AF=E9=80=89?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=E4=BD=99=E9=A2=9D=EF=BC=8C=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=E6=8F=90=E7=A4=BA=E4=B8=8E=E6=9E=84=E5=BB=BA=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=94=B6=E6=95=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 混合支付支持 UseBalance;微信/支付宝配置改为问号提示;Vite 堆降至 4G 并关闭 gzip 体积统计,减轻生产同机 CI 压力。 Co-authored-by: Cursor --- package.json | 8 +- src/api/recharge/alipayPay.ts | 5 +- src/api/recharge/wechatPay.ts | 9 + src/locale/en-US.ts | 51 +++- src/locale/zh-CN.ts | 51 +++- .../components/H5OrderPaySheet.vue | 54 +++- src/views/h5/customer-center/locale/en-US.ts | 1 + src/views/h5/customer-center/locale/zh-CN.ts | 1 + .../components/OrderPayConfirmModal.vue | 192 +++++++++---- src/views/system/otherConfig/index.vue | 263 +++++++++++++++++- vite.config.ts | 2 + 11 files changed, 550 insertions(+), 87 deletions(-) diff --git a/package.json b/package.json index a476a1f..515e143 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,10 @@ "dev": "vite", "dev:test": "vite --mode bcdship-test", "dev:nanafa": "vite --mode nanafa", - "build": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=1 node --max-old-space-size=8192 node_modules/vite/bin/vite.js build", - "build:prod": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=1 node --max-old-space-size=8192 node_modules/vite/bin/vite.js build --mode production", - "build:test": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=1 node --max-old-space-size=8192 node_modules/vite/bin/vite.js build --mode bcdship-test", - "build:nanafa": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=1 node --max-old-space-size=8192 node_modules/vite/bin/vite.js build --mode nanafa", + "build": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=1 node --max-old-space-size=4096 node_modules/vite/bin/vite.js build", + "build:prod": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=1 node --max-old-space-size=4096 node_modules/vite/bin/vite.js build --mode production", + "build:test": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=1 node --max-old-space-size=4096 node_modules/vite/bin/vite.js build --mode bcdship-test", + "build:nanafa": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=1 node --max-old-space-size=4096 node_modules/vite/bin/vite.js build --mode nanafa", "postbuild": "node scripts/postbuild-cleanup-dist.js", "report": "cross-env REPORT=true pnpm run build", "preview": "npm run build && vite preview --host", diff --git a/src/api/recharge/alipayPay.ts b/src/api/recharge/alipayPay.ts index 1363fab..b937876 100644 --- a/src/api/recharge/alipayPay.ts +++ b/src/api/recharge/alipayPay.ts @@ -106,17 +106,20 @@ export interface CreateOrderAlipayPayResult { lines: CreateOrderAlipayPayLine[] } -/** POST /order/pay/alipay/create — 余额优先,差额支付宝 */ +/** POST /order/pay/alipay/create — 可选余额,差额支付宝 */ export async function createOrderAlipayPay(params: { orderIds: number[] couponByOrderId?: Record scene: AlipayPayScene + /** 是否使用账户余额抵扣,默认 true */ + useBalance?: boolean returnUrl?: string }) { const res = await axiosInstance.post(omsUrl('/order/pay/alipay/create'), { orderIds: params.orderIds, couponByOrderId: params.couponByOrderId, scene: params.scene, + useBalance: params.useBalance !== false, returnUrl: params.returnUrl, }) const raw = unwrapData(res.data) ?? res.data diff --git a/src/api/recharge/wechatPay.ts b/src/api/recharge/wechatPay.ts index 3d83a95..e1167c0 100644 --- a/src/api/recharge/wechatPay.ts +++ b/src/api/recharge/wechatPay.ts @@ -135,6 +135,8 @@ export async function createOrderWeChatPay(params: { orderIds: number[] couponByOrderId?: Record scene: WeChatPayScene + /** 是否使用账户余额抵扣,默认 true */ + useBalance?: boolean oauthCode?: string }) { const headers: Record = {} @@ -147,6 +149,7 @@ export async function createOrderWeChatPay(params: { orderIds: params.orderIds, couponByOrderId: params.couponByOrderId, scene: params.scene, + useBalance: params.useBalance !== false, oauthCode: params.oauthCode, }, { headers }, @@ -191,9 +194,11 @@ export interface WeChatPayMerchantConfig { enabled: boolean mchId: string mchSerialNo: string + platformPublicKeyId: string notifyUrl: string hasApiV3Key: boolean hasPrivateKey: boolean + hasPlatformPublicKey: boolean appId?: string } @@ -205,9 +210,11 @@ export async function getWeChatPayMerchantConfig(): Promise{{ t('h5.pay.settleTitle') }} {{ - needsWechatPay + !useAccountBalance ? onlinePayChannel === 'alipay' - ? t('h5.pay.methodHybridAlipay') - : t('h5.pay.methodHybrid') - : t('h5.pay.methodBalance') + ? t('h5.pay.channelAlipay') + : t('h5.pay.channelWechat') + : needsWechatPay + ? onlinePayChannel === 'alipay' + ? t('h5.pay.methodHybridAlipay') + : t('h5.pay.methodHybrid') + : t('h5.pay.methodBalance') }} + +
- + {{ t('h5.pay.splitBalance') }} {{ formatPayMoney(needsWechatPay ? hybridBalanceUse : payableTotal) }} @@ -440,12 +450,16 @@ const payableTotal = computed(() => { return couponPricing.totalPayable.value; }); +const useAccountBalance = ref(true); +const canUseAccountBalance = computed( + () => customerBalance.value != null && customerBalance.value > 1e-6, +); const hybridBalanceUse = computed(() => { - if (customerBalance.value == null) return 0; + if (customerBalance.value == null || !useAccountBalance.value) return 0; return Math.min(customerBalance.value, payableTotal.value); }); const hybridWechatAmount = computed(() => { - if (customerBalance.value == null) return 0; + if (customerBalance.value == null && useAccountBalance.value) return 0; return Math.max(0, payableTotal.value - hybridBalanceUse.value); }); const needsWechatPay = computed(() => hybridWechatAmount.value > 1e-6); @@ -805,6 +819,7 @@ async function payWithWechatHybrid(oauthCode?: string) { orderIds: props.orders.map((o) => Number(o.id)).filter((id) => id > 0), couponByOrderId, scene: 'jsapi', + useBalance: useAccountBalance.value, oauthCode, }); } catch (e: any) { @@ -869,6 +884,7 @@ async function payWithAlipayHybrid() { orderIds: props.orders.map((o) => Number(o.id)).filter((id) => id > 0), couponByOrderId, scene: 'wap', + useBalance: useAccountBalance.value, returnUrl, }); @@ -1477,6 +1493,30 @@ watch( color: #4e5969; } +.h5-pay__use-balance { + display: flex; + align-items: center; + gap: 8px; + margin-bottom: 8px; + font-size: 13px; + color: #1d2129; + cursor: pointer; + + input { + width: 16px; + height: 16px; + accent-color: var(--app-primary-color); + } + + em { + margin-left: auto; + font-style: normal; + font-size: 12px; + color: #86909c; + font-variant-numeric: tabular-nums; + } +} + .h5-pay__split-inline { display: flex; flex-wrap: wrap; diff --git a/src/views/h5/customer-center/locale/en-US.ts b/src/views/h5/customer-center/locale/en-US.ts index 0648ad9..c1f46d4 100644 --- a/src/views/h5/customer-center/locale/en-US.ts +++ b/src/views/h5/customer-center/locale/en-US.ts @@ -1092,6 +1092,7 @@ export default { 'h5.pay.waybillNo': 'Waybill', 'h5.pay.orderTotal': 'Order due', 'h5.pay.methodBalance': 'Pay with balance', + 'h5.pay.useBalance': 'Use account balance', 'h5.pay.methodHybrid': 'Balance first · WeChat shortfall', 'h5.pay.methodHybridHint': 'Use balance {balance}, WeChat {wechat}', 'h5.pay.settleTitle': 'Payment', diff --git a/src/views/h5/customer-center/locale/zh-CN.ts b/src/views/h5/customer-center/locale/zh-CN.ts index 70e9cbe..1cf7c45 100644 --- a/src/views/h5/customer-center/locale/zh-CN.ts +++ b/src/views/h5/customer-center/locale/zh-CN.ts @@ -1072,6 +1072,7 @@ export default { 'h5.pay.orderTotal': '本单应付', 'h5.pay.methodBalance': '账户余额支付', 'h5.pay.methodHint': '支付成功后将从账户余额扣款', + 'h5.pay.useBalance': '使用账户余额', 'h5.pay.methodHybrid': '余额优先 · 微信补差', 'h5.pay.methodHybridAlipay': '余额优先 · 支付宝补差', 'h5.pay.methodHybridHint': '本次用余额 {balance},在线补差 {wechat}', diff --git a/src/views/order/myOrders/components/OrderPayConfirmModal.vue b/src/views/order/myOrders/components/OrderPayConfirmModal.vue index 00365f6..70cae43 100644 --- a/src/views/order/myOrders/components/OrderPayConfirmModal.vue +++ b/src/views/order/myOrders/components/OrderPayConfirmModal.vue @@ -17,6 +17,8 @@ import { createOrderAlipayPay, getAlipayPayStatus, } from '@/api/recharge/alipayPay' +import wxIcon from '@/assets/wx.png' +import zfbIcon from '@/assets/zfb.png' import { formatCouponBenefit, formatPayMoney, @@ -172,13 +174,21 @@ const singleBalance = computed(() => { const pricingLoading = computed(() => couponPricing.anyLoading.value) -/** 单客户:余额优先;多客户:仅余额(不足不可确认) */ +/** 单客户:是否用账户余额抵扣(可关,关则全额扫码) */ +const useAccountBalance = ref(true) +const canUseAccountBalance = computed( + () => !isMultiCustomer.value && singleBalance.value != null && singleBalance.value > 1e-6, +) + +/** 单客户:可选余额;多客户:仅余额(不足不可确认) */ const hybridBalanceUse = computed(() => { if (isMultiCustomer.value || singleBalance.value == null) return 0 + if (!useAccountBalance.value) return 0 return Math.min(singleBalance.value, totals.value.payable) }) const hybridWechatAmount = computed(() => { - if (isMultiCustomer.value || singleBalance.value == null) return 0 + if (isMultiCustomer.value) return 0 + if (singleBalance.value == null && useAccountBalance.value) return 0 return Math.max(0, totals.value.payable - hybridBalanceUse.value) }) const needsWechatPay = computed(() => hybridWechatAmount.value > 1e-6) @@ -473,11 +483,13 @@ async function handleConfirm() { orderIds: queue.map((p) => Number(p.id)), couponByOrderId, scene: 'precreate', + useBalance: useAccountBalance.value, }) : await createOrderWeChatPay({ orderIds: queue.map((p) => Number(p.id)), couponByOrderId, scene: 'native', + useBalance: useAccountBalance.value, }) if (created.paidImmediately) { for (const p of queue) { @@ -594,6 +606,8 @@ watch( () => [props.visible, props.orders] as const, ([visible]) => { if (visible) { + useAccountBalance.value = true + onlinePayChannel.value = 'wechat' loadPreviews() } else { stopWxPoll() @@ -640,7 +654,21 @@ watch(
{{ t('order.myOrders.modal.paySubtotal') }}
{{ formatPayMoney(totals.subtotal) }}
-
+ +
{{ t('order.myOrders.modal.payBalance') }}
{{ formatPayMoney(singleBalance) }}
@@ -658,21 +686,46 @@ watch(
{{ t('order.myOrders.modal.payMultiCustomerWxHint') }}
- - {{ t('order.myOrders.modal.payHybridHint', { amount: formatPayMoney(hybridWechatAmount) }) }} -
- {{ t('order.myOrders.modal.payOnlineChannel') }} - - {{ t('order.myOrders.modal.payChannelWechat') }} - {{ t('order.myOrders.modal.payChannelAlipay') }} - +
+ +
+ {{ t('order.myOrders.modal.payOnlineChannel') }} + +
- +
{{ t('order.myOrders.modal.paySkipHint', { count: blockedOrders.length }) }} @@ -840,26 +893,6 @@ watch( +
+ +
+ + +
+
+ @@ -476,6 +603,13 @@
{{ t('system.otherConfig.paymentQr.wechatPay.appId') }} + + + {{ wechatPayMeta.appId }} @@ -580,11 +714,22 @@ + +
- + + {{ t('system.otherConfig.paymentQr.alipayPay.privateKeyPem') }} + + + {{ t('system.otherConfig.paymentQr.alipayPay.alipayPublicKey') }} + + + { wechatPayForm.enabled !== wechatPaySnapshot.enabled || wechatPayForm.mchId !== wechatPaySnapshot.mchId || wechatPayForm.mchSerialNo !== wechatPaySnapshot.mchSerialNo || + wechatPayForm.platformPublicKeyId !== wechatPaySnapshot.platformPublicKeyId || wechatPayForm.notifyUrl !== wechatPaySnapshot.notifyUrl || wechatPayForm.apiV3Key !== wechatPaySnapshot.apiV3Key || - wechatPayForm.privateKeyPem !== wechatPaySnapshot.privateKeyPem + wechatPayForm.privateKeyPem !== wechatPaySnapshot.privateKeyPem || + wechatPayForm.platformPublicKeyPem !== wechatPaySnapshot.platformPublicKeyPem ) }) @@ -2282,9 +2472,11 @@ const wechatPayReady = computed(() => { wechatPayForm.enabled && !!wechatPayForm.mchId.trim() && !!wechatPayForm.mchSerialNo.trim() && + !!wechatPayForm.platformPublicKeyId.trim() && !!wechatPayForm.notifyUrl.trim() && (wechatPayMeta.hasApiV3Key || !!wechatPayForm.apiV3Key.trim()) && (wechatPayMeta.hasPrivateKey || !!wechatPayForm.privateKeyPem.trim()) && + (wechatPayMeta.hasPlatformPublicKey || !!wechatPayForm.platformPublicKeyPem.trim()) && !!wechatPayMeta.appId ) }) @@ -2292,7 +2484,10 @@ const wechatPayReady = computed(() => { const wechatPayChecklist = computed(() => [ { key: 'mch', - ok: !!wechatPayForm.mchId.trim() && !!wechatPayForm.mchSerialNo.trim(), + ok: + !!wechatPayForm.mchId.trim() && + !!wechatPayForm.mchSerialNo.trim() && + !!wechatPayForm.platformPublicKeyId.trim(), label: t('system.otherConfig.paymentQr.wechatPay.checkMerchant'), }, { @@ -2302,8 +2497,10 @@ const wechatPayChecklist = computed(() => [ }, { key: 'secret', - ok: (wechatPayMeta.hasApiV3Key || !!wechatPayForm.apiV3Key.trim()) && - (wechatPayMeta.hasPrivateKey || !!wechatPayForm.privateKeyPem.trim()), + ok: + (wechatPayMeta.hasApiV3Key || !!wechatPayForm.apiV3Key.trim()) && + (wechatPayMeta.hasPrivateKey || !!wechatPayForm.privateKeyPem.trim()) && + (wechatPayMeta.hasPlatformPublicKey || !!wechatPayForm.platformPublicKeyPem.trim()), label: t('system.otherConfig.paymentQr.wechatPay.checkSecret'), }, { @@ -2321,9 +2518,11 @@ function applyWechatPaySnapshot() { wechatPaySnapshot.enabled = wechatPayForm.enabled wechatPaySnapshot.mchId = wechatPayForm.mchId wechatPaySnapshot.mchSerialNo = wechatPayForm.mchSerialNo + wechatPaySnapshot.platformPublicKeyId = wechatPayForm.platformPublicKeyId wechatPaySnapshot.notifyUrl = wechatPayForm.notifyUrl wechatPaySnapshot.apiV3Key = wechatPayForm.apiV3Key wechatPaySnapshot.privateKeyPem = wechatPayForm.privateKeyPem + wechatPaySnapshot.platformPublicKeyPem = wechatPayForm.platformPublicKeyPem } function fillWechatPayNotifyUrl() { @@ -2335,11 +2534,14 @@ function resetWechatPayForm() { wechatPayForm.enabled = wechatPaySnapshot.enabled wechatPayForm.mchId = wechatPaySnapshot.mchId wechatPayForm.mchSerialNo = wechatPaySnapshot.mchSerialNo + wechatPayForm.platformPublicKeyId = wechatPaySnapshot.platformPublicKeyId wechatPayForm.notifyUrl = wechatPaySnapshot.notifyUrl wechatPayForm.apiV3Key = wechatPaySnapshot.apiV3Key wechatPayForm.privateKeyPem = wechatPaySnapshot.privateKeyPem + wechatPayForm.platformPublicKeyPem = wechatPaySnapshot.platformPublicKeyPem wechatPayErrors.mchId = '' wechatPayErrors.mchSerialNo = '' + wechatPayErrors.platformPublicKeyId = '' wechatPayErrors.notifyUrl = '' } @@ -2369,6 +2571,24 @@ async function onWechatPayPemFile(ev: Event) { Message.error(t('system.otherConfig.paymentQr.wechatPay.pemReadFailed')) } } + +async function onWechatPayPublicPemFile(ev: Event) { + const input = ev.target as HTMLInputElement + const file = input.files?.[0] + input.value = '' + if (!file) return + try { + const text = await file.text() + if (!text.includes('BEGIN PUBLIC KEY')) { + Message.warning(t('system.otherConfig.paymentQr.wechatPay.publicPemInvalid')) + return + } + wechatPayForm.platformPublicKeyPem = text.trim() + Message.success(t('system.otherConfig.paymentQr.wechatPay.publicPemImported')) + } catch { + Message.error(t('system.otherConfig.paymentQr.wechatPay.pemReadFailed')) + } +} const bankAccountRows = ref([]) const bankAccountFormVisible = ref(false) const bankAccountSaving = ref(false) @@ -2401,15 +2621,19 @@ async function loadWechatPayMerchant() { wechatPayForm.enabled = cfg.enabled wechatPayForm.mchId = cfg.mchId wechatPayForm.mchSerialNo = cfg.mchSerialNo + wechatPayForm.platformPublicKeyId = cfg.platformPublicKeyId wechatPayForm.notifyUrl = cfg.notifyUrl wechatPayForm.apiV3Key = '' wechatPayForm.privateKeyPem = '' + wechatPayForm.platformPublicKeyPem = '' wechatPayMeta.configured = cfg.configured wechatPayMeta.hasApiV3Key = cfg.hasApiV3Key wechatPayMeta.hasPrivateKey = cfg.hasPrivateKey + wechatPayMeta.hasPlatformPublicKey = cfg.hasPlatformPublicKey wechatPayMeta.appId = cfg.appId wechatPayErrors.mchId = '' wechatPayErrors.mchSerialNo = '' + wechatPayErrors.platformPublicKeyId = '' wechatPayErrors.notifyUrl = '' applyWechatPaySnapshot() } catch (e) { @@ -2423,6 +2647,7 @@ function validateWechatPayForm(): boolean { let ok = true wechatPayErrors.mchId = '' wechatPayErrors.mchSerialNo = '' + wechatPayErrors.platformPublicKeyId = '' wechatPayErrors.notifyUrl = '' if (!wechatPayForm.mchId.trim()) { wechatPayErrors.mchId = t('system.otherConfig.paymentQr.wechatPay.needMchId') @@ -2432,6 +2657,10 @@ function validateWechatPayForm(): boolean { wechatPayErrors.mchSerialNo = t('system.otherConfig.paymentQr.wechatPay.needSerial') ok = false } + if (!wechatPayForm.platformPublicKeyId.trim()) { + wechatPayErrors.platformPublicKeyId = t('system.otherConfig.paymentQr.wechatPay.needPublicKeyId') + ok = false + } if (!wechatPayForm.notifyUrl.trim()) { wechatPayErrors.notifyUrl = t('system.otherConfig.paymentQr.wechatPay.needNotify') ok = false @@ -2447,6 +2676,10 @@ function validateWechatPayForm(): boolean { Message.warning(t('system.otherConfig.paymentQr.wechatPay.needPrivateKey')) ok = false } + if (!wechatPayMeta.hasPlatformPublicKey && !wechatPayForm.platformPublicKeyPem.trim()) { + Message.warning(t('system.otherConfig.paymentQr.wechatPay.needPlatformPublicKey')) + ok = false + } return ok } @@ -2458,19 +2691,24 @@ async function handleWechatPaySave() { enabled: wechatPayForm.enabled, mchId: wechatPayForm.mchId.trim(), mchSerialNo: wechatPayForm.mchSerialNo.trim(), + platformPublicKeyId: wechatPayForm.platformPublicKeyId.trim(), notifyUrl: wechatPayForm.notifyUrl.trim() || undefined, apiV3Key: wechatPayForm.apiV3Key.trim() || undefined, privateKeyPem: wechatPayForm.privateKeyPem.trim() || undefined, + platformPublicKeyPem: wechatPayForm.platformPublicKeyPem.trim() || undefined, }) wechatPayForm.apiV3Key = '' wechatPayForm.privateKeyPem = '' + wechatPayForm.platformPublicKeyPem = '' wechatPayForm.enabled = cfg.enabled wechatPayForm.mchId = cfg.mchId wechatPayForm.mchSerialNo = cfg.mchSerialNo + wechatPayForm.platformPublicKeyId = cfg.platformPublicKeyId wechatPayForm.notifyUrl = cfg.notifyUrl wechatPayMeta.configured = cfg.configured wechatPayMeta.hasApiV3Key = cfg.hasApiV3Key wechatPayMeta.hasPrivateKey = cfg.hasPrivateKey + wechatPayMeta.hasPlatformPublicKey = cfg.hasPlatformPublicKey wechatPayMeta.appId = cfg.appId applyWechatPaySnapshot() Message.success(t('system.otherConfig.paymentQr.wechatPay.saveSuccess')) @@ -4357,6 +4595,9 @@ onMounted(() => { } .wx-pay-bind__label { + display: inline-flex; + align-items: center; + gap: 4px; font-size: 12px; color: var(--color-text-3); } diff --git a/vite.config.ts b/vite.config.ts index 3ef74cb..b11db8e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -584,6 +584,8 @@ export default defineConfig(({ mode }) => { cssCodeSplit: true, // 生成 source map(默认关闭,避免线上包体积变大;需要排查问题时可临时打开) sourcemap: false, + // 跳过 gzip 体积统计:chunk 多时收尾很吃 CPU/内存(8c16g 生产+CI 同机更明显) + reportCompressedSize: false, // 构建输出配置:使用 Vite 默认的代码分割策略,避免过度自定义导致库初始化顺序问题 rollupOptions: { onwarn(warning, warn) {