q-koa 10.2.2 → 10.4.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 CHANGED
@@ -266,7 +266,10 @@ class APP {
266
266
 
267
267
  starter.on('loadAll', async () => {
268
268
  const appName = this.config.includes[0]
269
- if (!this.app[appName]) throw new Error(`没有生成应用${this.config.includes[0]},请检查config includes`)
269
+ if (!this.app[appName])
270
+ throw new Error(
271
+ `没有生成应用${this.config.includes[0]},请检查config includes`
272
+ )
270
273
  this.server = this.app.listen(this.port, () => {
271
274
  console.log(
272
275
  `${moment().format(
@@ -1048,6 +1051,18 @@ class APP {
1048
1051
  Array.isArray(excludeInclude) &&
1049
1052
  excludeInclude.length > 0
1050
1053
  ) {
1054
+ // const attributes = _.omit(app[appName].attributes[controller].filter(
1055
+ // (i) => {
1056
+ // return i.type !== Sequelize.VIRTUAL
1057
+ // }
1058
+ // )
1059
+ // const currentAttribute = allAttributes.filter((item) => {
1060
+ // if (Array.isArray(attributes)) {
1061
+ // return attributes.includes(item)
1062
+ // } else {
1063
+ // return attributes.exclude.includes(item)
1064
+ // }
1065
+ // })
1051
1066
  myInclude = myInclude.filter((i) => {
1052
1067
  return excludeInclude.every((m) => {
1053
1068
  return app[appName].model[m] !== i.model
@@ -831,6 +831,35 @@ exports.h5_pay = async (ctx) => {
831
831
  )
832
832
  }
833
833
 
834
+ exports.pc_pay = async (ctx) => {
835
+ const { app, appName } = getAppByCtx(ctx)
836
+ const {
837
+ name,
838
+ order_id,
839
+ price,
840
+ prefix = '',
841
+ out_trade_no: _out_trade_no,
842
+ is_admin = false,
843
+ config = 'weixin_mp',
844
+ pay_config = 'weixin_pay',
845
+ } = ctx.request.body
846
+
847
+ if (price === 0) throw new Error('价格不能为0')
848
+ const result = await app.service.weixin.pc_pay({
849
+ ctx,
850
+ name,
851
+ order_id,
852
+ price,
853
+ config,
854
+ pay_config,
855
+ is_admin,
856
+ out_trade_no: _out_trade_no,
857
+ prefix,
858
+ })
859
+
860
+ return ctx.SUCCESS(result)
861
+ }
862
+
834
863
  exports.mp_pay = async (ctx) => {
835
864
  const { app, appName } = getAppByCtx(ctx)
836
865
  const {
@@ -1078,6 +1107,7 @@ exports.url_link = async (ctx) => {
1078
1107
  const { app } = getAppByCtx(ctx)
1079
1108
 
1080
1109
  const { page, scene, config = 'weixin_mp' } = ctx.request.body
1110
+ if (!app.service.weixin) throw new Error(`weixin可能没有service.js`)
1081
1111
  const result = await app.service.weixin.url_link({
1082
1112
  app,
1083
1113
  page,
@@ -1116,6 +1146,7 @@ exports.qr_code = async (ctx) => {
1116
1146
  config = 'weixin_mp',
1117
1147
  } = ctx.request.body
1118
1148
 
1149
+ if (!app.service.weixin) throw new Error(`weixin可能没有service.js`)
1119
1150
  const result = await app.service.weixin.qr_code({
1120
1151
  app,
1121
1152
  page,
@@ -1171,6 +1202,8 @@ exports.refund = async (ctx) => {
1171
1202
  } = ctx.request.body
1172
1203
 
1173
1204
  const fn = is_new_pay ? 'refund_new' : 'refund'
1205
+
1206
+ if (!app.service.weixin) throw new Error(`weixin可能没有service.js`)
1174
1207
  await app.service.weixin[fn]({
1175
1208
  ctx,
1176
1209
  id,
@@ -1440,6 +1473,7 @@ exports.messagePush = async (ctx) => {
1440
1473
  const result = ctx.request.body
1441
1474
  if (!lodash.isEmpty(result)) {
1442
1475
  const event = result.Event
1476
+ if (!app.service.weixin) throw new Error(`weixin可能没有service.js`)
1443
1477
  if (event) {
1444
1478
  if (app.service.weixin[event]) {
1445
1479
  await app.service.weixin[event]({
@@ -1,5 +1,6 @@
1
1
  const { getAppByCtx, getAppConfig, getConfig, lodash } = require('q-koa')
2
2
  const { Pay } = require('@sigodenjs/wechatpay')
3
+ const WXPay = require('weixin-pay-fork')
3
4
  const path = require('path')
4
5
  const fsPromise = require('fs/promises')
5
6
  const WeixinMp = require('../../services/weixinMP')
@@ -441,3 +442,67 @@ exports.funds_order_refund = async ({ app, result }) => {
441
442
  }
442
443
  }
443
444
  }
445
+
446
+ exports.pc_pay = async ({
447
+ ctx,
448
+ name,
449
+ order_id,
450
+ price,
451
+ config = 'weixin_mp',
452
+ pay_config = 'weixin_pay',
453
+ out_trade_no: _out_trade_no,
454
+ is_admin,
455
+ type = 'PC-WEIXIN',
456
+ prefix,
457
+ }) => {
458
+ const { app, appName } = getAppByCtx(ctx)
459
+ const appConfig = getConfig(app)
460
+ const app_id = (await appConfig.getObject(config)).app_id
461
+ const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
462
+
463
+ const { is_dev, site_host } = await appConfig.getObject('base')
464
+
465
+ const wxpay = WXPay({
466
+ appid: app_id,
467
+ mch_id: mchId,
468
+ partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
469
+ })
470
+
471
+ const pay = (options) =>
472
+ new Promise((resolve, reject) => {
473
+ wxpay.createUnifiedOrder(options, (err, result) => {
474
+ if (err) return reject(err)
475
+ return resolve(result)
476
+ })
477
+ })
478
+
479
+ const out_trade_no = _out_trade_no
480
+ ? _out_trade_no
481
+ : prefix
482
+ ? `${key.length > 10 ? appName : key}_${prefix}-${order_id}_${type}`
483
+ : `${key.length > 10 ? appName : key}_${order_id}_${type}`
484
+
485
+ const notify_url = `https://${
486
+ site_host || 'api.kuashou.com'
487
+ }/${appName}/weixin/notify`
488
+
489
+ const result = await pay({
490
+ body: name,
491
+ detail: '公众号支付测试',
492
+ out_trade_no,
493
+ trade_type: 'NATIVE',
494
+ total_fee: is_admin || is_dev ? 1 : Math.round(price * 100),
495
+ spbill_create_ip: '192.168.2.210',
496
+ notify_url,
497
+ })
498
+ if (result.return_code === 'FAIL') {
499
+ throw new Error(result.return_msg)
500
+ }
501
+ if (result.result_code === 'FAIL') {
502
+ throw new Error(result.err_code_des)
503
+ }
504
+
505
+ return `https://${
506
+ site_host || 'api.kuashou.com'
507
+ }/${appName}/common/createQr?url=${result.code_url}`
508
+ }
@@ -49,7 +49,7 @@ const getBrandListUrl =
49
49
  'https://api.weixin.qq.com/shop/account/get_brand_list?access_token=%s'
50
50
 
51
51
  const uploadImageUrl =
52
- 'https://api.weixin.qq.com/shop/img/upload?access_token=%s'
52
+ 'https://api.weixin.qq.com/channels/ec/basics/img/upload?access_token=%s'
53
53
 
54
54
  const fsPromise = require('fs/promises')
55
55
  const LRU = require('lru-cache')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "10.2.2",
3
+ "version": "10.4.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {