|
|
@@ -621,8 +621,14 @@ Page({
|
|
|
* 6. 员工邀请二维码(移动端): ?scanCount=0&storeId=xxx&employeeId=xxx
|
|
|
* 7. 我的二维码(老板): ?scanCount=0&storeId=xxx&ownerId=xxx
|
|
|
* 8. 我的二维码(员工): ?scanCount=0&storeId=xxx&employeeId=xxx
|
|
|
+ * 9. 方案分享二维码: ?scanCount=0&storeId=xxx&schemeId=xxx&shareUserId=xxx
|
|
|
*/
|
|
|
checkAndHandleScan(options) {
|
|
|
+ console.log('🔍🔍🔍 ========================================');
|
|
|
+ console.log('🔍 [扫码检测] 开始检查扫码参数');
|
|
|
+ console.log('🔍 完整 options 对象:', JSON.stringify(options, null, 2));
|
|
|
+ console.log('🔍🔍🔍 ========================================');
|
|
|
+
|
|
|
const {
|
|
|
scanCount,
|
|
|
ownerId,
|
|
|
@@ -632,15 +638,33 @@ Page({
|
|
|
productId,
|
|
|
caseId,
|
|
|
userId, // 推广员二维码使用userId
|
|
|
- activityId
|
|
|
+ activityId,
|
|
|
+ schemeId, // 方案ID
|
|
|
+ shareUserId, // 分享方案的用户ID
|
|
|
+ q // 扫码链接
|
|
|
} = options;
|
|
|
|
|
|
+ console.log('📋 [扫码参数] 提取的参数:');
|
|
|
+ console.log(' - scanCount:', scanCount || '无');
|
|
|
+ console.log(' - storeId:', storeId || '无');
|
|
|
+ console.log(' - ownerId:', ownerId || '无');
|
|
|
+ console.log(' - employeeId:', employeeId || '无');
|
|
|
+ console.log(' - partnerId:', partnerId || '无');
|
|
|
+ console.log(' - userId:', userId || '无');
|
|
|
+ console.log(' - productId:', productId || '无');
|
|
|
+ console.log(' - caseId:', caseId || '无');
|
|
|
+ console.log(' - activityId:', activityId || '无');
|
|
|
+ console.log(' - schemeId:', schemeId || '无');
|
|
|
+ console.log(' - shareUserId:', shareUserId || '无');
|
|
|
+ console.log(' - q (扫码链接):', q || '无');
|
|
|
+
|
|
|
// 处理活动海报二维码(activityId作为qrCode参数值)
|
|
|
if (activityId && !storeId) {
|
|
|
- console.log('===========================================');
|
|
|
- console.log('======= 检测到活动海报二维码 =======');
|
|
|
- console.log('活动ID (activityId):', activityId);
|
|
|
- console.log('===========================================');
|
|
|
+ console.log('🎯 ===========================================');
|
|
|
+ console.log('🎯 [活动二维码] 检测到活动海报二维码');
|
|
|
+ console.log('🎯 活动ID (activityId):', activityId);
|
|
|
+ console.log('🎯 来源类型: 活动海报');
|
|
|
+ console.log('🎯 ===========================================');
|
|
|
|
|
|
// 活动二维码需要跳转到活动页面,不需要跳转到店铺
|
|
|
wx.setStorageSync('scan_activityId', activityId);
|
|
|
@@ -650,10 +674,10 @@ Page({
|
|
|
|
|
|
// 如果存在 storeId,说明是扫码进入具体门店(包括异业分享)
|
|
|
if (storeId) {
|
|
|
- console.log('===========================================');
|
|
|
- console.log('======= 检测到扫码参数 =======');
|
|
|
- console.log('店铺ID (storeId):', storeId);
|
|
|
- console.log('扫码次数 (scanCount):', scanCount || '0');
|
|
|
+ console.log('🏪 ===========================================');
|
|
|
+ console.log('🏪 [店铺扫码] 检测到扫码参数');
|
|
|
+ console.log('🏪 店铺ID (storeId):', storeId);
|
|
|
+ console.log('🏪 扫码次数 (scanCount):', scanCount || '0');
|
|
|
|
|
|
// 确定来源类型
|
|
|
let sourceType = 'unknown';
|
|
|
@@ -662,40 +686,46 @@ Page({
|
|
|
if (employeeId) {
|
|
|
sourceType = 'employee';
|
|
|
sourceId = employeeId;
|
|
|
- console.log('来源类型: 员工展业');
|
|
|
- console.log('员工ID (employeeId):', employeeId);
|
|
|
+ console.log('👤 [来源识别] 来源类型: 员工展业');
|
|
|
+ console.log('👤 员工ID (employeeId):', employeeId);
|
|
|
} else if (userId) {
|
|
|
// 推广员二维码使用userId
|
|
|
sourceType = 'promoter';
|
|
|
sourceId = userId;
|
|
|
- console.log('来源类型: 推广员展业');
|
|
|
- console.log('推广员ID (userId):', userId);
|
|
|
+ console.log('📢 [来源识别] 来源类型: 推广员展业');
|
|
|
+ console.log('📢 推广员ID (userId):', userId);
|
|
|
} else if (ownerId) {
|
|
|
sourceType = 'owner';
|
|
|
sourceId = ownerId;
|
|
|
- console.log('来源类型: 老板展业');
|
|
|
- console.log('老板ID (ownerId):', ownerId);
|
|
|
+ console.log('👔 [来源识别] 来源类型: 老板展业');
|
|
|
+ console.log('👔 老板ID (ownerId):', ownerId);
|
|
|
} else if (partnerId) {
|
|
|
sourceType = 'partner';
|
|
|
sourceId = partnerId;
|
|
|
- console.log('来源类型: 异业合作伙伴');
|
|
|
- console.log('合作伙伴ID (partnerId):', partnerId);
|
|
|
+ console.log('🤝 [来源识别] 来源类型: 异业合作伙伴');
|
|
|
+ console.log('🤝 合作伙伴ID (partnerId):', partnerId);
|
|
|
} else {
|
|
|
sourceType = 'store';
|
|
|
- console.log('来源类型: 店铺分享');
|
|
|
+ console.log('🏬 [来源识别] 来源类型: 店铺分享(无具体来源人)');
|
|
|
}
|
|
|
|
|
|
if (productId) {
|
|
|
- console.log('产品ID (productId):', productId);
|
|
|
+ console.log('📦 [目标内容] 产品ID (productId):', productId);
|
|
|
}
|
|
|
|
|
|
if (caseId) {
|
|
|
- console.log('案例ID (caseId):', caseId);
|
|
|
+ console.log('📸 [目标内容] 案例ID (caseId):', caseId);
|
|
|
}
|
|
|
|
|
|
- console.log('===========================================');
|
|
|
+ if (schemeId) {
|
|
|
+ console.log('📋 [目标内容] 方案ID (schemeId):', schemeId);
|
|
|
+ console.log('👤 [分享人] 分享用户ID (shareUserId):', shareUserId || '无');
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('🏪 ===========================================');
|
|
|
|
|
|
// 保存到临时存储,用于后续跳转和统计
|
|
|
+ console.log('💾 [保存扫码信息] 开始保存到本地存储...');
|
|
|
wx.setStorageSync('scan_storeId', storeId);
|
|
|
wx.setStorageSync('scan_scanCount', scanCount || '0');
|
|
|
wx.setStorageSync('scan_sourceType', sourceType);
|
|
|
@@ -710,7 +740,20 @@ Page({
|
|
|
if (caseId) {
|
|
|
wx.setStorageSync('scan_caseId', caseId);
|
|
|
}
|
|
|
+ if (schemeId) {
|
|
|
+ wx.setStorageSync('scan_schemeId', schemeId);
|
|
|
+ if (shareUserId) {
|
|
|
+ wx.setStorageSync('scan_shareUserId', shareUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
wx.setStorageSync('need_scan_redirect', true);
|
|
|
+
|
|
|
+ console.log('✅ [保存完成] 扫码信息已保存');
|
|
|
+ console.log('📋 [保存内容摘要]:');
|
|
|
+ console.log(' - 来源类型:', sourceType);
|
|
|
+ console.log(' - 来源ID:', sourceId || '无');
|
|
|
+ console.log(' - 店铺ID:', storeId);
|
|
|
+ console.log(' - 需要跳转:', true);
|
|
|
} else if (partnerId) {
|
|
|
// 理论上异业二维码现在也必须带 storeId,这里仅作为兜底保护
|
|
|
console.warn('⚠️ 检测到异业合作伙伴二维码缺少 storeId,无法确定门店,请检查二维码生成逻辑');
|
|
|
@@ -730,6 +773,10 @@ Page({
|
|
|
*/
|
|
|
async redirectToScanPage() {
|
|
|
try {
|
|
|
+ console.log('🚀 ===========================================');
|
|
|
+ console.log('🚀 [跳转处理] 开始处理扫码跳转');
|
|
|
+ console.log('🚀 ===========================================');
|
|
|
+
|
|
|
// 获取所有扫码相关参数
|
|
|
const storeId = wx.getStorageSync('scan_storeId');
|
|
|
const scanCount = wx.getStorageSync('scan_scanCount');
|
|
|
@@ -741,8 +788,25 @@ Page({
|
|
|
const userId = wx.getStorageSync('scan_userId');
|
|
|
const productId = wx.getStorageSync('scan_productId');
|
|
|
const caseId = wx.getStorageSync('scan_caseId');
|
|
|
+ const schemeId = wx.getStorageSync('scan_schemeId');
|
|
|
+ const shareUserId = wx.getStorageSync('scan_shareUserId');
|
|
|
+
|
|
|
+ console.log('📖 [读取存储] 从本地存储读取扫码信息:');
|
|
|
+ console.log(' - storeId:', storeId || '无');
|
|
|
+ console.log(' - sourceType:', sourceType || '无');
|
|
|
+ console.log(' - sourceId:', sourceId || '无');
|
|
|
+ console.log(' - scanCount:', scanCount || '无');
|
|
|
+ console.log(' - ownerId:', ownerId || '无');
|
|
|
+ console.log(' - employeeId:', employeeId || '无');
|
|
|
+ console.log(' - partnerId:', partnerId || '无');
|
|
|
+ console.log(' - userId:', userId || '无');
|
|
|
+ console.log(' - productId:', productId || '无');
|
|
|
+ console.log(' - caseId:', caseId || '无');
|
|
|
+ console.log(' - schemeId:', schemeId || '无');
|
|
|
+ console.log(' - shareUserId:', shareUserId || '无');
|
|
|
|
|
|
// 清除临时存储
|
|
|
+ console.log('🧹 [清理存储] 清除临时扫码信息...');
|
|
|
wx.removeStorageSync('scan_storeId');
|
|
|
wx.removeStorageSync('scan_scanCount');
|
|
|
wx.removeStorageSync('scan_sourceType');
|
|
|
@@ -753,26 +817,33 @@ Page({
|
|
|
wx.removeStorageSync('scan_userId');
|
|
|
wx.removeStorageSync('scan_productId');
|
|
|
wx.removeStorageSync('scan_caseId');
|
|
|
+ wx.removeStorageSync('scan_schemeId');
|
|
|
+ wx.removeStorageSync('scan_shareUserId');
|
|
|
wx.removeStorageSync('need_scan_redirect');
|
|
|
+ console.log('✅ [清理完成] 临时存储已清除');
|
|
|
|
|
|
if (!storeId) {
|
|
|
- console.error('❌ 缺少 storeId 参数,无法跳转');
|
|
|
+ console.error('❌ [错误] 缺少 storeId 参数,无法跳转');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- console.log('===========================================');
|
|
|
- console.log('======= 扫码进入店铺 =======');
|
|
|
- console.log('店铺 ID (storeId):', storeId);
|
|
|
- console.log('来源类型 (sourceType):', sourceType);
|
|
|
- console.log('来源 ID (sourceId):', sourceId || '无');
|
|
|
- console.log('扫码次数 (scanCount):', scanCount);
|
|
|
- if (ownerId) console.log('老板 ID (ownerId):', ownerId);
|
|
|
- if (employeeId) console.log('员工 ID (employeeId):', employeeId);
|
|
|
- if (partnerId) console.log('合作伙伴 ID (partnerId):', partnerId);
|
|
|
- if (userId) console.log('推广员 ID (userId):', userId);
|
|
|
- if (productId) console.log('产品 ID (productId):', productId);
|
|
|
- if (caseId) console.log('案例 ID (caseId):', caseId);
|
|
|
- console.log('===========================================');
|
|
|
+ console.log('📊 ===========================================');
|
|
|
+ console.log('📊 [扫码来源汇总] 扫码进入店铺');
|
|
|
+ console.log('📊 店铺 ID:', storeId);
|
|
|
+ console.log('📊 来源类型:', sourceType);
|
|
|
+ console.log('📊 来源 ID:', sourceId || '无');
|
|
|
+ console.log('📊 扫码次数:', scanCount);
|
|
|
+ if (ownerId) console.log('📊 老板 ID:', ownerId);
|
|
|
+ if (employeeId) console.log('📊 员工 ID:', employeeId);
|
|
|
+ if (partnerId) console.log('📊 合作伙伴 ID:', partnerId);
|
|
|
+ if (userId) console.log('📊 推广员 ID:', userId);
|
|
|
+ if (productId) console.log('📊 产品 ID:', productId);
|
|
|
+ if (caseId) console.log('📊 案例 ID:', caseId);
|
|
|
+ if (schemeId) {
|
|
|
+ console.log('📊 方案 ID:', schemeId);
|
|
|
+ console.log('📊 分享用户 ID:', shareUserId || '无');
|
|
|
+ }
|
|
|
+ console.log('📊 ===========================================');
|
|
|
|
|
|
// 设置店铺 ID 到全局和本地存储
|
|
|
wx.setStorageSync('storeId', storeId);
|
|
|
@@ -788,9 +859,13 @@ Page({
|
|
|
// 检查用户是否已登录
|
|
|
const currentUser = Parse.User.current();
|
|
|
|
|
|
+ console.log('👤 [登录检查] 检查用户登录状态...');
|
|
|
+ console.log(' - 当前用户:', currentUser ? currentUser.id : '未登录');
|
|
|
+ console.log(' - 手机号:', currentUser?.get('mobile') || '无');
|
|
|
+
|
|
|
if (currentUser) {
|
|
|
// 用户已登录,立即记录扫码统计
|
|
|
- console.log('✅ 用户已登录,记录扫码统计');
|
|
|
+ console.log('✅ [已登录] 用户已登录,立即记录扫码统计');
|
|
|
await this.recordScanStatistics({
|
|
|
storeId,
|
|
|
sourceType,
|
|
|
@@ -804,8 +879,8 @@ Page({
|
|
|
});
|
|
|
} else {
|
|
|
// 用户未登录,保存扫码信息,等登录后再记录
|
|
|
- console.log('⚠️ 用户未登录,保存扫码信息待登录后记录');
|
|
|
- wx.setStorageSync('pending_scan_record', {
|
|
|
+ console.log('⚠️ [未登录] 用户未登录,保存扫码信息待登录后记录');
|
|
|
+ const pendingData = {
|
|
|
storeId,
|
|
|
sourceType,
|
|
|
sourceId,
|
|
|
@@ -816,7 +891,10 @@ Page({
|
|
|
productId,
|
|
|
scanCount,
|
|
|
timestamp: Date.now()
|
|
|
- });
|
|
|
+ };
|
|
|
+ console.log('💾 [待处理记录] 保存内容:', JSON.stringify(pendingData, null, 2));
|
|
|
+ wx.setStorageSync('pending_scan_record', pendingData);
|
|
|
+ console.log('✅ [保存成功] 待处理扫码记录已保存');
|
|
|
}
|
|
|
|
|
|
// 如果有产品ID,直接跳转到产品详情的 H5 页面
|
|
|
@@ -833,6 +911,13 @@ Page({
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // 如果有方案ID,跳转到门店首页并传递方案ID
|
|
|
+ if (schemeId) {
|
|
|
+ console.log('🎯 检测到方案ID,跳转到门店首页展示方案');
|
|
|
+ await this.redirectToStoreWithScheme(storeId, schemeId, shareUserId, partnerId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 获取默认首页路径并跳转
|
|
|
let url = getApp().globalData.rootPage || getApp().globalData.defaultTabBar.list[0].pagePath;
|
|
|
url += `?storeId=${storeId}`;
|
|
|
@@ -1052,6 +1137,82 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * 跳转到门店首页并展示方案
|
|
|
+ * @param {string} storeId - 店铺 ID
|
|
|
+ * @param {string} schemeId - 方案 ID
|
|
|
+ * @param {string} shareUserId - 分享方案的用户 ID
|
|
|
+ * @param {string} partnerId - 可选的合作伙伴 ID
|
|
|
+ */
|
|
|
+ async redirectToStoreWithScheme(storeId, schemeId, shareUserId = null, partnerId = null) {
|
|
|
+ try {
|
|
|
+ console.log('===========================================');
|
|
|
+ console.log('======= 跳转到门店首页展示方案 =======');
|
|
|
+ console.log('店铺 ID:', storeId);
|
|
|
+ console.log('方案 ID:', schemeId);
|
|
|
+ if (shareUserId) console.log('分享用户 ID:', shareUserId);
|
|
|
+ if (partnerId) console.log('合作伙伴 ID:', partnerId);
|
|
|
+ console.log('===========================================');
|
|
|
+
|
|
|
+ const currentUser = Parse.User.current();
|
|
|
+ const token = currentUser ? currentUser.getSessionToken() : null;
|
|
|
+
|
|
|
+ // 构建门店首页的 H5 URL,带上方案ID
|
|
|
+ let h5Url = `https://app.fmode.cn/dev/pobingfeng/owner/nav/home?storeId=${storeId}`;
|
|
|
+
|
|
|
+ // 如果有 token,添加到 URL
|
|
|
+ if (token) {
|
|
|
+ h5Url += `&token=${token}`;
|
|
|
+ } else {
|
|
|
+ // 如果没有 token,使用游客模式
|
|
|
+ h5Url += `&guestMode=true`;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加方案ID
|
|
|
+ h5Url += `&schemeId=${schemeId}`;
|
|
|
+
|
|
|
+ // 如果有分享用户ID,也添加到URL中
|
|
|
+ if (shareUserId) {
|
|
|
+ h5Url += `&shareUserId=${shareUserId}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果有合作伙伴ID,也添加到URL中
|
|
|
+ if (partnerId) {
|
|
|
+ h5Url += `&partnerId=${partnerId}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('🌐 H5 URL:', h5Url);
|
|
|
+
|
|
|
+ // 编码 URL
|
|
|
+ const encodedUrl = encodeURIComponent(h5Url);
|
|
|
+
|
|
|
+ // 构建 web-view 页面路径
|
|
|
+ let webViewPath = `/common-page/pages/web-view/index?path=${encodedUrl}&storeId=${storeId}`;
|
|
|
+
|
|
|
+ console.log('📄 web-view 页面路径:', webViewPath.substring(0, 100) + '...');
|
|
|
+ console.log('===========================================');
|
|
|
+
|
|
|
+ wx.redirectTo({
|
|
|
+ url: webViewPath,
|
|
|
+ success: () => {
|
|
|
+ console.log('✅ 跳转到门店首页展示方案成功');
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('❌ 跳转失败:', err);
|
|
|
+ // 如果 redirectTo 失败,尝试 reLaunch
|
|
|
+ wx.reLaunch({
|
|
|
+ url: webViewPath,
|
|
|
+ fail: (err2) => {
|
|
|
+ console.error('❌ reLaunch 也失败:', err2);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error('❌ 跳转到门店首页展示方案失败:', error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
* 记录扫码统计信息
|
|
|
* @param {Object} params - 扫码参数对象
|
|
|
@@ -1067,6 +1228,10 @@ Page({
|
|
|
*/
|
|
|
async recordScanStatistics(params) {
|
|
|
try {
|
|
|
+ console.log('📝 ===========================================');
|
|
|
+ console.log('📝 [扫码统计] 开始记录扫码统计');
|
|
|
+ console.log('📝 ===========================================');
|
|
|
+
|
|
|
const {
|
|
|
storeId,
|
|
|
sourceType,
|
|
|
@@ -1079,20 +1244,35 @@ Page({
|
|
|
scanCount
|
|
|
} = params;
|
|
|
|
|
|
+ console.log('📋 [统计参数] 接收到的参数:');
|
|
|
+ console.log(' - storeId:', storeId);
|
|
|
+ console.log(' - sourceType:', sourceType);
|
|
|
+ console.log(' - sourceId:', sourceId || '无');
|
|
|
+ console.log(' - ownerId:', ownerId || '无');
|
|
|
+ console.log(' - employeeId:', employeeId || '无');
|
|
|
+ console.log(' - partnerId:', partnerId || '无');
|
|
|
+ console.log(' - userId:', userId || '无');
|
|
|
+ console.log(' - productId:', productId || '无');
|
|
|
+ console.log(' - scanCount:', scanCount || '0');
|
|
|
+
|
|
|
// 检查用户是否已登录
|
|
|
const currentUser = Parse.User.current();
|
|
|
if (!currentUser) {
|
|
|
- console.log('⚠️ 用户未登录,不记录扫码统计');
|
|
|
+ console.log('⚠️ [未登录] 用户未登录,不记录扫码统计');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ console.log('👤 [用户信息] 当前登录用户:');
|
|
|
+ console.log(' - 用户ID:', currentUser.id);
|
|
|
+ console.log(' - 手机号:', currentUser.get('mobile') || '无');
|
|
|
+
|
|
|
// 如果没有来源信息,不记录统计
|
|
|
if (!sourceId && !ownerId && !employeeId && !partnerId && !userId) {
|
|
|
- console.log('ℹ️ 无来源信息,跳过统计记录');
|
|
|
+ console.log('ℹ️ [跳过] 无来源信息,跳过统计记录');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- console.log('✅ 用户已登录,记录扫码统计');
|
|
|
+ console.log('✅ [开始记录] 用户已登录且有来源信息,开始记录');
|
|
|
|
|
|
// 创建扫码记录
|
|
|
const ScanRecord = Parse.Object.extend('ScanRecord');
|
|
|
@@ -1108,21 +1288,33 @@ Page({
|
|
|
record.set('scanCount', parseInt(scanCount) || 0);
|
|
|
record.set('scanTime', new Date());
|
|
|
|
|
|
+ console.log('📦 [记录内容] 准备保存到 ScanRecord 表:');
|
|
|
+ console.log(' - company:', getApp().globalData.company);
|
|
|
+ console.log(' - storeId:', storeId);
|
|
|
+ console.log(' - sourceType:', sourceType || 'unknown');
|
|
|
+ console.log(' - scanCount:', parseInt(scanCount) || 0);
|
|
|
+ console.log(' - scanTime:', new Date().toISOString());
|
|
|
+
|
|
|
// 根据来源类型设置对应的ID
|
|
|
if (ownerId) {
|
|
|
record.set('ownerId', ownerId);
|
|
|
+ console.log(' - ownerId:', ownerId);
|
|
|
}
|
|
|
if (employeeId) {
|
|
|
record.set('employeeId', employeeId);
|
|
|
+ console.log(' - employeeId:', employeeId);
|
|
|
}
|
|
|
if (partnerId) {
|
|
|
record.set('partnerId', partnerId);
|
|
|
+ console.log(' - partnerId:', partnerId);
|
|
|
}
|
|
|
if (userId) {
|
|
|
record.set('userId', userId);
|
|
|
+ console.log(' - userId:', userId);
|
|
|
}
|
|
|
if (productId) {
|
|
|
record.set('productId', productId);
|
|
|
+ console.log(' - productId:', productId);
|
|
|
}
|
|
|
|
|
|
// 记录扫码用户
|
|
|
@@ -1131,35 +1323,39 @@ Page({
|
|
|
className: '_User',
|
|
|
objectId: currentUser.id
|
|
|
});
|
|
|
+ console.log(' - user:', currentUser.id);
|
|
|
|
|
|
await record.save();
|
|
|
- console.log('✅ 扫码记录已保存');
|
|
|
+ console.log('✅ [保存成功] 扫码记录已保存到数据库');
|
|
|
+ console.log(' - 记录ID:', record.id);
|
|
|
|
|
|
// 如果存在异业合作伙伴ID,处理异业绑定和扫码次数
|
|
|
if (partnerId) {
|
|
|
try {
|
|
|
- console.log('===========================================');
|
|
|
- console.log('======= 处理异业扫码逻辑 =======');
|
|
|
- console.log('用户ID:', currentUser.id);
|
|
|
- console.log('异业ID:', partnerId);
|
|
|
- console.log('门店ID:', storeId);
|
|
|
+ console.log('🤝 ===========================================');
|
|
|
+ console.log('🤝 [异业处理] 开始处理异业扫码逻辑');
|
|
|
+ console.log('🤝 用户ID:', currentUser.id);
|
|
|
+ console.log('🤝 异业ID:', partnerId);
|
|
|
+ console.log('🤝 门店ID:', storeId);
|
|
|
+ console.log('🤝 ===========================================');
|
|
|
|
|
|
// 检查用户是否已经绑定了异业合作伙伴
|
|
|
const userBoundPartner = currentUser.get('Partner');
|
|
|
const userBoundPartnerId = userBoundPartner ? userBoundPartner.id : null;
|
|
|
|
|
|
- console.log('用户已绑定的异业ID:', userBoundPartnerId || '无');
|
|
|
+ console.log('🔍 [绑定检查] 用户已绑定的异业ID:', userBoundPartnerId || '无');
|
|
|
|
|
|
// 规则1:如果用户已绑定其他异业,不处理当前异业的扫码
|
|
|
if (userBoundPartnerId && userBoundPartnerId !== partnerId) {
|
|
|
- console.log('⚠️ 用户已绑定其他异业,不处理当前异业的扫码');
|
|
|
- console.log(' 已绑定异业:', userBoundPartnerId);
|
|
|
- console.log(' 当前扫码异业:', partnerId);
|
|
|
- console.log('===========================================');
|
|
|
+ console.log('⚠️ [规则1] 用户已绑定其他异业,不处理当前异业的扫码');
|
|
|
+ console.log(' - 已绑定异业:', userBoundPartnerId);
|
|
|
+ console.log(' - 当前扫码异业:', partnerId);
|
|
|
+ console.log('🤝 ===========================================');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 规则2:检查该用户在该门店是否已经扫过该异业的码
|
|
|
+ console.log('🔍 [重复检查] 检查是否已扫过该异业的码...');
|
|
|
const ScanRecord = Parse.Object.extend('ScanRecord');
|
|
|
const scanQuery = new Parse.Query(ScanRecord);
|
|
|
scanQuery.equalTo('user', {
|
|
|
@@ -1173,17 +1369,19 @@ Page({
|
|
|
const existingScan = await scanQuery.first();
|
|
|
|
|
|
if (existingScan) {
|
|
|
- console.log('⚠️ 该用户在该门店已扫过该异业的码,不重复计数');
|
|
|
- console.log(' 首次扫码时间:', existingScan.get('scanTime'));
|
|
|
- console.log('===========================================');
|
|
|
+ console.log('⚠️ [规则2] 该用户在该门店已扫过该异业的码,不重复计数');
|
|
|
+ console.log(' - 首次扫码时间:', existingScan.get('scanTime'));
|
|
|
+ console.log(' - 记录ID:', existingScan.id);
|
|
|
+ console.log('🤝 ===========================================');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- console.log('✅ 该用户在该门店首次扫该异业码');
|
|
|
+ console.log('✅ [首次扫码] 该用户在该门店首次扫该异业码');
|
|
|
|
|
|
// 规则3:如果用户还没有绑定异业,绑定当前异业
|
|
|
if (!userBoundPartnerId) {
|
|
|
- console.log('🔗 用户首次扫异业码,绑定异业合作伙伴:', partnerId);
|
|
|
+ console.log('🔗 [规则3] 用户首次扫异业码,开始绑定异业合作伙伴');
|
|
|
+ console.log(' - 异业ID:', partnerId);
|
|
|
|
|
|
currentUser.set('Partner', {
|
|
|
__type: 'Pointer',
|
|
|
@@ -1191,38 +1389,51 @@ Page({
|
|
|
objectId: partnerId
|
|
|
});
|
|
|
await currentUser.save();
|
|
|
- console.log('✅ 异业绑定成功');
|
|
|
+ console.log('✅ [绑定成功] 异业绑定成功');
|
|
|
+ } else {
|
|
|
+ console.log('ℹ️ [已绑定] 用户已绑定该异业,无需重复绑定');
|
|
|
}
|
|
|
|
|
|
// 规则4:为该异业在该门店增加扫码次数
|
|
|
+ console.log('📊 [规则4] 开始更新异业扫码次数...');
|
|
|
const Partner = Parse.Object.extend('Partner');
|
|
|
const partnerQuery = new Parse.Query(Partner);
|
|
|
const partnerObj = await partnerQuery.get(partnerId);
|
|
|
|
|
|
if (partnerObj) {
|
|
|
+ console.log('📋 [异业信息] 找到异业合作伙伴记录');
|
|
|
+ console.log(' - 异业ID:', partnerObj.id);
|
|
|
+ console.log(' - 异业名称:', partnerObj.get('name') || '未设置');
|
|
|
+
|
|
|
// 获取或初始化门店扫码次数映射
|
|
|
let storeScans = partnerObj.get('storeScans') || {};
|
|
|
+ const oldCount = storeScans[storeId] || 0;
|
|
|
|
|
|
// 为该门店的扫码次数 +1
|
|
|
- storeScans[storeId] = (storeScans[storeId] || 0) + 1;
|
|
|
+ storeScans[storeId] = oldCount + 1;
|
|
|
|
|
|
partnerObj.set('storeScans', storeScans);
|
|
|
|
|
|
// 同时更新总扫码次数
|
|
|
+ const oldTotalCount = partnerObj.get('scanCount') || 0;
|
|
|
partnerObj.increment('scanCount', 1);
|
|
|
|
|
|
await partnerObj.save();
|
|
|
|
|
|
- console.log('✅ 异业扫码次数已更新');
|
|
|
- console.log(' 门店ID:', storeId);
|
|
|
- console.log(' 该门店扫码次数:', storeScans[storeId]);
|
|
|
- console.log(' 总扫码次数:', partnerObj.get('scanCount'));
|
|
|
+ console.log('✅ [更新成功] 异业扫码次数已更新');
|
|
|
+ console.log(' - 门店ID:', storeId);
|
|
|
+ console.log(' - 该门店扫码次数: %d → %d', oldCount, storeScans[storeId]);
|
|
|
+ console.log(' - 总扫码次数: %d → %d', oldTotalCount, oldTotalCount + 1);
|
|
|
+ } else {
|
|
|
+ console.error('❌ [错误] 未找到异业合作伙伴记录');
|
|
|
}
|
|
|
|
|
|
- console.log('===========================================');
|
|
|
+ console.log('🤝 ===========================================');
|
|
|
} catch (e) {
|
|
|
- console.error('❌ 处理异业合作伙伴绑定失败:', e);
|
|
|
- console.log('===========================================');
|
|
|
+ console.error('❌ [异业处理失败] 处理异业合作伙伴绑定失败:', e);
|
|
|
+ console.error(' - 错误信息:', e.message);
|
|
|
+ console.error(' - 错误堆栈:', e.stack);
|
|
|
+ console.log('🤝 ===========================================');
|
|
|
}
|
|
|
}
|
|
|
} catch (error) {
|