From 4708809846f9999fdca2685022be4efb5be5886e Mon Sep 17 00:00:00 2001 From: baoss <18018021075@163.com> Date: Fri, 27 Dec 2019 20:13:49 +0800 Subject: [PATCH] 替换模板消息 review by bevishuang --- app/models/common.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------- app/pages/index/index.js | 2 +- app/pages/product/detail/detail.js | 31 +++++++++++++++++-------------- app/utils/wechat-pay.js | 2 +- 4 files changed, 67 insertions(+), 57 deletions(-) diff --git a/app/models/common.js b/app/models/common.js index 495e550..e7f3a6c 100644 --- a/app/models/common.js +++ b/app/models/common.js @@ -1,5 +1,5 @@ import api from '../common/api'; -import config from '../common/config.js' +import config from '../common/config.js'; export default { getUnionTypeWithUid(uid) { let param = { @@ -13,46 +13,53 @@ export default { }); }, postTmplId(params) { - let app = getApp(); - let that = this; - //如果没有uid,不上报,否则接口报500 - if (!app.getUid() || params.tmplIds.length === 0) return - return new Promise(resolve => { - wx.requestSubscribeMessage({ - tmplIds: params.tmplIds, - success(res) { - console.log(res) - let tmplIds = res - delete tmplIds.errMsg - tmplIds = JSON.stringify(tmplIds) - //上报tmplIds - let tmplIdParams = { - uid: app.getUid(), - openId: app.getOpenID(), - miniAppType: config.mini_app_type, - templateIds: tmplIds, - method: 'mini.subscribe.add', + let app = getApp(); + let that = this; + + // 如果没有uid,不上报,否则接口报500 + + if (!app.getUid() || params.tmplIds.length === 0) { + return; + } + return new Promise(resolve => { + wx.requestSubscribeMessage({ + tmplIds: params.tmplIds, + success(res) { + console.log(res); + let tmplIds = res; + + delete tmplIds.errMsg; + tmplIds = JSON.stringify(tmplIds); + + // 上报tmplIds + let tmplIdParams = { + uid: app.getUid(), + openId: app.getOpenID(), + miniAppType: config.mini_app_type, + templateIds: tmplIds, + method: 'mini.subscribe.add', + }; + + console.log('params', tmplIdParams); + api.get({ + data: tmplIdParams + }).then(res => { + resolve(res); + }); + }, + fail(res) { + console.log(res); + wx.showToast({ + title: res.errCode === 20004 ? '消息未开启 请点击右上角,打开设置,开启消息' : res.errMsg, + icon: 'none', + duration: 3000, + }); + setTimeout(function() { + resolve(); + }, 3000); } - console.log('params', tmplIdParams) - api.get({ - data: tmplIdParams - }).then(res => { - resolve(res) - }) - }, - fail(res) { - console.log(res) - wx.showToast({ - title: res.errCode === 20004 ? '消息未开启 请点击右上角,打开设置,开启消息' : res.errMsg, - icon: 'none', - duration: 3000, - }) - setTimeout(function () { - resolve() - }, 3000) - } - }) - }) + }); + }); -} + } }; diff --git a/app/pages/index/index.js b/app/pages/index/index.js index c0d05d5..ee60bf2 100644 --- a/app/pages/index/index.js +++ b/app/pages/index/index.js @@ -134,7 +134,7 @@ Page({ } that.setData({ listData: list, - footText: list.length > 0 ? '':'暂无更多内容' + footText: list.length > 0 ? '' : '暂无更多内容' }); } }); diff --git a/app/pages/product/detail/detail.js b/app/pages/product/detail/detail.js index 4fbbc9d..c751503 100644 --- a/app/pages/product/detail/detail.js +++ b/app/pages/product/detail/detail.js @@ -11,7 +11,7 @@ import { stringify } from '../../../vendors/query-stringify'; import wx from '../../../utils/wx'; -import commonService from '../../../models/common.js' +import commonService from '../../../models/common.js'; let app = getApp(); let router = global.router; let yas; @@ -80,7 +80,7 @@ const QUEUE_SUCCESS = { const OFFLINE_STATUS = { OFFLINE: 1, OFFLINE_OVER: 0 -} +}; const YB_TO_ASSIST_C = 'YB_TO_ASSIST_C'; const YB_ASSIST_SUCCESS_L = 'YB_ASSIST_SUCCESS_L'; const YB_INVITE_ASSIST_C = 'YB_INVITE_ASSIST_C'; @@ -168,8 +168,9 @@ Page(Object.assign({ }); let userInfo = app.getUserInfo(); + if (!userInfo.wechat || !this.getUserWechatId()) { - this.goLogin({'login': '0', 'type': 'redirectTo'}); + this.goLogin({login: '0', type: 'redirectTo'}); return; } @@ -551,7 +552,7 @@ Page(Object.assign({ let userInfo = app.getUserInfo(); if (!userInfo.wechat || !this.getUserWechatId()) { - this.goLogin({'login': '0'}); + this.goLogin({login: '0'}); return; } @@ -615,7 +616,7 @@ Page(Object.assign({ let userInfo = app.getUserInfo(); if (!userInfo.wechat || !this.getUserWechatId()) { - this.goLogin({'login': '0'}); + this.goLogin({login: '0'}); return; } @@ -704,19 +705,21 @@ Page(Object.assign({ }); }, toFollow() { - let that = this - if(this.data.isFollow) { - return + let that = this; + + if (this.data.isFollow) { + return; } - let tmplIds = ['WhCBCAO2ci_gSrDSzpMExhYAdnhlF0aqgr2YWzJG4EM','3KKWG1j-1ui2wE19aLcpCVSoKTsbWpnlmPIBLesHJqs']; + let tmplIds = ['WhCBCAO2ci_gSrDSzpMExhYAdnhlF0aqgr2YWzJG4EM', '3KKWG1j-1ui2wE19aLcpCVSoKTsbWpnlmPIBLesHJqs']; + commonService.postTmplId({ tmplIds }).then(res => { that.setData({ isFollow: true - }) - }) - + }); + }); + }, assistCancel() { this.reload(); @@ -793,8 +796,8 @@ Page(Object.assign({ }, goLogin(params) { - let login = parseInt(params['login']) || 1; - let type = params['type'] || 'navigateTo'; + let login = parseInt(params.login) || 1; + let type = params.type || 'navigateTo'; let data = {}; if (this.data.originUid) { diff --git a/app/utils/wechat-pay.js b/app/utils/wechat-pay.js index c0347c1..c7c585a 100644 --- a/app/utils/wechat-pay.js +++ b/app/utils/wechat-pay.js @@ -97,7 +97,7 @@ function wechatPay(order) { signType: data.signType, paySign: data.paySign, success: function() { - + reportPayStatus(orderCode, orderAmount, true); -- libgit2 0.24.0