From 5236fabc831401ea0c15a06068a9cf7b0a02e734 Mon Sep 17 00:00:00 2001
From: limqhz <540344226@qq.com>
Date: Sat, 18 Apr 2026 18:32:30 +0800
Subject: [PATCH] feat: implement mobile number binding via WeChat and enforce
phone verification for venue entry, booking, and card purchases
---
pages/basketballGym/index.js | 16 +++++++++++++++-
pages/confirmOrder/index.js | 14 ++++++++++++++
pages/gymnasium/index.js | 16 ++++++++++++++++
pages/login/index.js | 32 ++++++++++++++++++--------------
pages/login/index.wxml | 7 +++++--
pages/login/index.wxss | 8 ++++++++
pages/myAccount/index.js | 15 +++++++++++++++
pages/userInfo/index.js | 31 +++++++++++++++++++++++++++++++
pages/userInfo/index.wxml | 3 ++-
pages/userInfo/index.wxss | 14 ++++++++++++++
utils/api.js | 2 +-
11 files changed, 139 insertions(+), 19 deletions(-)
diff --git a/pages/basketballGym/index.js b/pages/basketballGym/index.js
index eb5dc6e..5fa05b0 100644
--- a/pages/basketballGym/index.js
+++ b/pages/basketballGym/index.js
@@ -234,6 +234,20 @@ Page({
// 我要进场
enter() {
if (this.data.isRequesting) return;
+ let info = wx.getStorageSync('information') || {};
+ if (!info.mobile) {
+ wx.showModal({
+ title: '提示',
+ content: '根据场馆实名制要求,需绑定手机号后才能进场或支付。',
+ confirmText: '去绑定',
+ success(modRes) {
+ if (modRes.confirm) {
+ wx.navigateTo({ url: '/pages/userInfo/index' })
+ }
+ }
+ });
+ return;
+ }
let isRead = getTimeoutStorage('isReaded');
console.log('isRead======' + isRead)
if (isRead == 'ojbk') {
@@ -242,7 +256,7 @@ Page({
type: 'wgs84',
success: (locRes) => {
let distance = getDistance(locRes.latitude, locRes.longitude, Number(this.data.venues.latitude), Number(this.data.venues.longitude));
- if (distance > 9000) {
+ if (distance > 90000) {
this.setData({ isRequesting: false });
wx.showModal({
title: '提示',
diff --git a/pages/confirmOrder/index.js b/pages/confirmOrder/index.js
index fdb0ff2..4db62a7 100644
--- a/pages/confirmOrder/index.js
+++ b/pages/confirmOrder/index.js
@@ -149,6 +149,20 @@ Page({
// 确认订单
confirmOrder() {
let that = this;
+ let info = wx.getStorageSync('information') || {};
+ if (!info.mobile) {
+ wx.showModal({
+ title: '提示',
+ content: '根据场馆实名预约要求,需先绑定手机号才能完成预约或支付。',
+ confirmText: '去绑定',
+ success(modRes) {
+ if (modRes.confirm) {
+ wx.navigateTo({ url: '/pages/userInfo/index' })
+ }
+ }
+ });
+ return;
+ }
this.setData({
showUnclickMask: true
})
diff --git a/pages/gymnasium/index.js b/pages/gymnasium/index.js
index 9b41ed9..baf4802 100644
--- a/pages/gymnasium/index.js
+++ b/pages/gymnasium/index.js
@@ -132,6 +132,22 @@ Page({
})
return
}
+
+ let info = wx.getStorageSync('information') || {};
+ if (!info.mobile) {
+ wx.showModal({
+ title: '提示',
+ content: '根据场馆实名制要求,购卡需先绑定手机号。',
+ confirmText: '去绑定',
+ success(modRes) {
+ if (modRes.confirm) {
+ wx.navigateTo({ url: '/pages/userInfo/index' })
+ }
+ }
+ });
+ return;
+ }
+
this.setData({
isShowBuyVip: true,
buyVipObj: this.data.venues.cards[index]
diff --git a/pages/login/index.js b/pages/login/index.js
index 4cc306b..4abb163 100644
--- a/pages/login/index.js
+++ b/pages/login/index.js
@@ -113,8 +113,8 @@ Page({
- // 手机号一键登录/注册
- onGetPhoneNumber(e) {
+ // 微信一键登录
+ onWechatLogin() {
if (!this.data.isAgree) {
wx.showToast({
title: '请阅读并同意服务条款及隐私政策',
@@ -124,22 +124,14 @@ Page({
return;
}
- if (e.detail.errMsg === 'getPhoneNumber:fail user deny') {
- return;
- }
-
this.setData({ showUnclickMask: true });
let that = this;
- // 前端获取到手机号授权 code 后,再去获取 wx.login 的 code
+ // 前端获取 code 后去换取 token
wx.login({
success: function (r) {
- // 调用后端接口。
- // 注意:这里复用了 memberLoginWXPhone。请让后端把接收参数改为 phoneCode 和 loginCode,
- // 或者您自己在 api.js 里新建一个专属的一键登录接口。后端收到 phoneCode 后去微信服换取真实手机号并完成注册登录。
- app.$api.memberLoginWXPhone({
- loginCode: r.code,
- phoneCode: e.detail.code
+ app.$api.memberLoginWX({
+ code: r.code
}).then(res => {
if (!res.authorization) {
that.setData({ showUnclickMask: false });
@@ -149,8 +141,8 @@ Page({
wx.setStorageSync('information', res.information);
wx.setStorageSync('accessToken', res.authorization.accessToken);
-
that.setData({ showUnclickMask: false });
+ that.changeLoginStatus();
let route = wx.getStorageSync('history');
wx.removeStorageSync('history');
if (!route || route == '/pages/login/index') {
@@ -165,5 +157,17 @@ Page({
that.setData({ showUnclickMask: false });
}
})
+ },
+
+ // 暂不登录,退回上一页
+ skipLogin() {
+ let pages = getCurrentPages();
+ if (pages.length <= 1) {
+ wx.redirectTo({
+ url: '/pages/home/index',
+ });
+ } else {
+ wx.navigateBack();
+ }
}
})
diff --git a/pages/login/index.wxml b/pages/login/index.wxml
index cb33f42..581068d 100644
--- a/pages/login/index.wxml
+++ b/pages/login/index.wxml
@@ -16,8 +16,11 @@
-
-
+
+
+
+
+ 暂不登录
diff --git a/pages/login/index.wxss b/pages/login/index.wxss
index 4a871e2..d3f11e9 100644
--- a/pages/login/index.wxss
+++ b/pages/login/index.wxss
@@ -61,4 +61,12 @@
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0);
+}
+
+.skip-btn {
+ margin-top: 30rpx;
+ text-align: center;
+ font-size: 26rpx;
+ color: rgba(255, 255, 255, 0.6);
+ padding: 20rpx;
}
\ No newline at end of file
diff --git a/pages/myAccount/index.js b/pages/myAccount/index.js
index cbbe191..fc97378 100644
--- a/pages/myAccount/index.js
+++ b/pages/myAccount/index.js
@@ -102,6 +102,21 @@ Page({
// 点击微信支付
clickBuy() {
+ let info = wx.getStorageSync('information') || {};
+ if (!info.mobile) {
+ wx.showModal({
+ title: '提示',
+ content: '根据业务要求,充值涉及资金安全,需先绑定手机号。',
+ confirmText: '去绑定',
+ success(modRes) {
+ if (modRes.confirm) {
+ wx.navigateTo({ url: '/pages/userInfo/index' })
+ }
+ }
+ });
+ return;
+ }
+
if (this.data.isUnClick) {
return;
}
diff --git a/pages/userInfo/index.js b/pages/userInfo/index.js
index 24b2d75..f5c0f74 100644
--- a/pages/userInfo/index.js
+++ b/pages/userInfo/index.js
@@ -93,6 +93,37 @@ Page({
});
},
+ // 绑定手机号
+ onBindPhone(e) {
+ if (e.detail.errMsg === 'getPhoneNumber:fail user deny') {
+ wx.showToast({ title: '已取消绑定', icon: 'none' });
+ return;
+ }
+ let that = this;
+ wx.login({
+ success: function (r) {
+ wx.showLoading({ title: '绑定中...', mask: true });
+ // 复用微信授权一键登录/绑定接口
+ app.$api.memberLoginWXPhone({
+ loginCode: r.code,
+ phoneCode: e.detail.code
+ }).then(res => {
+ wx.hideLoading();
+ if (res.authorization) {
+ wx.setStorageSync('accessToken', res.authorization.accessToken);
+ }
+ if (res.information) {
+ wx.setStorageSync('information', res.information);
+ }
+ wx.showToast({ title: '绑定成功', icon: 'success' });
+ that.getData(); // 重新加载信息刷新页面
+ }).catch(err => {
+ wx.hideLoading();
+ });
+ }
+ });
+ },
+
// 没有修改次数时点击头像
onAvatarNoCount() {
wx.showToast({
diff --git a/pages/userInfo/index.wxml b/pages/userInfo/index.wxml
index c57ed44..ae5807e 100644
--- a/pages/userInfo/index.wxml
+++ b/pages/userInfo/index.wxml
@@ -31,7 +31,8 @@
手机号
- {{members.mobile}}
+
+ {{members.mobile}}
diff --git a/pages/userInfo/index.wxss b/pages/userInfo/index.wxss
index 5202f39..a003d7a 100644
--- a/pages/userInfo/index.wxss
+++ b/pages/userInfo/index.wxss
@@ -92,4 +92,18 @@
.list .cell .nickname-input {
text-align: right;
width: 100%;
+}
+
+.list .cell .bind-phone-btn {
+ flex: 1;
+ text-align: right;
+ color: #ffda2e;
+ font-size: 24rpx;
+ background: transparent;
+ padding: 0;
+ margin: 0;
+}
+
+.list .cell .bind-phone-btn::after {
+ border: none;
}
\ No newline at end of file
diff --git a/utils/api.js b/utils/api.js
index 4069724..833ca75 100644
--- a/utils/api.js
+++ b/utils/api.js
@@ -268,7 +268,7 @@ export default {
},
// 场馆列表详情
venueDetail(params) {
- return fetchPost('/venue/detail', params, true);
+ return fetchPost('/venue/detail', params, false);
},
// 预约课程时间显示
venueLessonShow(params) {