From c15705614c8aa96aff4c3c7f1d8fe0028bc214ce Mon Sep 17 00:00:00 2001 From: wangfukang <15630117759@163.com> Date: Tue, 24 Mar 2026 13:32:55 +0800 Subject: [PATCH] 0 --- package1/buyFood/buyFood.vue | 154 ++++++++++++++++++++---------- package1/group/groupBuySingle.vue | 30 ++++-- 2 files changed, 127 insertions(+), 57 deletions(-) diff --git a/package1/buyFood/buyFood.vue b/package1/buyFood/buyFood.vue index 94bd53c..6f97722 100644 --- a/package1/buyFood/buyFood.vue +++ b/package1/buyFood/buyFood.vue @@ -230,7 +230,7 @@ 支付剩余时间 59:09 - ¥{{totalAmountCalc.toFixed(2)}} + ¥{{backendTotalAmount ? backendTotalAmount.toFixed(2) : totalAmountCalc.toFixed(2)}} 若拼团失败,将会为您自动退款 @@ -287,7 +287,9 @@ isFaceToFace: false, assignedWorker: null, immediateTimeStr: '', - totalPackageFee: 0 + totalPackageFee: 0, + backendTotalAmount: 0, + currentOrderId: '' } }, components: { @@ -335,6 +337,8 @@ }, deliveryFeeCalc() { if(!this.isPaotui) return 0; + let isJoiningFaceToFace = this.isGroupBuy && this.groupItem && this.groupItem.groupId && this.groupItem.isFaceToFace; + if (isJoiningFaceToFace) return 0; // Front-end doesn't know exact fee, relies on backend after order creation let commission = 0; if(this.selected === 'zhiding') { if (!this.assignedWorker) return 0; @@ -344,7 +348,7 @@ commission = parseFloat(this.customCommission); } } - if(this.isGroupBuy && this.groupItem) { + if(this.isGroupBuy && this.groupItem && this.groupItem.isFaceToFace && !this.groupItem.groupId) { let members = parseInt(this.groupItem.groupRule.groupCount) || 1; if(this.selected === 'zhiding') { let extra = members > 2 ? (members - 2) * 0.5 : 0; @@ -415,13 +419,14 @@ return arr.join(','); }, submitPay(){ - if(this.isPaotui && !this.formData.address) { + let isJoiningFaceToFace = this.isGroupBuy && this.groupItem && this.groupItem.groupId && this.groupItem.isFaceToFace; + if(this.isPaotui && !this.formData.address && !isJoiningFaceToFace) { this.warnPopup = 'shdz'; this.$refs.warnPopup.open(); return; } - if(this.isPaotui && this.selected === 'buzhiding') { + if(this.isPaotui && this.selected === 'buzhiding' && !isJoiningFaceToFace) { let comm = parseFloat(this.customCommission); if (isNaN(comm) || comm <= 0) { this.warnPopup = 'psyj'; @@ -430,14 +435,14 @@ } } - if(this.isPaotui && this.selected === 'zhiding' && !this.assignedWorker) { + if(this.isPaotui && this.selected === 'zhiding' && !this.assignedWorker && !isJoiningFaceToFace) { this.warnPopup = 'psy'; this.$refs.warnPopup.open(); return; } - // Validation successful, open the payment popup - this.$refs.payPopup.open('bottom'); + // Validation successful, submit order to backend first to get backendTotalAmount + this.submitOrderToBackend(); }, goDetail(){ // Pass match conditions to worker list @@ -473,17 +478,18 @@ this.assignedWorker = null; } }, - //微信支付测试 wxPayment() { let that = this; - let amountInCents = Math.round(this.totalAmountCalc * 100); + if (!this.currentOrderId || !this.backendTotalAmount) return; + + let amountInCents = Math.round(this.backendTotalAmount * 100); let payDesc = this.isGroupBuy ? '拼团订单' : '商城订单'; this.tui.request("/api/wechat/pay/unified-order", "POST", { - openid: uni.getStorageSync('miniProgramOpenid'), + openid: uni.getStorageSync('miniProgramOpenid') || 'test-openid', amount: amountInCents, // 支付金额(分) description: payDesc, - outTradeNo: 'ORDER_' + Date.now() + outTradeNo: this.currentOrderId }, false, false).then((res) => { if (res.code == 200) { uni.requestPayment({ @@ -494,28 +500,57 @@ signType: res.signType, paySign: res.paySign, success: function(res2) { - console.log('success:' + JSON.stringify(res2)); that.$refs.payPopup.close(); - that.submitOrderToBackend(); + uni.showToast({ title: '支付成功', icon: 'success' }); + setTimeout(() => { + uni.navigateBack({ delta: 2 }); + }, 1500); }, fail: function(err) { - console.log('fail:' + JSON.stringify(err)); that.tui.toast("支付失败或取消"); } }); } else { - this.tui.toast(res.message) + // 模拟支付成功(用于测试环境) + if (res.code == 404 || res.code == 500 || res.code == 400 || !res.code) { + that.tui.request(`/hiver/order/payMallOrderSuccess?orderId=${that.currentOrderId}&workerId=${that.assignedWorker ? that.assignedWorker.workerId : ''}`, "POST", {}, false, false).then(res2 => { + that.$refs.payPopup.close(); + uni.showToast({ title: '支付成功(模拟)', icon: 'none' }); + setTimeout(() => { + uni.navigateBack({ delta: 2 }); + }, 1500); + }).catch(e => { + that.tui.toast("请求失败"); + }); + } else { + that.tui.toast(res.message); + } } }) }, + getMustFinishTime() { + if (!this.formData.deliveryTime || this.formData.deliveryTime === '自动送达' || this.formData.deliveryTime === '尽快送达') return null; + let timeStr = this.formData.deliveryTime; + if(timeStr.length === 5) { + let [h, m] = timeStr.split(':'); + let targetHour = parseInt(h); + let d = new Date(); + if (targetHour < d.getHours()) d.setDate(d.getDate() + 1); + let yyyy = d.getFullYear(); + let MM = String(d.getMonth() + 1).padStart(2, '0'); + let DD = String(d.getDate()).padStart(2, '0'); + return `${yyyy}-${MM}-${DD}T${timeStr}:00`; + } + return null; + }, submitOrderToBackend() { + let isJoiningFaceToFace = this.isGroupBuy && this.groupItem && this.groupItem.groupId && this.groupItem.isFaceToFace; + let items = []; if(this.isGroupBuy && this.groupItem) { items.push({ productId: this.groupItem.item.id, - productName: this.groupItem.item.productName, - productPicture: this.groupItem.item.productPicture, - specs: this.getSpecDisplayString(this.groupItem.specs), + specs: JSON.stringify(this.groupItem.specs || {}), price: parseFloat(this.groupItem.groupRule.groupPrice), quantity: 1 }); @@ -523,58 +558,77 @@ for(let cart of this.cartItems) { items.push({ productId: cart.item.id, - productName: cart.item.productName, - productPicture: cart.item.productPicture, - specs: this.getSpecDisplayString(cart.specs), + specs: JSON.stringify(cart.specs || {}), price: parseFloat(cart.price), quantity: cart.quantity }); } } + let deliveryType = this.isPaotui ? 1 : 2; let payload = { userId: uni.getStorageSync('id') || 'test-user123', shopId: this.shopItem.id, - orderType: this.isGroupBuy ? 2 : 1, - deliveryType: this.isPaotui ? 1 : 2, - totalAmount: this.totalAmountCalc, - goodsAmount: this.goodsAmountCalc, + deliveryType: deliveryType, packageFee: this.packageFee, - addressId: this.isPaotui && this.formData.address ? this.formData.address.id : null, - getAreaId: this.shopItem.shopArea || null, - putAreaId: this.isPaotui && this.formData.address ? this.formData.address.areaId : null, - items: items + remark: '', + items: items, + receiverName: this.formData.address ? this.formData.address.receiverName : '', + receiverPhone: this.formData.address ? this.formData.address.phone : '', + receiverAddress: this.formData.address ? ((this.formData.address.areaName || '') + (this.formData.address.floor ? this.formData.address.floor + '层' : '') + (this.formData.address.roomNum || '')) : '', + shopName: this.shopItem.shopName, + shopPhone: this.shopItem.shopPhone || '', + shopAddress: this.shopItem.shopAddress || '' }; - if(this.isGroupBuy && this.groupItem) { - payload.groupTargetMembers = parseInt(this.groupItem.groupRule.groupCount); - payload.groupPrice = parseFloat(this.groupItem.groupRule.groupPrice); + let mft = this.getMustFinishTime(); + if(mft) payload.mustFinishTime = mft; + + if (deliveryType === 1 && !isJoiningFaceToFace) { + payload.addressId = this.formData.address ? this.formData.address.id : null; + payload.getAreaId = this.shopItem.shopArea || null; + payload.putAreaId = this.formData.address ? this.formData.address.areaId : null; } - if(this.isPaotui) { - if(this.selected === 'zhiding' && this.assignedWorker) { - payload.workerId = this.assignedWorker.workerId; - payload.workerCommission = parseFloat(this.assignedWorker.orderBkge || 0); + if(this.isGroupBuy && this.groupItem) { + if (this.groupItem.groupId) { + payload.groupId = this.groupItem.groupId; } else { - payload.workerCommission = parseFloat(this.customCommission || 0); // Default unassigned pool + payload.groupParam = { + targetMembers: parseInt(this.groupItem.groupRule.groupCount), + isFaceToFace: this.groupItem.isFaceToFace ? 1 : 0, + selfCommission: this.selected === 'buzhiding' ? parseFloat(this.customCommission || 0) : null + }; } } - - uni.showLoading({ title: '提交中' }); - this.tui.request("/order/submitMallOrder", "POST", payload, false, false).then(res => { + + if (this.isPaotui && !isJoiningFaceToFace) { + if (this.selected === 'zhiding' && this.assignedWorker) { + payload.workerParam = { + workerId: this.assignedWorker.workerId, + orderBkge: parseFloat(this.assignedWorker.orderBkge || 0) + }; + } else if (this.selected === 'buzhiding') { + payload.workerParam = { + orderBkge: parseFloat(this.customCommission || 0) + }; + } + } + + uni.showLoading({ title: '创建订单中...' }); + this.tui.request("/mall/order/create", "POST", payload, false, false).then(res => { uni.hideLoading(); - if(res.code == 200) { - let orderId = res.result; - // Simulate successful payment instantly - this.tui.request(`/hiver/order/payMallOrderSuccess?orderId=${orderId}&workerId=${payload.workerId || ''}`, "POST", {}, false, false).then(res2 => { - uni.showToast({ title: '支付成功并生成对应详情', icon: 'none' }); - setTimeout(() => { - uni.navigateBack({ delta: 2 }); - }, 1500); - }); + if(res.success && res.result) { + let orderId = res.result.id; + let totalAmount = res.result.totalAmount; + this.backendTotalAmount = totalAmount; + this.currentOrderId = orderId; + this.$refs.payPopup.open('bottom'); } else { uni.showToast({ title: res.message || '下单失败', icon: 'none' }); } + }).catch(err => { + uni.hideLoading(); }); }, //时间选择器获取时间数据 diff --git a/package1/group/groupBuySingle.vue b/package1/group/groupBuySingle.vue index 54a7316..824e957 100644 --- a/package1/group/groupBuySingle.vue +++ b/package1/group/groupBuySingle.vue @@ -318,12 +318,19 @@ - - 面对面团 - - - 拼团购买¥{{selectedGroupRule && selectedGroupRule.groupPrice ? parseFloat(selectedGroupRule.groupPrice).toFixed(2) : '0.00'}} - + + 加入购物车 @@ -366,6 +373,8 @@ }, menuButtonInfo: {}, isPintuan:true, + groupId: '', + isFaceToFaceGroup: false, menuList:[{ categoryName:'猜你喜欢', id:'', @@ -442,6 +451,12 @@ }, onLoad(option) { this.type = option.type; + if (option.groupId) { + this.groupId = option.groupId; + } + if (option.isFaceToFace) { + this.isFaceToFaceGroup = option.isFaceToFace === '1' || option.isFaceToFace === 'true'; + } if (this.type == 'shop') { this.shopItem = JSON.parse(option.item); } else { @@ -617,7 +632,8 @@ groupRule: this.selectedGroupRule, specs: specChoices, orderType: 2, // 2 indicates Group Buy - isFaceToFace: isFaceToFace || false + groupId: this.groupId, + isFaceToFace: this.groupId ? this.isFaceToFaceGroup : (isFaceToFace || false) }; // Directly navigate to checkout uni.navigateTo({