q-koa 12.1.7 → 12.2.1

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.
@@ -128,6 +128,7 @@ exports.checkLogin = async (ctx) => {
128
128
  const result = await app.model.administrator.findOne({
129
129
  where: {
130
130
  id: ctx.request[`${appName}-user`].id,
131
+ name: ctx.request[`${appName}-user`].name || '',
131
132
  password: ctx.request[`${appName}-user`].password || '',
132
133
  },
133
134
  attributes: {
@@ -1817,27 +1817,45 @@ exports.getVisitTrend = async (ctx) => {
1817
1817
  const { config = 'weixin_mp', type = 'day', date } = ctx.request.body
1818
1818
  const { app_id, app_secrect } = await appConfig.getObject(config)
1819
1819
 
1820
- const weixinMp = new WeixinMp({
1821
- appid: app_id,
1822
- secrect: app_secrect,
1823
- })
1820
+ const diff = moment().hour() > 8 ? -1 : -2
1824
1821
 
1825
- weixinMp.init()
1822
+ const begin_date = moment(date ? date : moment().add(diff, 'days')).format(
1823
+ 'YYYYMMDD'
1824
+ )
1825
+
1826
+ if (app.model.weixin_visit) {
1827
+ const target = await app.model.weixin_visit.findOne({
1828
+ where: {
1829
+ ref_date: date
1830
+ ? Number(moment(date).format('YYYYMMDD'))
1831
+ : Number(moment(begin_date).format('YYYYMMDD')),
1832
+ },
1833
+ })
1834
+ if (target) {
1835
+ return ctx.SUCCESS({
1836
+ list: [target],
1837
+ })
1838
+ }
1839
+ }
1826
1840
 
1827
1841
  let obj = {}
1828
- const diff = moment().hour() > 8 ? -1 : -2
1829
1842
  if (type === 'day') {
1830
1843
  obj = {
1831
- begin_date: moment(date ? date : moment().add(diff, 'days')).format(
1832
- 'YYYYMMDD'
1833
- ),
1844
+ begin_date,
1834
1845
  end_date: moment(date ? date : moment().add(diff, 'days')).format(
1835
1846
  'YYYYMMDD'
1836
1847
  ),
1837
1848
  }
1838
1849
  }
1839
1850
 
1840
- const result = await weixinMp.getVisitTrend({ ...obj, type })
1851
+ const weixinMp = new WeixinMp({
1852
+ appid: app_id,
1853
+ secrect: app_secrect,
1854
+ })
1841
1855
 
1856
+ weixinMp.init()
1857
+
1858
+ const result = await weixinMp.getVisitTrend({ ...obj, type })
1859
+ await app.model.weixin_visit.create(result.list[0])
1842
1860
  ctx.SUCCESS(result)
1843
1861
  }
@@ -0,0 +1,22 @@
1
+ module.exports = {
2
+ name: '微信每日数据',
3
+ belongs: 'page',
4
+ multiple: false,
5
+ availableSort: false,
6
+ order: [],
7
+ referenceSelect: [],
8
+ select: [],
9
+ excludes: [],
10
+ limit: 20,
11
+ defaultOrder: [],
12
+ sortOrder: 1,
13
+ reference: [],
14
+ excludeAuth: [],
15
+ initList: [],
16
+ is_split: false,
17
+ is_split_count: false,
18
+ show_virtual: false,
19
+ deleteCheckList: [],
20
+ bulkCreateList: [],
21
+ indexList: [],
22
+ };
@@ -0,0 +1,93 @@
1
+ const { Sequelize, Random } = require('q-koa')
2
+
3
+ exports.ref_date = {
4
+ type: Sequelize.INTEGER,
5
+ comment: '日期',
6
+ allowNull: false,
7
+ is_mock: true,
8
+ defaultValue: 0,
9
+ sortOrder: 1,
10
+ mock: () => Random.natural(100, 1000),
11
+ }
12
+
13
+ exports.session_cnt = {
14
+ type: Sequelize.INTEGER.UNSIGNED,
15
+ comment: '数字',
16
+ allowNull: false,
17
+ is_mock: true,
18
+ defaultValue: 0,
19
+ sortOrder: 2,
20
+ mock: () => Random.natural(100, 1000),
21
+ }
22
+
23
+ exports.stay_time_session = {
24
+ type: Sequelize.DECIMAL,
25
+ comment: '两位小数',
26
+ allowNull: false,
27
+ is_mock: false,
28
+ defaultValue: '0.00',
29
+ sortOrder: 3,
30
+ get: function () {
31
+ return this.getDataValue('stay_time_session') === null
32
+ ? 0
33
+ : Number(this.getDataValue('stay_time_session'))
34
+ },
35
+ }
36
+
37
+ exports.stay_time_uv = {
38
+ type: Sequelize.DECIMAL,
39
+ comment: '两位小数',
40
+ allowNull: false,
41
+ is_mock: false,
42
+ defaultValue: '0.00',
43
+ sortOrder: 4,
44
+ get: function () {
45
+ return this.getDataValue('stay_time_uv') === null
46
+ ? 0
47
+ : Number(this.getDataValue('stay_time_uv'))
48
+ },
49
+ }
50
+
51
+ exports.visit_depth = {
52
+ type: Sequelize.DECIMAL,
53
+ comment: '两位小数',
54
+ allowNull: false,
55
+ is_mock: false,
56
+ defaultValue: '0.00',
57
+ sortOrder: 5,
58
+ get: function () {
59
+ return this.getDataValue('visit_depth') === null
60
+ ? 0
61
+ : Number(this.getDataValue('visit_depth'))
62
+ },
63
+ }
64
+
65
+ exports.visit_pv = {
66
+ type: Sequelize.INTEGER.UNSIGNED,
67
+ comment: '数字',
68
+ allowNull: false,
69
+ is_mock: true,
70
+ defaultValue: 0,
71
+ sortOrder: 6,
72
+ mock: () => Random.natural(100, 1000),
73
+ }
74
+
75
+ exports.visit_uv = {
76
+ type: Sequelize.INTEGER.UNSIGNED,
77
+ comment: '数字',
78
+ allowNull: false,
79
+ is_mock: true,
80
+ defaultValue: 0,
81
+ sortOrder: 7,
82
+ mock: () => Random.natural(100, 1000),
83
+ }
84
+
85
+ exports.visit_uv_new = {
86
+ type: Sequelize.INTEGER.UNSIGNED,
87
+ comment: '数字',
88
+ allowNull: false,
89
+ is_mock: true,
90
+ defaultValue: 0,
91
+ sortOrder: 8,
92
+ mock: () => Random.natural(100, 1000),
93
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.1.7",
3
+ "version": "12.2.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {