q-koa 13.4.5 → 13.5.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/config.js CHANGED
@@ -163,7 +163,7 @@ module.exports = {
163
163
  )
164
164
  router.get('/weixin/messagePush', app.controller.weixin.messagePush)
165
165
  }
166
-
166
+ router.get('/common/restart', app.controller.common.restart)
167
167
  router.get('/common/getAppConfig', app.controller.common.getAppConfig)
168
168
  router.get('/common/createQr', app.controller.common.createQr)
169
169
  router.get('/lanhu/:str', async (ctx) => {
@@ -16,6 +16,7 @@ const OSS = require('ali-oss')
16
16
  const axios = require('axios')
17
17
  const util = require('util')
18
18
  const jwt = require('jsonwebtoken')
19
+ const pm2 = require('pm2')
19
20
 
20
21
  const { getImageType } = require('../../utils')
21
22
  const Email = require('../../services/email')
@@ -746,3 +747,27 @@ exports.copyDB = async (ctx) => {
746
747
 
747
748
  ctx.SUCCESS('ok')
748
749
  }
750
+
751
+ exports.restart = async (ctx) => {
752
+ const { app, appName } = getAppByCtx(ctx)
753
+
754
+ const { hour: _hour } = ctx.request.query
755
+
756
+ const hour = moment().hour()
757
+ if (hour === Number(_hour)) {
758
+ pm2.connect((err) => {
759
+ console.log(err)
760
+ app.service.log.push({
761
+ app,
762
+ message: '重启了',
763
+ })
764
+ setTimeout(() => {
765
+ pm2.reload(appName)
766
+ }, 1000)
767
+ })
768
+
769
+ ctx.SUCCESS('ok')
770
+ } else {
771
+ return ctx.SUCCESS('?hour=')
772
+ }
773
+ }
@@ -1201,6 +1201,9 @@ exports.b2b_pay = async (ctx) => {
1201
1201
  pay_key: _pay_key,
1202
1202
  } = await appConfig.getObject('weixin_pay')
1203
1203
 
1204
+ if (!app_key) {
1205
+ throw new Error('缺少app_key')
1206
+ }
1204
1207
  const pay_key = _pay_key || key || appName
1205
1208
 
1206
1209
  const weixinMp = new WeixinMp({
@@ -1214,6 +1217,7 @@ exports.b2b_pay = async (ctx) => {
1214
1217
  ? `${pay_key}_${prefix}-${order_id}_${type}`
1215
1218
  : `${pay_key}_${order_id}_${type}`
1216
1219
 
1220
+ const order_amount = is_admin || is_dev ? 1 : Math.round(price * 100)
1217
1221
  const res = await weixinMp.b2bPay({
1218
1222
  mchid,
1219
1223
  app_key,
@@ -1222,7 +1226,7 @@ exports.b2b_pay = async (ctx) => {
1222
1226
  out_trade_no,
1223
1227
  description: name,
1224
1228
  amount: {
1225
- order_amount: is_admin || is_dev ? 1 : Math.round(price * 100),
1229
+ order_amount,
1226
1230
  },
1227
1231
  },
1228
1232
  })
@@ -1324,6 +1328,7 @@ exports.notify = async (ctx) => {
1324
1328
  out_trade_no: result.xml.out_trade_no,
1325
1329
  openid,
1326
1330
  pay_type_key,
1331
+ mch_id: result.xml.mch_id,
1327
1332
  })
1328
1333
  }
1329
1334
 
@@ -1607,6 +1612,7 @@ exports.checkPay = async (ctx, _data) => {
1607
1612
  pay_config = 'weixin_pay',
1608
1613
  type = 'MP-WEIXIN',
1609
1614
  out_trade_no: _out_trade_no,
1615
+ mch_id = '',
1610
1616
  } = _data || ctx.request.body
1611
1617
 
1612
1618
  const orderModel = prefix ? `${prefix}_order` : 'order'
@@ -1627,7 +1633,7 @@ exports.checkPay = async (ctx, _data) => {
1627
1633
 
1628
1634
  const wxpay = WXPay({
1629
1635
  appid: app_id,
1630
- mch_id: mchId,
1636
+ mch_id: mch_id || mchId,
1631
1637
  partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
1632
1638
  })
1633
1639
 
@@ -1664,6 +1670,7 @@ exports.checkPayOnly = async (ctx, _data) => {
1664
1670
  pay_config = 'weixin_pay',
1665
1671
  type = 'MP-WEIXIN',
1666
1672
  out_trade_no: _out_trade_no,
1673
+ mch_id = '',
1667
1674
  } = _data || ctx.request.body
1668
1675
 
1669
1676
  const appConfig = getConfig(app)
@@ -1672,7 +1679,7 @@ exports.checkPayOnly = async (ctx, _data) => {
1672
1679
 
1673
1680
  const wxpay = WXPay({
1674
1681
  appid: app_id,
1675
- mch_id: mchId,
1682
+ mch_id: mch_id || mchId,
1676
1683
  partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
1677
1684
  })
1678
1685
 
@@ -615,6 +615,7 @@ exports.funds_order_pay = async ({ ctx, app, result }) => {
615
615
  order: model,
616
616
  order_price: amount / 100,
617
617
  transactionid,
618
+ mch_id: result.order_info.mchid,
618
619
  })
619
620
  }
620
621
  }
@@ -678,6 +679,85 @@ exports.funds_order_refund = async ({ ctx, app, result }) => {
678
679
  }
679
680
  }
680
681
 
682
+ exports.retail_refund_notify = async ({ ctx, app, result }) => {
683
+ if (result) {
684
+ let prefix = ''
685
+ let order_id = result.out_trade_no.split('_')[1]
686
+ if (order_id.includes('-')) {
687
+ const arr = order_id.split('-')
688
+ order_id = Number(arr[1])
689
+ ;[prefix] = arr
690
+ } else {
691
+ order_id = Number(order_id)
692
+ }
693
+ const model = prefix ? `${prefix}_order` : 'order'
694
+
695
+ const trade_no = result.out_trade_no.split('_').slice(0, 2).join('_')
696
+
697
+ const type = trade_no.includes('_') ? trade_no.split('_')[1] : ''
698
+
699
+ if (app.service[model] && app.service[model].refund_notify) {
700
+ if (result.refund_status === 'REFUND_SUCC') {
701
+ await app.service[model].refund_notify({
702
+ ctx,
703
+ app,
704
+ order_id,
705
+ order: model,
706
+ refund_price: result.refund_amount / 100,
707
+ type,
708
+ mch_id: result.mchid,
709
+ })
710
+ } else {
711
+ app.service.log.push({
712
+ app,
713
+ message: JSON.stringify(result),
714
+ url: 'retail_refund_notify',
715
+ })
716
+ }
717
+ }
718
+ }
719
+ }
720
+
721
+ exports.retail_pay_notify = async ({ ctx, app, result }) => {
722
+ if (result) {
723
+ let prefix = ''
724
+ let order_id = result.out_trade_no.split('_')[1]
725
+ if (order_id.includes('-')) {
726
+ const arr = order_id.split('-')
727
+ order_id = Number(arr[1])
728
+ ;[prefix] = arr
729
+ } else {
730
+ order_id = Number(order_id)
731
+ }
732
+ const model = prefix ? `${prefix}_order` : 'order'
733
+ let transactionid = ''
734
+ try {
735
+ transactionid = result.wxpay_transaction_id
736
+ } catch (e) {}
737
+
738
+ console.log(result.mchid)
739
+ if (app.service[model] && app.service[model].notify) {
740
+ if (result.pay_status === 'ORDER_PAY_SUCC') {
741
+ await app.service[model].notify({
742
+ ctx,
743
+ app,
744
+ order_id,
745
+ order: model,
746
+ order_price: result.amount.order_amount / 100,
747
+ transactionid,
748
+ mch_id: result.mchid,
749
+ })
750
+ } else {
751
+ app.service.log.push({
752
+ app,
753
+ message: JSON.stringify(result),
754
+ url: 'retail_pay_notify',
755
+ })
756
+ }
757
+ }
758
+ }
759
+ }
760
+
681
761
  exports.pc_pay = async ({
682
762
  ctx,
683
763
  name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.4.5",
3
+ "version": "13.5.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -60,7 +60,8 @@
60
60
  "redis": "^4.0.3",
61
61
  "yly-nodejs-sdk": "^1.0.2",
62
62
  "vm2": "^3.9.19",
63
- "xlsx": "^0.18.5"
63
+ "xlsx": "^0.18.5",
64
+ "pm2": "^7.0.1"
64
65
  },
65
66
  "devDependencies": {
66
67
  "eslint": "^4.19.1",