q-koa 13.8.43 → 13.8.44

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.
@@ -269,9 +269,7 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
269
269
  if (obj.setting && apiVersion && cacheVersion) {
270
270
  let target = null
271
271
  if (config) {
272
- const application_key = `${app.appConfig.appName}-application`
273
-
274
- const application = app.cache.get(application_key)
272
+ const application = app.cache.get('application')
275
273
  if (application) {
276
274
  target = application.find((a) => a.config === config)
277
275
  }
@@ -2361,6 +2361,39 @@ exports.union_checkPay = async (ctx) => {
2361
2361
  ctx.SUCCESS({ prefix, ...payResult })
2362
2362
  }
2363
2363
 
2364
+ exports.union_check_balance = async (ctx) => {
2365
+ const { app, appName } = getAppByCtx(ctx)
2366
+
2367
+ const {
2368
+ pay_config = 'weixin_pay',
2369
+ accttype = '01', // 01:余额户 02:冻结户
2370
+ mch_id = '',
2371
+ } = ctx.request.body
2372
+
2373
+ const appConfig = getConfig(app)
2374
+ const {
2375
+ union_mchId,
2376
+ union_appid,
2377
+ union_privateKey,
2378
+ union_publicKey,
2379
+ } = await appConfig.getObject(pay_config)
2380
+
2381
+ const allinpay = new AllinPay({
2382
+ cusid: mch_id || union_mchId,
2383
+ appid: union_appid,
2384
+ isTest: false,
2385
+ privateKey: union_privateKey,
2386
+ publicKey: union_publicKey,
2387
+ })
2388
+
2389
+ const result = await allinpay.checkBalance(accttype)
2390
+
2391
+ // amount 单位为分,转换为元便于前端展示
2392
+ const balance = result.amount ? Number(result.amount) / 100 : 0
2393
+
2394
+ ctx.SUCCESS({ ...result, balance })
2395
+ }
2396
+
2364
2397
  exports.b2b_checkPay = async (ctx) => {
2365
2398
  const { app, appName, controller } = getAppByCtx(ctx)
2366
2399
 
@@ -286,6 +286,37 @@ class AllinPay {
286
286
  throw new Error(result.retmsg || 'Unknown error')
287
287
  }
288
288
 
289
+ async checkBalance(accttype = '01') {
290
+ const params = {
291
+ cusid: this.cusid,
292
+ appid: this.appid,
293
+ version: '12',
294
+ randomstr: this.generateRandomStr(),
295
+ accttype, // 01:余额户查询 02:冻结户查询
296
+ signtype: this.signType,
297
+ }
298
+ if (this.orgid) params.orgid = this.orgid
299
+
300
+ params.sign = this.sign(params)
301
+
302
+ const url = this.isTest
303
+ ? 'https://syb-test.allinpay.com/vsppcusapi/cusacct/querybalance'
304
+ : 'https://cus.allinpay.com/cusapi/cusacct/querybalance'
305
+ const result = await this.request(url, params)
306
+
307
+ if (result && result.retcode === 'SUCCESS') {
308
+ if (result.sign && this.verifySign(result)) {
309
+ return result
310
+ } else {
311
+ console.warn(
312
+ 'Sign verification failed, but retcode is SUCCESS. Returning result anyway.'
313
+ )
314
+ return result
315
+ }
316
+ }
317
+ throw new Error(result.retmsg || 'Unknown error')
318
+ }
319
+
289
320
  async refundOrder(orderData) {
290
321
  const { reqsn, trxamt, oldreqsn, remark = '', acct = '' } = orderData
291
322
 
@@ -60,8 +60,7 @@ exports.getObject = (config, app) => async (type) => {
60
60
  }
61
61
 
62
62
  if (app) {
63
- const application_key = `${app.appConfig.appName}-application`
64
- const applicationList = app.cache.get(application_key)
63
+ const applicationList = app.cache.get('application')
65
64
  const target = applicationList && applicationList.find(findConfig(type))
66
65
  if (target) {
67
66
  flag = true
@@ -77,7 +76,7 @@ exports.getObject = (config, app) => async (type) => {
77
76
 
78
77
  if (result.length > 0) {
79
78
  const formatData = JSON.parse(JSON.stringify(result))
80
- app.cache.set(application_key, formatData)
79
+ app.cache.set('application', formatData)
81
80
 
82
81
  const target = formatData.find(findConfig(type))
83
82
  if (target) {
@@ -189,11 +188,8 @@ exports.getImageType = (fileBuffer) => {
189
188
 
190
189
  exports.getAppConfig = async ({ app, config, key, app_id, id }) => {
191
190
  if (!(app && (config || key || app_id || id))) return null
192
-
193
- const application_key = `${app.appConfig.appName}-application`
194
-
195
191
  const application =
196
- app.cache.get(application_key) || (await app.model.application.findAll())
192
+ app.cache.get('application') || (await app.model.application.findAll())
197
193
  const target = application.find(findConfig(config || key || app_id || id))
198
194
 
199
195
  return target || null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.8.43",
3
+ "version": "13.8.44",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {