q-koa 9.3.0 → 9.3.3

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.
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
3
  const fsPromise = require('fs/promises')
4
+ const { lodash } = require('q-koa')
4
5
  exports.loadModel = async ({ app, appName }) => {
5
6
  const data = await fsPromise.readdir(
6
7
  path.resolve(__dirname, `${process.cwd()}/app/${appName}/plugins`)
@@ -15,7 +16,11 @@ exports.loadModel = async ({ app, appName }) => {
15
16
  })
16
17
  )
17
18
  )
18
-
19
+ const currentDisabledFindAllList = lodash.get(
20
+ app,
21
+ 'appConfig.disabledFindAllList',
22
+ []
23
+ )
19
24
  const dataList = []
20
25
  let disabledFindAllList = []
21
26
  const result = data.filter(
@@ -64,7 +69,7 @@ exports.loadModel = async ({ app, appName }) => {
64
69
 
65
70
  let countNumber = 0
66
71
  if (!['setting', 'auth'].includes(config.belongs)) {
67
- if (app.model[result[i]]) {
72
+ if (currentDisabledFindAllList.length === 0 && app.model[result[i]]) {
68
73
  countNumber = await app.model[result[i]].count()
69
74
  }
70
75
  if (countNumber >= 500) {
@@ -223,7 +228,11 @@ exports.loadModel = async ({ app, appName }) => {
223
228
 
224
229
  await Promise.all([promise1, promise2])
225
230
  console.log('lodaModel success!')
226
- console.warn(`disabledFindAllList: ${JSON.stringify(disabledFindAllList)}`)
231
+ if (currentDisabledFindAllList.length > 0) {
232
+ console.warn(`当前disabledFindAllList不为空,查看需清空`)
233
+ } else {
234
+ console.warn(`disabledFindAllList: ${JSON.stringify(disabledFindAllList)}`)
235
+ }
227
236
 
228
237
  if (app.service.routes && app.model.routes) {
229
238
  await app.service.routes.initRouter({ app })
@@ -14,11 +14,12 @@ exports.copyOther = async (ctx) => {
14
14
  const { app, appName } = getAppByCtx(ctx)
15
15
 
16
16
  const { type, source } = ctx.request.body
17
-
18
- const { data } = await axios
19
- .post(`http://localhost:3001/${source}/setting/findAll`)
20
- .then((res) => res.data)
21
-
17
+ const url = `http://localhost:3001/${source}/setting/findAll`
18
+ const result = await axios.post(url).then((res) => res.data)
19
+ if (result.code !== 200) {
20
+ throw new Error(result.message + url)
21
+ }
22
+ const { data } = result
22
23
  const copyType = data.find((item) => item.code === type)
23
24
 
24
25
  if (!copyType) throw new Error('克隆方找不到')
@@ -28,23 +29,37 @@ exports.copyOther = async (ctx) => {
28
29
  const list = await app.model.setting.findAll()
29
30
 
30
31
  const findType = list.find((item) => item.code === type)
31
- if (!findType) throw new Error('自己找不到')
32
-
33
- await app.model.setting.destroy({
34
- where: {
35
- parent_id: findType.id,
36
- },
37
- })
38
-
39
- await app.model.setting.bulkCreate(
40
- copyList.map((item) => {
41
- const { parent, id, ...rest } = item
42
- return {
43
- ...rest,
32
+ if (!findType) {
33
+ const { id, ...rest } = copyType
34
+ const newParent = await app.model.setting.create({
35
+ ...rest,
36
+ })
37
+ await app.model.setting.bulkCreate(
38
+ copyList.map((item) => {
39
+ const { parent, id, ...rest } = item
40
+ return {
41
+ ...rest,
42
+ parent_id: newParent.id,
43
+ }
44
+ })
45
+ )
46
+ } else {
47
+ await app.model.setting.destroy({
48
+ where: {
44
49
  parent_id: findType.id,
45
- }
50
+ },
46
51
  })
47
- )
52
+
53
+ await app.model.setting.bulkCreate(
54
+ copyList.map((item) => {
55
+ const { parent, id, ...rest } = item
56
+ return {
57
+ ...rest,
58
+ parent_id: findType.id,
59
+ }
60
+ })
61
+ )
62
+ }
48
63
 
49
64
  ctx.SUCCESS('ok')
50
65
  }
@@ -31,6 +31,8 @@ exports.initModel = async (ctx) => {
31
31
  return ctx.ERROR('请检查,model为空')
32
32
  const result = await app.model[model].sync(config)
33
33
  return ctx.SUCCESS(result)
34
+ } else {
35
+ return ctx.ERROR(`app.model没有${model}`)
34
36
  }
35
37
  return ctx.SUCCESS(null)
36
38
  }
@@ -0,0 +1,25 @@
1
+ module.exports = {
2
+ name: '小程序页面',
3
+ belongs: 'page',
4
+ multiple: false,
5
+ availableSort: false,
6
+ order: [],
7
+ referenceSelect: [],
8
+ select: [],
9
+ excludes: [],
10
+ limit: 20,
11
+ defaultOrder: [],
12
+ comment: {},
13
+ sortOrder: 1,
14
+ reference: [],
15
+ excludeAuth: [],
16
+ initList: [],
17
+ editInline: {},
18
+ autoData: {},
19
+ is_split: false,
20
+ is_split_count: false,
21
+ show_virtual: false,
22
+ modelQuery: {},
23
+ deleteCheckList: [],
24
+ bulkCreateList: [],
25
+ };
@@ -0,0 +1,31 @@
1
+ const { Sequelize, Random } = require('q-koa')
2
+
3
+ exports.name = {
4
+ type: Sequelize.STRING,
5
+ comment: '名字',
6
+ allowNull: false,
7
+ is_mock: true,
8
+ defaultValue: '',
9
+ sortOrder: 1,
10
+ mock: () => Random.ctitle(),
11
+ }
12
+
13
+ exports.route = {
14
+ type: Sequelize.STRING,
15
+ comment: '路由',
16
+ allowNull: false,
17
+ is_mock: true,
18
+ defaultValue: '',
19
+ sortOrder: 2,
20
+ mock: () => Random.ctitle(),
21
+ }
22
+
23
+ exports.route_type = {
24
+ type: Sequelize.ENUM('navigateTo', 'redirectTo', 'switchTab'),
25
+ comment: '跳转类型',
26
+ allowNull: false,
27
+ is_mock: true,
28
+ defaultValue: 'navigateTo',
29
+ sortOrder: 3,
30
+ mock: () => ['navigateTo', 'redirectTo', 'switchTab'][Random.integer(0, 2)],
31
+ }
@@ -759,13 +759,15 @@ exports.h5_pay = async (ctx) => {
759
759
  key: key.length > 10 ? key : partner_key,
760
760
  mchId,
761
761
  })
762
+
763
+ const notify_url = `https://${
764
+ site_host || 'api.kuashou.com'
765
+ }/${appName}/weixin/notify`
762
766
  const result = await payObj.run({
763
767
  body: name,
764
768
  out_trade_no: `${appName}_${order_id}_${type}`,
765
769
  total_fee: is_admin || is_dev ? 1 : Math.round(price * 100),
766
- notify_url: `https://${
767
- site_host || 'api.kuashou.com'
768
- }/${appName}/weixin/notify`,
770
+ notify_url,
769
771
  scene_info: `{"h5_info": {"type":"Wap","wap_url": ${
770
772
  site_host || 'https://api.kuashou.com'
771
773
  },"wap_name": "腾讯充值"}}`,
@@ -844,6 +846,9 @@ exports.mp_pay = async (ctx) => {
844
846
  ? `${appName}_${prefix}-${order_id}_${type}`
845
847
  : `${appName}_${order_id}_${type}`
846
848
 
849
+ const notify_url = `https://${
850
+ site_host || 'api.kuashou.com'
851
+ }/${appName}/weixin/notify`
847
852
  const prePayResult = await pay({
848
853
  openid: userDetail.openid,
849
854
  body: name,
@@ -851,9 +856,7 @@ exports.mp_pay = async (ctx) => {
851
856
  out_trade_no,
852
857
  total_fee: is_admin || is_dev ? 1 : Math.round(price * 100),
853
858
  spbill_create_ip: '192.168.2.210',
854
- notify_url: `http://${
855
- site_host || 'api.kuashou.com'
856
- }/${appName}/weixin/notify`,
859
+ notify_url,
857
860
  })
858
861
 
859
862
  const checkOrder = (obj) => {
@@ -892,6 +895,13 @@ exports.mp_pay = async (ctx) => {
892
895
  if (payResult.trade_state_desc === '支付成功') {
893
896
  return ctx.SUCCESS('ok')
894
897
  }
898
+ if (payResult.return_msg) {
899
+ throw new Error(
900
+ payResult.return_msg === '签名错误,请检查后再试'
901
+ ? payResult.return_msg + '(商户号/APIv2/关联)'
902
+ : payResult.return_msg
903
+ )
904
+ }
895
905
  throw new Error(`支付失败,请重试`)
896
906
  }
897
907
  return ctx.SUCCESS({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "9.3.0",
3
+ "version": "9.3.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {