q-koa 7.9.2 → 7.9.5
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
|
@@ -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
|
-
|
|
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:
|
|
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,14 +356,14 @@ exports.mp_login = async (ctx) => {
|
|
|
343
356
|
} else {
|
|
344
357
|
try {
|
|
345
358
|
await app.sequelize.transaction(async (transaction) => {
|
|
346
|
-
const
|
|
347
|
-
{
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
{
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
)
|
|
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
|
+
})
|
|
354
367
|
uid = user.id
|
|
355
368
|
await app.model.mp_user.create(
|
|
356
369
|
{
|
|
@@ -726,10 +739,11 @@ exports.h5_pay = async (ctx) => {
|
|
|
726
739
|
return_url,
|
|
727
740
|
type,
|
|
728
741
|
is_admin = false,
|
|
742
|
+
pay_config = 'weixin_pay',
|
|
729
743
|
} = ctx.request.body
|
|
730
744
|
|
|
731
745
|
const appConfig = getConfig(app)
|
|
732
|
-
const { appId, key, mchId } = await appConfig.getObject(
|
|
746
|
+
const { appId, key, mchId } = await appConfig.getObject(pay_config)
|
|
733
747
|
const { is_dev, site_host } = await appConfig.getObject('base')
|
|
734
748
|
|
|
735
749
|
const payObj = new WeixinPay({
|
|
@@ -769,6 +783,7 @@ exports.mp_pay = async (ctx) => {
|
|
|
769
783
|
out_trade_no,
|
|
770
784
|
is_admin = false,
|
|
771
785
|
config = 'weixin_mp',
|
|
786
|
+
pay_config = 'weixin_pay',
|
|
772
787
|
} = ctx.request.body
|
|
773
788
|
|
|
774
789
|
if (price === 0) throw new Error('价格不能为0')
|
|
@@ -788,7 +803,7 @@ exports.mp_pay = async (ctx) => {
|
|
|
788
803
|
}
|
|
789
804
|
const appConfig = getConfig(app)
|
|
790
805
|
|
|
791
|
-
const { mchId, key } = await appConfig.getObject(
|
|
806
|
+
const { mchId, key } = await appConfig.getObject(pay_config)
|
|
792
807
|
const { is_dev, site_host } = await appConfig.getObject('base')
|
|
793
808
|
// 公众号支付用 服务号 appid,其他用小程序 appid
|
|
794
809
|
const app_id =
|
|
@@ -1034,9 +1049,10 @@ const getRefundResultJson = async ({ req_info, app_key }) => {
|
|
|
1034
1049
|
exports.refund_notify = async (ctx) => {
|
|
1035
1050
|
const { app } = getAppByCtx(ctx)
|
|
1036
1051
|
const result = ctx.request.xmlBody
|
|
1052
|
+
const pay_config = ctx.request.query.pay_config || 'weixin_pay'
|
|
1037
1053
|
|
|
1038
1054
|
const appConfig = getConfig(app)
|
|
1039
|
-
const { key } = await appConfig.getObject(
|
|
1055
|
+
const { key } = await appConfig.getObject(pay_config)
|
|
1040
1056
|
|
|
1041
1057
|
const { req_info } = result.xml
|
|
1042
1058
|
const refundResult = await getRefundResultJson({
|
|
@@ -1097,7 +1113,12 @@ exports.article = async (ctx) => {
|
|
|
1097
1113
|
exports.checkPay = async (ctx) => {
|
|
1098
1114
|
const { app, appName, controller } = getAppByCtx(ctx)
|
|
1099
1115
|
|
|
1100
|
-
const {
|
|
1116
|
+
const {
|
|
1117
|
+
id,
|
|
1118
|
+
prefix,
|
|
1119
|
+
config = 'weixin_mp',
|
|
1120
|
+
pay_config = 'weixin_pay',
|
|
1121
|
+
} = ctx.request.body
|
|
1101
1122
|
|
|
1102
1123
|
const orderModel = prefix ? `${prefix}_order` : 'order'
|
|
1103
1124
|
const result = await app.model[orderModel].findOne({
|
|
@@ -1108,8 +1129,8 @@ exports.checkPay = async (ctx) => {
|
|
|
1108
1129
|
if (!result) return ctx.SUCCESS('找不到')
|
|
1109
1130
|
|
|
1110
1131
|
const appConfig = getConfig(app)
|
|
1111
|
-
const app_id = (await appConfig.getObject(
|
|
1112
|
-
const { mchId, key } = await appConfig.getObject(
|
|
1132
|
+
const app_id = (await appConfig.getObject(config)).app_id
|
|
1133
|
+
const { mchId, key } = await appConfig.getObject(pay_config)
|
|
1113
1134
|
|
|
1114
1135
|
const wxpay = WXPay({
|
|
1115
1136
|
appid: app_id,
|
|
@@ -1149,18 +1170,22 @@ exports.init_mp_openid = async (ctx) => {
|
|
|
1149
1170
|
const { app, appName } = getAppByCtx(ctx)
|
|
1150
1171
|
|
|
1151
1172
|
const list = await app.model.user.findAll({
|
|
1173
|
+
limit: 1000,
|
|
1174
|
+
order: [['id', 'DESC']],
|
|
1152
1175
|
where: {
|
|
1153
1176
|
mp_openid: '',
|
|
1154
1177
|
},
|
|
1155
1178
|
include: app.model.mp_user,
|
|
1156
1179
|
})
|
|
1157
1180
|
|
|
1158
|
-
const result = list
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
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
|
+
})
|
|
1164
1189
|
|
|
1165
1190
|
await app.model.user.bulkCreate(result, {
|
|
1166
1191
|
updateOnDuplicate: ['mp_openid'],
|
|
@@ -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(
|
|
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(
|
|
69
|
+
const { mchId, key, appId } = await appConfig.getObject(pay_config)
|
|
69
70
|
|
|
70
71
|
const { is_dev } = await appConfig.getObject('base')
|
|
71
72
|
|
|
@@ -76,7 +77,7 @@ exports.cash = async ({ ctx, id, user_id, number }) => {
|
|
|
76
77
|
pfx: await fsPromise.readFile(
|
|
77
78
|
path.resolve(
|
|
78
79
|
__dirname,
|
|
79
|
-
`${process.cwd()}/app/${appName}/plugins/weixin/apiclient_cert.p12`
|
|
80
|
+
`${process.cwd()}/app/${appName}/plugins/weixin/${pay_config}/apiclient_cert.p12`
|
|
80
81
|
)
|
|
81
82
|
), // 微信商户平台证书
|
|
82
83
|
})
|