增加支付检测是否锁定
This commit is contained in:
@@ -5,10 +5,10 @@ ENV = development
|
|||||||
# VITE_API_WSS = 'wss://sockets.sxczgkj.com/wss'
|
# VITE_API_WSS = 'wss://sockets.sxczgkj.com/wss'
|
||||||
|
|
||||||
# 正式ws
|
# 正式ws
|
||||||
VITE_API_WSS = 'wss://czgeatws.sxczgkj.com/wss'
|
# VITE_API_WSS = 'wss://czgeatws.sxczgkj.com/wss'
|
||||||
|
|
||||||
# 本地ws
|
# 本地ws
|
||||||
# VITE_API_WSS = 'ws://192.168.1.31:2348'
|
VITE_API_WSS = 'ws://192.168.1.31:2348'
|
||||||
|
|
||||||
# 正式 php
|
# 正式 php
|
||||||
VITE_API_PHP_URL = 'https://newblockwlx.sxczgkj.cn/index.php/api'
|
VITE_API_PHP_URL = 'https://newblockwlx.sxczgkj.cn/index.php/api'
|
||||||
@@ -20,10 +20,10 @@ VITE_API_PHP_URL = 'https://newblockwlx.sxczgkj.cn/index.php/api'
|
|||||||
VITE_API_KP_URL = 'https://invoice.sxczgkj.cn/api'
|
VITE_API_KP_URL = 'https://invoice.sxczgkj.cn/api'
|
||||||
|
|
||||||
# 本地调试连接
|
# 本地调试连接
|
||||||
# VITE_API_URL = 'http://192.168.1.31/'
|
VITE_API_URL = 'http://192.168.1.31/'
|
||||||
|
|
||||||
# 线上测试
|
# 线上测试
|
||||||
# VITE_API_URL = 'https://tapi.cashier.sxczgkj.cn'
|
# VITE_API_URL = 'https://tapi.cashier.sxczgkj.cn'
|
||||||
|
|
||||||
# 线上正式
|
# 线上正式
|
||||||
VITE_API_URL = 'https://cashier.sxczgkj.com'
|
# VITE_API_URL = 'https://cashier.sxczgkj.com'
|
||||||
@@ -401,6 +401,7 @@ async function payTypeChange(index, item) {
|
|||||||
// if (item.disabled) return
|
// if (item.disabled) return
|
||||||
payActive.value = index;
|
payActive.value = index;
|
||||||
payType.value = item.payType;
|
payType.value = item.payType;
|
||||||
|
|
||||||
if (item.payType == "scanCode") {
|
if (item.payType == "scanCode") {
|
||||||
scanModalRef.value.show();
|
scanModalRef.value.show();
|
||||||
}
|
}
|
||||||
@@ -426,6 +427,10 @@ async function payTypeChange(index, item) {
|
|||||||
// 结算支付
|
// 结算支付
|
||||||
async function confirmOrder() {
|
async function confirmOrder() {
|
||||||
try {
|
try {
|
||||||
|
// 判断订单是否锁定
|
||||||
|
await goodsStore.isOrderLock({
|
||||||
|
table_code: goodsStore.orderListInfo.tableCode
|
||||||
|
})
|
||||||
if (payLoading.value) return
|
if (payLoading.value) return
|
||||||
// await staffPermission("yun_xu_shou_kuan");
|
// await staffPermission("yun_xu_shou_kuan");
|
||||||
if (payList.value[payActive.value].payType == "arrears") {
|
if (payList.value[payActive.value].payType == "arrears") {
|
||||||
@@ -448,7 +453,6 @@ async function confirmOrder() {
|
|||||||
if (props.selecttype == 0) {
|
if (props.selecttype == 0) {
|
||||||
payLoading.loading = true
|
payLoading.loading = true
|
||||||
await cashPay(payData.value);
|
await cashPay(payData.value);
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case "member-account":
|
case "member-account":
|
||||||
@@ -467,12 +471,16 @@ async function confirmOrder() {
|
|||||||
emit("paySuccess");
|
emit("paySuccess");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
payLoading.value = false;
|
||||||
|
if (error.code == 1003) {
|
||||||
|
ElMessage.error(error.msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (error.code == 701) {
|
if (error.code == 701) {
|
||||||
// 订单已过期需刷新购物车和订单
|
// 订单已过期需刷新购物车和订单
|
||||||
emit('orderExpired')
|
emit('orderExpired')
|
||||||
}
|
}
|
||||||
console.log(error);
|
|
||||||
payLoading.value = false;
|
|
||||||
scanModalRef.value.loading = false;
|
scanModalRef.value.loading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ import { useGlobal } from '@/store/global.js'
|
|||||||
import { formatDecimal } from '@/utils'
|
import { formatDecimal } from '@/utils'
|
||||||
import { microPay, queryOrderStatus, microPayVip, vipPay, queryPayStatus } from '@/api/order.js'
|
import { microPay, queryOrderStatus, microPayVip, vipPay, queryPayStatus } from '@/api/order.js'
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
|
import { useGoods } from "@/store/goods.js";
|
||||||
|
const goodsStore = useGoods();
|
||||||
|
|
||||||
const store = useUser();
|
const store = useUser();
|
||||||
const emits = defineEmits(["success", 'orderExpired']);
|
const emits = defineEmits(["success", 'orderExpired']);
|
||||||
@@ -111,6 +113,7 @@ const userPayWait = ref(false);
|
|||||||
const fastOrder = ref('')
|
const fastOrder = ref('')
|
||||||
|
|
||||||
const submitHandle = _.throttle(submitHandleAjax, 200);
|
const submitHandle = _.throttle(submitHandleAjax, 200);
|
||||||
|
const table_code = ref('')
|
||||||
|
|
||||||
// 提交扫码支付
|
// 提交扫码支付
|
||||||
async function submitHandleAjax() {
|
async function submitHandleAjax() {
|
||||||
@@ -118,6 +121,12 @@ async function submitHandleAjax() {
|
|||||||
try {
|
try {
|
||||||
if (!scanCode.value || scanCode.value.length > 18) return;
|
if (!scanCode.value || scanCode.value.length > 18) return;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
|
||||||
|
// 判断订单是否锁定
|
||||||
|
await goodsStore.isOrderLock({
|
||||||
|
table_code: goodsStore.orderListInfo.tableCode
|
||||||
|
})
|
||||||
|
|
||||||
if (props.selecttype == 0) {
|
if (props.selecttype == 0) {
|
||||||
// 下单扫码支付
|
// 下单扫码支付
|
||||||
if (props.payType == 'scanCode') {
|
if (props.payType == 'scanCode') {
|
||||||
@@ -174,6 +183,11 @@ async function submitHandleAjax() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
if (error.code === 211) {
|
if (error.code === 211) {
|
||||||
|
// 开始锁单
|
||||||
|
goodsStore.isOrderLock({
|
||||||
|
table_code: table_code.value
|
||||||
|
}, 'pay_lock')
|
||||||
|
|
||||||
userPayWait.value = true;
|
userPayWait.value = true;
|
||||||
fastOrder.value = error.data
|
fastOrder.value = error.data
|
||||||
autoCheckOrder()
|
autoCheckOrder()
|
||||||
@@ -213,6 +227,10 @@ const timer = ref(null)
|
|||||||
function autoCheckOrder() {
|
function autoCheckOrder() {
|
||||||
closeStateTimerFuc()
|
closeStateTimerFuc()
|
||||||
timer.value = setInterval(() => {
|
timer.value = setInterval(() => {
|
||||||
|
// 开始锁单
|
||||||
|
goodsStore.isOrderLock({
|
||||||
|
table_code: table_code.value
|
||||||
|
}, 'pay_lock')
|
||||||
checkPayStauts(false)
|
checkPayStauts(false)
|
||||||
}, 2000)
|
}, 2000)
|
||||||
}
|
}
|
||||||
@@ -274,6 +292,11 @@ async function checkPayStauts(tips = true) {
|
|||||||
// 扫码下单
|
// 扫码下单
|
||||||
const res = await queryOrderStatus({ orderId: props.payData.checkOrderPay.orderId });
|
const res = await queryOrderStatus({ orderId: props.payData.checkOrderPay.orderId });
|
||||||
if (res == "done") {
|
if (res == "done") {
|
||||||
|
// 支付成功,解锁订单
|
||||||
|
await goodsStore.isOrderLock({
|
||||||
|
table_code: table_code.value
|
||||||
|
}, 'pay_unlock')
|
||||||
|
|
||||||
userPayWait.value = false
|
userPayWait.value = false
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
scanCode.value = "";
|
scanCode.value = "";
|
||||||
@@ -342,6 +365,7 @@ const inputChange = _.debounce(function (e) {
|
|||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
dialogVisible.value = true;
|
dialogVisible.value = true;
|
||||||
|
table_code.value = goodsStore.orderListInfo.tableCode
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
inputRef.value.focus();
|
inputRef.value.focus();
|
||||||
}, 500);
|
}, 500);
|
||||||
@@ -357,6 +381,11 @@ function reset() {
|
|||||||
scanCode.value = "";
|
scanCode.value = "";
|
||||||
closeState.value = false
|
closeState.value = false
|
||||||
closeStateTime.value = 5
|
closeStateTime.value = 5
|
||||||
|
|
||||||
|
// 关闭锁单
|
||||||
|
goodsStore.isOrderLock({
|
||||||
|
table_code: table_code.value
|
||||||
|
}, 'pay_unlock')
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import _ from "lodash";
|
import _, { reject } from "lodash";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { productPage, categoryList } from "@/api/product_new.js";
|
import { productPage, categoryList } from "@/api/product_new.js";
|
||||||
@@ -827,7 +827,7 @@ export const useGoods = defineStore("goods", {
|
|||||||
this.cartInfo.discountInfo = discountInfo.join(",");
|
this.cartInfo.discountInfo = discountInfo.join(",");
|
||||||
},
|
},
|
||||||
// 购物车操作
|
// 购物车操作
|
||||||
async operateCart(data, operate_type = "add") {
|
operateCart(data, operate_type = "add") {
|
||||||
const socket = useSocket();
|
const socket = useSocket();
|
||||||
const store = useUser();
|
const store = useUser();
|
||||||
if (socket.online) {
|
if (socket.online) {
|
||||||
@@ -844,5 +844,33 @@ export const useGoods = defineStore("goods", {
|
|||||||
console.log("离线操作");
|
console.log("离线操作");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 判断订单是否锁单
|
||||||
|
isOrderLock(data, operate_type = "search_pay_lock") {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const socket = useSocket();
|
||||||
|
this.operateCart(data, operate_type);
|
||||||
|
socket.ws.addEventListener("message", (e) => {
|
||||||
|
let data = JSON.parse(e.data);
|
||||||
|
console.log("isOrderLock===", data);
|
||||||
|
|
||||||
|
if (data.operate_type == "search_pay_lock") {
|
||||||
|
if (data.status == 0) {
|
||||||
|
reject({
|
||||||
|
code: 1003,
|
||||||
|
msg: "其他用户正在支付该订单,请稍后再试!",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (data.status == 1) {
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user