q-koa 7.7.7 → 7.8.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
@@ -243,7 +243,7 @@ class APP {
243
243
  // console.log(content);
244
244
  // });
245
245
 
246
- starter.on('loadAll', () => {
246
+ starter.on('loadAll', async () => {
247
247
  const appName = this.config.includes[0]
248
248
  this.server = this.app.listen(this.port, () => {
249
249
  console.log(`server is running at http://localhost:${this.port}`)
@@ -360,7 +360,7 @@ class APP {
360
360
  this.initFile(appName)
361
361
  }
362
362
 
363
- this.initPlugin(appName)
363
+ await this.initPlugin(appName)
364
364
  this.app[appName].event = new EventEmitter()
365
365
 
366
366
  const cacheConfig = _.get(this.app[appName], 'appConfig.cache', {
@@ -373,7 +373,7 @@ class APP {
373
373
  maxAge: cacheConfig.maxAge,
374
374
  })
375
375
 
376
- this.initModel(appName)
376
+ await this.initModel(appName)
377
377
  // const models = Object.keys(this.app[appName].model).join(' / ')
378
378
  if (taskConfig.is_available) {
379
379
  this.initTask(appName)
@@ -422,7 +422,7 @@ class APP {
422
422
  }
423
423
  }
424
424
 
425
- initTask(appName) {
425
+ async initTask(appName) {
426
426
  console.log(chalk.red(`启动任务${appName}`))
427
427
  const taskDir = path.resolve(
428
428
  __dirname,
@@ -431,7 +431,8 @@ class APP {
431
431
  const publicExist = fs.existsSync(taskDir)
432
432
  if (!publicExist) await fsPromise.mkdir(taskDir)
433
433
  const list = await fsPromise.readdir(taskDir)
434
- list.forEach((folder) => {
434
+ for (let i = 0; i < list.length; i++) {
435
+ const folder = list[i]
435
436
  const isFolder = fs.lstatSync(path.resolve(taskDir, folder)).isDirectory()
436
437
  if (isFolder) {
437
438
  const folderDir = await fsPromise.readdir(path.resolve(taskDir, folder))
@@ -450,10 +451,10 @@ class APP {
450
451
  }
451
452
  })
452
453
  }
453
- })
454
+ }
454
455
  }
455
456
 
456
- initPlugin(appName) {
457
+ async initPlugin(appName) {
457
458
  const pluginDir = path.resolve(
458
459
  __dirname,
459
460
  `${rootDirectory}/${APP_DIR}/${appName}/${PLUGINS_DIR}`
@@ -461,12 +462,15 @@ class APP {
461
462
  const publicExist = fs.existsSync(pluginDir)
462
463
  if (!publicExist) await fsPromise.mkdir(pluginDir)
463
464
  const pluginDirResult = await fsPromise.readdir(pluginDir)
464
- pluginDirResult.forEach((folder) => {
465
+ for (let i = 0; i < pluginDirResult.length; i++) {
466
+ const folder = pluginDirResult[i]
465
467
  const isFolder = fs
466
468
  .lstatSync(path.resolve(pluginDir, folder))
467
469
  .isDirectory()
468
470
  if (isFolder) {
469
- const folderResult = await fsPromise.readdir(path.resolve(pluginDir, folder))
471
+ const folderResult = await fsPromise.readdir(
472
+ path.resolve(pluginDir, folder)
473
+ )
470
474
  folderResult.forEach((filename) => {
471
475
  const extname = path.extname(filename)
472
476
  if (extname === '.js') {
@@ -662,7 +666,7 @@ class APP {
662
666
  }
663
667
  })
664
668
  }
665
- })
669
+ }
666
670
  }
667
671
 
668
672
  initModel(appName) {
@@ -956,15 +956,21 @@ exports.refund_notify = async (ctx) => {
956
956
  const prefix =
957
957
  out_trade_no.split('_').length === 4 ? out_trade_no.split('_')[1] : ''
958
958
 
959
- const order_id = Number(out_refund_no)
959
+ const order_id = out_refund_no.includes('_')
960
+ ? Number(out_refund_no.split('_')[0])
961
+ : Number(out_refund_no)
962
+ const type = out_refund_no.includes('_') ? out_refund_no.split('_')[1] : ''
960
963
  const model = prefix ? `${prefix}_order` : 'order'
961
- console.log(out_refund_no, '微信支付回调-----', model)
964
+ console.log(
965
+ `微信退款回调 prefix:${prefix}/model:${model}/order_id:${order_id}/type:${type}`
966
+ )
962
967
  if (app.service[model] && app.service[model].refund_notify) {
963
968
  await app.service[model].refund_notify({
964
969
  app,
965
970
  order_id,
966
971
  order: model,
967
972
  refund_price,
973
+ type,
968
974
  })
969
975
  }
970
976
 
@@ -11,6 +11,7 @@ exports.refund = async ({
11
11
  total_fee,
12
12
  refund_fee,
13
13
  price,
14
+ type = '',
14
15
  ...rest
15
16
  }) => {
16
17
  const { app, appName } = getAppByCtx(ctx)
@@ -43,7 +44,7 @@ exports.refund = async ({
43
44
  const { result_code, err_code_des } = await payObj.refund({
44
45
  ...rest,
45
46
  out_trade_no,
46
- out_refund_no: id + '',
47
+ out_refund_no: id + '_' + type,
47
48
  total_fee: Math.round((total_fee || refund_fee || price) * 100),
48
49
  refund_fee: Math.round((refund_fee || price) * 100),
49
50
  notify_url: `https://${
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "7.7.7",
3
+ "version": "7.8.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {