q-koa 13.8.10 → 13.8.12

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.
@@ -86,19 +86,17 @@ exports.init = async (ctx) => {
86
86
  raw: true,
87
87
  })
88
88
 
89
- let list = []
89
+ const list = []
90
90
  let number = 0
91
91
  for (let i = 0; i < parentList.length; i++) {
92
92
  number += 1
93
+ const parentId = number
93
94
  const { id: parent_id, ...rest } = parentList[i]
94
- list = [
95
- ...list,
96
- {
97
- id: number,
98
- ...rest,
99
- parent_id: 0,
100
- },
101
- ]
95
+ list.push({
96
+ id: parentId,
97
+ ...rest,
98
+ parent_id: 0,
99
+ })
102
100
  const childList = await app.model.setting.findAll({
103
101
  where: {
104
102
  parent_id,
@@ -106,20 +104,15 @@ exports.init = async (ctx) => {
106
104
  order: [['id', 'ASC']],
107
105
  raw: true,
108
106
  })
109
- list = [
110
- ...list,
111
- ...childList.map((item, index) => {
112
- const { id: child_id, ...restChild } = item
113
- const id = number + index + 1
114
-
115
- return {
116
- id,
117
- ...restChild,
118
- parent_id: number,
119
- }
120
- }),
121
- ]
122
- number += childList.length
107
+ for (let j = 0; j < childList.length; j++) {
108
+ number += 1
109
+ const { id: child_id, ...restChild } = childList[j]
110
+ list.push({
111
+ id: number,
112
+ ...restChild,
113
+ parent_id: parentId,
114
+ })
115
+ }
123
116
  }
124
117
 
125
118
  await app.model.setting.sync({ force: true })
@@ -127,7 +127,7 @@ const hmacSha256 = (data, secret) => {
127
127
  return crypto.createHmac('sha256', secret).update(data).digest('hex')
128
128
  }
129
129
  const uploadPromise = async (url, formData) => {
130
- const response = await axios.post(url, formData, {
130
+ const response = await wxAxios.post(url, formData, {
131
131
  headers: formData.getHeaders(),
132
132
  })
133
133
  return response.data
@@ -145,7 +145,10 @@ const wxHttpsAgent = new https.Agent({
145
145
  rejectUnauthorized: true,
146
146
  })
147
147
 
148
- axios.defaults.httpsAgent = wxHttpsAgent
148
+ // 微信专用 axios 实例,避免修改全局 axios.defaults 影响其他模块
149
+ const wxAxios = axios.create({
150
+ httpsAgent: wxHttpsAgent,
151
+ })
149
152
 
150
153
  module.exports = class Singleton {
151
154
  static _instanceMap = new Map()
@@ -177,7 +180,7 @@ module.exports = class Singleton {
177
180
  }
178
181
  const url = util.format(getAccessTokenUrl, grant_type, appid, secrect)
179
182
 
180
- const result = await axios.get(url).then((res) => res.data)
183
+ const result = await wxAxios.get(url).then((res) => res.data)
181
184
  const { errcode, errmsg, access_token } = result
182
185
 
183
186
  if (errcode) {
@@ -191,7 +194,7 @@ module.exports = class Singleton {
191
194
  async getExpress() {
192
195
  const access_token = await this.getAccessToken()
193
196
  const url = util.format(getExpressUrl, access_token)
194
- const result = await axios.post(url).then((res) => res.data)
197
+ const result = await wxAxios.post(url).then((res) => res.data)
195
198
  if (result.errcode) {
196
199
  if (result.errcode === 40001) {
197
200
  cache.clear()
@@ -231,7 +234,7 @@ module.exports = class Singleton {
231
234
  service,
232
235
  }
233
236
 
234
- const result = await axios.post(url, formatOptions).then((res) => res.data)
237
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
235
238
  if (result.errcode) {
236
239
  if (result.errcode === 40001) {
237
240
  cache.clear()
@@ -263,7 +266,7 @@ module.exports = class Singleton {
263
266
  username,
264
267
  }
265
268
 
266
- const result = await axios.post(url, formatOptions).then((res) => res.data)
269
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
267
270
  if (result.errcode) {
268
271
  if (result.errcode === 40001) {
269
272
  cache.clear()
@@ -285,7 +288,7 @@ module.exports = class Singleton {
285
288
  username,
286
289
  role,
287
290
  }
288
- const result = await axios.post(url, formatOptions).then((res) => res.data)
291
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
289
292
  if (result.errcode) {
290
293
  if (result.errcode === 40001) {
291
294
  cache.clear()
@@ -335,7 +338,7 @@ module.exports = class Singleton {
335
338
  closeShare: 1,
336
339
  closeKf: 1,
337
340
  }
338
- const result = await axios.post(url, formatOptions).then((res) => res.data)
341
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
339
342
  if (result.errcode) {
340
343
  if (result.errcode === 40001) {
341
344
  cache.clear()
@@ -366,7 +369,7 @@ module.exports = class Singleton {
366
369
  start,
367
370
  limit,
368
371
  }
369
- const result = await axios.post(url, formatOptions).then((res) => res.data)
372
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
370
373
  if (result.errcode) {
371
374
  if (result.errcode === 40001) {
372
375
  cache.clear()
@@ -380,7 +383,7 @@ module.exports = class Singleton {
380
383
  async getPhoneNumber(code) {
381
384
  const access_token = await this.getAccessToken()
382
385
  const url = util.format(getPhoneNumberUrl, access_token)
383
- const result = await axios.post(url, { code }).then((res) => res.data)
386
+ const result = await wxAxios.post(url, { code }).then((res) => res.data)
384
387
  if (result.errcode) {
385
388
  if (result.errcode === 40001) {
386
389
  cache.clear()
@@ -405,7 +408,7 @@ module.exports = class Singleton {
405
408
  : '',
406
409
  }
407
410
 
408
- const result = await axios.post(url, payLoad).then((res) => res.data)
411
+ const result = await wxAxios.post(url, payLoad).then((res) => res.data)
409
412
 
410
413
  if (result.errcode) {
411
414
  if (result.errcode === 40001) {
@@ -421,7 +424,7 @@ module.exports = class Singleton {
421
424
  const access_token = await this.getAccessToken()
422
425
  const url = util.format(queryUrlLinkUrl, access_token)
423
426
 
424
- const result = await axios
427
+ const result = await wxAxios
425
428
  .post(url, {
426
429
  url_link,
427
430
  })
@@ -458,7 +461,7 @@ module.exports = class Singleton {
458
461
  is_permanent: true,
459
462
  }
460
463
 
461
- const result = await axios.post(url, payLoad).then((res) => res.data)
464
+ const result = await wxAxios.post(url, payLoad).then((res) => res.data)
462
465
 
463
466
  if (result.errcode) {
464
467
  if (result.errcode === 40001) {
@@ -486,7 +489,7 @@ module.exports = class Singleton {
486
489
  },
487
490
  }
488
491
 
489
- const result = await axios.post(url, payLoad).then((res) => res.data)
492
+ const result = await wxAxios.post(url, payLoad).then((res) => res.data)
490
493
 
491
494
  if (result.errcode) {
492
495
  if (result.errcode === 40001) {
@@ -512,7 +515,7 @@ module.exports = class Singleton {
512
515
  }
513
516
  const creatuuid = uuid.v1()
514
517
 
515
- const bufferResult = await axios
518
+ const bufferResult = await wxAxios
516
519
  .post(url, payLoad, {
517
520
  responseType: 'arraybuffer',
518
521
  })
@@ -548,7 +551,7 @@ module.exports = class Singleton {
548
551
  : '',
549
552
  }
550
553
 
551
- const bufferResult = await axios
554
+ const bufferResult = await wxAxios
552
555
  .post(url, payLoad, {
553
556
  responseType: 'arraybuffer',
554
557
  })
@@ -579,7 +582,7 @@ module.exports = class Singleton {
579
582
  }
580
583
  }),
581
584
  }
582
- const result = await axios.post(url, formatOptions).then((res) => res.data)
585
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
583
586
  if (result.errcode) {
584
587
  if (result.errcode === 40001) {
585
588
  cache.clear()
@@ -593,7 +596,7 @@ module.exports = class Singleton {
593
596
  async handleMessage(options) {
594
597
  const access_token = await this.getAccessToken()
595
598
  const url = util.format(handleMessageUrl, access_token)
596
- const result = await axios.post(url, options).then((res) => res.data)
599
+ const result = await wxAxios.post(url, options).then((res) => res.data)
597
600
  if (result.errcode) {
598
601
  if (result.errcode === 40001) {
599
602
  cache.clear()
@@ -611,7 +614,7 @@ module.exports = class Singleton {
611
614
  }
612
615
  const access_token = await this.getAccessToken()
613
616
  const url = util.format(handleTypingUrl, access_token)
614
- const result = await axios.post(url, options).then((res) => res.data)
617
+ const result = await wxAxios.post(url, options).then((res) => res.data)
615
618
  if (result.errcode) {
616
619
  if (result.errcode === 40001) {
617
620
  cache.clear()
@@ -628,7 +631,7 @@ module.exports = class Singleton {
628
631
  const access_token = await this.getAccessToken()
629
632
  const url = util.format(uploadFile, access_token, 'image')
630
633
  const fullUrl = imgUrl.startsWith('//') ? `http:${imgUrl}` : imgUrl
631
- const stream = (await axios.get(fullUrl, { responseType: 'stream' })).data
634
+ const stream = (await wxAxios.get(fullUrl, { responseType: 'stream' })).data
632
635
  const formData = new FormData()
633
636
  formData.append('media', stream)
634
637
  const uploadResult = await uploadPromise(url, formData)
@@ -645,7 +648,7 @@ module.exports = class Singleton {
645
648
  async invokeService(payLoad) {
646
649
  const access_token = await this.getAccessToken()
647
650
  const url = util.format(serviceMarketUrl, access_token)
648
- const result = await axios
651
+ const result = await wxAxios
649
652
  .post(url, {
650
653
  ...payLoad,
651
654
  })
@@ -663,7 +666,7 @@ module.exports = class Singleton {
663
666
  async createOrder(payLoad) {
664
667
  const access_token = await this.getAccessToken()
665
668
  const url = util.format(createOrderUrl, access_token)
666
- const result = await axios
669
+ const result = await wxAxios
667
670
  .post(url, {
668
671
  ...payLoad,
669
672
  })
@@ -682,7 +685,7 @@ module.exports = class Singleton {
682
685
  async getOrder(payLoad) {
683
686
  const access_token = await this.getAccessToken()
684
687
  const url = util.format(getOrderUrl, access_token)
685
- const result = await axios
688
+ const result = await wxAxios
686
689
  .post(url, {
687
690
  ...payLoad,
688
691
  })
@@ -701,7 +704,7 @@ module.exports = class Singleton {
701
704
  async refundOrder(payLoad) {
702
705
  const access_token = await this.getAccessToken()
703
706
  const url = util.format(refundOrderUrl, access_token)
704
- const result = await axios
707
+ const result = await wxAxios
705
708
  .post(url, {
706
709
  ...payLoad,
707
710
  })
@@ -720,8 +723,7 @@ module.exports = class Singleton {
720
723
  async addGood(payLoad) {
721
724
  const access_token = await this.getAccessToken()
722
725
  const url = util.format(addGoodUrl, access_token)
723
- console.log('payLoad', payLoad)
724
- const result = await axios
726
+ const result = await wxAxios
725
727
  .post(url, {
726
728
  ...payLoad,
727
729
  })
@@ -741,7 +743,7 @@ module.exports = class Singleton {
741
743
  const access_token = await this.getAccessToken()
742
744
  const url = util.format(getCategoryUrl, access_token)
743
745
 
744
- const result = await axios
746
+ const result = await wxAxios
745
747
  .post(url, {
746
748
  ...payLoad,
747
749
  })
@@ -760,7 +762,7 @@ module.exports = class Singleton {
760
762
  const access_token = await this.getAccessToken()
761
763
  const url = util.format(getBrandListUrl, access_token)
762
764
 
763
- const result = await axios
765
+ const result = await wxAxios
764
766
  .post(url, {
765
767
  ...payLoad,
766
768
  })
@@ -779,7 +781,7 @@ module.exports = class Singleton {
779
781
  const access_token = await this.getAccessToken()
780
782
  const url = util.format(getShipTemplateUrl, access_token)
781
783
 
782
- const result = await axios
784
+ const result = await wxAxios
783
785
  .post(url, {
784
786
  ...payLoad,
785
787
  })
@@ -798,7 +800,7 @@ module.exports = class Singleton {
798
800
  const access_token = await this.getAccessToken()
799
801
  const url = util.format(uploadShipUrl, access_token)
800
802
 
801
- const result = await axios
803
+ const result = await wxAxios
802
804
  .post(url, {
803
805
  ...payLoad,
804
806
  })
@@ -817,7 +819,7 @@ module.exports = class Singleton {
817
819
  const access_token = await this.getAccessToken()
818
820
  const url = util.format(uploadPreShipUrl, access_token)
819
821
 
820
- const result = await axios
822
+ const result = await wxAxios
821
823
  .post(url, {
822
824
  ...payLoad,
823
825
  })
@@ -836,7 +838,7 @@ module.exports = class Singleton {
836
838
  const access_token = await this.getAccessToken()
837
839
  const url = util.format(getShipOrderListUrl, access_token)
838
840
 
839
- const result = await axios
841
+ const result = await wxAxios
840
842
  .post(url, {
841
843
  ...payLoad,
842
844
  })
@@ -862,7 +864,7 @@ module.exports = class Singleton {
862
864
  resp_type
863
865
  )
864
866
 
865
- const result = await axios
867
+ const result = await wxAxios
866
868
  .post(url, {
867
869
  ...rest,
868
870
  })
@@ -882,7 +884,7 @@ module.exports = class Singleton {
882
884
  const access_token = await this.getAccessToken()
883
885
  const url = util.format(setMsgJumpPathUrl, access_token)
884
886
 
885
- const result = await axios
887
+ const result = await wxAxios
886
888
  .post(url, {
887
889
  ...payLoad,
888
890
  })
@@ -901,7 +903,7 @@ module.exports = class Singleton {
901
903
  const access_token = await this.getAccessToken()
902
904
  const url = util.format(getDeliveryListUrl, access_token)
903
905
 
904
- const result = await axios
906
+ const result = await wxAxios
905
907
  .post(url, {
906
908
  ...payLoad,
907
909
  })
@@ -920,7 +922,7 @@ module.exports = class Singleton {
920
922
  const access_token = await this.getAccessToken()
921
923
  const url = util.format(getUserPortraitUrl, access_token)
922
924
 
923
- const result = await axios
925
+ const result = await wxAxios
924
926
  .post(url, {
925
927
  ...payLoad,
926
928
  })
@@ -955,7 +957,7 @@ module.exports = class Singleton {
955
957
  )
956
958
  }
957
959
 
958
- const result = await axios
960
+ const result = await wxAxios
959
961
  .post(url, {
960
962
  ...payLoad,
961
963
  })
@@ -977,7 +979,7 @@ module.exports = class Singleton {
977
979
  const access_token = await this.getAccessToken()
978
980
  const url = util.format(getCommentInfoUrl, commentId, access_token)
979
981
 
980
- const result = await axios.get(url).then((res) => res.data)
982
+ const result = await wxAxios.get(url).then((res) => res.data)
981
983
  if (result.errcode) {
982
984
  if (result.errcode === 40001) {
983
985
  cache.clear()
@@ -995,7 +997,7 @@ module.exports = class Singleton {
995
997
  const access_token = await this.getAccessToken()
996
998
  const url = util.format(createActivityUrl, access_token)
997
999
 
998
- const result = await axios.get(url).then((res) => res.data)
1000
+ const result = await wxAxios.get(url).then((res) => res.data)
999
1001
  if (result.errcode) {
1000
1002
  if (result.errcode === 40001) {
1001
1003
  cache.clear()
@@ -1062,7 +1064,7 @@ module.exports = class Singleton {
1062
1064
  if (!postData.template_info.parameter_list.length) {
1063
1065
  throw new ServiceError('?parameter_list length 0')
1064
1066
  }
1065
- const result = await axios.post(url, postData).then((res) => res.data)
1067
+ const result = await wxAxios.post(url, postData).then((res) => res.data)
1066
1068
  if (result.errcode) {
1067
1069
  if (result.errcode === 40001) {
1068
1070
  cache.clear()
@@ -1083,7 +1085,7 @@ module.exports = class Singleton {
1083
1085
  }) {
1084
1086
  const weixinLoginUrl = `https://api.weixin.qq.com/sns/jscode2session?appid=${this.config.appid}&secret=${this.config.secrect}&js_code=${code}&grant_type=authorization_code`
1085
1087
 
1086
- const weixinResult = await axios.get(weixinLoginUrl).then((res) => res.data)
1088
+ const weixinResult = await wxAxios.get(weixinLoginUrl).then((res) => res.data)
1087
1089
 
1088
1090
  const { session_key } = weixinResult
1089
1091
 
@@ -1119,7 +1121,7 @@ module.exports = class Singleton {
1119
1121
  const pay_sig = hmacSha256(`${uri}&${JSON.stringify(signData)}`, app_key)
1120
1122
 
1121
1123
  const url = util.format(requestUrl, access_token, pay_sig)
1122
- const result = await axios.post(url, signData).then((res) => res.data)
1124
+ const result = await wxAxios.post(url, signData).then((res) => res.data)
1123
1125
  if (result.errcode) {
1124
1126
  if (result.errcode === 40001) {
1125
1127
  cache.clear()
@@ -1145,7 +1147,7 @@ module.exports = class Singleton {
1145
1147
  const pay_sig = hmacSha256(`${uri}&${JSON.stringify(signData)}`, app_key)
1146
1148
 
1147
1149
  const url = util.format(requestUrl, access_token, pay_sig)
1148
- const result = await axios.post(url, signData).then((res) => res.data)
1150
+ const result = await wxAxios.post(url, signData).then((res) => res.data)
1149
1151
  if (result.errcode) {
1150
1152
  if (result.errcode === 40001) {
1151
1153
  cache.clear()
@@ -1171,7 +1173,7 @@ module.exports = class Singleton {
1171
1173
  const pay_sig = hmacSha256(`${uri}&${JSON.stringify(signData)}`, app_key)
1172
1174
 
1173
1175
  const url = util.format(requestUrl, access_token, pay_sig)
1174
- const result = await axios.post(url, signData).then((res) => res.data)
1176
+ const result = await wxAxios.post(url, signData).then((res) => res.data)
1175
1177
  if (result.errcode) {
1176
1178
  if (result.errcode === 40001) {
1177
1179
  cache.clear()
@@ -1186,7 +1188,7 @@ module.exports = class Singleton {
1186
1188
  const access_token = await this.getAccessToken()
1187
1189
  const url = util.format(b2bPreStoreUrl, access_token)
1188
1190
 
1189
- const result = await axios
1191
+ const result = await wxAxios
1190
1192
  .post(url, {
1191
1193
  retail_info_list: list,
1192
1194
  })
@@ -1216,7 +1218,7 @@ module.exports = class Singleton {
1216
1218
  const pay_sig = hmacSha256(`${uri}&${JSON.stringify(signData)}`, app_key)
1217
1219
 
1218
1220
  const url = util.format(requestUrl, access_token, pay_sig)
1219
- const result = await axios.post(url, signData).then((res) => res.data)
1221
+ const result = await wxAxios.post(url, signData).then((res) => res.data)
1220
1222
  if (result.errcode) {
1221
1223
  if (result.errcode === 40001) {
1222
1224
  cache.clear()
@@ -1231,7 +1233,7 @@ module.exports = class Singleton {
1231
1233
  const access_token = await this.getAccessToken()
1232
1234
  const url = util.format(b2bSendMessageUrl, access_token)
1233
1235
 
1234
- const result = await axios
1236
+ const result = await wxAxios
1235
1237
  .post(url, {
1236
1238
  type,
1237
1239
  to_user_list,
@@ -11,7 +11,10 @@ const wxHttpsAgent = new https.Agent({
11
11
  rejectUnauthorized: true,
12
12
  })
13
13
 
14
- axios.defaults.httpsAgent = wxHttpsAgent
14
+ // 微信专用 axios 实例,避免修改全局 axios.defaults 影响其他模块
15
+ const wxAxios = axios.create({
16
+ httpsAgent: wxHttpsAgent,
17
+ })
15
18
  const { lodash } = require('q-koa')
16
19
  const getAccessTokenUrl =
17
20
  'https://api.weixin.qq.com/cgi-bin/token?grant_type=%s&appid=%s&secret=%s'
@@ -65,7 +68,7 @@ module.exports = class Singleton {
65
68
  }
66
69
  const url = util.format(getAccessTokenUrl, grant_type, appid, secrect)
67
70
 
68
- const result = await axios.get(url).then((res) => res.data)
71
+ const result = await wxAxios.get(url).then((res) => res.data)
69
72
  const { errcode, errmsg, access_token } = result
70
73
 
71
74
  if (errcode) {
@@ -79,7 +82,7 @@ module.exports = class Singleton {
79
82
  async getOpenList() {
80
83
  const access_token = await this.getAccessToken()
81
84
  const url = util.format(getOpenListUrl, access_token)
82
- const result = await axios.post(url).then((res) => res.data)
85
+ const result = await wxAxios.post(url).then((res) => res.data)
83
86
  if (result.errcode) {
84
87
  if (result.errcode === 40001) {
85
88
  cache.clear()
@@ -93,7 +96,7 @@ module.exports = class Singleton {
93
96
  async getUserInfo(openid) {
94
97
  const access_token = await this.getAccessToken()
95
98
  const url = util.format(getUserInfoUrl, access_token, openid)
96
- const result = await axios.post(url).then((res) => res.data)
99
+ const result = await wxAxios.post(url).then((res) => res.data)
97
100
  if (result.errcode) {
98
101
  if (result.errcode === 40001) {
99
102
  cache.clear()
@@ -113,7 +116,7 @@ module.exports = class Singleton {
113
116
  })
114
117
  const access_token = await this.getAccessToken()
115
118
  const url = util.format(getUserInfoListUrl, access_token)
116
- const result = await axios
119
+ const result = await wxAxios
117
120
  .post(url, {
118
121
  user_list,
119
122
  })
@@ -140,7 +143,7 @@ module.exports = class Singleton {
140
143
  }),
141
144
  }
142
145
 
143
- const result = await axios.post(url, formatOptions).then((res) => res.data)
146
+ const result = await wxAxios.post(url, formatOptions).then((res) => res.data)
144
147
  if (result.errcode) {
145
148
  if (result.errcode === 40001) {
146
149
  cache.clear()
@@ -154,7 +157,7 @@ module.exports = class Singleton {
154
157
  async getTemplate() {
155
158
  const access_token = await this.getAccessToken()
156
159
  const url = util.format(getTemplateUrl, access_token)
157
- const result = await axios.post(url).then((res) => res.data)
160
+ const result = await wxAxios.post(url).then((res) => res.data)
158
161
  if (result.errcode) {
159
162
  if (result.errcode === 40001) {
160
163
  cache.clear()
@@ -359,7 +359,7 @@ const filterFunction = (target, data) => {
359
359
  return data[key] > target[key].$gt
360
360
  } else if ('$gte' in target[key]) {
361
361
  if (key.endsWith('time') || key.endsWith('_at')) {
362
- return moment(data[key]).diff(moment(target[key].$gt), 'seconds') >= 0
362
+ return moment(data[key]).diff(moment(target[key].$gte), 'seconds') >= 0
363
363
  }
364
364
  return data[key] >= target[key].$gte
365
365
  } else if ('$lt' in target[key]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.8.10",
3
+ "version": "13.8.12",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {