q-koa 9.9.9 → 10.0.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 +9 -2
- package/core/file/services/weixinMP.js +85 -3
- package/package.json +1 -1
package/core/app.js
CHANGED
|
@@ -978,6 +978,7 @@ class APP {
|
|
|
978
978
|
}
|
|
979
979
|
const _str = formatPostFunction(include)
|
|
980
980
|
const postInclude = nodeVm.runInNewContext(_str)
|
|
981
|
+
const strInclude = postInclude(app[appName])
|
|
981
982
|
// const postInclude = include.toFunction();
|
|
982
983
|
myInclude =
|
|
983
984
|
app[appName] &&
|
|
@@ -985,8 +986,14 @@ class APP {
|
|
|
985
986
|
app[appName].include[controller]
|
|
986
987
|
? _.uniqWith(
|
|
987
988
|
[
|
|
988
|
-
...
|
|
989
|
-
...app[appName].include[controller]
|
|
989
|
+
...strInclude,
|
|
990
|
+
...app[appName].include[controller].filter((item) => {
|
|
991
|
+
return !strInclude.some(
|
|
992
|
+
(i) =>
|
|
993
|
+
(i.model && i.model.getName()) ===
|
|
994
|
+
(item.model && item.model.getName())
|
|
995
|
+
)
|
|
996
|
+
}),
|
|
990
997
|
],
|
|
991
998
|
_.isEqual
|
|
992
999
|
)
|
|
@@ -41,8 +41,16 @@ const getOrderUrl =
|
|
|
41
41
|
const refundOrderUrl =
|
|
42
42
|
'https://api.weixin.qq.com/shop/pay/refundorder?access_token=%s'
|
|
43
43
|
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const addGoodUrl = 'https://api.weixin.qq.com/shop/spu/add?access_token=%s'
|
|
45
|
+
|
|
46
|
+
const getCategoryUrl = 'https://api.weixin.qq.com/shop/cat/get?access_token=%s'
|
|
47
|
+
|
|
48
|
+
const getBrandListUrl =
|
|
49
|
+
'https://api.weixin.qq.com/shop/account/get_brand_list?access_token=%s'
|
|
50
|
+
|
|
51
|
+
const uploadImageUrl =
|
|
52
|
+
'https://api.weixin.qq.com/shop/img/upload?access_token=%s'
|
|
53
|
+
|
|
46
54
|
const fsPromise = require('fs/promises')
|
|
47
55
|
const LRU = require('lru-cache')
|
|
48
56
|
const request = require('request')
|
|
@@ -51,7 +59,6 @@ const cache = new LRU({
|
|
|
51
59
|
maxAge: 1000 * 60 * 60,
|
|
52
60
|
})
|
|
53
61
|
const uuid = require('node-uuid')
|
|
54
|
-
const { rest } = require('lodash')
|
|
55
62
|
|
|
56
63
|
const uploadPromise = (options) => {
|
|
57
64
|
return new Promise((resolve, reject) => {
|
|
@@ -571,6 +578,81 @@ module.exports = class Singleton {
|
|
|
571
578
|
return result.data
|
|
572
579
|
}
|
|
573
580
|
|
|
581
|
+
async addGood(payLoad) {
|
|
582
|
+
const access_token = await this.getAccessToken()
|
|
583
|
+
const url = util.format(addGoodUrl, access_token)
|
|
584
|
+
const result = await axios
|
|
585
|
+
.post(url, {
|
|
586
|
+
...payLoad,
|
|
587
|
+
})
|
|
588
|
+
.then((res) => res.data)
|
|
589
|
+
if (result.errcode) {
|
|
590
|
+
if (result.errcode === 40001) {
|
|
591
|
+
cache.reset()
|
|
592
|
+
return await this.addGood(payLoad)
|
|
593
|
+
}
|
|
594
|
+
// return payLoad
|
|
595
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
596
|
+
}
|
|
597
|
+
return result.data
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
async getCategory(payLoad) {
|
|
601
|
+
const access_token = await this.getAccessToken()
|
|
602
|
+
const url = util.format(getCategoryUrl, access_token)
|
|
603
|
+
|
|
604
|
+
const result = await axios
|
|
605
|
+
.post(url, {
|
|
606
|
+
...payLoad,
|
|
607
|
+
})
|
|
608
|
+
.then((res) => res.data)
|
|
609
|
+
if (result.errcode) {
|
|
610
|
+
if (result.errcode === 40001) {
|
|
611
|
+
cache.reset()
|
|
612
|
+
return await this.getCategory(payLoad)
|
|
613
|
+
}
|
|
614
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
615
|
+
}
|
|
616
|
+
return result.third_cat_list
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
async getBrandList(payLoad) {
|
|
620
|
+
const access_token = await this.getAccessToken()
|
|
621
|
+
const url = util.format(getBrandListUrl, access_token)
|
|
622
|
+
|
|
623
|
+
const result = await axios
|
|
624
|
+
.post(url, {
|
|
625
|
+
...payLoad,
|
|
626
|
+
})
|
|
627
|
+
.then((res) => res.data)
|
|
628
|
+
if (result.errcode) {
|
|
629
|
+
if (result.errcode === 40001) {
|
|
630
|
+
cache.reset()
|
|
631
|
+
return await this.getBrandList(payLoad)
|
|
632
|
+
}
|
|
633
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
634
|
+
}
|
|
635
|
+
return result.data
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
async uploadImage(payLoad) {
|
|
639
|
+
const access_token = await this.getAccessToken()
|
|
640
|
+
const url = util.format(uploadImageUrl, access_token)
|
|
641
|
+
|
|
642
|
+
const result = await uploadPromise({
|
|
643
|
+
url,
|
|
644
|
+
formData: payLoad,
|
|
645
|
+
})
|
|
646
|
+
if (result.errcode) {
|
|
647
|
+
if (result.errcode === 40001) {
|
|
648
|
+
cache.reset()
|
|
649
|
+
return await this.uploadImage(payLoad)
|
|
650
|
+
}
|
|
651
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
652
|
+
}
|
|
653
|
+
return result.img_info
|
|
654
|
+
}
|
|
655
|
+
|
|
574
656
|
getConfig() {
|
|
575
657
|
return this.config
|
|
576
658
|
}
|