增加支付检测是否锁定

This commit is contained in:
gyq 2025-05-10 09:13:13 +08:00
parent ca3b0eddbc
commit 4d939b2889
4 changed files with 74 additions and 9 deletions

View File

@ -5,10 +5,10 @@ ENV = development
# VITE_API_WSS = 'wss://sockets.sxczgkj.com/wss'
# 正式ws
VITE_API_WSS = 'wss://czgeatws.sxczgkj.com/wss'
# VITE_API_WSS = 'wss://czgeatws.sxczgkj.com/wss'
# 本地ws
# VITE_API_WSS = 'ws://192.168.1.31:2348'
VITE_API_WSS = 'ws://192.168.1.31:2348'
# 正式 php
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_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://cashier.sxczgkj.com'
# VITE_API_URL = 'https://cashier.sxczgkj.com'

View File

@ -401,6 +401,7 @@ async function payTypeChange(index, item) {
// if (item.disabled) return
payActive.value = index;
payType.value = item.payType;
if (item.payType == "scanCode") {
scanModalRef.value.show();
}
@ -426,6 +427,10 @@ async function payTypeChange(index, item) {
//
async function confirmOrder() {
try {
//
await goodsStore.isOrderLock({
table_code: goodsStore.orderListInfo.tableCode
})
if (payLoading.value) return
// await staffPermission("yun_xu_shou_kuan");
if (payList.value[payActive.value].payType == "arrears") {
@ -448,7 +453,6 @@ async function confirmOrder() {
if (props.selecttype == 0) {
payLoading.loading = true
await cashPay(payData.value);
} else {
}
break
case "member-account":
@ -467,12 +471,16 @@ async function confirmOrder() {
emit("paySuccess");
}
} catch (error) {
console.log(error);
payLoading.value = false;
if (error.code == 1003) {
ElMessage.error(error.msg)
return
}
if (error.code == 701) {
//
emit('orderExpired')
}
console.log(error);
payLoading.value = false;
scanModalRef.value.loading = false;
}
}

View File

@ -64,6 +64,8 @@ import { useGlobal } from '@/store/global.js'
import { formatDecimal } from '@/utils'
import { microPay, queryOrderStatus, microPayVip, vipPay, queryPayStatus } from '@/api/order.js'
import { ElMessage } from "element-plus";
import { useGoods } from "@/store/goods.js";
const goodsStore = useGoods();
const store = useUser();
const emits = defineEmits(["success", 'orderExpired']);
@ -111,6 +113,7 @@ const userPayWait = ref(false);
const fastOrder = ref('')
const submitHandle = _.throttle(submitHandleAjax, 200);
const table_code = ref('')
//
async function submitHandleAjax() {
@ -118,6 +121,12 @@ async function submitHandleAjax() {
try {
if (!scanCode.value || scanCode.value.length > 18) return;
loading.value = true;
//
await goodsStore.isOrderLock({
table_code: goodsStore.orderListInfo.tableCode
})
if (props.selecttype == 0) {
//
if (props.payType == 'scanCode') {
@ -174,6 +183,11 @@ async function submitHandleAjax() {
} catch (error) {
console.log(error);
if (error.code === 211) {
//
goodsStore.isOrderLock({
table_code: table_code.value
}, 'pay_lock')
userPayWait.value = true;
fastOrder.value = error.data
autoCheckOrder()
@ -213,6 +227,10 @@ const timer = ref(null)
function autoCheckOrder() {
closeStateTimerFuc()
timer.value = setInterval(() => {
//
goodsStore.isOrderLock({
table_code: table_code.value
}, 'pay_lock')
checkPayStauts(false)
}, 2000)
}
@ -274,6 +292,11 @@ async function checkPayStauts(tips = true) {
//
const res = await queryOrderStatus({ orderId: props.payData.checkOrderPay.orderId });
if (res == "done") {
//
await goodsStore.isOrderLock({
table_code: table_code.value
}, 'pay_unlock')
userPayWait.value = false
loading.value = false;
scanCode.value = "";
@ -342,6 +365,7 @@ const inputChange = _.debounce(function (e) {
function show() {
dialogVisible.value = true;
table_code.value = goodsStore.orderListInfo.tableCode
setTimeout(() => {
inputRef.value.focus();
}, 500);
@ -357,6 +381,11 @@ function reset() {
scanCode.value = "";
closeState.value = false
closeStateTime.value = 5
//
goodsStore.isOrderLock({
table_code: table_code.value
}, 'pay_unlock')
}
defineExpose({

View File

@ -1,4 +1,4 @@
import _ from "lodash";
import _, { reject } from "lodash";
import dayjs from "dayjs";
import { defineStore } from "pinia";
import { productPage, categoryList } from "@/api/product_new.js";
@ -827,7 +827,7 @@ export const useGoods = defineStore("goods", {
this.cartInfo.discountInfo = discountInfo.join("");
},
// 购物车操作
async operateCart(data, operate_type = "add") {
operateCart(data, operate_type = "add") {
const socket = useSocket();
const store = useUser();
if (socket.online) {
@ -844,5 +844,33 @@ export const useGoods = defineStore("goods", {
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();
}
}
});
});
},
},
});