q-koa 8.3.2 → 8.4.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.
package/core/app.js
CHANGED
|
@@ -5,6 +5,7 @@ const path = require('path')
|
|
|
5
5
|
const fs = require('fs')
|
|
6
6
|
const fsPromise = require('fs/promises')
|
|
7
7
|
const Sequelize = require('sequelize')
|
|
8
|
+
const redis = require('redis')
|
|
8
9
|
const moment = require('moment')
|
|
9
10
|
const { EventEmitter } = require('events')
|
|
10
11
|
const nodeVm = require('vm')
|
|
@@ -351,13 +352,29 @@ class APP {
|
|
|
351
352
|
const configFile = path.resolve(__dirname, configPath)
|
|
352
353
|
const configExist = fs.existsSync(configFile)
|
|
353
354
|
|
|
354
|
-
this.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
355
|
+
if (this.config.redis && this.config.redis.url) {
|
|
356
|
+
const client = redis.createClient(this.config.redis)
|
|
357
|
+
client.on('error', (err) => console.log('Redis Client Error', err))
|
|
358
|
+
|
|
359
|
+
await client.connect()
|
|
360
|
+
this.app[appName] = {
|
|
361
|
+
sequelize: db,
|
|
362
|
+
redisClient: client,
|
|
363
|
+
appConfig: _.defaultsDeep(
|
|
364
|
+
configExist ? require(path.resolve(__dirname, configPath)) : {},
|
|
365
|
+
this.config.app
|
|
366
|
+
),
|
|
367
|
+
}
|
|
368
|
+
}else{
|
|
369
|
+
this.app[appName] = {
|
|
370
|
+
sequelize: db,
|
|
371
|
+
appConfig: _.defaultsDeep(
|
|
372
|
+
configExist ? require(path.resolve(__dirname, configPath)) : {},
|
|
373
|
+
this.config.app
|
|
374
|
+
),
|
|
375
|
+
}
|
|
360
376
|
}
|
|
377
|
+
|
|
361
378
|
|
|
362
379
|
// const proxyConfig = _.get(this.app[appName], 'appConfig.proxy');
|
|
363
380
|
// const taskConfig = _.get(this.app[appName], 'appConfig.task', {
|
|
@@ -1671,15 +1688,17 @@ class APP {
|
|
|
1671
1688
|
throw new Error('新增不能为空')
|
|
1672
1689
|
}
|
|
1673
1690
|
const _exclude =
|
|
1674
|
-
ctx.request
|
|
1675
|
-
(
|
|
1676
|
-
ctx.request[`${appName}-user`].name
|
|
1677
|
-
|
|
1678
|
-
ctx.request[`${appName}-user`].mobile
|
|
1679
|
-
|
|
1680
|
-
|
|
1691
|
+
ctx.request.clientType === 1 ||
|
|
1692
|
+
(ctx.request[`${appName}-user`] &&
|
|
1693
|
+
((ctx.request[`${appName}-user`].name &&
|
|
1694
|
+
ctx.request[`${appName}-user`].name === 'admin') ||
|
|
1695
|
+
(ctx.request[`${appName}-user`].mobile &&
|
|
1696
|
+
ctx.request[`${appName}-user`].mobile === '18978909244') ||
|
|
1697
|
+
ctx.request[`${appName}-user`].is_admin ||
|
|
1698
|
+
ctx.request[`${appName}-user`].is_dev))
|
|
1681
1699
|
? ['updated_at']
|
|
1682
1700
|
: ['created_at', 'updated_at']
|
|
1701
|
+
|
|
1683
1702
|
const newData = _.omit(_.omitBy(ctx.request.body, _.isNull), _exclude)
|
|
1684
1703
|
|
|
1685
1704
|
const flag = await app[appName].model[controller][fn]({
|
package/core/config.js
CHANGED
|
@@ -8,13 +8,15 @@ const superAdmin = {
|
|
|
8
8
|
|
|
9
9
|
exports.login = async (ctx) => {
|
|
10
10
|
const { app, appName } = getAppByCtx(ctx)
|
|
11
|
+
const { host } = ctx.request
|
|
11
12
|
const { name, password } = ctx.request.body
|
|
12
|
-
|
|
13
|
+
const is_dev = host.startsWith('localhost')
|
|
13
14
|
const permissionList = await app.model.permission.findAll({
|
|
14
15
|
attributes: {
|
|
15
16
|
exclude: ['createdid', 'updated_at', 'created_at', 'name'],
|
|
16
17
|
},
|
|
17
18
|
})
|
|
19
|
+
if (name === superAdmin.name && !is_dev) throw new Error('账号密码错误')
|
|
18
20
|
if (name === superAdmin.name && password === superAdmin.password) {
|
|
19
21
|
const token = await app.sign({
|
|
20
22
|
user: superAdmin,
|
|
@@ -85,12 +87,20 @@ exports.login = async (ctx) => {
|
|
|
85
87
|
|
|
86
88
|
exports.checkLogin = async (ctx) => {
|
|
87
89
|
const { app, appName } = getAppByCtx(ctx)
|
|
90
|
+
const { host } = ctx.request
|
|
91
|
+
const is_dev = host.startsWith('localhost')
|
|
88
92
|
const permissionList = await app.model.permission.findAll({
|
|
89
93
|
attributes: {
|
|
90
94
|
exclude: ['createdid', 'updated_at', 'created_at', 'name'],
|
|
91
95
|
},
|
|
92
96
|
})
|
|
93
97
|
if (ctx.request[`${appName}-user`]) {
|
|
98
|
+
if (ctx.request[`${appName}-user`].name === superAdmin.name && !is_dev) {
|
|
99
|
+
return ctx.SUCCESS({
|
|
100
|
+
token: null,
|
|
101
|
+
user: null,
|
|
102
|
+
})
|
|
103
|
+
}
|
|
94
104
|
if (ctx.request[`${appName}-user`].name === superAdmin.name) {
|
|
95
105
|
const token = await app.sign({
|
|
96
106
|
user: superAdmin,
|
|
@@ -70,7 +70,7 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
|
|
|
70
70
|
|
|
71
71
|
if (app.controller[model] && app.controller[model][fn]) {
|
|
72
72
|
return app.controller[model][fn](ctx, data).then((result) => {
|
|
73
|
-
if (!result) {
|
|
73
|
+
if (!result && process.env.NODE_ENV !== 'production') {
|
|
74
74
|
console.log(`需要在控制器${fn}中返回`)
|
|
75
75
|
}
|
|
76
76
|
return {
|
|
@@ -918,7 +918,7 @@ exports.notify = async (ctx) => {
|
|
|
918
918
|
transactionid = result.xml.transaction_id
|
|
919
919
|
} catch (e) {}
|
|
920
920
|
|
|
921
|
-
console.log(order_id, '微信支付回调-----', model, order_price, transactionid)
|
|
921
|
+
// console.log(order_id, '微信支付回调-----', model, order_price, transactionid)
|
|
922
922
|
if (app.service[model] && app.service[model].notify) {
|
|
923
923
|
await app.service[model].notify({
|
|
924
924
|
app,
|
|
@@ -1094,9 +1094,9 @@ exports.refund_notify = async (ctx) => {
|
|
|
1094
1094
|
: Number(out_refund_no)
|
|
1095
1095
|
const type = out_refund_no.includes('_') ? out_refund_no.split('_')[1] : ''
|
|
1096
1096
|
const model = prefix ? `${prefix}_order` : 'order'
|
|
1097
|
-
console.log(
|
|
1098
|
-
|
|
1099
|
-
)
|
|
1097
|
+
// console.log(
|
|
1098
|
+
// `微信退款回调 prefix:${prefix}/model:${model}/order_id:${order_id}/type:${type}`
|
|
1099
|
+
// )
|
|
1100
1100
|
if (app.service[model] && app.service[model].refund_notify) {
|
|
1101
1101
|
await app.service[model].refund_notify({
|
|
1102
1102
|
app,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "q-koa",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"wechat-oauth": "^1.5.0",
|
|
55
55
|
"weixin-pay-fork": "^1.0.0",
|
|
56
56
|
"node-uuid": "^1.4.8",
|
|
57
|
-
"sha1": "^1.1.1"
|
|
57
|
+
"sha1": "^1.1.1",
|
|
58
|
+
"redis": "^4.0.3"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
61
|
"eslint": "^4.19.1",
|