q-koa 7.9.1 → 7.9.4

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/config.js CHANGED
@@ -73,7 +73,7 @@ module.exports = {
73
73
  timezone: '+08:00',
74
74
  port: 3306,
75
75
  pool: {
76
- max: 30,
76
+ max: 10,
77
77
  min: 1,
78
78
  },
79
79
  operatorsAliases: {
@@ -104,7 +104,7 @@ exports.showTables = async (ctx) => {
104
104
  : app.config[_model]
105
105
  // const target = Object.keys(app.config[model])
106
106
 
107
- // console.log(model,mock,app.mock && app.mock[model] && app.mock[model]())
107
+ if (!target) throw new Error(`检查是否有${_model}/config.js`)
108
108
  const model = target.model ? target.model : _model
109
109
  return {
110
110
  modelName: _model,
@@ -1,5 +1,5 @@
1
1
  const md5 = require('js-md5')
2
- const { getAppByCtx, getConfig } = require('q-koa')
2
+ const { getAppByCtx, getConfig, lodash } = require('q-koa')
3
3
 
4
4
  exports.login = async (ctx) => {
5
5
  const { app, appName } = getAppByCtx(ctx)
@@ -331,10 +331,12 @@ exports.checkLogin = async (ctx) => {
331
331
  const token = await app.sign({
332
332
  user: tokenResult,
333
333
  })
334
-
334
+ console.log('app.appConfig.loginData', app.appConfig.loginData)
335
335
  return ctx.SUCCESS({
336
336
  token,
337
- user: result,
337
+ user: app.appConfig.loginData
338
+ ? lodash.omit(result.toJSON(), app.appConfig.loginData.omit)
339
+ : result,
338
340
  })
339
341
  }
340
342
 
@@ -332,6 +332,19 @@ exports.mp_login = async (ctx) => {
332
332
  openid: post.openid,
333
333
  },
334
334
  })
335
+ if (app.attributes.user.mp_openid) {
336
+ app.model.user.update(
337
+ {
338
+ mp_openid: post.openid,
339
+ },
340
+ {
341
+ where: {
342
+ id: openIdUser.user_id,
343
+ mp_openid: '',
344
+ },
345
+ }
346
+ )
347
+ }
335
348
  uid = openIdUser.user_id
336
349
  } else {
337
350
  if (post.user_id) {
@@ -343,12 +356,14 @@ exports.mp_login = async (ctx) => {
343
356
  } else {
344
357
  try {
345
358
  await app.sequelize.transaction(async (transaction) => {
346
- const user = await app.model.user.create(
347
- {},
348
- {
349
- transaction,
350
- }
351
- )
359
+ const target = app.attributes.user.mp_openid
360
+ ? {
361
+ mp_openid: post.openid,
362
+ }
363
+ : {}
364
+ const user = await app.model.user.create(target, {
365
+ transaction,
366
+ })
352
367
  uid = user.id
353
368
  await app.model.mp_user.create(
354
369
  {
@@ -724,10 +739,11 @@ exports.h5_pay = async (ctx) => {
724
739
  return_url,
725
740
  type,
726
741
  is_admin = false,
742
+ pay_config = 'weixin_pay',
727
743
  } = ctx.request.body
728
744
 
729
745
  const appConfig = getConfig(app)
730
- const { appId, key, mchId } = await appConfig.getObject('weixin_pay')
746
+ const { appId, key, mchId } = await appConfig.getObject(pay_config)
731
747
  const { is_dev, site_host } = await appConfig.getObject('base')
732
748
 
733
749
  const payObj = new WeixinPay({
@@ -767,6 +783,7 @@ exports.mp_pay = async (ctx) => {
767
783
  out_trade_no,
768
784
  is_admin = false,
769
785
  config = 'weixin_mp',
786
+ pay_config = 'weixin_pay',
770
787
  } = ctx.request.body
771
788
 
772
789
  if (price === 0) throw new Error('价格不能为0')
@@ -786,7 +803,7 @@ exports.mp_pay = async (ctx) => {
786
803
  }
787
804
  const appConfig = getConfig(app)
788
805
 
789
- const { mchId, key } = await appConfig.getObject('weixin_pay')
806
+ const { mchId, key } = await appConfig.getObject(pay_config)
790
807
  const { is_dev, site_host } = await appConfig.getObject('base')
791
808
  // 公众号支付用 服务号 appid,其他用小程序 appid
792
809
  const app_id =
@@ -1032,9 +1049,10 @@ const getRefundResultJson = async ({ req_info, app_key }) => {
1032
1049
  exports.refund_notify = async (ctx) => {
1033
1050
  const { app } = getAppByCtx(ctx)
1034
1051
  const result = ctx.request.xmlBody
1052
+ const pay_config = ctx.request.query.pay_config || 'weixin_pay'
1035
1053
 
1036
1054
  const appConfig = getConfig(app)
1037
- const { key } = await appConfig.getObject('weixin_pay')
1055
+ const { key } = await appConfig.getObject(pay_config)
1038
1056
 
1039
1057
  const { req_info } = result.xml
1040
1058
  const refundResult = await getRefundResultJson({
@@ -1095,7 +1113,12 @@ exports.article = async (ctx) => {
1095
1113
  exports.checkPay = async (ctx) => {
1096
1114
  const { app, appName, controller } = getAppByCtx(ctx)
1097
1115
 
1098
- const { id, prefix } = ctx.request.body
1116
+ const {
1117
+ id,
1118
+ prefix,
1119
+ config = 'weixin_mp',
1120
+ pay_config = 'weixin_pay',
1121
+ } = ctx.request.body
1099
1122
 
1100
1123
  const orderModel = prefix ? `${prefix}_order` : 'order'
1101
1124
  const result = await app.model[orderModel].findOne({
@@ -1106,8 +1129,8 @@ exports.checkPay = async (ctx) => {
1106
1129
  if (!result) return ctx.SUCCESS('找不到')
1107
1130
 
1108
1131
  const appConfig = getConfig(app)
1109
- const app_id = (await appConfig.getObject('weixin_mp')).app_id
1110
- const { mchId, key } = await appConfig.getObject('weixin_pay')
1132
+ const app_id = (await appConfig.getObject(config)).app_id
1133
+ const { mchId, key } = await appConfig.getObject(pay_config)
1111
1134
 
1112
1135
  const wxpay = WXPay({
1113
1136
  appid: app_id,
@@ -1142,3 +1165,31 @@ exports.checkPay = async (ctx) => {
1142
1165
 
1143
1166
  ctx.SUCCESS({ prefix, out_trade_no, ...payResult })
1144
1167
  }
1168
+
1169
+ exports.init_mp_openid = async (ctx) => {
1170
+ const { app, appName } = getAppByCtx(ctx)
1171
+
1172
+ const list = await app.model.user.findAll({
1173
+ limit: 1000,
1174
+ order: [['id', 'DESC']],
1175
+ where: {
1176
+ mp_openid: '',
1177
+ },
1178
+ include: app.model.mp_user,
1179
+ })
1180
+
1181
+ const result = list
1182
+ .filter((item) => item.mp_user && item.mp_user.openid)
1183
+ .map((item) => {
1184
+ return {
1185
+ id: item.id,
1186
+ mp_openid: item.mp_user.openid,
1187
+ }
1188
+ })
1189
+
1190
+ await app.model.user.bulkCreate(result, {
1191
+ updateOnDuplicate: ['mp_openid'],
1192
+ })
1193
+
1194
+ ctx.SUCCESS(result.length)
1195
+ }
@@ -12,11 +12,12 @@ exports.refund = async ({
12
12
  refund_fee,
13
13
  price,
14
14
  type = '',
15
+ pay_config = 'weixin_pay',
15
16
  ...rest
16
17
  }) => {
17
18
  const { app, appName } = getAppByCtx(ctx)
18
19
  const appConfig = getConfig(app)
19
- const { mchId, key, appId } = await appConfig.getObject('weixin_pay')
20
+ const { mchId, key, appId } = await appConfig.getObject(pay_config)
20
21
  const { site_host } = await appConfig.getObject('base')
21
22
 
22
23
  const payObj = new Pay({
@@ -49,7 +50,7 @@ exports.refund = async ({
49
50
  refund_fee: Math.round((refund_fee || price) * 100),
50
51
  notify_url: `https://${
51
52
  site_host || 'api.kuashou.com'
52
- }/${appName}/weixin/refund_notify`,
53
+ }/${appName}/weixin/refund_notify?pay_config=weixin_pay`,
53
54
  })
54
55
  if (result_code === 'SUCCESS') {
55
56
  return true
@@ -63,9 +64,9 @@ exports.refund = async ({
63
64
 
64
65
  exports.cash = async ({ ctx, id, user_id, number }) => {
65
66
  const { app, appName } = getAppByCtx(ctx)
66
-
67
+ const { pay_config = 'weixin_pay' } = ctx.request.body
67
68
  const appConfig = getConfig(app)
68
- const { mchId, key, appId } = await appConfig.getObject('weixin_pay')
69
+ const { mchId, key, appId } = await appConfig.getObject(pay_config)
69
70
 
70
71
  const { is_dev } = await appConfig.getObject('base')
71
72
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "7.9.1",
3
+ "version": "7.9.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {