q-koa 9.3.1 → 9.3.4
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
|
@@ -1819,6 +1819,7 @@ APP.getAppByCtx = (ctx) => {
|
|
|
1819
1819
|
const appName = ctx.router.opts.prefix.substring(1)
|
|
1820
1820
|
|
|
1821
1821
|
let controller = ''
|
|
1822
|
+
let payName = appName
|
|
1822
1823
|
try {
|
|
1823
1824
|
const url = ctx.request.url
|
|
1824
1825
|
const _split = url.split('/')
|
|
@@ -1826,10 +1827,23 @@ APP.getAppByCtx = (ctx) => {
|
|
|
1826
1827
|
} catch (e) {
|
|
1827
1828
|
console.warn(e)
|
|
1828
1829
|
}
|
|
1830
|
+
try {
|
|
1831
|
+
const url = ctx.request.url
|
|
1832
|
+
const referer = ctx.request.header.referer
|
|
1833
|
+
if (!referer.includes(url)) {
|
|
1834
|
+
const arr = ctx.request.header.referer.split('/').reverse()
|
|
1835
|
+
if (arr.length >= 4) {
|
|
1836
|
+
payName = arr[2]
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
} catch (e) {
|
|
1840
|
+
console.warn(e)
|
|
1841
|
+
}
|
|
1829
1842
|
const { [appName]: app } = ctx.app
|
|
1830
1843
|
return {
|
|
1831
1844
|
appName,
|
|
1832
1845
|
app,
|
|
1846
|
+
payName,
|
|
1833
1847
|
controller,
|
|
1834
1848
|
}
|
|
1835
1849
|
}
|
|
@@ -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
|
-
|
|
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,37 +14,64 @@ exports.copyOther = async (ctx) => {
|
|
|
14
14
|
const { app, appName } = getAppByCtx(ctx)
|
|
15
15
|
|
|
16
16
|
const { type, source } = ctx.request.body
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const url = source.startsWith('http')
|
|
18
|
+
? source
|
|
19
|
+
: `http://localhost:3001/${source}/setting/findAll`
|
|
20
|
+
const result = await axios.post(url).then((res) => res.data)
|
|
21
|
+
if (result.code !== 200) {
|
|
22
|
+
throw new Error(result.message + url)
|
|
23
|
+
}
|
|
24
|
+
const { data } = result
|
|
22
25
|
const copyType = data.find((item) => item.code === type)
|
|
23
26
|
|
|
24
27
|
if (!copyType) throw new Error('克隆方找不到')
|
|
25
28
|
|
|
26
|
-
const copyList = data.filter((item) => item.parent_id === copyType.id)
|
|
27
|
-
|
|
28
29
|
const list = await app.model.setting.findAll()
|
|
29
30
|
|
|
30
31
|
const findType = list.find((item) => item.code === type)
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
if (findType && findType.parent_id) {
|
|
33
|
+
if (!findType) {
|
|
34
|
+
throw new Error(`当前找不到${type}`)
|
|
35
|
+
}
|
|
36
|
+
await app.model.setting.upsert({
|
|
37
|
+
id: findType.id,
|
|
38
|
+
value: copyType.value,
|
|
39
|
+
})
|
|
40
|
+
return ctx.SUCCESS('ok')
|
|
41
|
+
}
|
|
42
|
+
const copyList = data.filter((item) => item.parent_id === copyType.id)
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
if (!findType) {
|
|
45
|
+
const { id, ...rest } = copyType
|
|
46
|
+
const newParent = await app.model.setting.create({
|
|
47
|
+
...rest,
|
|
48
|
+
})
|
|
49
|
+
await app.model.setting.bulkCreate(
|
|
50
|
+
copyList.map((item) => {
|
|
51
|
+
const { parent, id, ...rest } = item
|
|
52
|
+
return {
|
|
53
|
+
...rest,
|
|
54
|
+
parent_id: newParent.id,
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
)
|
|
58
|
+
} else {
|
|
59
|
+
await app.model.setting.destroy({
|
|
60
|
+
where: {
|
|
44
61
|
parent_id: findType.id,
|
|
45
|
-
}
|
|
62
|
+
},
|
|
46
63
|
})
|
|
47
|
-
|
|
64
|
+
|
|
65
|
+
await app.model.setting.bulkCreate(
|
|
66
|
+
copyList.map((item) => {
|
|
67
|
+
const { parent, id, ...rest } = item
|
|
68
|
+
return {
|
|
69
|
+
...rest,
|
|
70
|
+
parent_id: findType.id,
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
)
|
|
74
|
+
}
|
|
48
75
|
|
|
49
76
|
ctx.SUCCESS('ok')
|
|
50
77
|
}
|
|
@@ -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
|
|
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": "腾讯充值"}}`,
|
|
@@ -780,7 +782,7 @@ exports.h5_pay = async (ctx) => {
|
|
|
780
782
|
}
|
|
781
783
|
|
|
782
784
|
exports.mp_pay = async (ctx) => {
|
|
783
|
-
const { app, appName } = getAppByCtx(ctx)
|
|
785
|
+
const { app, appName, payName } = getAppByCtx(ctx)
|
|
784
786
|
const {
|
|
785
787
|
name,
|
|
786
788
|
order_id,
|
|
@@ -841,9 +843,12 @@ exports.mp_pay = async (ctx) => {
|
|
|
841
843
|
const out_trade_no = _out_trade_no
|
|
842
844
|
? _out_trade_no
|
|
843
845
|
: prefix
|
|
844
|
-
? `${
|
|
845
|
-
: `${
|
|
846
|
+
? `${payName}_${prefix}-${order_id}_${type}`
|
|
847
|
+
: `${payName}_${order_id}_${type}`
|
|
846
848
|
|
|
849
|
+
const notify_url = `https://${
|
|
850
|
+
site_host || 'api.kuashou.com'
|
|
851
|
+
}/${payName}/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
|
|
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({
|