Bladeren bron

Merge branch '2024鹅状元' of https://gogs.mtavip.com/wangguoyu/uniProject into 2024鹅状元

tanxue 1 maand geleden
bovenliggende
commit
85e17f629f
4 gewijzigde bestanden met toevoegingen van 846 en 84 verwijderingen
  1. 410 33
      pages/mall/detailDialog.vue
  2. 411 17
      pages/mall/mallPage.vue
  3. 25 25
      pages/my/index.vue
  4. 0 9
      utils/cacheManager.js

+ 410 - 33
pages/mall/detailDialog.vue

@@ -40,13 +40,22 @@
 						<icon :class="mxjtClass"></icon>
 					</view>
 				</view>
-				<view class="pay-status-box" v-if="showPayWay" @click="switchPayWay">
+				<view class="pay-status-box" v-if="payType =='weixin'&&currentPlatform =='android'"
+					@click="switchPayWay">
 					<icon class="wx-icon"></icon>微信
 				</view>
-				<view class="pay-status-box" v-if="!showPayWay" @click="switchPayWay">
+				<view class="pay-status-box" v-if="payType =='zhifubao'&&currentPlatform =='android'"
+					@click="switchPayWay">
 					<icon class="zfb-icon"></icon>支付宝
 				</view>
-				<view class="pay-btn" @click="handlePay">立即支付</view>
+				<view class="pay-status-box apple-status-box" v-if="currentPlatform =='ios'">
+					<icon class="apple-icon"></icon>apple
+				</view>
+
+				<view v-if="currentPlatform =='android'" class="open-svip-btn" @touchstart="creatOrder">立即支付
+				</view>
+				<view v-if="currentPlatform =='ios'" style="margin-top: 20rpx;" class="open-svip-btn"
+					@touchstart="creatOrderIos">立即支付</view>
 			</view>
 		</view>
 	</uni-popup>
@@ -56,9 +65,21 @@
 	import {
 		ref,
 		computed,
+		onMounted,
 		watch
 	} from 'vue';
-
+	import {
+		debounce,
+		toast
+	} from "@/utils/common";
+	import cacheManager from "@/utils/cacheManager.js";
+	import {
+		orderAdd,
+		orderPayAli,
+		orderPayWx,
+		orderPayApple,
+		orderCheck
+	} from "@/api/order.js"
 	const props = defineProps({
 		selectedList: { // 父组件传入的初始选中商品列表
 			type: Array,
@@ -66,23 +87,405 @@
 		}
 	});
 
-	const showPayWay = ref(true);
+	const payType = ref('weixin');
 	const mxjtClass = ref('mxjt-sq-icon');
 
 	// 本地维护的商品列表(独立于父组件)
 	const localList = ref([]);
 	const selectedIds = ref([]); // 存储选中项的id
+	let orderId = ref('');
 	// 本地选中状态管理
 	const localSelectedMap = ref({});
-
+	let currentPlatform = ref('android')
 	// 初始化本地数据
 	// 初始化数据
 	watch(() => props.selectedList, (newVal) => {
+
 		localList.value = [...newVal];
 		selectedIds.value = newVal.map(item => item.id); // 初始全部选中
+
 	}, {
 		immediate: true
 	});
+	onMounted(() => {
+		isIOSorAndroid()
+	})
+	const isIOSorAndroid = () => {
+		const systemInfo = uni.getSystemInfoSync();
+
+		console.log('systemInfo', systemInfo);
+
+		if (systemInfo.platform == 'ios') {
+
+			return currentPlatform.value = 'ios'
+		} else {
+			return currentPlatform.value = 'android'
+		}
+
+	}
+
+	function genggaiVip(data) {
+		uni.hideLoading();
+		const localList = cacheManager.get('auth').levelIdList || []
+		const mergeList = [...new Set([...localList, ...data.levelIdList])]
+		cacheManager.updateObject('auth', {
+			levelIdList: mergeList
+		})
+		toast("chenggong!!!! 之后跳转我的订单页面")
+
+		// if (formPage.value == 'my') {
+		// 	uni.redirectTo({
+		// 		url: '/pages/my/index'
+		// 	})
+		// } else {
+		// 	uni.redirectTo({
+		// 		url: '/pages/study/index'
+		// 	})
+		// }
+	}
+
+	const creatOrderIos = debounce((data => {
+
+
+		const selectedItems = localList.value
+			.filter(item => selectedIds.value.includes(item.id));
+		console.log('selectedItems', selectedItems);
+		const cardIds = selectedItems.map(item => item.id);
+		if (cardIds.length === 0) {
+			uni.showToast({
+				title: '请选择至少一个商品',
+				icon: 'none'
+			});
+			return;
+		}
+		uni.showLoading({
+			title: '',
+			mask: true
+		});
+		if (appleFlag.value.toString() == 'true') {
+			productId.value = 'llisoftEzhuangyuanceshi'
+		} else {
+			if (cardId.value == 1) {
+				productId.value = 'llisoftEzhuangyuan'
+			} else {
+				productId.value = 'llisoftEzhuangyuanYingyu'
+			}
+		}
+		let req = {
+			cardIds: cardIds
+		}
+		orderAdd(req).then(res => {
+			console.log('res', res);
+			if (res.code == 0) {
+				uni.hideLoading();
+				orderId.value = res.data.id
+				// 测试ios 1元
+				applePay()
+			} else {
+				uni.hideLoading();
+				return false
+				console.log('请求失败');
+			}
+		}).catch((e) => {
+			uni.hideLoading();
+			toast("订单创建失败")
+			return false
+
+		})
+
+
+	}), 500)
+
+	function applePaySuccess(data) {
+		uni.showLoading({
+			title: '会员开通中',
+			mask: true
+		});
+		let req = {
+			"id": orderId.value,
+			"paynum": data.transactionIdentifier,
+			"receipt": data.transactionReceipt
+		}
+		console.log('reqreq', req);
+		orderPayApple(req).then(res => {
+			if (res.code == 0 && res.data) {
+				iapChannel.finishTransaction(data.transactionIdentifier)
+				console.log('resiapChanneliapChanneliapChannel', res);
+				genggaiVip()
+			} else {
+				iapChannel.finishTransaction(data.transactionIdentifier)
+				uni.hideLoading();
+				toast("苹果内购失败")
+				console.log('orderPayApple失败');
+				return false
+			}
+		})
+	}
+
+	function applePay() {
+		console.log('123123');
+		if (!productId.value) {
+			uni.showToast({
+				title: '苹果内购ID缺失,请选择其它支付方式或联系客服',
+				icon: "none"
+			});
+			return false;
+		}
+		uni.showLoading({
+			title: '正在支付中...'
+		});
+		try {
+			plus.payment.getChannels(function(channels) { //判读项目支付通道开通情况
+					for (var i in channels) {
+						iapChannel = channels[i];
+						// 获取 id 为 'appleiap' 的 channel  
+						console.info("支付通道", iapChannel)
+						if (iapChannel.id === 'appleiap') { //开通了app应用内支付,在manifest.josn中设置,开通后需打自定议基座
+							console.info("苹果支付通道", iapChannel)
+							// ids 数组中的项为 App Store Connect 配置的内购买项目产品ID(productId)
+							var ids = [productId.value];
+							// iap 为应用内支付对象 
+							iapChannel.requestOrder(ids, function(e) {
+									// 获取订单信息成功回调方法  
+									console.log('requestOrder success: ' + JSON.stringify(e));
+									uni.requestPayment({
+										provider: 'appleiap',
+										orderInfo: {
+											productid: productId.value, //产品id,来自于苹果
+											quantity: quantity.value, //产品数量
+											manualFinishTransaction: true
+										},
+										success: (e) => {
+											uni.hideLoading();
+
+											//	toast("苹果内购成功")
+											console.info("苹果内购成功", e)
+											applePaySuccess(e)
+											//e.payment.orderNo = that.orderNo
+											//支付成功回调,前端调用后台接口
+										},
+										fail: (e) => {
+											uni.hideLoading();
+											toast("苹果内购失败")
+											console.info("苹果内购失败", e)
+										},
+									})
+								},
+								function(e) {
+									// 获取订单信息失败回调方法  
+									console.log('requestOrder failed: ' + JSON.stringify(e));
+								});
+						} else {
+							console.log('不支持苹果支付')
+						}
+					}
+				},
+				function(e) {
+					console.log("获取iap支付通道失败:" + e.message);
+				});
+
+		} catch (e) {
+			uni.showModal({
+				title: "init",
+				content: e.message,
+				showCancel: false
+			});
+		} finally {
+			uni.hideLoading();
+		}
+
+
+
+	}
+
+
+	function wxPay() {
+		orderPayWx({
+			id: orderId.value
+		}).then(res2 => {
+			uni.hideLoading();
+			console.log('res2', res2);
+			uni.requestPayment({
+				"provider": "wxpay",
+				"orderInfo": {
+					"appid": res2.data.appid, // 应用ID(AppID)
+					"partnerid": res2.data.partnerId, // 商户号(PartnerID)
+					"prepayid": res2.data.prepayId, // 预支付交易会话ID
+					"package": res2.data.packageVal, // 固定值
+					"noncestr": res2.data.nonceStr, // 随机字符串
+					"timestamp": res2.data.timestamp, // 时间戳(单位:秒)
+					"sign": res2.data.sign // 签名,这里用的 MD5 签名
+				}, //此处为服务器返回的订单信息字符串
+				success: function(res) {
+
+					//var rawdata = JSON.parse(res.rawdata);
+					//	console.log('res',res);	
+					//	console.log('支付成功');
+					//	console.log('rawdata', rawdata);
+					uni.showLoading({
+						title: '会员开通中,请稍后...'
+					});
+					orderCheck({
+						id: orderId.value
+					}).then(res3 => {
+						console.log('res3', res3);
+						if (res3.code == 0) {
+
+							genggaiVip(res3.data)
+						} else {
+							setTimeout(() => {
+								orderCheck({
+									id: orderId.value
+								}).then(res4 => {
+									if (res4.code == 0) {
+										genggaiVip(res4.data)
+									} else {
+										toast(
+											"开通失败,请联系管理员!"
+										)
+										uni
+											.hideLoading();
+										return false
+									}
+								}).catch(() => {
+									uni.hideLoading();
+									toast("check接口报错")
+									return false
+								})
+							}, 5000)
+						}
+					}).catch(() => {
+						uni.hideLoading();
+						toast("check接口报错")
+						return false
+					})
+
+				},
+				fail: function(err) {
+					uni.hideLoading();
+					//  toast('支付失败:' + JSON.stringify(err));
+					console.log('支付失败:' + JSON.stringify(err));
+				}
+			});
+		}).catch((error) => {
+			uni.hideLoading();
+
+			console.log(error);
+		})
+	}
+
+	function aliApy() {
+		orderPayAli({
+			id: orderId.value
+		}).then(res2 => {
+			console.log('res2', res2);
+			uni.hideLoading();
+			uni.requestPayment({
+				"provider": "alipay",
+				"orderInfo": res2.data.text, //此处为服务器返回的订单信息字符串
+				success: function(res) {
+					// var rawdata = JSON.parse(res.rawdata);
+					// console.log('支付成功');
+					// console.log('rawdata', rawdata);
+
+					uni.showLoading({
+						title: '会员开通中,请稍后...'
+					});
+					orderCheck({
+						id: orderId.value
+					}).then(res3 => {
+						if (res3.code == 0) {
+							genggaiVip(res3.data)
+						} else {
+							setTimeout(() => {
+								orderCheck({
+									id: orderId.value
+								}).then(res4 => {
+									if (res4.code ==
+										0) {
+										genggaiVip(res4.data)
+									} else {
+										toast(
+											"开通失败,请联系管理员!"
+										)
+										uni
+											.hideLoading();
+										return false
+									}
+								}).catch(() => {
+									uni.hideLoading();
+									toast("check接口报错")
+									return false
+								})
+							}, 5000)
+						}
+					}).catch(() => {
+						uni.hideLoading();
+						toast("check接口报错")
+						return false
+					})
+				},
+				fail: function(err) {
+					console.log('支付失败:' + JSON.stringify(err));
+					uni.hideLoading();
+				}
+			});
+		})
+	}
+
+	const creatOrder = debounce((data) => {
+
+		const selectedItems = localList.value
+			.filter(item => selectedIds.value.includes(item.id));
+		console.log('selectedItems', selectedItems);
+		const cardIds = selectedItems.map(item => item.id);
+		if (cardIds.length === 0) {
+			uni.showToast({
+				title: '请选择至少一个商品',
+				icon: 'none'
+			});
+			return;
+		}
+		console.log('123123123123');
+		uni.showLoading({
+			title: '',
+			mask: true
+		});
+		if (payType.value == 'weixin') {
+			console.log('创建订单11');
+			let req = {
+				cardIds: cardIds
+			}
+			orderAdd(req).then(res => {
+				console.log('res', res);
+				console.log(' res.data.id', res.data.id);
+				orderId.value = res.data.id
+				wxPay()
+			}).catch((err) => {
+				uni.hideLoading();
+				toast("订单创建失败")
+				return false
+			})
+
+		} else {
+			let req = {
+				cardIds: cardIds
+			}
+			orderAdd(req).then(res => {
+				console.log('res', res);
+				orderId.value = res.data.id
+				aliApy()
+			}).catch((err) => {
+				uni.hideLoading();
+				toast("订单创建失败")
+				return false
+			})
+
+		}
+
+	}, 500)
+
+
 
 
 	// 是否全选
@@ -112,37 +515,11 @@
 
 	// 支付方式切换
 	function switchPayWay() {
-		showPayWay.value = !showPayWay.value;
+		payType.value = payType.value == 'weixin' ? 'zhifubao' : 'weixin'
 	}
 
 	// 支付处理
-	function handlePay() {
-		// 获取选中商品的完整信息和cardId
-		const selectedItems = localList.value
-			.filter(item => selectedIds.value.includes(item.id));
-		console.log('selectedItems',selectedItems);
-		const cardIds = selectedItems.map(item => item.id);
-		const total = selectedItems.reduce((sum, item) => sum + parseFloat(item.xianjia || 0), 0);
-
-		if (cardIds.length === 0) {
-			uni.showToast({
-				title: '请选择至少一个商品',
-				icon: 'none'
-			});
-			return;
-		}
-		console.log('cardIds',cardIds);
 
-		// 构造支付数据
-		const paymentData = {
-			cardIds: cardIds,
-			items: selectedItems,
-			totalAmount: total.toFixed(2),
-			paymentMethod: showPayWay.value ? 'wechat' : 'alipay'
-		};
-
-
-	}
 
 	const detailPopup = ref(null);
 

+ 411 - 17
pages/mall/mallPage.vue

@@ -58,18 +58,20 @@
 				<view>购买即同意虚拟产品不支持退订</view>
 			</view>
 			<!-- 微信 -->
-			<view class="pay-status-box" v-if="showPayWay" @click="switchPayWay">
+			<view class="pay-status-box" v-if="payType =='weixin'&&currentPlatform =='android'" @click="switchPayWay">
 				<icon class="wx-icon"></icon>微信
 			</view>
-			<!-- 支付宝 -->
-			<view class="pay-status-box" v-if="!showPayWay" @click="switchPayWay">
+			<view class="pay-status-box" v-if="payType =='zhifubao'&&currentPlatform =='android'" @click="switchPayWay">
 				<icon class="zfb-icon"></icon>支付宝
 			</view>
-			<!-- 苹果 -->
-			<view class="pay-status-box apple-status-box" v-if="false">
+			<view class="pay-status-box apple-status-box" v-if="currentPlatform =='ios'">
 				<icon class="apple-icon"></icon>apple
 			</view>
-			<view class="pay-btn">立即支付</view>
+
+			<view v-if="currentPlatform =='android'" class="open-svip-btn" @touchstart="creatOrder">立即支付
+			</view>
+			<view v-if="currentPlatform =='ios'" style="margin-top: 20rpx;" class="open-svip-btn"
+				@touchstart="creatOrderIos">立即支付</view>
 		</view>
 		<detail-dialog ref="mallDetailPopup" :selected-list="getSelectedProducts"></detail-dialog>
 
@@ -89,10 +91,18 @@
 		getMallist
 	} from "@/api/productMall.js";
 	import {
+		orderAdd,
+		orderPayAli,
+		orderPayWx,
+		orderPayApple,
+		orderCheck
+	} from "@/api/order.js"
+	import {
 		onLoad
 	} from "@dcloudio/uni-app";
 	import {
 		toast,
+		debounce,
 		getUserIdentity
 	} from "@/utils/common";
 	import cacheManager from '@/utils/cacheManager.js';
@@ -113,6 +123,14 @@
 		list: [],
 		selectedIds: [] // 新增选中状态存储
 	})
+	let currentPlatform = ref('android')
+	const payType = ref('weixin');
+	let orderId = ref('');
+	let productId = ref(null)
+	let iapChannel = ref(null)
+	let quantity = ref(1)
+	let channel = ref('')
+	let appleFlag = ref('')
 	const totalPrice = computed(() => {
 		return productData.list
 			.filter(item => productData.selectedIds.includes(item.id))
@@ -123,13 +141,8 @@
 		return productData.list.filter(item => productData.selectedIds.includes(item.id));
 	});
 
-	function updateSelection(selectedIds) {
-		productData.selectedIds = selectedIds;
-
-	}
-
 	function switchPayWay() {
-		showPayWay.value = !showPayWay.value
+		payType.value = payType.value == 'weixin' ? 'zhifubao' : 'weixin'
 	}
 
 	function productBtn() {
@@ -137,6 +150,21 @@
 	}
 
 	function detailBtn() {
+
+
+		// // 获取选中商品的cardId列表
+		// const selectedProducts = productData.list.filter(
+		// 	item => productData.selectedIds.includes(item.id)
+		// );
+
+		// const cardIds = selectedProducts.map(item => item.id);
+		// console.log('cardIds', cardIds);
+
+		if (productData.selectedIds.length === 0) {
+			toast("请选择至少一个商品查看明细");
+			return;
+		}
+
 		showDetail.value = !showDetail.value;
 		if (showDetail.value) {
 			mxjtClass.value = 'mxjt-zk-icon';
@@ -147,17 +175,382 @@
 		}
 
 	}
+	const isIOSorAndroid = () => {
+		const systemInfo = uni.getSystemInfoSync();
+
+		console.log('systemInfo', systemInfo);
+
+		if (systemInfo.platform == 'ios') {
+
+			return currentPlatform.value = 'ios'
+		} else {
+			return currentPlatform.value = 'android'
+		}
+
+	}
+
+	function genggaiVip(data) {
+		uni.hideLoading();
+		const localList = cacheManager.get('auth').levelIdList || []
+		const mergeList = [...new Set([...localList, ...data.levelIdList])]
+		cacheManager.updateObject('auth', {
+			levelIdList: mergeList
+		})
+		toast("chenggong!!!! 之后跳转我的订单页面")
+
+		// if (formPage.value == 'my') {
+		// 	uni.redirectTo({
+		// 		url: '/pages/my/index'
+		// 	})
+		// } else {
+		// 	uni.redirectTo({
+		// 		url: '/pages/study/index'
+		// 	})
+		// }
+	}
 
-	function handlePay(item) {
+	const creatOrderIos = debounce((data => {
 		if (productData.selectedIds.length === 0) {
 			toast("请选择至少一个商品");
 			return;
 		}
-		// uni.redirectTo({
-		//   url: `/pages/pay/svip?cardIds=${productData.selectedIds.join(',')}&formPage=my`
-		// });
+		const selectedProducts = productData.list.filter(
+			item => productData.selectedIds.includes(item.id)
+		);
+
+		const cardIds = selectedProducts.map(item => item.id);
+		console.log('cardIds', cardIds);
+		uni.showLoading({
+			title: '',
+			mask: true
+		});
+		if (appleFlag.value.toString() == 'true') {
+			productId.value = 'llisoftEzhuangyuanceshi'
+		} else {
+			if (cardId.value == 1) {
+				productId.value = 'llisoftEzhuangyuan'
+			} else {
+				productId.value = 'llisoftEzhuangyuanYingyu'
+			}
+		}
+		let req = {
+			cardIds: cardIds
+		}
+		orderAdd(req).then(res => {
+			console.log('res', res);
+			if (res.code == 0) {
+				uni.hideLoading();
+				orderId.value = res.data.id
+				// 测试ios 1元
+				applePay()
+			} else {
+				uni.hideLoading();
+
+				return false
+				console.log('请求失败');
+			}
+		}).catch((e) => {
+			uni.hideLoading();
+
+			toast("订单创建失败")
+			return false
+
+		})
+
+
+	}), 500)
+
+	function applePaySuccess(data) {
+		uni.showLoading({
+			title: '会员开通中',
+			mask: true
+		});
+		let req = {
+			"id": orderId.value,
+			"paynum": data.transactionIdentifier,
+			"receipt": data.transactionReceipt
+		}
+		console.log('reqreq', req);
+		orderPayApple(req).then(res => {
+			if (res.code == 0 && res.data) {
+				iapChannel.finishTransaction(data.transactionIdentifier)
+				console.log('resiapChanneliapChanneliapChannel', res);
+				genggaiVip()
+			} else {
+
+				iapChannel.finishTransaction(data.transactionIdentifier)
+				uni.hideLoading();
+				toast("苹果内购失败")
+				console.log('orderPayApple失败');
+				return false
+			}
+		})
+	}
+
+	function applePay() {
+		console.log('123123');
+		if (!productId.value) {
+			uni.showToast({
+				title: '苹果内购ID缺失,请选择其它支付方式或联系客服',
+				icon: "none"
+			});
+			return false;
+		}
+		uni.showLoading({
+			title: '正在支付中...'
+		});
+		try {
+			plus.payment.getChannels(function(channels) { //判读项目支付通道开通情况
+					for (var i in channels) {
+						iapChannel = channels[i];
+						// 获取 id 为 'appleiap' 的 channel  
+						console.info("支付通道", iapChannel)
+						if (iapChannel.id === 'appleiap') { //开通了app应用内支付,在manifest.josn中设置,开通后需打自定议基座
+							console.info("苹果支付通道", iapChannel)
+							// ids 数组中的项为 App Store Connect 配置的内购买项目产品ID(productId)
+							var ids = [productId.value];
+							// iap 为应用内支付对象 
+							iapChannel.requestOrder(ids, function(e) {
+									// 获取订单信息成功回调方法  
+									console.log('requestOrder success: ' + JSON.stringify(e));
+									uni.requestPayment({
+										provider: 'appleiap',
+										orderInfo: {
+											productid: productId.value, //产品id,来自于苹果
+											quantity: quantity.value, //产品数量
+											manualFinishTransaction: true
+										},
+										success: (e) => {
+											uni.hideLoading();
+
+											//	toast("苹果内购成功")
+											console.info("苹果内购成功", e)
+											applePaySuccess(e)
+											//e.payment.orderNo = that.orderNo
+											//支付成功回调,前端调用后台接口
+										},
+										fail: (e) => {
+											uni.hideLoading();
+											toast("苹果内购失败")
+											console.info("苹果内购失败", e)
+										},
+									})
+								},
+								function(e) {
+									// 获取订单信息失败回调方法  
+									console.log('requestOrder failed: ' + JSON.stringify(e));
+								});
+						} else {
+							console.log('不支持苹果支付')
+						}
+					}
+				},
+				function(e) {
+					console.log("获取iap支付通道失败:" + e.message);
+				});
+
+		} catch (e) {
+			uni.showModal({
+				title: "init",
+				content: e.message,
+				showCancel: false
+			});
+		} finally {
+			uni.hideLoading();
+		}
+
+
+
+	}
+
+
+	function wxPay() {
+		orderPayWx({
+			id: orderId.value
+		}).then(res2 => {
+			uni.hideLoading();
+			console.log('res2', res2);
+			uni.requestPayment({
+				"provider": "wxpay",
+				"orderInfo": {
+					"appid": res2.data.appid, // 应用ID(AppID)
+					"partnerid": res2.data.partnerId, // 商户号(PartnerID)
+					"prepayid": res2.data.prepayId, // 预支付交易会话ID
+					"package": res2.data.packageVal, // 固定值
+					"noncestr": res2.data.nonceStr, // 随机字符串
+					"timestamp": res2.data.timestamp, // 时间戳(单位:秒)
+					"sign": res2.data.sign // 签名,这里用的 MD5 签名
+				}, //此处为服务器返回的订单信息字符串
+				success: function(res) {
+
+					//var rawdata = JSON.parse(res.rawdata);
+					//	console.log('res',res);	
+					//	console.log('支付成功');
+					//	console.log('rawdata', rawdata);
+					uni.showLoading({
+						title: '会员开通中,请稍后...'
+					});
+					orderCheck({
+						id: orderId.value
+					}).then(res3 => {
+						console.log('res3', res3);
+						if (res3.code == 0) {
+
+							genggaiVip(res3.data)
+						} else {
+							setTimeout(() => {
+								orderCheck({
+									id: orderId.value
+								}).then(res4 => {
+									if (res4.code == 0) {
+										genggaiVip(res4.data)
+									} else {
+										toast(
+											"开通失败,请联系管理员!"
+										)
+										uni
+											.hideLoading();
+										return false
+									}
+								}).catch(() => {
+									uni.hideLoading();
+									toast("check接口报错")
+									return false
+								})
+							}, 5000)
+						}
+					}).catch(() => {
+						uni.hideLoading();
+						toast("check接口报错")
+						return false
+					})
+
+				},
+				fail: function(err) {
+					uni.hideLoading();
+					//  toast('支付失败:' + JSON.stringify(err));
+					console.log('支付失败:' + JSON.stringify(err));
+				}
+			});
+		}).catch((error) => {
+			uni.hideLoading();
+
+			console.log(error);
+		})
+	}
+
+	function aliApy() {
+		orderPayAli({
+			id: orderId.value
+		}).then(res2 => {
+			console.log('res2', res2);
+			uni.hideLoading();
+			uni.requestPayment({
+				"provider": "alipay",
+				"orderInfo": res2.data.text, //此处为服务器返回的订单信息字符串
+				success: function(res) {
+					// var rawdata = JSON.parse(res.rawdata);
+					// console.log('支付成功');
+					// console.log('rawdata', rawdata);
+
+					uni.showLoading({
+						title: '会员开通中,请稍后...'
+					});
+					orderCheck({
+						id: orderId.value
+					}).then(res3 => {
+						if (res3.code == 0) {
+							genggaiVip(res3.data)
+						} else {
+							setTimeout(() => {
+								orderCheck({
+									id: orderId.value
+								}).then(res4 => {
+									if (res4.code ==
+										0) {
+										genggaiVip(res4.data)
+									} else {
+										toast(
+											"开通失败,请联系管理员!"
+										)
+										uni
+											.hideLoading();
+										return false
+									}
+								}).catch(() => {
+									uni.hideLoading();
+									toast("check接口报错")
+									return false
+								})
+							}, 5000)
+						}
+					}).catch(() => {
+						uni.hideLoading();
+						toast("check接口报错")
+						return false
+					})
+				},
+				fail: function(err) {
+					console.log('支付失败:' + JSON.stringify(err));
+					uni.hideLoading();
+				}
+			});
+		})
 	}
 
+	const creatOrder = debounce((data) => {
+
+		if (productData.selectedIds.length === 0) {
+			toast("请选择至少一个商品");
+			return;
+		}
+		// 获取选中商品的cardId列表
+		const selectedProducts = productData.list.filter(
+			item => productData.selectedIds.includes(item.id)
+		);
+
+		const cardIds = selectedProducts.map(item => item.id);
+		console.log('cardIds', cardIds);
+
+		uni.showLoading({
+			title: '',
+			mask: true
+		});
+		if (payType.value == 'weixin') {
+			console.log('创建订单11');
+			let req = {
+				cardIds: cardIds
+			}
+			orderAdd(req).then(res => {
+				console.log('res', res);
+				console.log(' res.data.id', res.data.id);
+				orderId.value = res.data.id
+				wxPay()
+			}).catch((err) => {
+				uni.hideLoading();
+				toast("订单创建失败")
+				return false
+			})
+
+		} else {
+
+			let req = {
+				cardIds: cardIds
+			}
+			orderAdd(req).then(res => {
+				console.log('res', res);
+				orderId.value = res.data.id
+				aliApy()
+			}).catch((err) => {
+				uni.hideLoading();
+				toast("订单创建失败")
+				return false
+			})
+
+		}
+
+	}, 500)
+
 	function onChangeTab(e) {
 		console.log('e', e);
 		productData.current = e.currentIndex
@@ -241,8 +634,9 @@
 		} else {
 			productData.current = Number(cacheManager.get('auth').subjectId) - 1
 		}
-
+		//isIOSorAndroid()
 		getMore();
+
 	})
 </script>
 

+ 25 - 25
pages/my/index.vue

@@ -351,36 +351,36 @@
 
 	// 获取会员权益card class
 	function getHyqyClass(index) {
-		let VipIndex = index + 1;
-		if (cacheManager.get('auth')) {
-			// 非游客
-			let VipArr = cacheManager.get('auth').cardList;
-			if (VipArr.includes(VipIndex)) {
-				return 'hyqy-box' + VipIndex;
-			} else {
-				return 'hyqy-disabled-box' + VipIndex;
-			}
-		} else {
-			// 游客
-			return 'yk-disabled-box';
-		}
+		// let VipIndex = index + 1;
+		// if (cacheManager.get('auth')) {
+		// 	// 非游客
+		// 	let VipArr = cacheManager.get('auth').cardList;
+		// 	if (VipArr.includes(VipIndex)) {
+		// 		return 'hyqy-box' + VipIndex;
+		// 	} else {
+		// 		return 'hyqy-disabled-box' + VipIndex;
+		// 	}
+		// } else {
+		// 	// 游客
+		// 	return 'yk-disabled-box';
+		// }
 
 	}
 
 	//获取会员权益按钮是否显示
 	function getHyqyBtn(index) {
-		let VipIndex = index + 1;
-		if (cacheManager.get('auth')) {
-			let VipArr = cacheManager.get('auth').cardList;
-			if (VipArr.includes(VipIndex)) {
-				return false;
-			} else {
-				return true;
-			}
-		} else {
-			// 游客
-			return false;
-		}
+		// let VipIndex = index + 1;
+		// if (cacheManager.get('auth')) {
+		// 	let VipArr = cacheManager.get('auth').cardList;
+		// 	if (VipArr.includes(VipIndex)) {
+		// 		return false;
+		// 	} else {
+		// 		return true;
+		// 	}
+		// } else {
+		// 	// 游客
+		// 	return false;
+		// }
 	}
 	function isIOSorAndroid(){
 		const systemInfo = uni.getSystemInfoSync();

+ 0 - 9
utils/cacheManager.js

@@ -55,14 +55,6 @@ const cacheManager = (function() {
 		}
 		set(key, obj);
 	}
-	// 更新会员
-	function updateVipStatus(key, cardId) {
-		let obj = get(key) || {};
-		if (!obj.cardList.includes(cardId)) {
-			obj.cardList.push(Number(cardId));
-		}
-		set(key, obj);
-	}
 	// 获得当前jie参数
 	function getCurrentJieData(key, index, currentJieId) {
 		let obj = get(key) || {};
@@ -123,7 +115,6 @@ const cacheManager = (function() {
 		updateJieStatus,
 		getCurrentJieData,
 		updateObject,
-		updateVipStatus,
 		findArrayInObject,
 		clearAll
 	};