潘超林 1 viikko sitten
vanhempi
commit
91ea8493ad
7 muutettua tiedostoa jossa 287 lisäystä ja 201 poistoa
  1. 35 8
      api/index.js
  2. 6 6
      api/request.js
  3. 3 3
      app.config.js
  4. 3 3
      pages/index/index.vue
  5. 77 128
      pages/index/pay-zfb.vue
  6. 162 52
      pages/index/pay.vue
  7. 1 1
      unpackage/dist/build/web/index.html

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 35 - 8
api/index.js


+ 6 - 6
api/request.js

@@ -152,9 +152,9 @@ class Request {
 
 		// 添加授权信息
 		const token = this.getToken();
-		// if (token && !headers['Authorization']) {
-		// 	headers['Authorization'] = 'Bearer ' + token;
-		// }
+		if (token && !headers['Authorization']) {
+			headers['Authorization'] = 'Bearer ' + token;
+		}
 
 		// 流式请求需要特殊处理
 		if (param.isStream) {
@@ -210,16 +210,16 @@ class Request {
 								// this.handleError({ code: 501 }, param)
 								// 	.then(refreshedRes => resolve(refreshedRes))
 								// 	.catch(err => reject(err));
-								
+
 								uni.reLaunch({
 									url:
 										"/pages/index/index?shopId=" + uni.getStorageSync('shopId'),
-								});	
+								});
 								localStorage.clear();
 							} else if (res.data.code === 400 && res.data.msg === '登录凭证不为空') {
 								const error = new Error(res.data.msg);
 								error.response = res;
-								
+
 								// if (showToast) {
 								uni.reLaunch({
 									url:

+ 3 - 3
app.config.js

@@ -4,11 +4,11 @@
 export const requestConfig = {
 	/**接口请求地址 */
 	BaseUrl: '/api',
-	// BaseUrl: 'https://app.sxdirectpurchase.com/api/',
+	// BaseUrl: 'https://pay.ai-tianshucloud.com/api',
 	/**微信信息*/
 	/**授权回调地址 */
 	// 授权后重定向的回调链接地址, 请使用 urlEncode 对链接进行处理
-	// wx_redirect_uri: "https://ne.sxdirectpurchase.com/#/pages/index/pay",
+	// wx_redirect_uri: "https://pay.ai-tianshucloud.com/#/pages/index/pay",
 	wx_redirect_uri: "http://192.168.124.7:80/#/pages/index/pay",
 	// wx_redirectOpen: "https://ne.sxdirectpurchase.com/#/pages/index/paySuccess",
 	/**公众号信息 */
@@ -34,7 +34,7 @@ export const requestConfig = {
 
 	//支付宝回调地址
 	// zfb_redirect_uri: "http://192.168.3.183:80/#/pages/index/pay-zfb",
-	zfb_redirect_uri: "https://ne.sxdirectpurchase.com/#/pages/index/pay-zfb",
+	zfb_redirect_uri: "https://pay.ai-tianshucloud.com/#/pages/index/pay-zfb",
 
 	// farming-ne
 

+ 3 - 3
pages/index/index.vue

@@ -50,6 +50,7 @@ export default {
 	},
 	onLoad(options) {
 		this.shopId = options.shopId;
+		this.storeId = options.storeId;
 		this.uid = options.uid || '';
 		let alipayuserinfo = localStorage.getItem("aliPayUserInfo")
 		let wechatuserinfo = localStorage.getItem("weChatUserInfo")
@@ -91,14 +92,13 @@ export default {
 					&redirect_uri=${encodeURIComponent(requestConfig.zfb_redirect_uri)}
 					&state=STATE
 					&shopId=${this.shopId}
-					${this.uid ? '&uid=' + this.uid : ''}
+					&storeId=${this.storeId}
 					&type=zfb`
-			console.log(url);
 			window.location = url;
 		},
 		wxLink() {
 			/*微信授权登录*/
-			let redirect_uri = encodeURIComponent(requestConfig.wx_redirect_uri + '?shopId=' + this.shopId)
+			let redirect_uri = encodeURIComponent(requestConfig.wx_redirect_uri + '?shopId=' + this.shopId + '&storeId=' + this.storeId)
 			let url = `https://open.weixin.qq.com/connect/oauth2/authorize?
 							appid=${requestConfig.wx_appid}
 							&redirect_uri=${redirect_uri}

+ 77 - 128
pages/index/pay-zfb.vue

@@ -18,8 +18,8 @@
 
 			<view class="login-contont">
 				<view class="uInput">
-					<u-input placeholder="请输入金额" border="bottom" :fontSize="40" type="digit"
-						@change="validateInput($event, 1)" v-model="price" :customStyle="inpustyle">
+					<u-input placeholder="请输入金额" border="bottom" :fontSize="40" type="digit" v-model="price"
+						:customStyle="inpustyle">
 						<span slot="prefix" style="font-size: 30px">¥</span>
 					</u-input>
 				</view>
@@ -73,11 +73,11 @@
 	</view>
 </template>
 <script>
+import api from "@/api/index.js";
 import ap from "../../static/zfb.js"
 import {
 	requestConfig
 } from "@/app.config.js";
-import axios from "axios";
 export default {
 	data() {
 		return {
@@ -113,171 +113,120 @@ export default {
 		let info = localStorage.getItem('aliPayUserInfo');
 		this.localUserInfo = JSON.parse(info)
 		if (this.localUserInfo) {
-			this.vidTokenExist()
-		} else {
 			this.getShopInfo();
+		} else {
 			this.getInfo();
 		}
 	},
 	methods: {
-		async vidTokenExist() {
-			let res = await axios.get(
-				`${requestConfig.BaseUrl}user/app/v1/user/vidTokenExist`, {
-				headers: {
-					'token': `${this.localUserInfo.token}`
-				}
-			});
-			if (res.data.code == 200) {
-				this.userInfo = this.localUserInfo;
-				this.getShopInfo();
-			} else {
-				uni.$u.toast('登录已过期,请重新登录!');
-				localStorage.removeItem('aliPayUserInfo');
-				setTimeout(() => {
-					uni.redirectTo({
-						url: '/pages/index/index?shopId=' + this.shopId + '&uid=' + this.uid
-					})
-				}, 1000)
-			}
-		},
-
 		async getInfo() {
-			const res = await axios.post(
-				`${requestConfig.BaseUrl}user/app/v1/user/alipayLogin?code=${this.zfbInfo.auth_code}`
-			);
-			if (res.data.code == 200) {
-				this.userInfo = res.data.data;
-				localStorage.setItem('aliPayUserInfo', JSON.stringify(this.userInfo))
-				if (this.userInfo.bindPhoneStatus == 0) {
-					this.showPhone = true
+			api.alipayLogin({
+				code: this.zfbInfo.auth_code
+			}).then(res => {
+				if (res.code == 200) {
+					this.userInfo = res.data;
+					localStorage.setItem('aliPayUserInfo', JSON.stringify(this.userInfo))
+					if (this.userInfo.bindPhoneStatus == 0) {
+						this.showPhone = true
+					} else {
+						this.showPhone = false
+						this.getShopInfo()
+					}
 				} else {
-					this.showPhone = false
-					this.getShopInfo()
+					uni.$u.toast('获取登录信息失败!');
 				}
+			})
 
-			} else {
-				uni.$u.toast('获取登录信息失败!');
-			}
 		},
 
 		async Pay() {
 			uni.showLoading({
 				title: '支付中'
 			});
-
 			if (!this.price) {
 				uni.$u.toast('请输入支付金额!');
 			}
-
-			let res = await axios.get(`${requestConfig.BaseUrl}order/app/v1/buyer/order/createOfflineOrder
-						?shopId=${this.zfbInfo.shopId}&price=${this.price}${this.uid ? '&uid=' + this.uid : ''}`, {
-				headers: {
-					'token': `${this.userInfo.token}`
-				}
-			});
-			if (res.data.code == 200) {
-				let data = {
-					"orderId": res.data.data, //订单id
-					"orderType": 11, //订单类型  -1--其他 2-司机保证金 3-商品交易  11-线下交易
-					"payKinds": 1, //支付类型  0-微信  1-支付宝
-					"payMeth": 7 //5-微信小程序支付  6-微信H5支付 7-支付宝app支付
-				}
-				const pay = await axios.post(`${requestConfig.BaseUrl}order/app/v1/buyer/order/offlineOrderPay
-								`, data, {
-					headers: {
-						'Token': `${this.userInfo.token}`
-					}
-				});
-				if (pay.data.code == 200) {
+			api.payOrder({
+				shopType: this.shopInfo.shopType,
+				shopUserId: this.shopInfo.shopUserId,
+				shopId: this.shopInfo.shopId,
+				payAmount: Number(this.price),
+				payWay: 7,
+				userId: this.localUserInfo.userId
+			}).then(res => {
+				if (res.code == 200) {
 					uni.hideLoading();
 					window.location.href =
-						// pay.data.data.result
 						`alipays://platformapi/startapp?appId=20000067&url=${encodeURIComponent(pay.data.data.result)}`
-					// window.close(); // 关闭当前页面
-					// ap.popWindow()
 
 				} else {
 					uni.hideLoading();
 					uni.$u.toast(pay.data.msg);
 				}
-			} else {
-				uni.$u.toast('创建线下支付订单失败!');
-			}
-
+			})
+		}
 
+	},
 
 
-		},
-		validateInput(e, num) {
-			const inputTypeNum = /[^\d]/g //数字
-			switch (num) {
-				case 1:
-					//要写nextTick 不然无效 
-					this.$nextTick(() => {
-						this.listData.integral = e.replace(inputTypeNum, '');
-					})
-					break;
-			}
-		},
-
-		async getShopInfo() {
-			let res = await axios.get(
-				`${requestConfig.BaseUrl}user/app/v1/store/getStoreInfoByScan?shopId=${this.zfbInfo.shopId}
-					${this.uid ? '&uid=' + this.uid : ''}
-					`, {
-				headers: {
-					'token': `${this.userInfo.token}`
-				}
-			});
-			if (res.data.code == 200) {
-				this.shopInfo = res.data.data
+	async getShopInfo() {
+		api.getStoreInfoByScan({
+			shopId: this.zfbInfo.shopId,
+			uid: this.uid
+		}).then(res => {
+			if (res.code == 200) {
+				this.shopInfo = res.data
 			} else {
-				uni.$u.toast(res.data.msg);
+				uni.$u.toast(res.msg);
 			}
-		},
+		});
 
-		async submitOk() {
-			if (this.phone == "") {
-				uni.$u.toast('请输入手机号');
-			} else if (this.yzm == "") {
-				uni.$u.toast('请输入验证码');
-			}
-			const res = await axios.post(
-				`${requestConfig.BaseUrl}user/app/v1/user/bindPhone?
-					phone=${this.phone}
-					&code=${this.yzm}
-					&alipayUserId=${this.userInfo.alipayUserId}
-					`
-			);
-			if (res.data.code == 200) {
+	},
+
+	async submitOk() {
+		if (this.phone == "") {
+			uni.$u.toast('请输入手机号');
+		} else if (this.yzm == "") {
+			uni.$u.toast('请输入验证码');
+		}
+		api.bindH5Phone({
+			phone: this.phone,
+			code: this.yzm,
+			password: 123456,
+			confirmPassword: 123456,
+			type: 0
+		}).then(res => {
+			if (res.code == 200) {
 				uni.$u.toast('绑定手机号成功');
-				this.userInfo = res.data.data
+				this.userInfo = res.data
 				this.showPhone = false
 				this.getShopInfo()
-
+			} else {
+				uni.$u.toast(res.msg);
 			}
+		})
 
-		},
-		codeChange(text) {
-			this.tips = text;
-		},
-		async getCode() {
-			if (this.$refs.uCode.canGetCode) {
-				const res = await axios.post(
-					`${requestConfig.BaseUrl}third/app/v1/third/getSMSCode?phone=${this.phone}`
-				);
-				uni.showLoading({
-					title: '正在获取验证码'
-				})
-				setTimeout(() => {
+
+	},
+	async getCode() {
+		if (this.$refs.uCode.canGetCode) {
+			uni.showLoading({
+				title: '正在获取验证码'
+			})
+			api.sendSms({
+				phone: this.phone,
+				type: 0
+			}).then(res => {
+				if (res.code == 200) {
 					uni.hideLoading();
 					uni.$u.toast('验证码已发送');
 					this.$refs.uCode.start();
-				}, 2000);
-			} else {
-				uni.$u.toast('倒计时结束后再发送');
-			}
-		},
+				} else {
+					uni.$u.toast('倒计时结束后再发送');
+				}
+			})
+		}
+
 	},
 };
 </script>

+ 162 - 52
pages/index/pay.vue

@@ -18,18 +18,26 @@
 
 			<view class="login-contont">
 				<view class="uInput">
-					<u-input placeholder="请输入金额" border="bottom" :fontSize="40" type="digit"
-						@change="validateInput($event, 1)" v-model="price" :customStyle="inpustyle">
+					<u-input placeholder="请输入金额" border="bottom" :fontSize="40" type="digit" v-model="price"
+						:customStyle="inpustyle">
 						<span slot="prefix" style="font-size: 30px">¥</span>
 					</u-input>
 				</view>
+				<view style="padding: 20rpx" v-if="voucherRadio">
+					<text style="font-size: 25rpx;">抵扣代金券后,实付金额</text><text
+						style="color: orange;font-size: 40rpx;margin-left: 10rpx;"> {{ payment }}</text>
+
+				</view>
 				<view class="login-contont-button">
 					<button class="btn" @click="Pay">立即支付</button>
 					<view style="padding: 0px 30rpx">
 						<view style="margin-top: 66rpx; background: #fff7f6">
 							<u-cell-group :border="false">
-								<u-cell title="代金券折扣" :value="couponList.length + '个券可使用'" :border="false" isLink
-									@click="voucher"></u-cell>
+								<u-cell title="代金券折扣" :border="false" isLink @click="voucher">
+									<template slot="value">
+										<text style="color: orange;">{{ CellText }}</text>
+									</template>
+								</u-cell>
 							</u-cell-group>
 						</view>
 
@@ -50,26 +58,31 @@
 				</view>
 
 				<view class="coupon-list">
-					<view class="coupon-item" :class="item.status === 0 ? 'disabled' : 'active'"
-						v-for="(item, index) in couponList" :key="index" @click="selectCoupon(index)">
-						<view class="left">
-							<view class="tag" :class="item.type === 1 ? 'independent' : 'chain'">
-								{{ item.type === 1 ? '独立券' : '连锁券' }}
-							</view>
-							<view class="price">
-								<text class="yen">¥</text>
-								<text class="num">{{ item.price }}</text>
-								<text class="tip">{{ item.desc }}</text>
+					<u-radio-group v-model="voucherRadio" placement="column" @change="groupChange" iconSize="30"
+						size="40">
+						<view class="coupon-item" :class="item.status === 0 ? 'disabled' : 'active'"
+							v-for="(item, index) in couponList" :key="index" @click="selectCoupon(index)">
+							<view class="left">
+								<view class="tag" :class="item.voucherType === 1 ? 'independent' : 'chain'">
+									{{ item.voucherType === 1 ? '独立券' : item.voucherType === 2 ? '连锁券' : '联合券' }}
+								</view>
+								<view class="price">
+									<text class="yen">¥</text>
+									<text class="num">{{ item.amount }}</text>
+									<text class="tip">{{ item.voucherRule == 1 ? '无门槛' : '满' + item.minOrderAmount + '减'
+										+
+										item.discountAmount }}</text>
+								</view>
+								<view class="info">
+									<text>{{ item.createTime }}</text>
+									<!-- <text>{{ item.scope }}</text> -->
+								</view>
 							</view>
-							<view class="info">
-								<text>{{ item.time }}</text>
-								<text>{{ item.scope }}</text>
+							<view class="right">
+								<u-radio :name="item.id" iconSize="30" />
 							</view>
 						</view>
-						<view class="right">
-							<u-radio :checked="selectIndex === index" disabled :custom-style="radioStyle" />
-						</view>
-					</view>
+					</u-radio-group>
 				</view>
 			</view>
 		</u-popup>
@@ -95,39 +108,150 @@ export default {
 			},
 			price: null,
 			shopId: "",
+			storeId: "",
 			shopInfo: {},
 			localUserInfo: {},
-			couponList: []
+			voucherRadio: null,
+			couponList: [
+				// 	{
+				// 	"amount": 2,
+				// 	"applyAllProducts": 1,
+				// 	"applyProductIds": [],
+				// 	"bizType": 14,
+				// 	"claimTime": "2026-04-11 09:56:51",
+				// 	"createTime": "2026-04-11 09:56:51",
+				// 	"discountAmount": null,
+				// 	"endTime": "2026-04-30 10:33:38",
+				// 	"id": "2042783907267350530",
+				// 	"isApply": 0,
+				// 	"minOrderAmount": null,
+				// 	"orderNo": "",
+				// 	"productIds": [],
+				// 	"ruleDisplay": "无门槛",
+				// 	"startTime": "2026-04-10 10:33:26",
+				// 	"status": 1,
+				// 	"storeCount": 1,
+				// 	"storeId": "2018881434293329922",
+				// 	"storeList": [
+				// 		{
+				// 			"isCreator": 1,
+				// 			"storeId": "2018881434293329922",
+				// 			"storeName": "医药one店",
+				// 			"voucherId": "2042068417733718017"
+				// 		}
+				// 	],
+				// 	"storeName": "",
+				// 	"unApplyReason": "",
+				// 	"updateTime": "2026-04-11 09:56:47",
+				// 	"useTime": null,
+				// 	"userId": "1965353825816576001",
+				// 	"voucherId": "2042068417733718017",
+				// 	"voucherName": "2元代金券",
+				// 	"voucherRule": 1,
+				// 	"voucherType": 3,
+				// 	"voucherTypeDesc": "联合券"
+				// },
+				// {
+				// 	"amount": 2,
+				// 	"applyAllProducts": 1,
+				// 	"applyProductIds": [],
+				// 	"bizType": 14,
+				// 	"claimTime": "2026-04-11 09:56:50",
+				// 	"createTime": "2026-04-11 09:56:50",
+				// 	"discountAmount": null,
+				// 	"endTime": "2026-04-16 21:21:31",
+				// 	"id": "2042783902674587650",
+				// 	"isApply": 0,
+				// 	"minOrderAmount": null,
+				// 	"orderNo": "",
+				// 	"productIds": [],
+				// 	"ruleDisplay": "无门槛",
+				// 	"startTime": "2026-04-07 15:14:37",
+				// 	"status": 1,
+				// 	"storeCount": 1,
+				// 	"storeId": "2018881434293329922",
+				// 	"storeList": [
+				// 		{
+				// 			"isCreator": 1,
+				// 			"storeId": "2018881434293329922",
+				// 			"storeName": "医药one店",
+				// 			"voucherId": "2042139544933875713"
+				// 		}
+				// 	],
+				// 	"storeName": "",
+				// 	"unApplyReason": "",
+				// 	"updateTime": "2026-04-11 09:56:46",
+				// 	"useTime": null,
+				// 	"userId": "1965353825816576001",
+				// 	"voucherId": "2042139544933875713",
+				// 	"voucherName": "联合券",
+				// 	"voucherRule": 1,
+				// 	"voucherType": 3,
+				// 	"voucherTypeDesc": "联合券"
+				// }
+			],
+			CellText: "暂无代金券",
+			payment: ""
 		};
 	},
 	onLoad(options) {
 		this.shopId = options.shopId;
+		this.storeId = options.storeId;
 		localStorage.setItem("shopId", this.shopId);
+		localStorage.setItem("storeId", this.storeId);
 		let info = localStorage.getItem("weChatUserInfo");
 		this.localUserInfo = JSON.parse(info);
 		if (this.localUserInfo) {
 			this.getShopInfo();
+			this.getVoucher();
 		} else {
 			this.getInfo();
-			this.getVoucher();
+
 		}
 	},
 	methods: {
+		groupChange(e) {
+			this.showPopup = false;
+			let targetObj = this.couponList.find(item => item.id === e)
+			if (targetObj.voucherRule === 1) {
+				this.CellText = `- ¥${targetObj.amount}`
+			} else {
+				this.CellText = `满${targetObj.minOrderAmount}减${targetObj.discountAmount}`
+			}
+			this.payment = this.price - targetObj.amount
+			console.log(this.price - targetObj.amount);
+
+		},
 		getVoucher() {
 			api
-				.byStore({
-					storeId: '2018881434293329922',
+				.availableList({
+					storeId: this.storeId,
 				})
 				.then((res) => {
 					if (res.code == 200) {
-						this.couponList = res.data;
+						if (res.data.length > 0) {
+							this.couponList = res.data.filter(item => item.applyAllProducts !== 0)
+							this.CellText = '可使用' + this.couponList.length + '个'
+						} else {
+							this.CellText = '暂无代金券'
+						}
 					} else {
 						uni.$u.toast(res.msg);
 					}
 				});
 		},
 		voucher() {
-			this.showPopup = true;
+			if (!this.price) {
+				uni.$u.toast("请输入支付金额!");
+				return
+			}
+			if (this.couponList.length == 0) {
+				uni.$u.toast("暂无代金券");
+				return;
+			} else {
+				this.showPopup = true;
+			}
+
 		},
 		getInfo() {
 			let code = this.GetQueryString("code");
@@ -138,20 +262,15 @@ export default {
 					code: code,
 				})
 				.then((res) => {
-					console.log(res);
 					if (res.code == 200) {
 						this.userInfo = res.data;
-						localStorage.setItem("token", this.userInfo.token);
+						localStorage.setItem("token", this.userInfo.access_token);
 						localStorage.setItem(
 							"weChatUserInfo",
 							JSON.stringify(this.userInfo),
 						);
-						if (this.userInfo.bindPhoneStatus == 0) {
-							this.showPhone = true;
-						} else {
-							this.showPhone = false;
-						}
 						this.getShopInfo();
+						this.getVoucher();
 					} else {
 						uni.$u.toast("获取微信登录信息失败,请重新登录!");
 					}
@@ -174,17 +293,20 @@ export default {
 			uni.showLoading({
 				title: "支付中",
 			});
+			console.log(this.price);
+
 			if (!this.price) {
 				uni.$u.toast("请输入支付金额!");
+				return
 			}
 			api
 				.payOrder({
 					shopType: this.shopInfo.shopType,
 					shopUserId: this.shopInfo.shopUserId,
 					shopId: this.shopInfo.shopId,
-					payAmount: Number(this.price),
+					payAmount: Number(this.payment) || Number(this.price),
 					payWay: 6,
-					userId: this.localUserInfo.userId
+					// userId: this.localUserInfo.userId
 				})
 				.then((res) => {
 					if (res.code == 200) {
@@ -205,14 +327,10 @@ export default {
 							},
 							function (res) {
 								if (res.err_msg == "get_brand_wcpay_request:ok") {
-									// 使用以上方式判断前端返回,
-									// 微信团队郑重提示:
 									uni.hideLoading();
-									// window.location.href = requestConfig.redirectOpen;
 									uni.navigateTo({
 										url: `/pages/index/paySuccess`,
 									});
-									// res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
 								} else {
 									uni.hideLoading();
 									uni.$u.toast("支付失败!");
@@ -236,17 +354,7 @@ export default {
 			if (r != null) return unescape(r[2]);
 			return null;
 		},
-		validateInput(e, num) {
-			const inputTypeNum = /[^\d]/g; //数字
-			// switch (num) {
-			// 	case 1:
-			// 		//要写nextTick 不然无效
-			// 		this.$nextTick(() => {
-			// 			this.price = e.replace(inputTypeNum, "");
-			// 		});
-			// 		break;
-			// }
-		},
+
 	},
 };
 </script>
@@ -284,7 +392,7 @@ export default {
 }
 
 .coupon-item.active {
-	border-color: #ff4d4f;
+	// border-color: #ff4d4f;
 	background: #fffbf4;
 }
 
@@ -305,10 +413,12 @@ export default {
 }
 
 .independent {
+	width: 70rpx;
 	background: #5c8dff;
 }
 
 .chain {
+	width: 70rpx;
 	background: #ff7d00;
 }
 

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
unpackage/dist/build/web/index.html