index.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. // var Parse = getApp().Parse;
  2. // var app = getApp()
  3. // const { wxLogin } = require('./utils/login')
  4. const CONFIG = require("config.js");
  5. let config = {
  6. appid: CONFIG.default.appid,
  7. company: CONFIG.default.company,
  8. rootPage: CONFIG.default.rootPage,
  9. }
  10. const plugin = requirePlugin('fm-plugin')
  11. const { Parse, checkAuth } = plugin
  12. Page({
  13. /**
  14. * 页面的初始数据
  15. */
  16. data: {
  17. splashUrl: wx.getStorageSync("enabledOptions")[0],
  18. loading:true
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: async function (options) {
  24. wx.login({
  25. success: function (res) {
  26. if (res.code) {
  27. console.log(res);
  28. // wx.request({
  29. // url: "https://server.fmode.cn/api/wxapp/auth_wxapp",
  30. // data: {
  31. // c: getApp().globalData.company,
  32. // code: res.code,
  33. // },
  34. // async success(res) {
  35. // wx.setStorageSync("userInfo", res.data);
  36. // resolve(res)
  37. // },
  38. // });
  39. }
  40. },
  41. fail: function (err) {
  42. wx.showToast({
  43. title: '服务器繁忙,请稍后重试',
  44. })
  45. }
  46. });
  47. wx.setStorageSync("invite", null);
  48. // 处理扫码链接(options.q 包含完整的URL或activityId)
  49. if (options.q) {
  50. let str = decodeURIComponent(options.q); // 扫描二维码获得的跳转链接
  51. // 兼容一些环境中把 & 编码成 & 的情况,防止参数解析错误(如 scanCount=0&storeId=...)
  52. if (str.indexOf('&') !== -1) {
  53. console.log('🔧 检测到 URL 中包含 &,自动还原为 &');
  54. str = str.replace(/&/g, '&');
  55. }
  56. // 检查是否是员工邀请链接(app.fmode.cn/dev/pobingfeng/manager/staff?invite=xxx)
  57. if (str.includes('app.fmode.cn/dev/pobingfeng/manager/staff')) {
  58. let obj = this.getParaName(str);
  59. if (obj && obj.invite) {
  60. wx.setStorageSync("invite", obj.invite);
  61. console.log('✅ 检测到员工邀请链接,invite:', obj.invite);
  62. }
  63. // 员工邀请链接不需要跳转到店铺,直接返回
  64. this.setData({ options: options });
  65. plugin.init(config, wx.getStorageSync('invite'));
  66. return;
  67. }
  68. // 检查是否是活动海报二维码(activityId作为qrCode参数值)
  69. // 如果str不包含http/https,且看起来像是一个ID,则可能是activityId
  70. if (!str.includes('http://') && !str.includes('https://') && !str.includes('?')) {
  71. // 可能是活动ID,尝试作为activityId处理
  72. if (str && str.length > 0 && !isNaN(str)) {
  73. options.activityId = str;
  74. console.log('✅ 检测到活动海报二维码,activityId:', str);
  75. // 活动二维码需要特殊处理,先保存activityId
  76. wx.setStorageSync("activityId", str);
  77. }
  78. }
  79. // 处理店铺相关的二维码链接(pwa.fmode.cn/gomini/pmd/)
  80. // 从完整URL中提取参数
  81. if (str.includes('pwa.fmode.cn/gomini/pmd') || str.includes('?')) {
  82. let obj = this.getParaName(str);
  83. if (obj && obj.invite) {
  84. wx.setStorageSync("invite", obj.invite);
  85. }
  86. // 将所有参数合并到 options 中
  87. obj && Object.keys(obj).forEach(key=> options[key] = obj[key]);
  88. }
  89. }
  90. // 兼容从编译参数或页面直达传入的 storeId
  91. if (options && options.scene && !options.storeId) {
  92. try {
  93. const sceneStr = decodeURIComponent(options.scene)
  94. if (sceneStr) {
  95. const pairs = sceneStr.split('&')
  96. for (const p of pairs) {
  97. const [k, v] = p.split('=')
  98. if (k === 'storeId' && v) {
  99. options.storeId = v
  100. break
  101. }
  102. }
  103. }
  104. } catch (e) {
  105. console.warn('解析 scene 失败:', e)
  106. }
  107. }
  108. this.setData({
  109. options: options
  110. })
  111. let {
  112. time,
  113. dramaId,
  114. roomId,
  115. orderId,
  116. shopId,
  117. invite,
  118. activityId,
  119. company,
  120. inviteHost,
  121. storeId
  122. } = options
  123. time && wx.setStorageSync("time", time);
  124. dramaId && wx.setStorageSync("dramaId", dramaId);
  125. roomId && wx.setStorageSync("roomId", roomId);
  126. orderId && wx.setStorageSync("orderId", orderId);
  127. shopId && wx.setStorageSync("shopId", shopId);
  128. invite && wx.setStorageSync("invite", invite);
  129. activityId && wx.setStorageSync("activityId", activityId);
  130. inviteHost && wx.setStorageSync("inviteHost", true);
  131. if (storeId) {
  132. wx.setStorageSync('storeId', storeId)
  133. getApp().globalData.storeId = storeId
  134. console.log('✅ 入口页已设置店铺 ID:', storeId)
  135. }
  136. if (company) getApp().globalData.toCompany = true;
  137. // 检查是否是扫码进入(需要统计扫码次数)
  138. this.checkAndHandleScan(options);
  139. plugin.init(config, wx.getStorageSync('invite'))
  140. },
  141. /**
  142. * 生命周期函数--监听页面初次渲染完成
  143. */
  144. onReady: async function () { },
  145. /**
  146. * 生命周期函数--监听页面显示
  147. */
  148. onShow: async function () {
  149. await this.review()
  150. },
  151. async review(force){
  152. try {
  153. let options = this.data.options
  154. let url = getApp().globalData.rootPage || getApp().globalData.defaultTabBar.list[0].pagePath
  155. if (options) {
  156. let objArr = Object.keys(options)
  157. if (objArr && objArr.length > 0) {
  158. let parms = '?'
  159. objArr.forEach((o, index) => {
  160. if (index > 0) {
  161. parms += '&' + o + '=' + options[o]
  162. } else {
  163. parms += o + '=' + options[o]
  164. }
  165. })
  166. url += parms
  167. }
  168. }
  169. let currentUser = Parse.User.current()
  170. console.log(Parse.User.current())
  171. if (!currentUser || force) {
  172. // let data = await wxLogin()
  173. // if (data.statusCode == 200) {
  174. let r = await checkAuth(true)
  175. console.log(r);
  176. // getApp().Parse = Parse
  177. // getApp().checkAuth = checkAuth
  178. if(!r) return
  179. // }
  180. } else {
  181. this.updateUser(currentUser.id)
  182. }
  183. getApp().Parse = Parse
  184. getApp().checkAuth = checkAuth
  185. if (!await this.getCompanyServerExpire(url)) {
  186. return
  187. }
  188. // 检查是否需要跳转到活动页面
  189. if (wx.getStorageSync('need_activity_redirect') === true) {
  190. await this.redirectToActivityPage();
  191. return;
  192. }
  193. // 检查是否需要跳转到扫码统计页面
  194. if (this.shouldRedirectToScanPage()) {
  195. await this.redirectToScanPage();
  196. return;
  197. }
  198. wx.redirectTo({
  199. url: url,
  200. });
  201. }
  202. catch (err) {
  203. console.log(err);
  204. /* 登录身份信息到期,重新登陆 */
  205. if((err?.message.indexOf('Session token is expired') != -1 || err?.message.indexOf('Invalid session token') != -1) && !force){
  206. let invite = wx.getStorageSync('invite')
  207. wx.clearStorageSync()
  208. invite && wx.setStorageSync('invite', invite)
  209. /* 强制重新登录 */
  210. this.review(true)
  211. return
  212. }
  213. this.setData({
  214. loading:false
  215. })
  216. wx.showModal({
  217. title: '温馨提示',
  218. content: '服务器正在升级,请稍后重试。',
  219. showCancel: false,
  220. cancelText: '取消',
  221. cancelColor: '#000000',
  222. confirmText: '确定',
  223. confirmColor: '#3CC51F',
  224. success: (result) => {
  225. if (result.confirm) {
  226. wx.exitMiniProgram()
  227. }
  228. },
  229. });
  230. }
  231. },
  232. async updateUser(id) {
  233. let User = new Parse.Query('_User')
  234. let user = await User.get(id)
  235. let invite = wx.getStorageSync('invite')
  236. //查询邀请人user
  237. let query = new Parse.Query("_User")
  238. query.equalTo('objectId', invite)
  239. let result = await query.first()
  240. if (result && result.id && result.get("invite")?.id == user.id) {
  241. console.error('邀请人不能是自己的下级')
  242. return
  243. }
  244. if (invite && !user.get('invite') && user.id != invite && !user.get('agentLevel')) {
  245. console.log('上下级绑定成功');
  246. user.set('invite', {
  247. __type: "Pointer",
  248. className: "_User",
  249. objectId: invite
  250. })
  251. user.set('agent', {
  252. __type: "Pointer",
  253. className: "_User",
  254. objectId: invite
  255. })
  256. await Parse.Cloud.run('user_save', {
  257. userJson: user.toJSON()
  258. })
  259. }
  260. },
  261. async getCompanyServerExpire(url) {
  262. let query = new Parse.Query('Company')
  263. query.equalTo('objectId', getApp().globalData.company)
  264. query.select('expireDate', 'expireMap')
  265. let com = await query.first()
  266. if (com?.id && com?.get('expireDate')) {
  267. let now = + new Date()
  268. let expireTime = + new Date(com?.get('expireDate'))
  269. if (com?.get('expireMap') && com.get('expireMap')[getApp().globalData.appid]) {
  270. expireTime = + new Date(com.get('expireMap')[getApp().globalData.appid])
  271. }
  272. if (now >= expireTime) {
  273. console.log('服务器到期');
  274. wx.reLaunch({
  275. url: `common-page/pages/loading/index?url=${url}`,
  276. });
  277. return
  278. }
  279. }
  280. return true
  281. },
  282. onUnload: function () {
  283. wx.setStorageSync("active", 0);
  284. },
  285. getParaName(url) {
  286. if (!url || url.indexOf('?') == -1) {
  287. return
  288. }
  289. // 兼容 URL 中 & 的情况,先统一还原为 &
  290. if (url.indexOf('&') !== -1) {
  291. url = url.replace(/&/g, '&');
  292. }
  293. // 提取查询参数部分(去除可能的 hash 部分)
  294. let queryString = url.split('?')[1];
  295. // 如果包含 #,只取 # 之前的部分
  296. if (queryString.indexOf('#') !== -1) {
  297. queryString = queryString.split('#')[0];
  298. }
  299. return this.setObject(queryString) //封装成对象
  300. },
  301. setObject(paraArr) {
  302. let obj = {}
  303. let arr1 = paraArr.split('&')
  304. arr1.forEach(item => {
  305. let str = item.split('=')
  306. let key = str[0]
  307. let val = str[1]
  308. obj[key] = val
  309. })
  310. return obj
  311. },
  312. /**
  313. * 检查并处理扫码参数
  314. * 支持所有类型的二维码:
  315. * 1. 推广员二维码: ?scanCount=0&storeId=xxx&userId=xxx
  316. * 2. 产品二维码: ?scanCount=0&storeId=xxx&productId=xxx
  317. * 3. 活动海报二维码: activityId作为qrCode参数值
  318. * 4. 异业合作伙伴二维码(移动端 / PC端统一): ?scanCount=xxx&storeId=xxx&partnerId=xxx
  319. * 5. 员工邀请二维码(移动端): ?scanCount=0&storeId=xxx&employeeId=xxx
  320. * 6. 我的二维码(老板): ?scanCount=0&storeId=xxx&ownerId=xxx
  321. * 7. 我的二维码(员工): ?scanCount=0&storeId=xxx&employeeId=xxx
  322. */
  323. checkAndHandleScan(options) {
  324. const {
  325. scanCount,
  326. ownerId,
  327. employeeId,
  328. partnerId,
  329. storeId,
  330. productId,
  331. userId, // 推广员二维码使用userId
  332. activityId
  333. } = options;
  334. // 处理活动海报二维码(activityId作为qrCode参数值)
  335. if (activityId && !storeId) {
  336. console.log('===========================================');
  337. console.log('======= 检测到活动海报二维码 =======');
  338. console.log('活动ID (activityId):', activityId);
  339. console.log('===========================================');
  340. // 活动二维码需要跳转到活动页面,不需要跳转到店铺
  341. wx.setStorageSync('scan_activityId', activityId);
  342. wx.setStorageSync('need_activity_redirect', true);
  343. return;
  344. }
  345. // 如果存在 storeId,说明是扫码进入具体门店(包括异业分享)
  346. if (storeId) {
  347. console.log('===========================================');
  348. console.log('======= 检测到扫码参数 =======');
  349. console.log('店铺ID (storeId):', storeId);
  350. console.log('扫码次数 (scanCount):', scanCount || '0');
  351. // 确定来源类型
  352. let sourceType = 'unknown';
  353. let sourceId = null;
  354. if (employeeId) {
  355. sourceType = 'employee';
  356. sourceId = employeeId;
  357. console.log('来源类型: 员工展业');
  358. console.log('员工ID (employeeId):', employeeId);
  359. } else if (userId) {
  360. // 推广员二维码使用userId
  361. sourceType = 'promoter';
  362. sourceId = userId;
  363. console.log('来源类型: 推广员展业');
  364. console.log('推广员ID (userId):', userId);
  365. } else if (ownerId) {
  366. sourceType = 'owner';
  367. sourceId = ownerId;
  368. console.log('来源类型: 老板展业');
  369. console.log('老板ID (ownerId):', ownerId);
  370. } else if (partnerId) {
  371. sourceType = 'partner';
  372. sourceId = partnerId;
  373. console.log('来源类型: 异业合作伙伴');
  374. console.log('合作伙伴ID (partnerId):', partnerId);
  375. } else {
  376. sourceType = 'store';
  377. console.log('来源类型: 店铺分享');
  378. }
  379. if (productId) {
  380. console.log('产品ID (productId):', productId);
  381. }
  382. console.log('===========================================');
  383. // 保存到临时存储,用于后续跳转和统计
  384. wx.setStorageSync('scan_storeId', storeId);
  385. wx.setStorageSync('scan_scanCount', scanCount || '0');
  386. wx.setStorageSync('scan_sourceType', sourceType);
  387. wx.setStorageSync('scan_sourceId', sourceId || '');
  388. wx.setStorageSync('scan_ownerId', ownerId || '');
  389. wx.setStorageSync('scan_employeeId', employeeId || '');
  390. wx.setStorageSync('scan_partnerId', partnerId || '');
  391. wx.setStorageSync('scan_userId', userId || '');
  392. if (productId) {
  393. wx.setStorageSync('scan_productId', productId);
  394. }
  395. wx.setStorageSync('need_scan_redirect', true);
  396. } else if (partnerId) {
  397. // 理论上异业二维码现在也必须带 storeId,这里仅作为兜底保护
  398. console.warn('⚠️ 检测到异业合作伙伴二维码缺少 storeId,无法确定门店,请检查二维码生成逻辑');
  399. }
  400. },
  401. /**
  402. * 判断是否需要跳转到扫码统计页面
  403. */
  404. shouldRedirectToScanPage() {
  405. return wx.getStorageSync('need_scan_redirect') === true;
  406. },
  407. /**
  408. * 跳转到扫码对应的店铺页面
  409. * 根据 storeId 跳转到对应店铺,同时记录所有来源信息用于统计
  410. */
  411. async redirectToScanPage() {
  412. try {
  413. // 获取所有扫码相关参数
  414. const storeId = wx.getStorageSync('scan_storeId');
  415. const scanCount = wx.getStorageSync('scan_scanCount');
  416. const sourceType = wx.getStorageSync('scan_sourceType');
  417. const sourceId = wx.getStorageSync('scan_sourceId');
  418. const ownerId = wx.getStorageSync('scan_ownerId');
  419. const employeeId = wx.getStorageSync('scan_employeeId');
  420. const partnerId = wx.getStorageSync('scan_partnerId');
  421. const userId = wx.getStorageSync('scan_userId');
  422. const productId = wx.getStorageSync('scan_productId');
  423. // 清除临时存储
  424. wx.removeStorageSync('scan_storeId');
  425. wx.removeStorageSync('scan_scanCount');
  426. wx.removeStorageSync('scan_sourceType');
  427. wx.removeStorageSync('scan_sourceId');
  428. wx.removeStorageSync('scan_ownerId');
  429. wx.removeStorageSync('scan_employeeId');
  430. wx.removeStorageSync('scan_partnerId');
  431. wx.removeStorageSync('scan_userId');
  432. wx.removeStorageSync('scan_productId');
  433. wx.removeStorageSync('need_scan_redirect');
  434. if (!storeId) {
  435. console.error('❌ 缺少 storeId 参数,无法跳转');
  436. return;
  437. }
  438. console.log('===========================================');
  439. console.log('======= 扫码进入店铺 =======');
  440. console.log('店铺 ID (storeId):', storeId);
  441. console.log('来源类型 (sourceType):', sourceType);
  442. console.log('来源 ID (sourceId):', sourceId || '无');
  443. console.log('扫码次数 (scanCount):', scanCount);
  444. if (ownerId) console.log('老板 ID (ownerId):', ownerId);
  445. if (employeeId) console.log('员工 ID (employeeId):', employeeId);
  446. if (partnerId) console.log('合作伙伴 ID (partnerId):', partnerId);
  447. if (userId) console.log('推广员 ID (userId):', userId);
  448. if (productId) console.log('产品 ID (productId):', productId);
  449. console.log('===========================================');
  450. // 设置店铺 ID 到全局和本地存储
  451. wx.setStorageSync('storeId', storeId);
  452. getApp().globalData.storeId = storeId;
  453. // 保存来源信息到本地存储(用于后续统计或绑定关系)
  454. if (sourceId) {
  455. wx.setStorageSync('scan_from_sourceType', sourceType);
  456. wx.setStorageSync('scan_from_sourceId', sourceId);
  457. console.log('✅ 已记录来源信息:', sourceType, sourceId);
  458. }
  459. // 记录扫码统计(调用后端接口记录扫码次数)
  460. await this.recordScanStatistics({
  461. storeId,
  462. sourceType,
  463. sourceId,
  464. ownerId,
  465. employeeId,
  466. partnerId,
  467. userId,
  468. productId,
  469. scanCount
  470. });
  471. // 获取默认首页路径并跳转
  472. let url = getApp().globalData.rootPage || getApp().globalData.defaultTabBar.list[0].pagePath;
  473. url += `?storeId=${storeId}`;
  474. // 如果有产品ID,添加到URL参数中
  475. if (productId) {
  476. url += `&productId=${productId}`;
  477. }
  478. console.log('✅ 跳转到店铺页面:', url);
  479. wx.redirectTo({
  480. url: url,
  481. fail: (err) => {
  482. console.error('❌ 跳转失败:', err);
  483. // 如果 redirectTo 失败,尝试 reLaunch
  484. wx.reLaunch({
  485. url: url,
  486. fail: (err2) => {
  487. console.error('❌ reLaunch 也失败:', err2);
  488. }
  489. });
  490. }
  491. });
  492. } catch (error) {
  493. console.error('❌ 跳转到店铺页面失败:', error);
  494. }
  495. },
  496. /**
  497. * 跳转到活动页面
  498. */
  499. async redirectToActivityPage() {
  500. try {
  501. const activityId = wx.getStorageSync('scan_activityId');
  502. // 清除临时存储
  503. wx.removeStorageSync('scan_activityId');
  504. wx.removeStorageSync('need_activity_redirect');
  505. if (!activityId) {
  506. console.error('❌ 缺少 activityId 参数,无法跳转');
  507. return;
  508. }
  509. console.log('===========================================');
  510. console.log('======= 扫码进入活动页面 =======');
  511. console.log('活动 ID (activityId):', activityId);
  512. console.log('===========================================');
  513. // 保存活动ID
  514. wx.setStorageSync('activityId', activityId);
  515. // 获取默认首页路径并跳转(活动页面可能需要根据实际路由调整)
  516. let url = getApp().globalData.rootPage || getApp().globalData.defaultTabBar.list[0].pagePath;
  517. url += `?activityId=${activityId}`;
  518. console.log('✅ 跳转到活动页面:', url);
  519. wx.redirectTo({
  520. url: url,
  521. fail: (err) => {
  522. console.error('❌ 跳转失败:', err);
  523. wx.reLaunch({
  524. url: url,
  525. fail: (err2) => {
  526. console.error('❌ reLaunch 也失败:', err2);
  527. }
  528. });
  529. }
  530. });
  531. } catch (error) {
  532. console.error('❌ 跳转到活动页面失败:', error);
  533. }
  534. },
  535. /**
  536. * 记录扫码统计信息
  537. * @param {Object} params - 扫码参数对象
  538. * @param {string} params.storeId - 店铺 ID
  539. * @param {string} params.sourceType - 来源类型 (employee/owner/partner/promoter/store)
  540. * @param {string} params.sourceId - 来源 ID
  541. * @param {string} params.ownerId - 老板 ID
  542. * @param {string} params.employeeId - 员工 ID
  543. * @param {string} params.partnerId - 合作伙伴 ID
  544. * @param {string} params.userId - 推广员 ID
  545. * @param {string} params.productId - 产品 ID
  546. * @param {string} params.scanCount - 扫码次数
  547. */
  548. async recordScanStatistics(params) {
  549. try {
  550. const {
  551. storeId,
  552. sourceType,
  553. sourceId,
  554. ownerId,
  555. employeeId,
  556. partnerId,
  557. userId,
  558. productId,
  559. scanCount
  560. } = params;
  561. // 如果没有来源信息,不记录统计
  562. if (!sourceId && !ownerId && !employeeId && !partnerId && !userId) {
  563. console.log('ℹ️ 无来源信息,跳过统计记录');
  564. return;
  565. }
  566. // 创建扫码记录
  567. const ScanRecord = Parse.Object.extend('ScanRecord');
  568. const record = new ScanRecord();
  569. record.set('company', {
  570. __type: 'Pointer',
  571. className: 'Company',
  572. objectId: getApp().globalData.company
  573. });
  574. record.set('storeId', storeId);
  575. record.set('sourceType', sourceType || 'unknown');
  576. record.set('scanCount', parseInt(scanCount) || 0);
  577. record.set('scanTime', new Date());
  578. // 根据来源类型设置对应的ID
  579. if (ownerId) {
  580. record.set('ownerId', ownerId);
  581. }
  582. if (employeeId) {
  583. record.set('employeeId', employeeId);
  584. }
  585. if (partnerId) {
  586. record.set('partnerId', partnerId);
  587. }
  588. if (userId) {
  589. record.set('userId', userId);
  590. }
  591. if (productId) {
  592. record.set('productId', productId);
  593. }
  594. // 如果用户已登录,记录扫码用户
  595. const currentUser = Parse.User.current();
  596. if (currentUser) {
  597. record.set('user', {
  598. __type: 'Pointer',
  599. className: '_User',
  600. objectId: currentUser.id
  601. });
  602. }
  603. await record.save();
  604. console.log('✅ 扫码记录已保存');
  605. // 如果存在异业合作伙伴ID,则在其 scanCount 字段上自增 1(数据库中的 Partner 表)
  606. if (partnerId) {
  607. try {
  608. const Partner = Parse.Object.extend('Partner');
  609. const partnerQuery = new Parse.Query(Partner);
  610. const partnerObj = await partnerQuery.get(partnerId);
  611. if (partnerObj) {
  612. partnerObj.increment('scanCount', 1);
  613. await partnerObj.save();
  614. console.log('✅ 已为异业合作伙伴累加一次扫码次数,partnerId:', partnerId);
  615. }
  616. } catch (e) {
  617. console.warn('⚠️ 更新异业合作伙伴扫码次数失败:', e);
  618. }
  619. }
  620. } catch (error) {
  621. console.warn('⚠️ 保存扫码记录失败:', error);
  622. // 不影响主流程
  623. }
  624. }
  625. });