q-koa 7.9.8 → 8.0.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
@@ -236,7 +236,7 @@ class APP {
236
236
  ) {
237
237
  this.app[appName].model.log.upsert(errorData)
238
238
  }
239
- throw new Error(err)
239
+ throw new Error(err.message)
240
240
  })
241
241
 
242
242
  // this.app.on('message', async (content) => {
@@ -381,7 +381,7 @@ class APP {
381
381
  } catch (e) {
382
382
  console.log(`${appName}数据库连接失败`)
383
383
  console.log(e)
384
- throw new Error(e)
384
+ throw new Error(e.message)
385
385
  }
386
386
  if (
387
387
  this.app[appName] &&
@@ -795,11 +795,11 @@ class APP {
795
795
  }
796
796
  await next()
797
797
  })
798
- router.post('/:controller/:fn', async (ctx) => {
798
+ const handleRouter = async (ctx) => {
799
799
  const appName = router.opts.prefix.substring(1)
800
800
  const { app } = ctx
801
801
 
802
- const { controller, fn } = ctx.params
802
+ const { controller, fn, sub } = ctx.params
803
803
  if (_.get(app, `${appName}.model.${controller}`) && fn === 'mock') {
804
804
  return ctx.SUCCESS(await app[appName].mock[controller]())
805
805
  }
@@ -1724,7 +1724,10 @@ class APP {
1724
1724
  })
1725
1725
  }
1726
1726
  }
1727
- })
1727
+ }
1728
+
1729
+ router.post('/:controller/:fn', handleRouter)
1730
+ router.post('/:controller/:fn/:sub', handleRouter)
1728
1731
  }
1729
1732
  }
1730
1733
 
@@ -1761,7 +1764,14 @@ APP.getAppByCtx = (ctx) => {
1761
1764
  controller,
1762
1765
  }
1763
1766
  }
1764
-
1767
+ APP.getUserByCtx = (ctx) => {
1768
+ try {
1769
+ const appName = ctx.router.opts.prefix.substring(1)
1770
+ return ctx.request[`${appName}-user`].id
1771
+ } catch (e) {
1772
+ return 0
1773
+ }
1774
+ }
1765
1775
  APP.getClientTypeByCtx = (ctx) => {
1766
1776
  const typeEnum = {
1767
1777
  1: 'admin',
@@ -80,7 +80,7 @@ exports.mp_getPhone = async (ctx) => {
80
80
  (!exist.mp_user.appid || exist.mp_user.appid === app_id)
81
81
 
82
82
  if (mobileExist) {
83
- throw new Error('系统已存在该手机号')
83
+ return ctx.ERROR('系统已存在该手机号')
84
84
  }
85
85
 
86
86
  const userResult = await app.model.mp_user.findOne({
@@ -90,7 +90,7 @@ exports.mp_getPhone = async (ctx) => {
90
90
  })
91
91
 
92
92
  if (!userResult || !userResult.user_id)
93
- throw new Error('微信获取手机失败,请重试')
93
+ return ctx.ERROR('微信获取手机失败,请重试')
94
94
 
95
95
  await app.model.user.upsert({
96
96
  id: userResult.user_id,
@@ -207,7 +207,7 @@ exports.mp_getPhoneNew = async (ctx) => {
207
207
  (!exist.mp_user.appid || exist.mp_user.appid === app_id)
208
208
 
209
209
  if (mobileExist) {
210
- throw new Error('系统已存在该手机号')
210
+ return ctx.ERROR('系统已存在该手机号')
211
211
  }
212
212
 
213
213
  await app.model.user.upsert({
@@ -1050,7 +1050,7 @@ const getRefundResultJson = async ({ req_info, app_key }) => {
1050
1050
  exports.refund_notify = async (ctx) => {
1051
1051
  const { app } = getAppByCtx(ctx)
1052
1052
  const result = ctx.request.xmlBody
1053
- const pay_config = ctx.request.query.pay_config || 'weixin_pay'
1053
+ const pay_config = ctx.params.sub || 'weixin_pay'
1054
1054
 
1055
1055
  const appConfig = getConfig(app)
1056
1056
  const { key } = await appConfig.getObject(pay_config)
@@ -50,7 +50,7 @@ exports.refund = async ({
50
50
  refund_fee: Math.round((refund_fee || price) * 100),
51
51
  notify_url: `https://${
52
52
  site_host || 'api.kuashou.com'
53
- }/${appName}/weixin/refund_notify?pay_config=weixin_pay`,
53
+ }/${appName}/weixin/refund_notify/${pay_config}`,
54
54
  })
55
55
  if (result_code === 'SUCCESS') {
56
56
  return true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "7.9.8",
3
+ "version": "8.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {