From 9f909d60c3f0f007ae4a509cf218cc6fdfc8f5d5 Mon Sep 17 00:00:00 2001 From: zeyan <258785420@qq.com> Date: Tue, 14 Oct 2025 17:12:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiController/ResourceSharing.php | 2 + .../customer_resources/CustomerResources.php | 12 + .../api/apiService/ResourceSharingService.php | 8 +- uniapp/App.vue | 246 +++++++++++++++--- 4 files changed, 225 insertions(+), 43 deletions(-) diff --git a/niucloud/app/api/controller/apiController/ResourceSharing.php b/niucloud/app/api/controller/apiController/ResourceSharing.php index 057dacda..36d15f77 100644 --- a/niucloud/app/api/controller/apiController/ResourceSharing.php +++ b/niucloud/app/api/controller/apiController/ResourceSharing.php @@ -32,6 +32,7 @@ class ResourceSharing extends BaseApiService $name = $request->param('name','');////客户资源表-姓名 $phone_number = $request->param('phone_number','');//客户资源表-手机号 $campus_name = $request->param('campus_name','');//客户资源表-校区 + $age = $request->param('age','');//客户资源表-年龄 // 新增搜索参数 $source = $request->param('source','');//来源类型 @@ -64,6 +65,7 @@ class ResourceSharing extends BaseApiService 'name'=>$name, 'phone_number'=>$phone_number, 'campus_name' => $campus_name, + 'age' => $age, 'source' => $source, 'source_channel' => $source_channel, 'attendance_type' => $attendance_type, diff --git a/niucloud/app/model/customer_resources/CustomerResources.php b/niucloud/app/model/customer_resources/CustomerResources.php index ca4d4da6..3000fed0 100644 --- a/niucloud/app/model/customer_resources/CustomerResources.php +++ b/niucloud/app/model/customer_resources/CustomerResources.php @@ -149,6 +149,18 @@ class CustomerResources extends BaseModel } } + /** + * 搜索器:年龄 - 支持模糊匹配(如4可匹配4.1、4.12、14、24等) + * @param $value + * @param $data + */ + public function searchAgeAttr($query, $value, $data) + { + if ($value !== '' && $value !== null) { + $query->where("age", 'like', '%' . trim($value) . '%'); + } + } + /** * 搜索器:黑名单状态 * @param $value diff --git a/niucloud/app/service/api/apiService/ResourceSharingService.php b/niucloud/app/service/api/apiService/ResourceSharingService.php index 5df15c3d..f2842d81 100644 --- a/niucloud/app/service/api/apiService/ResourceSharingService.php +++ b/niucloud/app/service/api/apiService/ResourceSharingService.php @@ -348,9 +348,9 @@ class ResourceSharingService extends BaseApiService $resource_conditions[] = ['source_channel', 'like', '%' . $where['source_channel'] . '%']; } - // 年龄查询 + // 年龄查询 - varchar类型使用like查询,支持模糊匹配(如4可匹配4.1、4.12、14、24等) if (isset($where['age']) && $where['age'] !== '' && $where['age'] !== null) { - $resource_conditions[] = ['age', '=', $where['age']]; + $resource_conditions[] = ['age', 'like', '%' . trim($where['age']) . '%']; } // 黑名单状态查询 @@ -992,9 +992,9 @@ class ResourceSharingService extends BaseApiService $resource_conditions[] = ['source_channel', 'like', '%' . $where['source_channel'] . '%']; } - // 年龄查询 + // 年龄查询 - varchar类型使用like查询,支持模糊匹配(如4可匹配4.1、4.12、14、24等) if (isset($where['age']) && $where['age'] !== '' && $where['age'] !== null) { - $resource_conditions[] = ['age', '=', $where['age']]; + $resource_conditions[] = ['age', 'like', '%' . trim($where['age']) . '%']; } // 黑名单状态查询 diff --git a/uniapp/App.vue b/uniapp/App.vue index 987df1eb..deade80b 100644 --- a/uniapp/App.vue +++ b/uniapp/App.vue @@ -2,15 +2,16 @@ import { WxToken } from './common/wx_token.js' - // import user from '@/api/user.js' - import Api_url from '@/common/config.js' var wxtoken = new WxToken(); export default { async onLaunch() { - // 检查小程序更新 + // 初始化版本信息 + this.initializeVersionInfo(); + + // 检查更新 this.checkForUpdate(); - + // #ifdef MP-WEIXIN uni.login({ provider: 'weixin', @@ -34,9 +35,9 @@ console.log("非公众号-暂不登陆") return false; } else { - wxtoken.verify('userinfo'); //静默获取openid + wxtoken.verify('userinfo'); //静默获取openid } - //微信公众号获取token -必须是认证的服务号 + //微信公众号获取token -必须是认证的服务号 // #endif }, onShow: function() { @@ -46,6 +47,22 @@ onHide: function() {}, methods: { + /** + * 初始化版本信息 + */ + initializeVersionInfo() { + // 设置应用版本号(可配置化) + const appVersion = '1.0.0'; // 可从配置文件读取 + const buildTime = Date.now(); + + // 如果没有存储过版本信息,则设置初始值 + if (!uni.getStorageSync('app_version')) { + uni.setStorageSync('app_version', appVersion); + uni.setStorageSync('build_time', buildTime); + console.log(`初始化版本信息: ${appVersion}`); + } + }, + /** * 检查小程序更新 */ @@ -185,6 +202,24 @@ }); }, + /** + * 统一的版本检查方法(支持多平台) + */ + checkVersionUpdate() { + // 检查是否需要提醒更新(避免频繁提示) + const reminderTime = uni.getStorageSync('update_reminder_time'); + const now = Date.now(); + + // 如果用户选择稍后更新,24小时内不再提示 + if (reminderTime && (now - reminderTime < 24 * 60 * 60 * 1000)) { + console.log('用户选择稍后更新,暂不提示'); + return; + } + + // 执行服务器版本检查 + this.checkVersionFromServer(); + }, + /** * H5环境下的更新检查(可选功能) */ @@ -195,61 +230,194 @@ const currentVersion = uni.getStorageSync('app_version') || '1.0.0'; const buildTime = uni.getStorageSync('build_time') || Date.now(); const now = Date.now(); - - // 每小时检查一次更新 - if (now - buildTime > 60 * 60 * 1000) { + + // 每30分钟检查一次更新 + if (now - buildTime > 30 * 60 * 1000) { console.log('H5环境检查更新'); - // 这里可以调用API检查是否有新版本 - // 如果有新版本,可以提示用户刷新页面 - this.checkVersionFromServer(); + this.checkVersionUpdate(); } } catch (error) { console.error('H5更新检查失败:', error); } // #endif + + // #ifdef MP-WEIXIN + // 微信小程序也进行服务器版本检查 + this.checkVersionUpdate(); + // #endif }, /** - * 从服务器检查版本信息(H5环境) + * 从服务器检查版本信息(通用) */ async checkVersionFromServer() { try { - // 这里应该调用你的API来获取最新版本信息 - // const response = await uni.request({ - // url: Api_url.domain + '/api/app/version', - // method: 'GET' - // }); - // - // if (response.data.code === 1) { - // const serverVersion = response.data.data.version; - // const currentVersion = uni.getStorageSync('app_version') || '1.0.0'; - // - // if (this.compareVersion(serverVersion, currentVersion) > 0) { - // this.showH5UpdateDialog(); - // } - // } - - console.log('从服务器检查H5版本更新'); + const currentVersion = uni.getStorageSync('app_version') || '1.0.0'; + const platform = this.getPlatform(); + + console.log(`检查版本更新 - 当前版本: ${currentVersion}, 平台: ${platform}`); + + // 调用API获取最新版本信息 + const response = await uni.request({ + url: Api_url.domain + '/api/app/version', + method: 'GET', + data: { + platform: platform, + version: currentVersion + } + }); + + if (response.data && response.data.code === 1) { + const versionData = response.data.data; + const serverVersion = versionData.version; + const forceUpdate = versionData.force_update || false; + const updateLog = versionData.update_log || ''; + + console.log(`服务器版本: ${serverVersion}, 强制更新: ${forceUpdate}`); + + if (this.compareVersion(serverVersion, currentVersion) > 0) { + // 保存更新信息 + uni.setStorageSync('latest_version', serverVersion); + uni.setStorageSync('update_log', updateLog); + uni.setStorageSync('force_update', forceUpdate); + + // #ifdef MP-WEIXIN + // 微信小程序的更新由微信管理,这里只提示用户 + this.showVersionUpdateDialog(serverVersion, updateLog, forceUpdate); + // #endif + + // #ifdef H5 + // H5环境直接提示刷新 + this.showH5UpdateDialog(serverVersion, updateLog, forceUpdate); + // #endif + } else { + console.log('当前版本已是最新'); + // 清除过期的更新信息 + uni.removeStorageSync('latest_version'); + uni.removeStorageSync('update_log'); + uni.removeStorageSync('force_update'); + } + } else { + console.warn('获取版本信息失败:', response.data?.msg || '未知错误'); + } } catch (error) { console.error('服务器版本检查失败:', error); } }, + + /** + * 获取当前平台标识 + */ + getPlatform() { + // #ifdef MP-WEIXIN + return 'mp-weixin'; + // #endif + + // #ifdef H5 + return 'h5'; + // #endif + + // #ifdef APP-PLUS + return 'app'; + // #endif + + return 'unknown'; + }, + + /** + * 显示版本更新对话框(微信小程序) + */ + showVersionUpdateDialog(newVersion, updateLog, forceUpdate) { + const content = `发现新版本 ${newVersion}\n${updateLog}`; + + if (forceUpdate) { + // 强制更新 + uni.showModal({ + title: '重要更新', + content: content + '\n\n此为重要更新,必须立即更新才能继续使用。', + showCancel: false, + confirmText: '立即更新', + success: () => { + this.triggerWeChatUpdate(); + } + }); + } else { + // 可选更新 + uni.showModal({ + title: '发现新版本', + content: content, + confirmText: '立即更新', + cancelText: '稍后更新', + success: (res) => { + if (res.confirm) { + this.triggerWeChatUpdate(); + } else { + // 记录用户选择稍后更新,24小时后再提示 + uni.setStorageSync('update_reminder_time', Date.now()); + } + } + }); + } + }, + + /** + * 触发微信小程序更新检查 + */ + triggerWeChatUpdate() { + // #ifdef MP-WEIXIN + try { + if (typeof uni !== 'undefined' && typeof uni.getUpdateManager === 'function') { + const updateManager = uni.getUpdateManager(); + + if (updateManager && typeof updateManager.checkForUpdate === 'function') { + updateManager.checkForUpdate(); + } + } + } catch (error) { + console.error('触发微信更新失败:', error); + uni.showToast({ + title: '请手动删除小程序重新进入', + icon: 'none', + duration: 3000 + }); + } + // #endif + }, /** * 显示H5更新对话框 */ - showH5UpdateDialog() { - uni.showModal({ - title: '发现新版本', - content: '检测到新版本,建议刷新页面以获得最佳体验', - confirmText: '立即刷新', - cancelText: '稍后刷新', - success: (res) => { - if (res.confirm) { + showH5UpdateDialog(newVersion, updateLog, forceUpdate) { + const content = `发现新版本 ${newVersion}\n${updateLog}\n\n检测到新版本,建议刷新页面以获得最佳体验`; + + if (forceUpdate) { + // 强制更新 + uni.showModal({ + title: '重要更新', + content: content + '\n\n此为重要更新,必须立即刷新才能继续使用。', + showCancel: false, + confirmText: '立即刷新', + success: () => { location.reload(); } - } - }); + }); + } else { + // 可选更新 + uni.showModal({ + title: '发现新版本', + content: content, + confirmText: '立即刷新', + cancelText: '稍后刷新', + success: (res) => { + if (res.confirm) { + location.reload(); + } else { + // 记录用户选择稍后更新,24小时后再提示 + uni.setStorageSync('update_reminder_time', Date.now()); + } + } + }); + } }, /**