q-koa 12.0.6 → 12.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1744,23 +1744,61 @@ exports.getUserPortrait = async (ctx) => {
1744
1744
  weixinMp.init()
1745
1745
 
1746
1746
  let obj = {}
1747
+ const diff = moment().hour() > 8 ? -1 : -2
1747
1748
  if (type === 'day') {
1748
1749
  obj = {
1749
- begin_date: moment().add(-1, 'days').format('YYYYMMDD'),
1750
- end_date: moment().add(-1, 'days').format('YYYYMMDD'),
1750
+ begin_date: moment().add(diff, 'days').format('YYYYMMDD'),
1751
+ end_date: moment().add(diff, 'days').format('YYYYMMDD'),
1751
1752
  }
1752
1753
  } else if (type === 'week') {
1753
1754
  obj = {
1754
- begin_date: moment().add(-7, 'days').format('YYYYMMDD'),
1755
- end_date: moment().add(-1, 'days').format('YYYYMMDD'),
1755
+ begin_date: moment()
1756
+ .add(-6 + diff, 'days')
1757
+ .format('YYYYMMDD'),
1758
+ end_date: moment().add(diff, 'days').format('YYYYMMDD'),
1756
1759
  }
1757
1760
  } else if (type === 'month') {
1758
1761
  obj = {
1759
- begin_date: moment().add(-30, 'days').format('YYYYMMDD'),
1760
- end_date: moment().add(-1, 'days').format('YYYYMMDD'),
1762
+ begin_date: moment()
1763
+ .add(-29 + diff, 'days')
1764
+ .format('YYYYMMDD'),
1765
+ end_date: moment().add(diff, 'days').format('YYYYMMDD'),
1761
1766
  }
1762
1767
  }
1768
+ console.log('obj', obj)
1763
1769
  const result = await weixinMp.getUserPortrait(obj)
1764
1770
 
1765
1771
  ctx.SUCCESS(result)
1766
1772
  }
1773
+
1774
+ exports.getVisitTrend = async (ctx) => {
1775
+ const { app, appName } = getAppByCtx(ctx)
1776
+ const appConfig = getConfig(app)
1777
+
1778
+ const { config = 'weixin_mp', type = 'day', date } = ctx.request.body
1779
+ const { app_id, app_secrect } = await appConfig.getObject(config)
1780
+
1781
+ const weixinMp = new WeixinMp({
1782
+ appid: app_id,
1783
+ secrect: app_secrect,
1784
+ })
1785
+
1786
+ weixinMp.init()
1787
+
1788
+ let obj = {}
1789
+ const diff = moment().hour() > 8 ? -1 : -2
1790
+ if (type === 'day') {
1791
+ obj = {
1792
+ begin_date: moment(date ? date : moment().add(diff, 'days')).format(
1793
+ 'YYYYMMDD'
1794
+ ),
1795
+ end_date: moment(date ? date : moment().add(diff, 'days')).format(
1796
+ 'YYYYMMDD'
1797
+ ),
1798
+ }
1799
+ }
1800
+
1801
+ const result = await weixinMp.getVisitTrend({ ...obj, type })
1802
+
1803
+ ctx.SUCCESS(result)
1804
+ }
@@ -775,6 +775,44 @@ module.exports = class Singleton {
775
775
  return result
776
776
  }
777
777
 
778
+ async getVisitTrend(payLoad) {
779
+ const access_token = await this.getAccessToken()
780
+ let url = ''
781
+ if (payLoad.type === 'month') {
782
+ url = util.format(
783
+ 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend?access_token=%s',
784
+ access_token
785
+ )
786
+ } else if (payLoad.type === 'week') {
787
+ url = util.format(
788
+ 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyvisittrend?access_token=%s',
789
+ access_token
790
+ )
791
+ } else if (payLoad.type === 'day') {
792
+ url = util.format(
793
+ 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend?access_token=%s',
794
+ access_token
795
+ )
796
+ }
797
+
798
+ const result = await axios
799
+ .post(url, {
800
+ ...payLoad,
801
+ })
802
+ .then((res) => res.data)
803
+ if (result.errcode) {
804
+ if (result.errcode === 40001) {
805
+ cache.reset()
806
+ return await this.getVisitTrend(payLoad)
807
+ }
808
+ if (result.errcode === 61503) {
809
+ return null
810
+ }
811
+ throw new Error(`${result.errcode};${result.errmsg}`)
812
+ }
813
+ return result
814
+ }
815
+
778
816
  getConfig() {
779
817
  return this.config
780
818
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.0.6",
3
+ "version": "12.0.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {