diff --git a/miniprogram/pages/match/match.js b/miniprogram/pages/match/match.js index 7e87ffde..194cc3d8 100644 --- a/miniprogram/pages/match/match.js +++ b/miniprogram/pages/match/match.js @@ -80,12 +80,36 @@ Page({ // 匹配价格(可配置) matchPrice: 1, - extraMatches: 0 + extraMatches: 0, + // 好友优惠展示(与 read 页一致) + userDiscount: 5, + hasReferralDiscount: false, + showDiscountHint: false, + displayMatchPrice: 1 }, - onLoad() { + onLoad(options = {}) { + // ref:支持 query.ref 或 scene 中的 ref=xxx(分享进入时) + let ref = options.ref + if (!ref && options.scene) { + const sceneStr = (typeof options.scene === 'string' ? decodeURIComponent(options.scene) : '').trim() + const parts = sceneStr.split(/[&_]/) + for (const part of parts) { + const eq = part.indexOf('=') + if (eq > 0) { + const k = part.slice(0, eq) + const v = part.slice(eq + 1) + if (k === 'ref' && v) { ref = v; break } + } + } + } + if (ref) { + wx.setStorageSync('referral_code', ref) + app.handleReferralCode({ query: { ref } }) + } this.setData({ - statusBarHeight: app.globalData.statusBarHeight || 44 + statusBarHeight: app.globalData.statusBarHeight || 44, + _ref: ref }) this.loadMatchConfig() this.loadStoredContact() @@ -105,31 +129,39 @@ Page({ this.refreshMatchCountAndStatus() }, - // 加载匹配配置 + // 加载匹配配置(含 userDiscount 用于好友优惠展示) async loadMatchConfig() { try { - const res = await app.request('/api/miniprogram/match/config', { - method: 'GET' + const userId = app.globalData.userInfo?.id + const [matchRes, configRes] = await Promise.all([ + app.request('/api/miniprogram/match/config', { method: 'GET' }), + app.request('/api/miniprogram/config', { method: 'GET' }) + ]) + + const matchPrice = matchRes?.success && matchRes?.data ? (matchRes.data.matchPrice || 1) : 1 + const userDiscount = configRes?.userDiscount ?? 5 + const hasReferral = !!(wx.getStorageSync('referral_code') || this.data._ref) + const hasReferralDiscount = hasReferral && userDiscount > 0 + const displayMatchPrice = hasReferralDiscount + ? Math.round(matchPrice * (1 - userDiscount / 100) * 100) / 100 + : matchPrice + + if (matchRes?.success && matchRes?.data) { + MATCH_TYPES = matchRes.data.matchTypes || MATCH_TYPES + FREE_MATCH_LIMIT = matchRes.data.freeMatchLimit || FREE_MATCH_LIMIT + } + + this.setData({ + matchTypes: MATCH_TYPES, + totalMatchesAllowed: FREE_MATCH_LIMIT, + matchPrice, + userDiscount, + hasReferralDiscount, + showDiscountHint: userDiscount > 0, + displayMatchPrice }) - if (res.success && res.data) { - // 更新全局配置 - MATCH_TYPES = res.data.matchTypes || MATCH_TYPES - FREE_MATCH_LIMIT = res.data.freeMatchLimit || FREE_MATCH_LIMIT - const matchPrice = res.data.matchPrice || 1 - - this.setData({ - matchTypes: MATCH_TYPES, - totalMatchesAllowed: FREE_MATCH_LIMIT, - matchPrice: matchPrice - }) - - console.log('[Match] 加载匹配配置成功:', { - types: MATCH_TYPES.length, - freeLimit: FREE_MATCH_LIMIT, - price: matchPrice - }) - } + console.log('[Match] 加载匹配配置成功:', { matchPrice, userDiscount, hasReferralDiscount, displayMatchPrice }) } catch (e) { console.log('[Match] 加载匹配配置失败,使用默认配置:', e) } @@ -155,6 +187,15 @@ Page({ if (res.success && res.data) { app.globalData.matchCount = res.data.matchCount ?? 0 app.globalData.matchQuota = res.data.matchQuota || null + // 根据 hasReferrer 更新优惠展示(与 read 页一致) + const hasReferral = !!(wx.getStorageSync('referral_code') || this.data._ref || res.data.hasReferrer) + const matchPrice = this.data.matchPrice ?? 1 + const userDiscount = this.data.userDiscount ?? 5 + const hasReferralDiscount = hasReferral && userDiscount > 0 + const displayMatchPrice = hasReferralDiscount + ? Math.round(matchPrice * (1 - userDiscount / 100) * 100) / 100 + : matchPrice + this.setData({ hasReferralDiscount, displayMatchPrice }) } } catch (e) { console.log('[Match] 拉取 matchQuota 失败:', e) @@ -254,8 +295,8 @@ Page({ return } - // 创业合伙类型 - 真正的匹配功能(仅当登录且服务端确认次数用尽时,弹出购买) - if (this.data.showQuotaExhausted) { + // 创业合伙类型 - 超过匹配次数时直接弹出付费弹窗 + if (this.data.showQuotaExhausted || this.data.needPayToMatch) { this.setData({ showUnlockModal: true }) return } @@ -355,17 +396,9 @@ Page({ setTimeout(() => { clearInterval(timer) - // 次数用尽(后端校验) + // 次数用尽(后端校验)- 直接弹出付费弹窗 if (quotaExceeded) { - this.setData({ isMatching: false }) - wx.showModal({ - title: '今日匹配次数已用完', - content: '请购买更多次数继续匹配', - confirmText: '去购买', - success: (r) => { - if (r.confirm) this.setData({ showUnlockModal: true }) - } - }) + this.setData({ isMatching: false, showUnlockModal: true }) this.refreshMatchCountAndStatus() return } diff --git a/miniprogram/pages/match/match.wxml b/miniprogram/pages/match/match.wxml index 2efda433..fd174f77 100644 --- a/miniprogram/pages/match/match.wxml +++ b/miniprogram/pages/match/match.wxml @@ -39,7 +39,7 @@ 购买次数 - ¥1 = 1次匹配 + ¥{{displayMatchPrice || matchPrice || 1}} = 1次匹配 👥 @@ -344,7 +344,16 @@ 单价 - ¥{{matchPrice || 1}} / 次 + + ¥{{matchPrice || 1}} + ¥{{displayMatchPrice || matchPrice || 1}} / 次 + 省{{userDiscount}}% + + + ¥{{matchPrice || 1}} / 次 + 好友链接立省{{userDiscount}}% + + ¥{{matchPrice || 1}} / 次 已购买 @@ -353,7 +362,7 @@ - 立即购买 ¥{{matchPrice || 1}} + 立即购买 ¥{{hasReferralDiscount ? (displayMatchPrice || matchPrice || 1) : (matchPrice || 1)}} 明天再来 diff --git a/miniprogram/pages/match/match.wxss b/miniprogram/pages/match/match.wxss index 3719ae27..b662a249 100644 --- a/miniprogram/pages/match/match.wxss +++ b/miniprogram/pages/match/match.wxss @@ -1110,6 +1110,28 @@ color: #ffffff; } +.info-value-row { + display: flex; + align-items: center; + gap: 12rpx; +} + +.info-original { + font-size: 24rpx; + color: rgba(255, 255, 255, 0.5); + text-decoration: line-through; +} + +.info-discount { + font-size: 22rpx; + color: #00CED1; +} + +.info-discount-hint { + font-size: 22rpx; + color: rgba(255, 255, 255, 0.5); +} + .unlock-buttons { display: flex; flex-direction: column; diff --git a/miniprogram/pages/settings/settings.js b/miniprogram/pages/settings/settings.js index c46ab852..230a7582 100644 --- a/miniprogram/pages/settings/settings.js +++ b/miniprogram/pages/settings/settings.js @@ -45,7 +45,7 @@ Page({ if (isLoggedIn && userInfo) { // 从本地存储或用户信息中获取绑定数据 const phoneNumber = wx.getStorageSync('user_phone') || userInfo.phone || '' - const wechatId = wx.getStorageSync('user_wechat') || userInfo.wechat || '' + const wechatId = wx.getStorageSync('user_wechat') || userInfo.wechatId || userInfo.wechat || '' const alipayAccount = wx.getStorageSync('user_alipay') || userInfo.alipay || '' const address = wx.getStorageSync('user_address') || userInfo.address || '' // 默认开启自动提现 diff --git a/miniprogram/project.private.config.json b/miniprogram/project.private.config.json index 6ec30cf3..072fabb7 100644 --- a/miniprogram/project.private.config.json +++ b/miniprogram/project.private.config.json @@ -24,12 +24,19 @@ "miniprogram": { "list": [ { - "name": "pages/referral/referral", - "pathName": "pages/referral/referral", + "name": "pages/addresses/addresses", + "pathName": "pages/addresses/addresses", "query": "", "scene": null, "launchMode": "default" }, + { + "name": "pages/referral/referral", + "pathName": "pages/referral/referral", + "query": "", + "launchMode": "default", + "scene": null + }, { "name": "pages/read/read", "pathName": "pages/read/read", diff --git a/soul-api/soul-api b/soul-api/soul-api index 1a1011c7..e72095d3 100644 Binary files a/soul-api/soul-api and b/soul-api/soul-api differ