q-koa 13.5.0 → 13.6.0
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 +45 -10
- package/core/file/plugins/weixin/service.js +37 -14
- package/package.json +1 -1
package/core/app.js
CHANGED
|
@@ -446,6 +446,7 @@ class APP {
|
|
|
446
446
|
router
|
|
447
447
|
)
|
|
448
448
|
|
|
449
|
+
const { push } = require('./file/plugins/log/service')
|
|
449
450
|
try {
|
|
450
451
|
const target = includeList.find((i) => i.app === appName)
|
|
451
452
|
const dbName =
|
|
@@ -465,18 +466,54 @@ class APP {
|
|
|
465
466
|
const configFile = path.resolve(__dirname, configPath)
|
|
466
467
|
const configExist = fs.existsSync(configFile)
|
|
467
468
|
|
|
468
|
-
if (
|
|
469
|
-
|
|
470
|
-
|
|
469
|
+
if (
|
|
470
|
+
this.config.redis &&
|
|
471
|
+
this.config.redis.host &&
|
|
472
|
+
this.config.redis.port
|
|
473
|
+
) {
|
|
474
|
+
let subscriber
|
|
475
|
+
let client
|
|
476
|
+
try {
|
|
477
|
+
client = redis.createClient({
|
|
478
|
+
socket: {
|
|
479
|
+
host: this.config.redis.host,
|
|
480
|
+
port: this.config.redis.port,
|
|
481
|
+
reconnectStrategy: false,
|
|
482
|
+
},
|
|
483
|
+
...(this.config.redis.database
|
|
484
|
+
? {
|
|
485
|
+
database: this.config.redis.database,
|
|
486
|
+
}
|
|
487
|
+
: {}),
|
|
488
|
+
})
|
|
489
|
+
|
|
490
|
+
client.on('error', (err) => console.log('Redis Client Error', err))
|
|
491
|
+
|
|
492
|
+
await client.connect()
|
|
493
|
+
|
|
494
|
+
subscriber = client.duplicate()
|
|
495
|
+
await subscriber.connect()
|
|
496
|
+
push({
|
|
497
|
+
appName,
|
|
498
|
+
message: `${appName}连接redis成功,${this.config.ip}:${this.port}`,
|
|
499
|
+
})
|
|
500
|
+
} catch (e) {
|
|
501
|
+
client = null
|
|
471
502
|
|
|
472
|
-
|
|
503
|
+
push({
|
|
504
|
+
appName,
|
|
505
|
+
message: `${appName}连接redis失败,${e.message}`,
|
|
506
|
+
})
|
|
507
|
+
}
|
|
473
508
|
|
|
474
|
-
const subscriber = client.duplicate()
|
|
475
|
-
await subscriber.connect()
|
|
476
509
|
this.app[appName] = {
|
|
477
510
|
sequelize: db,
|
|
478
|
-
|
|
479
|
-
|
|
511
|
+
...(client
|
|
512
|
+
? {
|
|
513
|
+
redisClient: client,
|
|
514
|
+
subscriber,
|
|
515
|
+
}
|
|
516
|
+
: {}),
|
|
480
517
|
appConfig: _.defaultsDeep(
|
|
481
518
|
configExist ? require(path.resolve(__dirname, configPath)) : {},
|
|
482
519
|
this.config.app,
|
|
@@ -531,8 +568,6 @@ class APP {
|
|
|
531
568
|
await this.initModel(appName)
|
|
532
569
|
// const models = Object.keys(this.app[appName].model).join(' / ')
|
|
533
570
|
} catch (e) {
|
|
534
|
-
const { push } = require('./file/plugins/log/service')
|
|
535
|
-
|
|
536
571
|
push({
|
|
537
572
|
appName,
|
|
538
573
|
message: `${appName}数据库连接失败`,
|
|
@@ -97,6 +97,7 @@ exports.refund = async ({
|
|
|
97
97
|
out_trade_no: _out_trade_no,
|
|
98
98
|
out_refund_no: _out_refund_no,
|
|
99
99
|
is_pem = false,
|
|
100
|
+
mch_id = '',
|
|
100
101
|
...rest
|
|
101
102
|
}) => {
|
|
102
103
|
if (!ctx) throw new Error('?ctx')
|
|
@@ -110,12 +111,14 @@ exports.refund = async ({
|
|
|
110
111
|
|
|
111
112
|
const payObj = new Pay({
|
|
112
113
|
appId: appId,
|
|
113
|
-
mchId: mchId,
|
|
114
|
+
mchId: mch_id || mchId,
|
|
114
115
|
key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥,
|
|
115
116
|
pfx: await fsPromise.readFile(
|
|
116
117
|
path.resolve(
|
|
117
118
|
__dirname,
|
|
118
|
-
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
119
|
+
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
120
|
+
mch_id || key
|
|
121
|
+
}/apiclient_cert.p12`
|
|
119
122
|
)
|
|
120
123
|
),
|
|
121
124
|
})
|
|
@@ -134,20 +137,24 @@ exports.refund = async ({
|
|
|
134
137
|
if (!orderDetail) throw new Error('不存在该订单')
|
|
135
138
|
const wxpay = WXPay({
|
|
136
139
|
appid: appId,
|
|
137
|
-
mch_id: mchId,
|
|
140
|
+
mch_id: mch_id || mchId,
|
|
138
141
|
partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
|
|
139
142
|
...(isPem
|
|
140
143
|
? {
|
|
141
144
|
cert_pem: await fsPromise.readFile(
|
|
142
145
|
path.resolve(
|
|
143
146
|
__dirname,
|
|
144
|
-
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
147
|
+
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
148
|
+
mch_id || key
|
|
149
|
+
}/apiclient_cert.pem`
|
|
145
150
|
)
|
|
146
151
|
),
|
|
147
152
|
key_pem: await fsPromise.readFile(
|
|
148
153
|
path.resolve(
|
|
149
154
|
__dirname,
|
|
150
|
-
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
155
|
+
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
156
|
+
mch_id || key
|
|
157
|
+
}/apiclient_key.pem`
|
|
151
158
|
)
|
|
152
159
|
),
|
|
153
160
|
}
|
|
@@ -210,6 +217,7 @@ exports.refundOnly = async ({
|
|
|
210
217
|
out_trade_no: _out_trade_no,
|
|
211
218
|
out_refund_no: _out_refund_no,
|
|
212
219
|
is_pem = false,
|
|
220
|
+
mch_id = '',
|
|
213
221
|
...rest
|
|
214
222
|
}) => {
|
|
215
223
|
if (!ctx) throw new Error('?ctx')
|
|
@@ -223,12 +231,14 @@ exports.refundOnly = async ({
|
|
|
223
231
|
|
|
224
232
|
const payObj = new Pay({
|
|
225
233
|
appId: appId,
|
|
226
|
-
mchId: mchId,
|
|
234
|
+
mchId: mch_id || mchId,
|
|
227
235
|
key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥,
|
|
228
236
|
pfx: await fsPromise.readFile(
|
|
229
237
|
path.resolve(
|
|
230
238
|
__dirname,
|
|
231
|
-
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
239
|
+
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
240
|
+
mch_id || key
|
|
241
|
+
}/apiclient_cert.p12`
|
|
232
242
|
)
|
|
233
243
|
), // 微信商户平台证书
|
|
234
244
|
})
|
|
@@ -238,7 +248,7 @@ exports.refundOnly = async ({
|
|
|
238
248
|
|
|
239
249
|
const wxpay = WXPay({
|
|
240
250
|
appid: appId,
|
|
241
|
-
mch_id: mchId,
|
|
251
|
+
mch_id: mch_id || mchId,
|
|
242
252
|
partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
|
|
243
253
|
...(isPem
|
|
244
254
|
? {
|
|
@@ -364,6 +374,7 @@ exports.cash = async ({
|
|
|
364
374
|
user_id,
|
|
365
375
|
number,
|
|
366
376
|
pay_config = 'weixin_pay',
|
|
377
|
+
mch_id = '',
|
|
367
378
|
}) => {
|
|
368
379
|
if (!ctx) throw new Error('?ctx')
|
|
369
380
|
const { app, appName } = getAppByCtx(ctx)
|
|
@@ -388,12 +399,14 @@ exports.cash = async ({
|
|
|
388
399
|
|
|
389
400
|
const payObj = new Pay({
|
|
390
401
|
appId: appId,
|
|
391
|
-
mchId: mchId,
|
|
402
|
+
mchId: mch_id || mchId,
|
|
392
403
|
key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥,
|
|
393
404
|
pfx: await fsPromise.readFile(
|
|
394
405
|
path.resolve(
|
|
395
406
|
__dirname,
|
|
396
|
-
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
407
|
+
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
408
|
+
mch_id || key
|
|
409
|
+
}/apiclient_cert.p12`
|
|
397
410
|
)
|
|
398
411
|
), // 微信商户平台证书
|
|
399
412
|
})
|
|
@@ -952,8 +965,10 @@ const handleBillData = (result) => {
|
|
|
952
965
|
return {
|
|
953
966
|
header: arr[0],
|
|
954
967
|
list,
|
|
955
|
-
result: list.map((item) => {
|
|
968
|
+
result: list.map((item, index) => {
|
|
956
969
|
const array = item.split(',')
|
|
970
|
+
|
|
971
|
+
const mchid = array[2].substring(1)
|
|
957
972
|
const orderdate = array[20].substring(1).slice(2, 10)
|
|
958
973
|
const orderPrefix = array[6].substring(1).split('_')[1]
|
|
959
974
|
let order_id = 0
|
|
@@ -976,6 +991,7 @@ const handleBillData = (result) => {
|
|
|
976
991
|
).format('YYYY-MM-DD')
|
|
977
992
|
}
|
|
978
993
|
return {
|
|
994
|
+
mchid,
|
|
979
995
|
created_at: array[0].substring(1),
|
|
980
996
|
transactionid: array[5].substring(1),
|
|
981
997
|
[`${[prefix, 'order_id'].filter(Boolean).join('_')}`]: order_id,
|
|
@@ -1000,7 +1016,12 @@ const handleBillData = (result) => {
|
|
|
1000
1016
|
}
|
|
1001
1017
|
}
|
|
1002
1018
|
|
|
1003
|
-
exports.downloadBill = async ({
|
|
1019
|
+
exports.downloadBill = async ({
|
|
1020
|
+
ctx,
|
|
1021
|
+
pay_config = 'weixin_pay',
|
|
1022
|
+
mch_id = '',
|
|
1023
|
+
...rest
|
|
1024
|
+
}) => {
|
|
1004
1025
|
if (!ctx) throw new Error('?ctx')
|
|
1005
1026
|
const { app, appName } = getAppByCtx(ctx)
|
|
1006
1027
|
const appConfig = getConfig(app)
|
|
@@ -1009,12 +1030,14 @@ exports.downloadBill = async ({ ctx, pay_config = 'weixin_pay', ...rest }) => {
|
|
|
1009
1030
|
)
|
|
1010
1031
|
const payObj = new Pay({
|
|
1011
1032
|
appId: appId,
|
|
1012
|
-
mchId: mchId,
|
|
1033
|
+
mchId: mch_id || mchId,
|
|
1013
1034
|
key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥,
|
|
1014
1035
|
pfx: await fsPromise.readFile(
|
|
1015
1036
|
path.resolve(
|
|
1016
1037
|
__dirname,
|
|
1017
|
-
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
1038
|
+
`${process.cwd()}/app/${appName}/plugins/weixin/${
|
|
1039
|
+
mch_id || key
|
|
1040
|
+
}/apiclient_cert.p12`
|
|
1018
1041
|
)
|
|
1019
1042
|
), // 微信商户平台证书
|
|
1020
1043
|
})
|