From a732eab59fc18ee642a446bdaf83f6b1d6d1551a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AF=85?= <1335909236@qq.com> Date: Wed, 17 Sep 2025 16:05:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=8E=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=89=A7=E8=A1=8C=E7=AB=8B=E5=8D=B3=E4=BB=98?= =?UTF-8?q?=E6=AC=BE=E6=97=B6=E7=9A=84=E6=89=A7=E8=A1=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/myOrders/groupOrders/index.vue | 3 +- packages/myOrders/index/index.vue | 3 +- packages/myOrders/orderDetails/index.vue | 3 +- packages/shop/groupPurchaseSubmit/index.vue | 189 +++++++++++--------- 4 files changed, 111 insertions(+), 87 deletions(-) diff --git a/packages/myOrders/groupOrders/index.vue b/packages/myOrders/groupOrders/index.vue index ba350a44..63eef026 100644 --- a/packages/myOrders/groupOrders/index.vue +++ b/packages/myOrders/groupOrders/index.vue @@ -291,7 +291,8 @@ export default { goToPay(item) { // 创建转换后的商品数组 const transformedItems = item.commodity_order_item_list.map(goods => ({ - checked: true, + isafterSale: true, + orderId: item.id, commodity_goods_info: { commodity_brief: "", commodity_id: goods.commodity_id, diff --git a/packages/myOrders/index/index.vue b/packages/myOrders/index/index.vue index c0aad497..1430fbce 100644 --- a/packages/myOrders/index/index.vue +++ b/packages/myOrders/index/index.vue @@ -292,7 +292,8 @@ export default { goToPay(item) { // 创建转换后的商品数组 const transformedItems = item.commodity_order_item_list.map(goods => ({ - checked: true, + isafterSale: true, + orderId: item.id, commodity_goods_info: { commodity_brief: "", commodity_id: goods.commodity_id, diff --git a/packages/myOrders/orderDetails/index.vue b/packages/myOrders/orderDetails/index.vue index c9253cf2..8e3d5343 100644 --- a/packages/myOrders/orderDetails/index.vue +++ b/packages/myOrders/orderDetails/index.vue @@ -263,7 +263,8 @@ export default { gotoPayment() { // 创建转换后的商品数组 const transformedItems = this.orderInfo.commodity_order_item_list.map(goods => ({ - checked: true, + isafterSale: true, + orderId: item.id, commodity_goods_info: { commodity_brief: "", commodity_id: goods.goods_id, diff --git a/packages/shop/groupPurchaseSubmit/index.vue b/packages/shop/groupPurchaseSubmit/index.vue index 75e4f8b5..22b66529 100644 --- a/packages/shop/groupPurchaseSubmit/index.vue +++ b/packages/shop/groupPurchaseSubmit/index.vue @@ -562,109 +562,130 @@ export default { if (!isGroupBuyValid) break; } - const params = { - user_id: uni.getStorageSync('userId'), - is_group_buy: isGroupBuyValid, - goods_list: Object.keys(this.supplierGroups).map(supplierId => { - const group = this.supplierGroups[supplierId]; - const firstItem = group[0]; + // 检查是否存在isafterSale属性且值为true + const hasAfterSaleItem = this.carList.some(item => item.isafterSale === true); + const orderIdFromAfterSale = hasAfterSaleItem ? this.carList.find(item => item.isafterSale === true)?.orderId : null; - // 团购活动id - this.group_buy_activity_id = firstItem.commodity_goods_info.group_buy_activity_id; + // 根据平台设置不同的trans_type值 + // 小程序: 71, App: 51 + const systemInfo = uni.getSystemInfoSync(); + let trans_type = 51; // 默认App环境 - // 根据供应商id获取自提点信息 - const ztAddress = this.defZTAddress.find(adItem => adItem.id == supplierId) || {}; - - return { - supplier_id: firstItem.supplier_id, - supplier_name: firstItem.supplier_name || '', - is_same_day: firstItem.commodity_goods_info.is_same_day, - receiving_name: ztAddress.name || '', - receiving_phone: ztAddress.phone || '', - receiving_address: ztAddress.address || '', - group_buy_activity_id: firstItem.commodity_goods_info.group_buy_activity_id, - goods_and_count: group.map(item => { - const activityInfo = item.commodity_goods_info.group_buy_activity_info; - const isGroupBuy = activityInfo && - currentTime >= new Date(activityInfo.start_time).getTime() && - currentTime <= new Date(activityInfo.end_time).getTime(); - return { - goods_id: item.goods_id, - count: item.count, - price: isGroupBuy ? item.commodity_goods_info.group_buy_price : item.commodity_goods_info.sales_price, - freight: item.commodity_goods_info.freight, - } - }) - } - }) + // 运行时判断是否为小程序环境 + if (systemInfo.platform === 'devtools' || systemInfo.platform === 'unknown') { + trans_type = 71; // 开发工具或未知环境默认为小程序 } + // 条件编译:针对不同平台设置不同值 + // #ifdef MP + trans_type = 71; // 所有小程序平台 + // #endif - request(apiArr.createOrder, "POST", params).then(resVal => { - // 根据平台设置不同的trans_type值 - // 小程序: 71, App: 51 - const systemInfo = uni.getSystemInfoSync(); - let trans_type = 51; // 默认App环境 - - // 运行时判断是否为小程序环境 - if (systemInfo.platform === 'devtools' || systemInfo.platform === 'unknown') { - trans_type = 71; // 开发工具或未知环境默认为小程序 - } - - // 条件编译:针对不同平台设置不同值 - // #ifdef MP - trans_type = 71; // 所有小程序平台 - // #endif - - // #ifdef APP-PLUS - trans_type = 51; // App平台 - // #endif + // #ifdef APP-PLUS + trans_type = 51; // App平台 + // #endif + // 如果存在isafterSale属性且为true,则跳过createOrder接口调用 + if (hasAfterSaleItem && orderIdFromAfterSale) { const param = { - order_id: resVal.order_id, + order_id: orderIdFromAfterSale, user_id: uni.getStorageSync('userId'), trans_type: trans_type } request(apiArr.mergePreorder, "POST", param).then(res => { + this.handleMergePreorderResponse(res, orderIdFromAfterSale); + }) + } else { + // 原始逻辑:创建订单后再进行支付 + const params = { + user_id: uni.getStorageSync('userId'), + is_group_buy: isGroupBuyValid, + goods_list: Object.keys(this.supplierGroups).map(supplierId => { + const group = this.supplierGroups[supplierId]; + const firstItem = group[0]; - if (res && res.timeStamp && res.nonceStr && res.package && res.signType && res.paySign) { - // 调用微信支付 - uni.requestPayment({ - timeStamp: res.timeStamp, - nonceStr: res.nonceStr, - package: res.package, - signType: res.signType, - paySign: res.paySign, - success: (payRes) => { - const params = { - order_id: resVal.order_id, - from: 2, - group_buy_activity_id: this.group_buy_activity_id, + // 团购活动id + this.group_buy_activity_id = firstItem.commodity_goods_info.group_buy_activity_id; + + // 根据供应商id获取自提点信息 + const ztAddress = this.defZTAddress.find(adItem => adItem.id == supplierId) || {}; + + return { + supplier_id: firstItem.supplier_id, + supplier_name: firstItem.supplier_name || '', + is_same_day: firstItem.commodity_goods_info.is_same_day, + receiving_name: ztAddress.name || '', + receiving_phone: ztAddress.phone || '', + receiving_address: ztAddress.address || '', + group_buy_activity_id: firstItem.commodity_goods_info.group_buy_activity_id, + goods_and_count: group.map(item => { + const activityInfo = item.commodity_goods_info.group_buy_activity_info; + const isGroupBuy = activityInfo && + currentTime >= new Date(activityInfo.start_time).getTime() && + currentTime <= new Date(activityInfo.end_time).getTime(); + return { + goods_id: item.goods_id, + count: item.count, + price: isGroupBuy ? item.commodity_goods_info.group_buy_price : item.commodity_goods_info.sales_price, + freight: item.commodity_goods_info.freight, } - request(apiArr.queryOrder, "POST", params).then(res => { - this.verifyCode = res.verification_code - this.boxshadow1 = true - }) - }, - fail: (payErr) => { - uni.showToast({ - title: payErr.errMsg == 'requestPayment:fail cancel' ? '用户取消支付' : '支付失败', - icon: 'none' - }) - }, - complete: () => { - // 支付完成后的回调,无论成功失败都会执行 - } + }) + } + }) + } + + request(apiArr.createOrder, "POST", params).then(resVal => { + const param = { + order_id: resVal.order_id, + user_id: uni.getStorageSync('userId'), + trans_type: trans_type + } + request(apiArr.mergePreorder, "POST", param).then(res => { + this.handleMergePreorderResponse(res, resVal.order_id); + }) + }) + } + }, + + // 处理mergePreorder接口的响应 + handleMergePreorderResponse(res, orderId) { + if (res && res.timeStamp && res.nonceStr && res.package && res.signType && res.paySign) { + // 调用微信支付 + uni.requestPayment({ + timeStamp: res.timeStamp, + nonceStr: res.nonceStr, + package: res.package, + signType: res.signType, + paySign: res.paySign, + success: (payRes) => { + const params = { + order_id: orderId, + from: 2, + group_buy_activity_id: this.group_buy_activity_id, + } + request(apiArr.queryOrder, "POST", params).then(res => { + this.verifyCode = res.verification_code + this.boxshadow1 = true }) - } else { - console.error("获取支付参数失败,缺少必要参数") + }, + fail: (payErr) => { uni.showToast({ - title: '获取支付信息失败', + title: payErr.errMsg == 'requestPayment:fail cancel' ? '用户取消支付' : '支付失败', icon: 'none' }) + }, + complete: () => { + // 支付完成后的回调,无论成功失败都会执行 } }) - }) + } else { + console.error("获取支付参数失败,缺少必要参数") + uni.showToast({ + title: '获取支付信息失败', + icon: 'none' + }) + } + } }, // 复制收货地址 copyAddress() {