diff --git a/app/api/miniprogram/phone/route.ts b/app/api/miniprogram/phone/route.ts index 880b0c0..0b27261 100644 --- a/app/api/miniprogram/phone/route.ts +++ b/app/api/miniprogram/phone/route.ts @@ -7,7 +7,7 @@ import { NextRequest, NextResponse } from 'next/server' import { query } from '@/lib/db' const APPID = process.env.WECHAT_APPID || 'wxb8bbb2b10dec74aa' -const APPSECRET = process.env.WECHAT_APPSECRET || '25b7e7fdb7998e5107e242ebb6ddabd0' +const APPSECRET = process.env.WECHAT_APPSECRET || '3c1fb1f63e6e052222bbcead9d07fe0c' /** * POST - 解密手机号 diff --git a/app/api/miniprogram/qrcode/route.ts b/app/api/miniprogram/qrcode/route.ts index eed0e6a..0208a81 100644 --- a/app/api/miniprogram/qrcode/route.ts +++ b/app/api/miniprogram/qrcode/route.ts @@ -4,7 +4,7 @@ import { NextRequest, NextResponse } from 'next/server' const APPID = process.env.WECHAT_APPID || 'wxb8bbb2b10dec74aa' -const APPSECRET = process.env.WECHAT_APPSECRET || '25b7e7fdb7998e5107e242ebb6ddabd0' +const APPSECRET = process.env.WECHAT_APPSECRET || '3c1fb1f63e6e052222bbcead9d07fe0c' // 获取access_token async function getAccessToken() { diff --git a/miniprogram/pages/match/match.js b/miniprogram/pages/match/match.js index 7cc8c9b..7eec603 100644 --- a/miniprogram/pages/match/match.js +++ b/miniprogram/pages/match/match.js @@ -185,6 +185,40 @@ Page({ handleMatchClick() { const currentType = MATCH_TYPES.find(t => t.id === this.data.selectedType) + // 资源对接类型需要登录+购买章节才能使用 + if (currentType && currentType.id === 'investor') { + // 检查是否登录 + if (!this.data.isLoggedIn) { + wx.showModal({ + title: '需要登录', + content: '请先登录后再使用资源对接功能', + confirmText: '去登录', + success: (res) => { + if (res.confirm) { + wx.switchTab({ url: '/pages/my/my' }) + } + } + }) + return + } + + // 检查是否购买过章节 + const hasPurchased = app.globalData.purchasedSections?.length > 0 || app.globalData.hasFullBook + if (!hasPurchased) { + wx.showModal({ + title: '需要购买章节', + content: '购买任意章节后即可使用资源对接功能', + confirmText: '去购买', + success: (res) => { + if (res.confirm) { + wx.switchTab({ url: '/pages/catalog/catalog' }) + } + } + }) + return + } + } + // 如果是需要填写联系方式的类型(资源对接、导师顾问、团队招募) if (currentType && currentType.showJoinAfterMatch) { // 先检查是否已绑定联系方式 diff --git a/miniprogram/pages/match/match.wxml b/miniprogram/pages/match/match.wxml index ff1f7d0..ccd08bf 100644 --- a/miniprogram/pages/match/match.wxml +++ b/miniprogram/pages/match/match.wxml @@ -207,20 +207,16 @@ - + - 我能帮到什么 - + 我能帮到你什么 + 我需要什么帮助 - - - - 我擅长什么 - + diff --git a/miniprogram/pages/referral/referral.js b/miniprogram/pages/referral/referral.js index f1fcf77..f9bb086 100644 --- a/miniprogram/pages/referral/referral.js +++ b/miniprogram/pages/referral/referral.js @@ -185,7 +185,7 @@ Page({ // 生成推广海报 async generatePoster() { - wx.showLoading({ title: '生成中...' }) + wx.showLoading({ title: '生成中...', mask: true }) this.setData({ showPosterModal: true, isGeneratingPoster: true }) try { @@ -196,16 +196,29 @@ Page({ // 获取小程序码(带推荐人参数) let qrcodeImage = null try { + // scene格式:ref=用户ID前20位 const scene = userId ? `ref=${userId.slice(0,20)}` : 'ref=soul' + console.log('[Poster] 请求小程序码, scene:', scene) + const qrRes = await app.request('/api/miniprogram/qrcode', { method: 'POST', - data: { scene, page: 'pages/index/index', width: 280 } + data: { + scene, + page: 'pages/index/index', + width: 280 + } }) - if (qrRes.success && qrRes.image) { + + console.log('[Poster] 小程序码响应:', qrRes?.success, qrRes?.image?.length) + + if (qrRes && qrRes.success && qrRes.image) { qrcodeImage = qrRes.image + console.log('[Poster] 小程序码获取成功') + } else { + console.log('[Poster] 响应无效:', qrRes) } } catch (e) { - console.log('[Poster] 获取小程序码失败,使用占位符') + console.error('[Poster] 获取小程序码失败:', e) } // 海报尺寸 300x450 diff --git a/miniprogram/pages/settings/settings.js b/miniprogram/pages/settings/settings.js index cf51467..d653992 100644 --- a/miniprogram/pages/settings/settings.js +++ b/miniprogram/pages/settings/settings.js @@ -64,38 +64,63 @@ Page({ }, // 一键获取收货地址 - async getAddress() { - try { - const res = await wx.chooseAddress() - if (res) { - const fullAddress = `${res.provinceName}${res.cityName}${res.countyName}${res.detailInfo}` + getAddress() { + wx.chooseAddress({ + success: (res) => { + console.log('[Settings] 获取地址成功:', res) + const fullAddress = `${res.provinceName || ''}${res.cityName || ''}${res.countyName || ''}${res.detailInfo || ''}` - wx.setStorageSync('user_address', fullAddress) - this.setData({ address: fullAddress }) - - // 更新用户信息 - if (app.globalData.userInfo) { - app.globalData.userInfo.address = fullAddress - wx.setStorageSync('userInfo', app.globalData.userInfo) - } - - // 同步到服务器 - this.syncProfileToServer() - - wx.showToast({ title: '地址已获取', icon: 'success' }) - } - } catch (e) { - console.log('[Settings] 获取地址失败:', e) - if (e.errMsg?.includes('auth deny')) { - wx.showModal({ - title: '需要授权', - content: '请允许获取收货地址', - confirmText: '去设置', - success: (res) => { - if (res.confirm) wx.openSetting() + if (fullAddress.trim()) { + wx.setStorageSync('user_address', fullAddress) + this.setData({ address: fullAddress }) + + // 更新用户信息 + if (app.globalData.userInfo) { + app.globalData.userInfo.address = fullAddress + wx.setStorageSync('userInfo', app.globalData.userInfo) } - }) + + // 同步到服务器 + this.syncAddressToServer(fullAddress) + + wx.showToast({ title: '地址已获取', icon: 'success' }) + } + }, + fail: (e) => { + console.log('[Settings] 获取地址失败:', e) + if (e.errMsg?.includes('cancel')) { + // 用户取消,不提示 + return + } + if (e.errMsg?.includes('auth deny') || e.errMsg?.includes('authorize')) { + wx.showModal({ + title: '需要授权', + content: '请在设置中允许获取收货地址', + confirmText: '去设置', + success: (res) => { + if (res.confirm) wx.openSetting() + } + }) + } else { + wx.showToast({ title: '获取失败,请重试', icon: 'none' }) + } } + }) + }, + + // 同步地址到服务器 + async syncAddressToServer(address) { + try { + const userId = app.globalData.userInfo?.id + if (!userId) return + + await app.request('/api/user/update', { + method: 'POST', + data: { userId, address } + }) + console.log('[Settings] 地址已同步到服务器') + } catch (e) { + console.log('[Settings] 同步地址失败:', e) } }, @@ -334,10 +359,11 @@ Page({ wx.showLoading({ title: '获取中...', mask: true }) - // 调用服务器解密手机号 + // 调用服务器解密手机号(传入userId以便同步到数据库) + const userId = app.globalData.userInfo?.id const res = await app.request('/api/miniprogram/phone', { method: 'POST', - data: { code } + data: { code, userId } }) wx.hideLoading() diff --git a/开发文档/10、项目管理/小程序20260129-2.pdf b/开发文档/10、项目管理/小程序20260129-2.pdf new file mode 100644 index 0000000..c4aa961 Binary files /dev/null and b/开发文档/10、项目管理/小程序20260129-2.pdf differ