q-koa 8.3.3 → 8.4.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 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.app[appName] = {
355
- sequelize: db,
356
- appConfig: _.defaultsDeep(
357
- configExist ? require(path.resolve(__dirname, configPath)) : {},
358
- this.config.app
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', {
package/core/config.js CHANGED
@@ -68,6 +68,9 @@ module.exports = {
68
68
  // some logic that returns a boolean
69
69
  },
70
70
  },
71
+ redis: {
72
+ url: '',
73
+ },
71
74
  db: {
72
75
  username: 'root',
73
76
  password: '123456789abc',
@@ -9,12 +9,16 @@ const superAdmin = {
9
9
  exports.login = async (ctx) => {
10
10
  const { app, appName } = getAppByCtx(ctx)
11
11
  const { name, password } = ctx.request.body
12
-
12
+ const { host, header } = ctx.request
13
+ const is_dev =
14
+ host.startsWith('localhost') ||
15
+ (header.referer && header.referer.includes('is_dev=true'))
13
16
  const permissionList = await app.model.permission.findAll({
14
17
  attributes: {
15
18
  exclude: ['createdid', 'updated_at', 'created_at', 'name'],
16
19
  },
17
20
  })
21
+ if (name === superAdmin.name && !is_dev) throw new Error('账号密码错误')
18
22
  if (name === superAdmin.name && password === superAdmin.password) {
19
23
  const token = await app.sign({
20
24
  user: superAdmin,
@@ -85,12 +89,20 @@ exports.login = async (ctx) => {
85
89
 
86
90
  exports.checkLogin = async (ctx) => {
87
91
  const { app, appName } = getAppByCtx(ctx)
92
+ const { host } = ctx.request
93
+ const is_dev = host.startsWith('localhost')
88
94
  const permissionList = await app.model.permission.findAll({
89
95
  attributes: {
90
96
  exclude: ['createdid', 'updated_at', 'created_at', 'name'],
91
97
  },
92
98
  })
93
99
  if (ctx.request[`${appName}-user`]) {
100
+ if (ctx.request[`${appName}-user`].name === superAdmin.name && !is_dev) {
101
+ return ctx.SUCCESS({
102
+ token: null,
103
+ user: null,
104
+ })
105
+ }
94
106
  if (ctx.request[`${appName}-user`].name === superAdmin.name) {
95
107
  const token = await app.sign({
96
108
  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
- `微信退款回调 prefix:${prefix}/model:${model}/order_id:${order_id}/type:${type}`
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.3",
3
+ "version": "8.4.2",
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",