q-koa 13.7.0 → 13.7.2
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.
- package/core/app.js +7 -7
- package/core/file/plugins/common/controller.js +3 -3
- package/core/file/plugins/common/service.js +2 -2
- package/core/file/plugins/douyin/controller.js +3 -3
- package/core/file/plugins/setting/model.js +3 -3
- package/core/file/plugins/system/controller.js +3 -3
- package/core/file/plugins/user/controller.js +5 -5
- package/core/file/plugins/weixin/controller.js +19 -19
- package/core/file/plugins/weixin/service.js +6 -6
- package/core/file/services/weixinArticle.js +2 -2
- package/core/file/utils/index.js +5 -5
- package/package.json +1 -1
package/core/app.js
CHANGED
|
@@ -6,7 +6,7 @@ const fs = require('fs')
|
|
|
6
6
|
const fsPromise = require('fs/promises')
|
|
7
7
|
const Sequelize = require('sequelize')
|
|
8
8
|
const redis = require('redis')
|
|
9
|
-
const
|
|
9
|
+
const moment = require('dayjs')
|
|
10
10
|
const { EventEmitter } = require('events')
|
|
11
11
|
const nodeVm = require('vm')
|
|
12
12
|
const { LRUCache } = require('lru-cache')
|
|
@@ -241,7 +241,7 @@ class APP {
|
|
|
241
241
|
|
|
242
242
|
if (url.length > 2 && this.config.log.request) {
|
|
243
243
|
console.log(
|
|
244
|
-
|
|
244
|
+
moment().format('HH:mm:ss'),
|
|
245
245
|
url,
|
|
246
246
|
host,
|
|
247
247
|
ctx.request.clientType
|
|
@@ -323,7 +323,7 @@ class APP {
|
|
|
323
323
|
}
|
|
324
324
|
this.server = this.app.listen(this.port, () => {
|
|
325
325
|
console.log(
|
|
326
|
-
`${
|
|
326
|
+
`${moment().format(
|
|
327
327
|
'HH:mm:ss'
|
|
328
328
|
)} server is running at http://localhost:${this.port}`
|
|
329
329
|
)
|
|
@@ -923,7 +923,7 @@ class APP {
|
|
|
923
923
|
}
|
|
924
924
|
}
|
|
925
925
|
}
|
|
926
|
-
const start =
|
|
926
|
+
const start = moment().valueOf()
|
|
927
927
|
for (const fn of ['service']) {
|
|
928
928
|
const cloneTarget = this.app[appName][fn]
|
|
929
929
|
|
|
@@ -940,7 +940,7 @@ class APP {
|
|
|
940
940
|
}
|
|
941
941
|
|
|
942
942
|
if (is_dev) {
|
|
943
|
-
console.log('挂载service bind',
|
|
943
|
+
console.log('挂载service bind', moment().valueOf() - start)
|
|
944
944
|
}
|
|
945
945
|
}
|
|
946
946
|
|
|
@@ -2279,11 +2279,11 @@ APP.Random = Random
|
|
|
2279
2279
|
APP.Validator = Validator
|
|
2280
2280
|
APP.ServiceError = ServiceError
|
|
2281
2281
|
APP.TransactionError = TransactionError
|
|
2282
|
-
APP.
|
|
2282
|
+
APP.moment = moment
|
|
2283
2283
|
APP.utils = require('./file/utils')
|
|
2284
2284
|
APP.is_dev = is_dev
|
|
2285
2285
|
|
|
2286
|
-
global.
|
|
2286
|
+
global.moment = moment
|
|
2287
2287
|
global.Sequelize = Sequelize
|
|
2288
2288
|
global.lodash = _
|
|
2289
2289
|
|
|
@@ -467,9 +467,9 @@ const expressFn = async ({ app, express_number: _express_number, mobile }) => {
|
|
|
467
467
|
},
|
|
468
468
|
})
|
|
469
469
|
if (history) {
|
|
470
|
-
const diffNoLong =
|
|
470
|
+
const diffNoLong = moment().diff(moment(history.updated_at), 'hours') < 1
|
|
471
471
|
const isTooLong =
|
|
472
|
-
|
|
472
|
+
moment().diff(moment(history.result.updateTime), 'days') > 30
|
|
473
473
|
|
|
474
474
|
if (diffNoLong || isTooLong) {
|
|
475
475
|
return history.result
|
|
@@ -753,7 +753,7 @@ exports.restart = async (ctx) => {
|
|
|
753
753
|
|
|
754
754
|
const { hour: _hour } = ctx.request.query
|
|
755
755
|
|
|
756
|
-
const hour =
|
|
756
|
+
const hour = moment().hour()
|
|
757
757
|
if (hour === Number(_hour)) {
|
|
758
758
|
pm2.connect((err) => {
|
|
759
759
|
console.log(err)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { getConfig, ServiceError } = require('q-koa')
|
|
2
2
|
const axios = require('axios')
|
|
3
3
|
const XLSX = require('xlsx')
|
|
4
|
-
const
|
|
4
|
+
const moment = require('dayjs')
|
|
5
5
|
|
|
6
6
|
exports.gpt = async ({ app, content }) => {
|
|
7
7
|
if (!content) throw new ServiceError('?content')
|
|
@@ -34,7 +34,7 @@ exports.gpt = async ({ app, content }) => {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
exports.formatXLSX = ({ header, data, fileName: _fileName }) => {
|
|
37
|
-
const fileName = `${_fileName ||
|
|
37
|
+
const fileName = `${_fileName || moment().format('YYYYMMDDHHmmss') + ''}.xlsx`
|
|
38
38
|
const workbook = XLSX.utils.book_new()
|
|
39
39
|
const worksheetData = [header, ...data]
|
|
40
40
|
const worksheet = XLSX.utils.aoa_to_sheet(worksheetData)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { getAppByCtx, getConfig, lodash,
|
|
1
|
+
const { getAppByCtx, getConfig, lodash, moment, getService } = require('q-koa')
|
|
2
2
|
const util = require('util')
|
|
3
3
|
const axios = require('axios')
|
|
4
4
|
const qr = require('qr-image')
|
|
@@ -343,7 +343,7 @@ const updateTask = async ({ app, list, active_time, douyin }) => {
|
|
|
343
343
|
digg_count: statistics.digg_count,
|
|
344
344
|
download_count: statistics.download_count,
|
|
345
345
|
forward_count: statistics.forward_count,
|
|
346
|
-
created_at:
|
|
346
|
+
created_at: moment(create_time * 1000),
|
|
347
347
|
is_reviewed,
|
|
348
348
|
name: title,
|
|
349
349
|
video_status: status[video_status],
|
|
@@ -366,7 +366,7 @@ exports.hotSearch = async (ctx) => {
|
|
|
366
366
|
|
|
367
367
|
const hotWord = await app.model.hot_search.findOne()
|
|
368
368
|
const minutes = hotWord
|
|
369
|
-
?
|
|
369
|
+
? moment().diff(moment(hotWord.created_at), 'minutes')
|
|
370
370
|
: 1000
|
|
371
371
|
|
|
372
372
|
if (minutes < 30) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { Sequelize, Random, lodash,
|
|
1
|
+
const { Sequelize, Random, lodash, moment } = require('q-koa')
|
|
2
2
|
|
|
3
3
|
exports.name = {
|
|
4
4
|
type: Sequelize.STRING(),
|
|
@@ -74,9 +74,9 @@ exports.value = {
|
|
|
74
74
|
? 0
|
|
75
75
|
: Number(this.getDataValue('value'))
|
|
76
76
|
case 'datetime':
|
|
77
|
-
return
|
|
77
|
+
return moment(this.getDataValue('value')).format('YYYY-MM-DD HH:mm:ss')
|
|
78
78
|
case 'date':
|
|
79
|
-
return
|
|
79
|
+
return moment(this.getDataValue('value')).format('YYYY-MM-DD')
|
|
80
80
|
case 'image':
|
|
81
81
|
return this.getDataValue('value').startsWith('//')
|
|
82
82
|
? `https:${this.getDataValue('value')}`
|
|
@@ -3,7 +3,7 @@ const path = require('path')
|
|
|
3
3
|
const fsPromise = require('fs/promises')
|
|
4
4
|
const { VM } = require('vm2')
|
|
5
5
|
const axios = require('axios')
|
|
6
|
-
const { lodash, getAppByCtx, getConfig, Sequelize,
|
|
6
|
+
const { lodash, getAppByCtx, getConfig, Sequelize, moment } = require('q-koa')
|
|
7
7
|
const { LRUCache } = require('lru-cache')
|
|
8
8
|
const cache = new LRUCache({
|
|
9
9
|
max: 10,
|
|
@@ -90,7 +90,7 @@ exports.countAndMaxId = async (ctx, _data) => {
|
|
|
90
90
|
attributes: ['id'],
|
|
91
91
|
where: {
|
|
92
92
|
created_at: {
|
|
93
|
-
$lt:
|
|
93
|
+
$lt: moment().add(-1, 'months'),
|
|
94
94
|
},
|
|
95
95
|
},
|
|
96
96
|
order: [['id', 'DESC']],
|
|
@@ -822,7 +822,7 @@ exports.mockPay = async (ctx) => {
|
|
|
822
822
|
...(rest.transactionid
|
|
823
823
|
? {}
|
|
824
824
|
: {
|
|
825
|
-
transactionid:
|
|
825
|
+
transactionid: moment().valueOf() + '',
|
|
826
826
|
}),
|
|
827
827
|
})
|
|
828
828
|
ctx.SUCCESS('ok')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const md5 = require('js-md5')
|
|
2
|
-
const { getAppByCtx, getConfig, lodash,
|
|
2
|
+
const { getAppByCtx, getConfig, lodash, moment } = require('q-koa')
|
|
3
3
|
const { getAppConfig } = require('../../utils')
|
|
4
4
|
|
|
5
5
|
exports.login = async (ctx) => {
|
|
@@ -229,11 +229,11 @@ exports.login = async (ctx) => {
|
|
|
229
229
|
|
|
230
230
|
if (
|
|
231
231
|
result.updated_at &&
|
|
232
|
-
|
|
232
|
+
moment().diff(moment(result.updated_at), 'hours') > 24
|
|
233
233
|
) {
|
|
234
234
|
app.model.user.upsert({
|
|
235
235
|
id: result.id,
|
|
236
|
-
updated_at:
|
|
236
|
+
updated_at: moment(),
|
|
237
237
|
})
|
|
238
238
|
}
|
|
239
239
|
|
|
@@ -481,11 +481,11 @@ exports.checkLogin = async (ctx) => {
|
|
|
481
481
|
|
|
482
482
|
if (
|
|
483
483
|
result.updated_at &&
|
|
484
|
-
|
|
484
|
+
moment().diff(moment(result.updated_at), 'hours') > 24
|
|
485
485
|
) {
|
|
486
486
|
app.model.user.upsert({
|
|
487
487
|
id: result.id,
|
|
488
|
-
updated_at:
|
|
488
|
+
updated_at: moment(),
|
|
489
489
|
})
|
|
490
490
|
}
|
|
491
491
|
return ctx.SUCCESS({
|
|
@@ -2,7 +2,7 @@ const {
|
|
|
2
2
|
lodash,
|
|
3
3
|
getAppByCtx,
|
|
4
4
|
getConfig,
|
|
5
|
-
|
|
5
|
+
moment,
|
|
6
6
|
ServiceError,
|
|
7
7
|
getUserByCtx,
|
|
8
8
|
} = require('q-koa')
|
|
@@ -551,11 +551,11 @@ exports.mp_login = async (ctx) => {
|
|
|
551
551
|
|
|
552
552
|
if (
|
|
553
553
|
result.updated_at &&
|
|
554
|
-
|
|
554
|
+
moment().diff(moment(result.updated_at), 'hours') > 24
|
|
555
555
|
) {
|
|
556
556
|
app.model.user.upsert({
|
|
557
557
|
id: result.id,
|
|
558
|
-
updated_at:
|
|
558
|
+
updated_at: moment(),
|
|
559
559
|
})
|
|
560
560
|
}
|
|
561
561
|
|
|
@@ -1614,7 +1614,7 @@ exports.query_url_link = async (ctx, _data) => {
|
|
|
1614
1614
|
const result = await weixinMp.queryUrlLink(url_link)
|
|
1615
1615
|
const payLoad = {
|
|
1616
1616
|
...result,
|
|
1617
|
-
is_out: result.expire_time * 1000 -
|
|
1617
|
+
is_out: result.expire_time * 1000 - moment().valueOf() < 0,
|
|
1618
1618
|
}
|
|
1619
1619
|
|
|
1620
1620
|
ctx.SUCCESS(payLoad)
|
|
@@ -2389,25 +2389,25 @@ exports.getUserPortrait = async (ctx) => {
|
|
|
2389
2389
|
weixinMp.init()
|
|
2390
2390
|
|
|
2391
2391
|
let obj = {}
|
|
2392
|
-
const diff =
|
|
2392
|
+
const diff = moment().hour() > 8 ? -1 : -2
|
|
2393
2393
|
if (type === 'day') {
|
|
2394
2394
|
obj = {
|
|
2395
|
-
begin_date:
|
|
2396
|
-
end_date:
|
|
2395
|
+
begin_date: moment().add(diff, 'days').format('YYYYMMDD'),
|
|
2396
|
+
end_date: moment().add(diff, 'days').format('YYYYMMDD'),
|
|
2397
2397
|
}
|
|
2398
2398
|
} else if (type === 'week') {
|
|
2399
2399
|
obj = {
|
|
2400
|
-
begin_date:
|
|
2401
|
-
.add(-6 + diff, '
|
|
2400
|
+
begin_date: moment()
|
|
2401
|
+
.add(-6 + diff, 'days')
|
|
2402
2402
|
.format('YYYYMMDD'),
|
|
2403
|
-
end_date:
|
|
2403
|
+
end_date: moment().add(diff, 'days').format('YYYYMMDD'),
|
|
2404
2404
|
}
|
|
2405
2405
|
} else if (type === 'month') {
|
|
2406
2406
|
obj = {
|
|
2407
|
-
begin_date:
|
|
2408
|
-
.add(-29 + diff, '
|
|
2407
|
+
begin_date: moment()
|
|
2408
|
+
.add(-29 + diff, 'days')
|
|
2409
2409
|
.format('YYYYMMDD'),
|
|
2410
|
-
end_date:
|
|
2410
|
+
end_date: moment().add(diff, 'days').format('YYYYMMDD'),
|
|
2411
2411
|
}
|
|
2412
2412
|
}
|
|
2413
2413
|
console.log('obj', obj)
|
|
@@ -2423,9 +2423,9 @@ exports.getVisitTrend = async (ctx, _data) => {
|
|
|
2423
2423
|
const { config = 'weixin_mp', type = 'day', date } = _data || ctx.request.body
|
|
2424
2424
|
const { app_id, app_secrect } = await appConfig.getObject(config)
|
|
2425
2425
|
|
|
2426
|
-
const diff =
|
|
2426
|
+
const diff = moment().hour() > 8 ? -1 : -2
|
|
2427
2427
|
|
|
2428
|
-
const begin_date =
|
|
2428
|
+
const begin_date = moment(date ? date : moment().add(diff, 'days')).format(
|
|
2429
2429
|
'YYYYMMDD'
|
|
2430
2430
|
)
|
|
2431
2431
|
|
|
@@ -2433,8 +2433,8 @@ exports.getVisitTrend = async (ctx, _data) => {
|
|
|
2433
2433
|
const target = await app.model.weixin_visit.findOne({
|
|
2434
2434
|
where: {
|
|
2435
2435
|
ref_date: date
|
|
2436
|
-
? Number(
|
|
2437
|
-
: Number(
|
|
2436
|
+
? Number(moment(date).format('YYYYMMDD'))
|
|
2437
|
+
: Number(moment(begin_date).format('YYYYMMDD')),
|
|
2438
2438
|
},
|
|
2439
2439
|
})
|
|
2440
2440
|
if (target) {
|
|
@@ -2448,7 +2448,7 @@ exports.getVisitTrend = async (ctx, _data) => {
|
|
|
2448
2448
|
if (type === 'day') {
|
|
2449
2449
|
obj = {
|
|
2450
2450
|
begin_date,
|
|
2451
|
-
end_date:
|
|
2451
|
+
end_date: moment(date ? date : moment().add(diff, 'days')).format(
|
|
2452
2452
|
'YYYYMMDD'
|
|
2453
2453
|
),
|
|
2454
2454
|
}
|
|
@@ -2467,7 +2467,7 @@ exports.getVisitTrend = async (ctx, _data) => {
|
|
|
2467
2467
|
} else {
|
|
2468
2468
|
return app.controller.weixin.getVisitTrend(ctx, {
|
|
2469
2469
|
type,
|
|
2470
|
-
date:
|
|
2470
|
+
date: moment(date).add(-1, 'days').format('YYYYMMDD'),
|
|
2471
2471
|
})
|
|
2472
2472
|
}
|
|
2473
2473
|
|
|
@@ -3,7 +3,7 @@ const {
|
|
|
3
3
|
getAppConfig,
|
|
4
4
|
getConfig,
|
|
5
5
|
lodash,
|
|
6
|
-
|
|
6
|
+
moment,
|
|
7
7
|
sleep,
|
|
8
8
|
} = require('q-koa')
|
|
9
9
|
const { Pay } = require('@sigodenjs/wechatpay')
|
|
@@ -1010,9 +1010,9 @@ const handleBillData = (result) => {
|
|
|
1010
1010
|
}
|
|
1011
1011
|
let order_date
|
|
1012
1012
|
if (prefix) {
|
|
1013
|
-
order_date =
|
|
1013
|
+
order_date = moment(array[0].substring(1)).format('YYYY-MM-DD') + ''
|
|
1014
1014
|
} else {
|
|
1015
|
-
order_date =
|
|
1015
|
+
order_date = moment(
|
|
1016
1016
|
`${orderdate.slice(0, 4)}-${orderdate.slice(4, 6)}-${orderdate.slice(
|
|
1017
1017
|
6,
|
|
1018
1018
|
8
|
|
@@ -1150,7 +1150,7 @@ exports.union_downloadBill = async ({
|
|
|
1150
1150
|
})
|
|
1151
1151
|
|
|
1152
1152
|
const result = await allinpay.downloadBill({
|
|
1153
|
-
date: date ||
|
|
1153
|
+
date: date || moment().add(-1, 'days').format('YYYYMMDD'),
|
|
1154
1154
|
})
|
|
1155
1155
|
|
|
1156
1156
|
if (result && result.url) {
|
|
@@ -1292,7 +1292,7 @@ exports.union_downloadBill = async ({
|
|
|
1292
1292
|
const orderTarget = orderList.find((o) => o.id === item.order_id)
|
|
1293
1293
|
openid = orderTarget.user && orderTarget.user.mp_openid
|
|
1294
1294
|
remark = `订单${orderTarget.orderid}`
|
|
1295
|
-
order_date =
|
|
1295
|
+
order_date = moment(orderTarget.created_at).format('YYYY-MM-DD')
|
|
1296
1296
|
application_id = orderTarget.application_id
|
|
1297
1297
|
} else if (item.member_order_id) {
|
|
1298
1298
|
const orderTarget = member_order_list.find(
|
|
@@ -1300,7 +1300,7 @@ exports.union_downloadBill = async ({
|
|
|
1300
1300
|
)
|
|
1301
1301
|
openid = orderTarget.user && orderTarget.user.mp_openid
|
|
1302
1302
|
remark = `购买${orderTarget.application.name}会员${item.member_order_id}`
|
|
1303
|
-
order_date =
|
|
1303
|
+
order_date = moment(orderTarget.created_at).format('YYYY-MM-DD')
|
|
1304
1304
|
application_id = orderTarget.application_id
|
|
1305
1305
|
}
|
|
1306
1306
|
returnRes.push({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const cheerio = require('cheerio')
|
|
2
|
-
const
|
|
2
|
+
const moment = require('dayjs')
|
|
3
3
|
|
|
4
4
|
exports.handleHtml = async function (html) {
|
|
5
5
|
const $ = cheerio.load(html, {
|
|
@@ -40,7 +40,7 @@ exports.handleHtml = async function (html) {
|
|
|
40
40
|
// html = deal(html)
|
|
41
41
|
// html = html.replace('url("', 'url(\'')
|
|
42
42
|
// html = html.replace('")', '\')')
|
|
43
|
-
const publish_time =
|
|
43
|
+
const publish_time = moment(parseInt(ct + '000'))
|
|
44
44
|
return {
|
|
45
45
|
asyncTasks,
|
|
46
46
|
image,
|
package/core/file/utils/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { lodash } = require('q-koa')
|
|
2
2
|
const Sequelize = require('sequelize')
|
|
3
3
|
const md5 = require('md5')
|
|
4
|
-
const
|
|
4
|
+
const moment = require('dayjs')
|
|
5
5
|
const _ = require('lodash')
|
|
6
6
|
|
|
7
7
|
const findConfig = (type) => (item) =>
|
|
@@ -354,22 +354,22 @@ const filterFunction = (target, data) => {
|
|
|
354
354
|
if (_.isObject(target[key])) {
|
|
355
355
|
if ('$gt' in target[key]) {
|
|
356
356
|
if (key.endsWith('time') || key.endsWith('_at')) {
|
|
357
|
-
return
|
|
357
|
+
return moment(data[key]).diff(moment(target[key].$gt), 'seconds') > 0
|
|
358
358
|
}
|
|
359
359
|
return data[key] > target[key].$gt
|
|
360
360
|
} else if ('$gte' in target[key]) {
|
|
361
361
|
if (key.endsWith('time') || key.endsWith('_at')) {
|
|
362
|
-
return
|
|
362
|
+
return moment(data[key]).diff(moment(target[key].$gt), 'seconds') >= 0
|
|
363
363
|
}
|
|
364
364
|
return data[key] >= target[key].$gte
|
|
365
365
|
} else if ('$lt' in target[key]) {
|
|
366
366
|
if (key.endsWith('time') || key.endsWith('_at')) {
|
|
367
|
-
return
|
|
367
|
+
return moment(target[key].$lt).diff(moment(data[key]), 'seconds') < 0
|
|
368
368
|
}
|
|
369
369
|
return data[key] < target[key].$lt
|
|
370
370
|
} else if ('$lte' in target[key]) {
|
|
371
371
|
if (key.endsWith('time') || key.endsWith('_at')) {
|
|
372
|
-
return
|
|
372
|
+
return moment(target[key].$lte).diff(moment(data[key]), 'seconds') <= 0
|
|
373
373
|
}
|
|
374
374
|
return data[key] <= target[key].$lte
|
|
375
375
|
} else if ('$notIn' in target[key]) {
|