puyao před 1 měsícem
rodič
revize
0c9b94752d

+ 4 - 1
api/payment.js

@@ -5,7 +5,10 @@ let request = new Request().http
  export function payment(data) {
  	 return request('/app/payment/payment',data,'POST','application/json;charset=UTF-8');
  }
-  
+ //查询订单详情
+  export function checkpayment(data) {
+  	 return request('/app/storeOrder/getStoreOrderByOrderIdTz',data,'GET');
+  } 
  
  
  

+ 2 - 2
common/request.js

@@ -2,8 +2,8 @@
 export default class Request {
 	http(router, data = {}, method,contentType) {
 		let that = this;
-		// let path = 'http://111.230.193.88:7014';
-		let path = 'https://api.zxfh.cdwjyyh.com'; 
+		let path =  'http://192.168.10.122:7014';
+		// let path = 'https://api.zxfh.cdwjyyh.com'; 
 		uni.setStorageSync('requestPath',path)
 		// uni.showLoading({
 		// 	title: '加载中'

+ 2 - 2
pages_user/user/otherPaymentOrder.vue

@@ -52,7 +52,7 @@
 </template>
 
 <script>
-	import {otherPayment,getStoreOrderById} from '@/api/storeOrder'
+	import {otherPayment,getStoreOrderById,getMyStoreOrderById} from '@/api/storeOrder'
 	export default {
 		data() {
 			return {
@@ -128,7 +128,7 @@
 					res => {
 						if(res.code==200){
 							console.log('json;;;;;',res.result)
-							var result=JSON.parse(res.result);
+							var result=res.result;
 							wx.navigateToMiniProgram({
 								   appId: 'wx1b63de1096c46cde', // 收银台小程序 AppId 固定值
 								   path: '/pages/pay/pay', // 收银台小程序 固定路径

+ 34 - 7
pages_user/user/pay.vue

@@ -29,7 +29,7 @@
 </template>
 
 <script>
-	import {payment} from '@/api/payment'
+	import {payment,checkpayment} from '@/api/payment'
 	export default {
 		data() {
 			return {
@@ -38,6 +38,9 @@
 				desc:"",
 				money:null,
 				wxPay: true,
+				checkTimer: null, // 轮询定时器 ID
+				maxRetryCount: 10, // 最大轮询次数(可选)
+				retryCount: 0      // 当前轮询次数(可选)
 			}
 		},
 		onLoad: function(options) {
@@ -53,6 +56,10 @@
 		 //   }
 			this.companyId=options.companyId;
 		 	this.companyUserId=options.companyUserId;
+			if (this.checkTimer) {
+			    clearInterval(this.checkTimer);
+			    this.checkTimer = null;
+			  }
 		},
 		onShareAppMessage(res) {
 			return {
@@ -98,7 +105,7 @@
 				payment(data).then(
 					res => {
 						if(res.code==200){
-							 console.log(res);
+							 console.log(1111,res);
 							 var result=res.result;
               wx.navigateToMiniProgram({
                 appId: 'wx1b63de1096c46cde', // 收银台小程序 AppId 固定值
@@ -116,15 +123,35 @@
                   uni.showLoading({
                     title:"查询支付结果中..."
                   })
-				  setTimeout(()=>{
-					 uni.navigateTo({
-					 	url: 'pages_user/user/storeOrder'
-					 })
-				  },4000)
+				 // 启动定时器并保存 ID
+				   that.checkTimer = setInterval(() => {
+							 const data = { orderId: result.payCode };
+							 checkpayment(data).then(res => {
+							   if (res.code == 200) {
+								   console.log(res)
+								 if (res.status == 3) {
+								   // 跳转前清除定时器
+								   clearInterval(that.checkTimer);
+								   uni.navigateTo({
+									  url: './success'
+								   });
+								 }else{
+									 setTimeout(()=>{
+										 clearInterval(that.checkTimer);
+										 	uni.showToast({
+										 		icon:'none',
+										 		title: "用户未支付",
+										 	});
+									 },500)
+								 }
+							   }
+							 });
+				   }, 4000);
                   console.log(res)
 // 接口调用成功的回调函数
                 },
                 fail(res) {
+					if (that.checkTimer) clearInterval(that.checkTimer);
 // 接口调用失败的回调函数
                 }
               })