支持设置默认企业

This commit is contained in:
Ghost
2026-03-24 10:07:00 +08:00
parent 79512b2fc6
commit 41f016b1ab
22 changed files with 594 additions and 166 deletions

View File

@@ -0,0 +1,52 @@
/**
* 小程序企业上下文:显式入口参数 > 用户绑定企业 > 超管配置的默认企业
*/
/**
* 企业版落地页、分享带 eid、充值等完整回落链
* @returns {number|null}
*/
function getEffectiveEnterpriseId() {
const app = getApp()
const gd = app.globalData || {}
const fromScene = gd.enterpriseIdFromScene
if (fromScene != null && Number(fromScene) > 0) {
return Number(fromScene)
}
const u = gd.userInfo || wx.getStorageSync('userInfo') || {}
const bound = u.enterpriseId
if (bound != null && Number(bound) > 0) {
return Number(bound)
}
const def = gd.defaultEnterpriseId
if (def != null && Number(def) > 0) {
return Number(def)
}
return null
}
/**
* 提交给后端的 enterpriseIdanalyze、test/submit、支付创建订单、简历分析等
* - 个人版 TabappScope=personal仅传递「本次入口携带的 eid」enterpriseIdFromScene
* 不因「已绑定企业」或「超管默认企业」带参,避免个人入口却走企业定价/落库企业字段。
* - 企业版appScope=enterprise与 getEffectiveEnterpriseId 一致。
* @returns {number|null}
*/
function getEnterpriseIdForApiPayload() {
const app = getApp()
const gd = app.globalData || {}
const scope = gd.appScope || 'personal'
if (scope === 'personal') {
const fromScene = gd.enterpriseIdFromScene
if (fromScene != null && Number(fromScene) > 0) {
return Number(fromScene)
}
return null
}
return getEffectiveEnterpriseId()
}
module.exports = {
getEffectiveEnterpriseId,
getEnterpriseIdForApiPayload
}

View File

@@ -2,6 +2,13 @@
// 微信支付工具类 - 复刻自Soul项目
const app = getApp()
const { getEnterpriseIdForApiPayload } = require('./enterpriseContext.js')
/** 创建订单时传给后端的 enterpriseId0 表示无企业上下文);与个人/企业 Tab 一致 */
function enterpriseIdForOrder() {
const eid = getEnterpriseIdForApiPayload()
return eid != null && Number(eid) > 0 ? Number(eid) : 0
}
/**
* 生成符合微信规则的订单号
@@ -364,6 +371,7 @@ function purchaseByPricing(productType, description, extra, maybeFail) {
description,
productType,
testResultId,
enterpriseId: enterpriseIdForOrder(),
success,
fail
})
@@ -486,6 +494,7 @@ function purchasePersonalDeepService(arg1, arg2, arg3) {
description: desc,
productType: 'deep_personal',
deepProductId,
enterpriseId: enterpriseIdForOrder(),
success,
fail
})
@@ -502,6 +511,7 @@ function purchaseTeamDeepService(success, fail) {
amount: 0,
description: '团队深度服务(团队画像+策略)',
productType: 'deep_team',
enterpriseId: enterpriseIdForOrder(),
success,
fail
})

View File

@@ -8,6 +8,8 @@
* 接收方(落地页 onLoad options直接读 options.uid / options.eid
*/
const { getEffectiveEnterpriseId } = require('./enterpriseContext.js')
function getApp_() {
try { return getApp() } catch (e) { return null }
}
@@ -24,9 +26,7 @@ function buildShareQuery() {
const parts = []
if (uid) parts.push('uid=' + uid)
if (scope === 'enterprise') {
const eid = (app && app.globalData && app.globalData.enterpriseIdFromScene)
|| userInfo.enterpriseId
|| ''
const eid = getEffectiveEnterpriseId() || ''
if (eid) parts.push('eid=' + eid)
}
return parts.join('&')