55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
import {
|
||
autoBindInviteUser
|
||
} from '@/common/api/market/distribution.js'
|
||
|
||
const accountInfo = wx.getAccountInfoSync();
|
||
export const envVersion = accountInfo.miniProgram.envVersion;
|
||
let type = 3;
|
||
if (envVersion === 'trial') {
|
||
console.log('当前环境是体验版');
|
||
type = 2;
|
||
} else if (envVersion === 'release') {
|
||
console.log('当前环境是正式版');
|
||
type = 0;
|
||
} else {
|
||
type = 1;
|
||
console.log('当前环境是开发版或其他');
|
||
}
|
||
|
||
|
||
/**
|
||
* 绑定用户邀请关系(核心函数)
|
||
* 功能说明:校验邀请码有效性,有效则调用自动绑定接口完成邀请关系绑定
|
||
* @param {Object} args - 绑定邀请关系的入参对象
|
||
* @param {number} [args.shopUserId] - 需要绑定邀请人的用户ID(integer <int64>,可选)
|
||
* @param {number} [args.shopId] - 店铺ID(integer <int64>,可选)
|
||
* @param {string} args.inviteCode - 邀请人的邀请码(必填,非空校验通过后才会执行绑定逻辑)
|
||
* @returns {void} 无返回值
|
||
*/
|
||
export function bindInvite(args) {
|
||
// 解构入参对象,获取需要的核心参数
|
||
const {
|
||
shopUserId,
|
||
shopId,
|
||
inviteCode
|
||
} = args;
|
||
|
||
// 校验邀请码有效性:若邀请码为空、null、undefined,则直接返回,不执行后续绑定逻辑
|
||
if (!inviteCode || inviteCode === null || inviteCode === undefined) {
|
||
return;
|
||
}
|
||
|
||
// 邀请码有效,调用自动绑定邀请人接口,传递绑定所需参数
|
||
autoBindInviteUser({
|
||
id: shopUserId,
|
||
shopId,
|
||
inviteCode
|
||
});
|
||
}
|
||
|
||
export function wxShare(par) {
|
||
return {
|
||
...par,
|
||
type
|
||
}
|
||
} |