q-koa 10.4.2 → 10.5.1

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
@@ -956,6 +956,7 @@ class APP {
956
956
  excludeInclude,
957
957
  raw = false,
958
958
  is_split = false,
959
+ autoInclude = true,
959
960
  omit = [],
960
961
  ...other
961
962
  } = ctx.request.body
@@ -1008,7 +1009,10 @@ class APP {
1008
1009
  ? _.uniqWith(
1009
1010
  [
1010
1011
  ...strInclude,
1011
- ...app[appName].include[controller].filter((item) => {
1012
+ ...(autoInclude
1013
+ ? app[appName].include[controller]
1014
+ : []
1015
+ ).filter((item) => {
1012
1016
  return !strInclude.some(
1013
1017
  (i) =>
1014
1018
  (i.model && i.model.getName()) ===
@@ -1023,7 +1027,9 @@ class APP {
1023
1027
  myInclude = null
1024
1028
  } else {
1025
1029
  myInclude = app[appName].include
1026
- ? app[appName].include[controller]
1030
+ ? autoInclude
1031
+ ? app[appName].include[controller]
1032
+ : []
1027
1033
  : null
1028
1034
  }
1029
1035
 
@@ -1371,6 +1371,56 @@ exports.checkPay = async (ctx) => {
1371
1371
  ctx.SUCCESS({ prefix, out_trade_no, ...payResult })
1372
1372
  }
1373
1373
 
1374
+ exports.checkRefund = async (ctx) => {
1375
+ const { app, appName, controller } = getAppByCtx(ctx)
1376
+
1377
+ const {
1378
+ id,
1379
+ prefix,
1380
+ config = 'weixin_mp',
1381
+ pay_config = 'weixin_pay',
1382
+ out_trade_no: _out_trade_no,
1383
+ } = ctx.request.body
1384
+
1385
+ const appConfig = getConfig(app)
1386
+ const { appId, mchId, key, partner_key } = await appConfig.getObject(
1387
+ pay_config
1388
+ )
1389
+
1390
+ const payObj = new WeixinPay({
1391
+ appId,
1392
+ mchId,
1393
+ key: key.length > 10 ? key : partner_key,
1394
+ })
1395
+
1396
+ if (_out_trade_no) {
1397
+ const result = await payObj.checkRefund({
1398
+ out_trade_no: _out_trade_no,
1399
+ })
1400
+ return ctx.SUCCESS(result)
1401
+ }
1402
+
1403
+ if (!id) return ctx.ERROR('?id')
1404
+ const orderModel = prefix ? `${prefix}_order` : 'order'
1405
+ const orderDetail = await app.model[orderModel].findOne({
1406
+ where: {
1407
+ id,
1408
+ },
1409
+ })
1410
+
1411
+ if (!orderDetail) return ctx.SUCCESS('找不到')
1412
+ const orderPrefix = prefix ? `${prefix}-` : ''
1413
+ const out_trade_no = _out_trade_no
1414
+ ? _out_trade_no
1415
+ : `${key}_${orderPrefix}${id}_MP-WEIXIN`
1416
+
1417
+ const result = await payObj.checkRefund({
1418
+ out_trade_no,
1419
+ })
1420
+
1421
+ ctx.SUCCESS(result)
1422
+ }
1423
+
1374
1424
  exports.checkPayNew = async (ctx) => {
1375
1425
  const { app, appName, controller } = getAppByCtx(ctx)
1376
1426
 
@@ -41,15 +41,20 @@ const getOrderUrl =
41
41
  const refundOrderUrl =
42
42
  'https://api.weixin.qq.com/shop/pay/refundorder?access_token=%s'
43
43
 
44
- const addGoodUrl = 'https://api.weixin.qq.com/shop/spu/add?access_token=%s'
44
+ const addGoodUrl =
45
+ 'https://api.weixin.qq.com/channels/ec/product/add?access_token=%s'
45
46
 
46
- const getCategoryUrl = 'https://api.weixin.qq.com/shop/cat/get?access_token=%s'
47
+ const getCategoryUrl =
48
+ 'https://api.weixin.qq.com/channels/ec/category/all?access_token=%s'
47
49
 
48
50
  const getBrandListUrl =
49
51
  'https://api.weixin.qq.com/shop/account/get_brand_list?access_token=%s'
50
52
 
51
53
  const uploadImageUrl =
52
- 'https://api.weixin.qq.com/channels/ec/basics/img/upload?access_token=%s'
54
+ 'https://api.weixin.qq.com/channels/ec/basics/img/upload?access_token=%s&upload_type=%s&resp_type=%s'
55
+
56
+ const getShipTemplateUrl =
57
+ 'https://api.weixin.qq.com/channels/ec/merchant/getfreighttemplatelist?access_token=%s'
53
58
 
54
59
  const fsPromise = require('fs/promises')
55
60
  const LRU = require('lru-cache')
@@ -581,6 +586,7 @@ module.exports = class Singleton {
581
586
  async addGood(payLoad) {
582
587
  const access_token = await this.getAccessToken()
583
588
  const url = util.format(addGoodUrl, access_token)
589
+ console.log('payLoad', payLoad)
584
590
  const result = await axios
585
591
  .post(url, {
586
592
  ...payLoad,
@@ -613,7 +619,7 @@ module.exports = class Singleton {
613
619
  }
614
620
  throw new Error(`${result.errcode};${result.errmsg}`)
615
621
  }
616
- return result.third_cat_list
622
+ return result
617
623
  }
618
624
 
619
625
  async getBrandList(payLoad) {
@@ -635,14 +641,42 @@ module.exports = class Singleton {
635
641
  return result.data
636
642
  }
637
643
 
644
+ async getShipTemplate(payLoad) {
645
+ const access_token = await this.getAccessToken()
646
+ const url = util.format(getShipTemplateUrl, access_token)
647
+
648
+ const result = await axios
649
+ .post(url, {
650
+ ...payLoad,
651
+ })
652
+ .then((res) => res.data)
653
+ if (result.errcode) {
654
+ if (result.errcode === 40001) {
655
+ cache.reset()
656
+ return await this.getShipTemplate(payLoad)
657
+ }
658
+ throw new Error(`${result.errcode};${result.errmsg}`)
659
+ }
660
+ return result
661
+ }
662
+
638
663
  async uploadImage(payLoad) {
639
664
  const access_token = await this.getAccessToken()
640
- const url = util.format(uploadImageUrl, access_token)
665
+ const { upload_type, resp_type, ...rest } = payLoad
666
+
667
+ const url = util.format(
668
+ uploadImageUrl,
669
+ access_token,
670
+ upload_type,
671
+ resp_type
672
+ )
673
+
674
+ const result = await axios
675
+ .post(url, {
676
+ ...rest,
677
+ })
678
+ .then((res) => res.data)
641
679
 
642
- const result = await uploadPromise({
643
- url,
644
- formData: payLoad,
645
- })
646
680
  if (result.errcode) {
647
681
  if (result.errcode === 40001) {
648
682
  cache.reset()
@@ -650,7 +684,7 @@ module.exports = class Singleton {
650
684
  }
651
685
  throw new Error(`${result.errcode};${result.errmsg}`)
652
686
  }
653
- return result.img_info
687
+ return result.pic_file
654
688
  }
655
689
 
656
690
  getConfig() {
@@ -26,6 +26,10 @@ module.exports = class WeixinPay {
26
26
  return await this.pay.unifiedOrder(config)
27
27
  }
28
28
 
29
+ async checkRefund(payLoad) {
30
+ return await this.pay.refundQuery(payLoad)
31
+ }
32
+
29
33
  async getXMLBody(data) {
30
34
  return await getXMLBody(data, {
31
35
  limit: '1mb',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "10.4.2",
3
+ "version": "10.5.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {