Files
MBTI_wang/miniprogram/utils/gaokaoJourneyState.js
Ghost c4ac0f8a08 feat: 高考志愿与定价分销链路更新(管理端/API/小程序)
- 新增高考志愿核心服务、模型、控制器与迁移脚本

- 同步管理端定价/分销/设置与小程序入口、历史、测试选择和支付逻辑

- 补充相关开发文档

Made-with: Cursor
2026-04-25 16:19:08 +08:00

64 lines
1.5 KiB
JavaScript

/**
* 高考报告页「两步解锁」:看全文 → 分享朋友圈(不与 MBTI 的 mbti_journey_unlocks 混用)
* storage: gaokao_journey_<testResultId> = { sharedMoment: ts }
*/
function storageKey(testResultId) {
const id =
testResultId != null && String(testResultId) !== '' && String(testResultId) !== '0'
? String(testResultId)
: '0'
return 'gaokao_journey_' + id
}
function read(testResultId) {
try {
const v = wx.getStorageSync(storageKey(testResultId))
if (v && typeof v === 'object') return v
} catch (e) {}
return {}
}
function write(testResultId, obj) {
try {
wx.setStorageSync(storageKey(testResultId), obj || {})
} catch (e) {}
}
function isStep1Unlocked({ profileGate, payRequired, isPaid }) {
if (profileGate) return false
if (payRequired && !isPaid) return false
return true
}
function markShared(testResultId) {
const v = read(testResultId)
v.sharedMoment = Date.now()
write(testResultId, v)
}
/**
* @param {{ profileGate: boolean, payRequired: boolean, isPaid: boolean }} ctx
* @param {string|number} testResultId
* @returns {{ step1Unlocked: boolean, step2Unlocked: boolean, activeStep: number }}
*/
function computeJourney(ctx, testResultId) {
const s1 = isStep1Unlocked(ctx)
const s2 = s1 && !!read(testResultId).sharedMoment
let activeStep = 1
if (!s1) activeStep = 1
else if (!s2) activeStep = 2
else activeStep = 0
return {
step1Unlocked: s1,
step2Unlocked: s2,
activeStep
}
}
module.exports = {
computeJourney,
markShared,
isStep1Unlocked
}