From b40af3ea230df47026a902e96e4f8da50123a75b Mon Sep 17 00:00:00 2001 From: wwz <1144797966@qq.com> Date: Mon, 3 Mar 2025 18:13:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E8=B4=AD=E7=89=A9=E8=BD=A6?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81=E6=94=B9=E4=BB=B7?= =?UTF-8?q?=E5=8F=8A=E6=97=B6=E6=9B=B4=E6=96=B0=EF=BC=8C=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/api/order/index.js | 26 ++++ pages/order/index.vue | 2 +- pages/product/components/shoppingCartes.vue | 2 +- stores/pay.js | 133 +++++++++++++++++--- 4 files changed, 142 insertions(+), 21 deletions(-) diff --git a/common/api/order/index.js b/common/api/order/index.js index d063966..1b691f5 100644 --- a/common/api/order/index.js +++ b/common/api/order/index.js @@ -8,4 +8,30 @@ export const APIuserorder = (data) => { method: 'get', data: data }) +} + +//生成订单 +export const APIcreateOrder = (data) => { + return request({ + url: url + '/user/order/createOrder', + method: 'post', + data: data + }) +} + +//删除订单 +export const APIputuserorder = (data) => { + return request({ + url: url + '/user/order/' + data, + method: 'put' + }) +} + +//订单列表 +export const orderhistoryOrder = (data) => { + return request({ + url: url + '/user/order/historyOrder', + method: 'get', + data: data + }) } \ No newline at end of file diff --git a/pages/order/index.vue b/pages/order/index.vue index b303d7a..f067ffc 100644 --- a/pages/order/index.vue +++ b/pages/order/index.vue @@ -62,7 +62,7 @@ - + - + diff --git a/stores/pay.js b/stores/pay.js index e1821a4..c9caf91 100644 --- a/stores/pay.js +++ b/stores/pay.js @@ -11,8 +11,13 @@ import { APIpayltPayVip } from '@/common/api/pay.js' +import { + APIcreateOrder +} from '@/common/api/order/index.js' + export const Memberpay = defineStore('memberpay', { actions: { + //会员充值 actionspayltPayVip(data) { return new Promise(async (resolve, reject) => { try { @@ -51,16 +56,14 @@ export const Memberpay = defineStore('memberpay', { orderInfo: res.tradeNo, // 微信支付商户号 // #endif success: (res) => { - console.log(res) uni.hideLoading() - let pages = getCurrentPages() // #ifdef MP-WEIXIN uni.showToast({ title: "支付成功" }) + console.log('支付成功') resolve(res) // #endif - // #ifdef MP-ALIPAY if (res.resultCode == '9000') { uni.showToast({ @@ -75,35 +78,127 @@ export const Memberpay = defineStore('memberpay', { // #endif }, fail: (res) => { - uni.hideLoading() + setTimeout(() => { + uni.hideLoading() + }, 1000) reject(false) } }); } } catch (e) { - uni.hideLoading() + uni.showToast({ + title: "支付失败" + }) + setTimeout(() => { + uni.hideLoading() + }, 1000) reject(false) } }) }, - actionsltPayOrder() { + //下单支付 + actionsltPayOrder(data) { return new Promise(async (resolve, reject) => { - let res = await APIpayltPayOrder({ - shopId: uni.cache.get('shopId'), - checkOrderPay: {}, - // #ifdef MP-WEIXIN - payType: 'wechatPay', - openId: uni.cache.get('userInfo').wechatOpenId, - // #endif - // #ifdef MP-ALIPAY - payType: 'aliPay', - openId: uni.cache.get('alipayOpenId').wechatOpenId, - // #endif - returnUrl: '', - buyerRemark: '', + try { + let res = await APIpayltPayOrder({ + shopId: uni.cache.get('shopId'), + checkOrderPay: data.checkOrderPay, + // #ifdef MP-WEIXIN + payType: 'wechatPay', + openId: uni.cache.get('userInfo').wechatOpenId, + // #endif + // #ifdef MP-ALIPAY + payType: 'aliPay', + openId: uni.cache.get('alipayOpenId').wechatOpenId, + // #endif + returnUrl: '', + buyerRemark: data.buyerRemark, + }) + if (res) { + uni.showLoading({ + title: '加载中', + mask: true + }) + uni.requestPayment({ + // #ifdef MP-WEIXIN + provider: 'wxpay', //支付类型-固定值 + partnerid: res.appId, // 微信支付商户号 + timeStamp: res.timeStamp, // 时间戳(单位:秒) + nonceStr: res.nonceStr, // 随机字符串 + package: res.package, // 固定值 + signType: res.signType, //固定值 + paySign: res.paySign, //签名 + // #endif + // #ifdef MP-ALIPAY + provider: 'alipay', //支付类型-固定值 + orderInfo: res.tradeNo, // 微信支付商户号 + // #endif + success: (res) => { + uni.hideLoading() + // #ifdef MP-WEIXIN + uni.showToast({ + title: "支付成功" + }) + console.log('支付成功') + resolve(res) + // #endif + // #ifdef MP-ALIPAY + if (res.resultCode == '9000') { + uni.showToast({ + title: "支付成功" + }) + resolve(res) + } else { + uni.showToast({ + title: "支付失败" + }) + } + // #endif + }, + fail: (res) => { + setTimeout(() => { + uni.hideLoading() + }, 1000) + reject(false) + } + }); + } + } catch (e) { + uni.showToast({ + title: "支付失败" + }) + setTimeout(() => { + uni.hideLoading() + }, 1000) + reject(false) + } + }) + }, + + // 生成订单 + actionscreateOrder(data) { + return new Promise(async (resolve, reject) => { + let res = await APIcreateOrder({ + orderId: data.orderId, //多次下单时使用 + shopId: uni.cache.get('shopId'), //店铺Id + userId: uni.cache.get('userInfo').id || '', // + seatNum: data.seatNum, //用餐人数 + packFee: data.packFee, //打包费 + originAmount: data.originAmount, //订单原金额(包含打包费) 不含折扣价格 不含餐位费 + tableCode: uni.cache.get('tableCode'), //台桌编码 + dineMode: 'dine-in', //堂食 dine-in 外带 take-out 外卖 take-away + remark: data.remark, //备注 + placeNum: data.placeNum, //当前订单下单次数 + waitCall: data.waitCall //是否等叫 0 否 1 等叫 }) + if (res) { + resolve(res) + } else { + reject(false) + } }) } + } }); \ No newline at end of file