推广分佣功能开发

This commit is contained in:
Dev
2026-10-14 14:44:01 +08:00
parent da26eb5306
commit 1754df972d
34 changed files with 1414 additions and 16 deletions
+29 -5
View File
@@ -1,32 +1,56 @@
import updateManager from './common/updateManager';
import {
QUERY_KEY as PROMOTER_KEY,
savePendingPromoter,
getPendingPromoter,
clearPendingPromoter,
bindPendingPromoter,
} from './utils/promoter';
var util = require('utils/util.js');
var api = require('config/api.js');
App({
onLaunch: function () {
onLaunch: function (options) {
wx.$api = api
wx.$util = util
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
//通过分享链接/小程序码冷启动时缓存推广人,随登录请求一起绑定
savePendingPromoter(options && options.query);
this.loggingIn = true;
// 登录
wx.login({
success: (res) => {
util.request(api.AuthLoginByWeixin, {
code: res.code
}, 'POST').then(function (res) {
console.log('App Launch')
code: res.code,
[PROMOTER_KEY]: getPendingPromoter(),
}, 'POST').then((res) => {
this.loggingIn = false;
if (res.code === 1) {
let userInfo = res.data.userinfo;
wx.setStorageSync('token', res.data.token);
wx.setStorageSync('userInfo', userInfo);
//推广关系为永久绑定,登录成功后无论是否绑定都无需再次提交
clearPendingPromoter();
}
}).catch((err) => {
this.loggingIn = false;
console.error('wxLogin failed:', err);
});
},
fail: () => {
this.loggingIn = false;
},
});
},
onShow: function () {
onShow: function (options) {
//热启动从分享进入:已登录时直接绑定,冷启动由 onLaunch 的登录请求处理
savePendingPromoter(options && options.query);
if (!this.loggingIn) {
bindPendingPromoter();
}
updateManager();
//从后台切回前台时刷新一次未读红点(不使用定时轮询,避免请求堆积导致页面卡死)
this.refreshUnread();