From f053c272d7a555f6e58ec9f90ec9bb97cef5b3cb Mon Sep 17 00:00:00 2001 From: p-honggang.li <p-honggang.li@pcitc.com> Date: 星期三, 03 九月 2025 16:58:49 +0800 Subject: [PATCH] Merge branch 'master' of http://xearth.cn:6600/r/web-manage/web-manage --- src/views/tradeManage/confirm/index.vue | 75 +++++++++++++++++++++++++++++++++++++ 1 files changed, 74 insertions(+), 1 deletions(-) diff --git a/src/views/tradeManage/confirm/index.vue b/src/views/tradeManage/confirm/index.vue index 9c4a6d7..0a0506b 100644 --- a/src/views/tradeManage/confirm/index.vue +++ b/src/views/tradeManage/confirm/index.vue @@ -237,6 +237,7 @@ import { Document, User, Goods, List } from '@element-plus/icons-vue' import { ElMessage, ElMessageBox } from 'element-plus' import orderApi from '@/api/orderApi' +import pointsApi from '@/api/pointsApi' // 鏂板绉垎API瀵煎叆 import { useUserInfo } from '@/stores/modules/userInfo' import createAxios from '@/utils/axios' @@ -401,6 +402,41 @@ return } + // 妫�鏌ヨ鍗曟槸鍚︽秹鍙婄Н鍒嗘墸鍑� + const hasPointsDeduction = detail.items && detail.items.some((item: any) => Number(item.pricePoint || 0) > 0) + + if (hasPointsDeduction) { + // 璁$畻闇�瑕佹墸鍑忕殑绉垎鎬婚 + const totalPointsToDeduct = detail.items.reduce((sum: number, item: any) => { + return sum + (Number(item.pricePoint || 0) * Number(item.quantity || 0)) + }, 0) + + if (totalPointsToDeduct > 0) { + // 鑾峰彇褰撳墠鐢ㄦ埛绉垎浣欓 + try { + const userPointsRes = await pointsApi.getUserPoints(userId) + if (userPointsRes.code !== 200 || !userPointsRes.data) { + ElMessage.error('鑾峰彇绉垎浣欓澶辫触') + return + } + + const currentPoints = userPointsRes.data.balance || 0 + + if (currentPoints < totalPointsToDeduct) { + ElMessage.error(`绉垎浣欓涓嶈冻锛佸綋鍓嶇Н鍒嗭細${currentPoints.toLocaleString()}锛岄渶瑕佺Н鍒嗭細${totalPointsToDeduct.toLocaleString()}`) + return + } + + // 绉垎浣欓鍏呰冻锛岀户缁墽琛� + console.log(`绉垎浣欓妫�鏌ラ�氳繃锛氬綋鍓�${currentPoints}锛岄渶瑕�${totalPointsToDeduct}`) + } catch (error) { + console.error('鑾峰彇绉垎浣欓澶辫触:', error) + ElMessage.error('鑾峰彇绉垎浣欓澶辫触锛岃閲嶈瘯') + return + } + } + } + // 纭鎿嶄綔 await ElMessageBox.confirm('纭畾瑕佺‘璁や氦鏄擄紵', '纭鎿嶄綔', { confirmButtonText: '纭畾', @@ -408,8 +444,45 @@ type: 'warning' }) - // 鏇存柊璁㈠崟鐘舵�佽繘鍏ヤ笅涓�涓姸鎬� + // 濡傛灉娑夊強绉垎鎵e噺锛屽厛杩涜绉垎鎵e噺鍜屾祦姘磋褰� + if (hasPointsDeduction) { + const totalPointsToDeduct = detail.items.reduce((sum: number, item: any) => { + return sum + (Number(item.pricePoint || 0) * Number(item.quantity || 0)) + }, 0) + + if (totalPointsToDeduct > 0) { + try { + // 鑾峰彇鐢ㄦ埛鍗曚綅ID + const unitId = userStore.getUserInfo?.unitId || userStore.getUserInfo?.unitId || '' + + // 鑾峰彇褰撳墠璁㈣喘鐨勪骇鍝佸悕绉颁綔涓哄娉紙浣跨敤浜у搧鍚嶇О锛屼笉鏄浠跺悕绉帮級 + const productNames = detail.productName || '璁㈠崟浜ゆ槗鎵e噺绉垎' + + // 鍏堟墽琛岀Н鍒嗘墸鍑� + const deductRes: any = await pointsApi.deductPointsByFlow( + userId.toString(), + unitId, + totalPointsToDeduct, + orderId, + productNames || '璁㈠崟浜ゆ槗鎵e噺绉垎', // 浣跨敤浜у搧鍚嶇О浣滀负澶囨敞 + '绉垎浜ゆ槗' // 鏁版嵁绫诲埆 + ) + if (!deductRes || deductRes.code !== 200) { + ElMessage.error(deductRes?.msg || deductRes?.message || '绉垎鎵e噺澶辫触锛屼氦鏄撶‘璁ょ粓姝�') + return + } + console.log(`绉垎鎵e噺鎴愬姛锛�${totalPointsToDeduct}`) + } catch (error) { + console.error('绉垎鎵e噺澶辫触:', error) + ElMessage.error('绉垎鎵e噺澶辫触锛屼氦鏄撶‘璁ょ粓姝�') + return + } + } + } + + // 绉垎鎵e噺鎴愬姛鍚庯紝鏇存柊璁㈠崟鐘舵�佽繘鍏ヤ笅涓�涓姸鎬� await orderApi.updateOrderStatusToNext(orderId) + ElMessage.success('浜ゆ槗纭鎴愬姛') router.back() } catch (error) { -- Gitblit v1.8.0