q-koa 13.4.2 → 13.4.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.
- package/core/config.js +2 -0
- package/core/file/plugins/administrator/config.js +1 -1
- package/core/file/plugins/app/controller.js +7 -1
- package/core/file/plugins/common/controller.js +70 -3
- package/core/file/plugins/douyin/controller.js +7 -1
- package/core/file/plugins/model/model.js +1 -1
- package/core/file/plugins/model_attributes/config.js +8 -1
- package/core/file/plugins/setting/controller.js +44 -0
- package/core/file/plugins/setting/model.js +7 -1
- package/core/file/plugins/system/service.js +1 -0
- package/core/file/plugins/toutiao/controller.js +6 -1
- package/core/file/plugins/user/controller.js +23 -5
- package/core/file/plugins/weixin/controller.js +37 -5
- package/core/file/plugins/weixin/service.js +1 -1
- package/core/file/services/weixinMP.js +44 -0
- package/package.json +1 -1
package/core/config.js
CHANGED
|
@@ -7,6 +7,7 @@ module.exports = {
|
|
|
7
7
|
dir: 'public',
|
|
8
8
|
},
|
|
9
9
|
is_check_admin: false,
|
|
10
|
+
is_token_name: true,
|
|
10
11
|
log: {
|
|
11
12
|
request: true,
|
|
12
13
|
},
|
|
@@ -67,6 +68,7 @@ module.exports = {
|
|
|
67
68
|
'log/create',
|
|
68
69
|
'log/upsert',
|
|
69
70
|
'auto/minute',
|
|
71
|
+
'auto/second',
|
|
70
72
|
].every((item) => {
|
|
71
73
|
return !ctx.request.url.includes(item)
|
|
72
74
|
})
|
|
@@ -24,9 +24,15 @@ exports.login = async (ctx) => {
|
|
|
24
24
|
result = hasUser
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
const is_token_name = app.appConfig.is_token_name
|
|
28
|
+
|
|
27
29
|
const tokenResult = {
|
|
28
30
|
id: result.id,
|
|
29
|
-
|
|
31
|
+
...(is_token_name
|
|
32
|
+
? {
|
|
33
|
+
name: result.name,
|
|
34
|
+
}
|
|
35
|
+
: {}),
|
|
30
36
|
mp_user: result.mp_user
|
|
31
37
|
? {
|
|
32
38
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -439,12 +439,15 @@ exports.verify = async (ctx) => {
|
|
|
439
439
|
ctx.SUCCESS(result)
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
-
const expressFn = async ({ app, express_number: _express_number }) => {
|
|
442
|
+
const expressFn = async ({ app, express_number: _express_number, mobile }) => {
|
|
443
443
|
const appConfig = getConfig(app)
|
|
444
|
-
const { app_code, express_mobile } =
|
|
444
|
+
const { app_code, express_mobile: default_express_mobile } =
|
|
445
|
+
await appConfig.getObject('express')
|
|
445
446
|
|
|
446
447
|
const express_number = _express_number.replace(/\t/, '').trim()
|
|
447
448
|
|
|
449
|
+
const express_mobile = mobile || default_express_mobile
|
|
450
|
+
|
|
448
451
|
const lastFour = express_mobile
|
|
449
452
|
.split('')
|
|
450
453
|
.slice(express_mobile.length - 4, express_mobile.length)
|
|
@@ -501,7 +504,7 @@ const expressFn = async ({ app, express_number: _express_number }) => {
|
|
|
501
504
|
exports.express = async (ctx) => {
|
|
502
505
|
const { app } = getAppByCtx(ctx)
|
|
503
506
|
|
|
504
|
-
const { express_number } = ctx.request.body
|
|
507
|
+
const { express_number, mobile } = ctx.request.body
|
|
505
508
|
|
|
506
509
|
if (Array.isArray(express_number)) {
|
|
507
510
|
const result = await Promise.all(
|
|
@@ -518,6 +521,7 @@ exports.express = async (ctx) => {
|
|
|
518
521
|
const result = await expressFn({
|
|
519
522
|
app,
|
|
520
523
|
express_number,
|
|
524
|
+
mobile,
|
|
521
525
|
})
|
|
522
526
|
|
|
523
527
|
return ctx.SUCCESS(result)
|
|
@@ -674,3 +678,66 @@ exports.gpt = async (ctx) => {
|
|
|
674
678
|
})
|
|
675
679
|
await sleep(1000000)
|
|
676
680
|
}
|
|
681
|
+
|
|
682
|
+
exports.copyDB = async (ctx) => {
|
|
683
|
+
const { app, appName: currentAppName } = getAppByCtx(ctx)
|
|
684
|
+
const {
|
|
685
|
+
host = '',
|
|
686
|
+
ori_appname = '',
|
|
687
|
+
break_list = [],
|
|
688
|
+
limit = 3000,
|
|
689
|
+
} = ctx.request.body
|
|
690
|
+
if (!host) {
|
|
691
|
+
throw new Error(`?host`)
|
|
692
|
+
}
|
|
693
|
+
const list = Object.keys(app.model)
|
|
694
|
+
const appName = ori_appname || currentAppName
|
|
695
|
+
|
|
696
|
+
for (const model of list) {
|
|
697
|
+
if (break_list.includes(model)) {
|
|
698
|
+
console.log(`跳过`)
|
|
699
|
+
continue
|
|
700
|
+
}
|
|
701
|
+
const count = await app.model[model].count()
|
|
702
|
+
if (count > 0) {
|
|
703
|
+
console.log(`有数据,跳过`)
|
|
704
|
+
continue
|
|
705
|
+
}
|
|
706
|
+
await app.model[model].sync({
|
|
707
|
+
force: true,
|
|
708
|
+
})
|
|
709
|
+
const url = `${host}/${appName}/${model}/findAll`
|
|
710
|
+
for (let i = 0; i < 10000; i++) {
|
|
711
|
+
console.log(`page-${i}`)
|
|
712
|
+
const { code, data } = await axios
|
|
713
|
+
.post(url, {
|
|
714
|
+
offset: i * limit,
|
|
715
|
+
limit,
|
|
716
|
+
where: {
|
|
717
|
+
id: {
|
|
718
|
+
$gt: 0,
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
...(model === 'setting'
|
|
722
|
+
? {
|
|
723
|
+
raw: true,
|
|
724
|
+
}
|
|
725
|
+
: {}),
|
|
726
|
+
autoInclude: false,
|
|
727
|
+
})
|
|
728
|
+
.then((res) => res.data)
|
|
729
|
+
|
|
730
|
+
if (code !== 200) {
|
|
731
|
+
break
|
|
732
|
+
}
|
|
733
|
+
await app.model[model].bulkCreate(data)
|
|
734
|
+
if (data.length < limit) {
|
|
735
|
+
break
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
console.log(`${model}结束`)
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
ctx.SUCCESS('ok')
|
|
743
|
+
}
|
|
@@ -147,9 +147,15 @@ exports.login_callback = async (ctx) => {
|
|
|
147
147
|
],
|
|
148
148
|
})
|
|
149
149
|
|
|
150
|
+
const is_token_name = app.appConfig.is_token_name
|
|
151
|
+
|
|
150
152
|
const tokenResult = {
|
|
151
153
|
id: result.id,
|
|
152
|
-
|
|
154
|
+
...(is_token_name
|
|
155
|
+
? {
|
|
156
|
+
name: result.name,
|
|
157
|
+
}
|
|
158
|
+
: {}),
|
|
153
159
|
h5_user: result.h5_user
|
|
154
160
|
? {
|
|
155
161
|
openid: result.h5_user && result.h5_user.openid,
|
|
@@ -157,3 +157,47 @@ exports.html = async (ctx) => {
|
|
|
157
157
|
</body>
|
|
158
158
|
</html>`
|
|
159
159
|
}
|
|
160
|
+
|
|
161
|
+
exports.getList = async (ctx, _data) => {
|
|
162
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
163
|
+
|
|
164
|
+
const { type = 'is_custom' } = _data || ctx.request.body
|
|
165
|
+
|
|
166
|
+
const settingList = await app.model.setting.findAll({
|
|
167
|
+
where: {
|
|
168
|
+
$or: [
|
|
169
|
+
{
|
|
170
|
+
is_front: true,
|
|
171
|
+
},
|
|
172
|
+
type
|
|
173
|
+
? {
|
|
174
|
+
extra: {
|
|
175
|
+
[type]: true,
|
|
176
|
+
},
|
|
177
|
+
}
|
|
178
|
+
: null,
|
|
179
|
+
].filter(Boolean),
|
|
180
|
+
},
|
|
181
|
+
attributes: {
|
|
182
|
+
exclude: [
|
|
183
|
+
'name',
|
|
184
|
+
'created_at',
|
|
185
|
+
'updated_at',
|
|
186
|
+
'createdid',
|
|
187
|
+
'is_cache',
|
|
188
|
+
'is_front',
|
|
189
|
+
'is_control',
|
|
190
|
+
'extra',
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
const payLoad = settingList.map((item) => {
|
|
196
|
+
return lodash.omit(item.toJSON(), [
|
|
197
|
+
'type',
|
|
198
|
+
item.parent_id === 0 ? '' : 'id',
|
|
199
|
+
])
|
|
200
|
+
})
|
|
201
|
+
ctx.SUCCESS(payLoad)
|
|
202
|
+
return payLoad
|
|
203
|
+
}
|
|
@@ -141,7 +141,13 @@ exports.extra = {
|
|
|
141
141
|
sortOrder: 9,
|
|
142
142
|
set: function (value) {
|
|
143
143
|
try {
|
|
144
|
-
const dataValue =
|
|
144
|
+
const dataValue =
|
|
145
|
+
value === null
|
|
146
|
+
? {}
|
|
147
|
+
: typeof value === 'object'
|
|
148
|
+
? value
|
|
149
|
+
: JSON.parse(value)
|
|
150
|
+
|
|
145
151
|
this.setDataValue('extra', dataValue)
|
|
146
152
|
} catch {
|
|
147
153
|
throw new Error('extra值不合法')
|
|
@@ -80,6 +80,7 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
|
|
|
80
80
|
const omit = data && data.omit ? data.omit : []
|
|
81
81
|
const pick = data && data.pick ? data.pick : []
|
|
82
82
|
const cacheData = app.cache.get(`${model}`) || []
|
|
83
|
+
|
|
83
84
|
const cacheList = cacheData
|
|
84
85
|
.map((i) => (i.toJSON ? i.toJSON() : i))
|
|
85
86
|
.filter((c) => {
|
|
@@ -160,10 +160,15 @@ exports.login = async (ctx) => {
|
|
|
160
160
|
...app.include.user,
|
|
161
161
|
],
|
|
162
162
|
})
|
|
163
|
+
const is_token_name = app.appConfig.is_token_name
|
|
163
164
|
|
|
164
165
|
const tokenResult = {
|
|
165
166
|
id: result.id,
|
|
166
|
-
|
|
167
|
+
...(is_token_name
|
|
168
|
+
? {
|
|
169
|
+
name: result.name,
|
|
170
|
+
}
|
|
171
|
+
: {}),
|
|
167
172
|
mp_user: result.mp_user
|
|
168
173
|
? {
|
|
169
174
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -8,6 +8,8 @@ exports.login = async (ctx) => {
|
|
|
8
8
|
|
|
9
9
|
const config = _config || ctx.request.header.config || 'weixin_mp'
|
|
10
10
|
|
|
11
|
+
const is_token_name = app.appConfig.is_token_name
|
|
12
|
+
|
|
11
13
|
const where =
|
|
12
14
|
process.env.NODE_ENV !== 'production'
|
|
13
15
|
? {
|
|
@@ -41,7 +43,11 @@ exports.login = async (ctx) => {
|
|
|
41
43
|
if (_config === 'none') {
|
|
42
44
|
const tokenResult = {
|
|
43
45
|
id: result.id,
|
|
44
|
-
|
|
46
|
+
...(is_token_name
|
|
47
|
+
? {
|
|
48
|
+
name: result.name,
|
|
49
|
+
}
|
|
50
|
+
: {}),
|
|
45
51
|
}
|
|
46
52
|
const token = await app.sign({
|
|
47
53
|
user: tokenResult,
|
|
@@ -192,7 +198,11 @@ exports.login = async (ctx) => {
|
|
|
192
198
|
|
|
193
199
|
const tokenResult = {
|
|
194
200
|
id: result.id,
|
|
195
|
-
|
|
201
|
+
...(is_token_name
|
|
202
|
+
? {
|
|
203
|
+
name: result.name,
|
|
204
|
+
}
|
|
205
|
+
: {}),
|
|
196
206
|
mp_user: result.mp_user
|
|
197
207
|
? {
|
|
198
208
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -315,11 +325,12 @@ exports.checkLogin = async (ctx) => {
|
|
|
315
325
|
const config = _config || 'weixin_mp'
|
|
316
326
|
const appConfig = getConfig(app)
|
|
317
327
|
if (ctx.request[`${appName}-user`] && ctx.request[`${appName}-user`].id) {
|
|
328
|
+
const { app_id: appid } = await appConfig.getObject(config)
|
|
318
329
|
const h5_user_include = config.includes('h5')
|
|
319
330
|
? {
|
|
320
331
|
model: app.model.h5_user,
|
|
321
332
|
where: {
|
|
322
|
-
appid
|
|
333
|
+
appid,
|
|
323
334
|
},
|
|
324
335
|
attributes: {
|
|
325
336
|
exclude: ['created_at', 'updated_at', 'createdid'],
|
|
@@ -332,7 +343,7 @@ exports.checkLogin = async (ctx) => {
|
|
|
332
343
|
? {
|
|
333
344
|
model: app.model.mp_user,
|
|
334
345
|
where: {
|
|
335
|
-
appid
|
|
346
|
+
appid,
|
|
336
347
|
},
|
|
337
348
|
}
|
|
338
349
|
: {
|
|
@@ -428,9 +439,15 @@ exports.checkLogin = async (ctx) => {
|
|
|
428
439
|
}
|
|
429
440
|
}
|
|
430
441
|
|
|
442
|
+
const is_token_name = app.appConfig.is_token_name
|
|
443
|
+
|
|
431
444
|
const tokenResult = {
|
|
432
445
|
id: result.id,
|
|
433
|
-
|
|
446
|
+
...(is_token_name
|
|
447
|
+
? {
|
|
448
|
+
name: result.name,
|
|
449
|
+
}
|
|
450
|
+
: {}),
|
|
434
451
|
mp_user: result.mp_user
|
|
435
452
|
? {
|
|
436
453
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -451,6 +468,7 @@ exports.checkLogin = async (ctx) => {
|
|
|
451
468
|
}
|
|
452
469
|
: {}),
|
|
453
470
|
}
|
|
471
|
+
|
|
454
472
|
const token = await app.sign({
|
|
455
473
|
user: tokenResult,
|
|
456
474
|
})
|
|
@@ -130,9 +130,15 @@ exports.mp_getPhone = async (ctx) => {
|
|
|
130
130
|
].filter((item) => item.model),
|
|
131
131
|
})
|
|
132
132
|
|
|
133
|
+
const is_token_name = app.appConfig.is_token_name
|
|
134
|
+
|
|
133
135
|
const tokenResult = {
|
|
134
136
|
id: result.id,
|
|
135
|
-
|
|
137
|
+
...(is_token_name
|
|
138
|
+
? {
|
|
139
|
+
name: result.name,
|
|
140
|
+
}
|
|
141
|
+
: {}),
|
|
136
142
|
mp_user: result.mp_user
|
|
137
143
|
? {
|
|
138
144
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -251,9 +257,15 @@ exports.mp_getPhoneNew = async (ctx) => {
|
|
|
251
257
|
].filter((item) => item.model),
|
|
252
258
|
})
|
|
253
259
|
|
|
260
|
+
const is_token_name = app.appConfig.is_token_name
|
|
261
|
+
|
|
254
262
|
const tokenResult = {
|
|
255
263
|
id: result.id,
|
|
256
|
-
|
|
264
|
+
...(is_token_name
|
|
265
|
+
? {
|
|
266
|
+
name: result.name,
|
|
267
|
+
}
|
|
268
|
+
: {}),
|
|
257
269
|
mp_user: result.mp_user
|
|
258
270
|
? {
|
|
259
271
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -492,9 +504,15 @@ exports.mp_login = async (ctx) => {
|
|
|
492
504
|
|
|
493
505
|
if (!(result && result.id)) throw new Error('登录失败')
|
|
494
506
|
|
|
507
|
+
const is_token_name = app.appConfig.is_token_name
|
|
508
|
+
|
|
495
509
|
const tokenResult = {
|
|
496
510
|
id: result.id,
|
|
497
|
-
|
|
511
|
+
...(is_token_name
|
|
512
|
+
? {
|
|
513
|
+
name: result.name,
|
|
514
|
+
}
|
|
515
|
+
: {}),
|
|
498
516
|
mp_user: result.mp_user
|
|
499
517
|
? {
|
|
500
518
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -671,9 +689,15 @@ exports.h5_login_callback = async (ctx) => {
|
|
|
671
689
|
].filter((item) => item.model),
|
|
672
690
|
})
|
|
673
691
|
|
|
692
|
+
const is_token_name = app.appConfig.is_token_name
|
|
693
|
+
|
|
674
694
|
const tokenResult = {
|
|
675
695
|
id: result.id,
|
|
676
|
-
|
|
696
|
+
...(is_token_name
|
|
697
|
+
? {
|
|
698
|
+
name: result.name,
|
|
699
|
+
}
|
|
700
|
+
: {}),
|
|
677
701
|
mp_user: result.mp_user
|
|
678
702
|
? {
|
|
679
703
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -805,9 +829,15 @@ exports.h5_login_info_callback = async (ctx) => {
|
|
|
805
829
|
].filter((item) => item.model),
|
|
806
830
|
})
|
|
807
831
|
|
|
832
|
+
const is_token_name = app.appConfig.is_token_name
|
|
833
|
+
|
|
808
834
|
const tokenResult = {
|
|
809
835
|
id: result.id,
|
|
810
|
-
|
|
836
|
+
...(is_token_name
|
|
837
|
+
? {
|
|
838
|
+
name: result.name,
|
|
839
|
+
}
|
|
840
|
+
: {}),
|
|
811
841
|
mp_user: result.mp_user
|
|
812
842
|
? {
|
|
813
843
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -2044,6 +2074,7 @@ exports.getCommentInfo = async (ctx, _data) => {
|
|
|
2044
2074
|
const {
|
|
2045
2075
|
content: {
|
|
2046
2076
|
orderInfo: { busiOrderId },
|
|
2077
|
+
content,
|
|
2047
2078
|
},
|
|
2048
2079
|
} = info
|
|
2049
2080
|
|
|
@@ -2060,6 +2091,7 @@ exports.getCommentInfo = async (ctx, _data) => {
|
|
|
2060
2091
|
const result = {
|
|
2061
2092
|
prefix,
|
|
2062
2093
|
order_id,
|
|
2094
|
+
content,
|
|
2063
2095
|
}
|
|
2064
2096
|
ctx.SUCCESS(result)
|
|
2065
2097
|
return result
|
|
@@ -65,6 +65,12 @@ const getShipTemplateUrl =
|
|
|
65
65
|
const uploadShipUrl =
|
|
66
66
|
'https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=%s'
|
|
67
67
|
|
|
68
|
+
const uploadPreShipUrl =
|
|
69
|
+
'https://api.weixin.qq.com/wxa/sec/order/opspecialorder?access_token=%s'
|
|
70
|
+
|
|
71
|
+
const getShipOrderListUrl =
|
|
72
|
+
'https://api.weixin.qq.com/wxa/sec/order/get_order_list?access_token=%s'
|
|
73
|
+
|
|
68
74
|
const setMsgJumpPathUrl =
|
|
69
75
|
'https://api.weixin.qq.com/wxa/sec/order/set_msg_jump_path?access_token=%s'
|
|
70
76
|
|
|
@@ -786,6 +792,44 @@ module.exports = class Singleton {
|
|
|
786
792
|
return result
|
|
787
793
|
}
|
|
788
794
|
|
|
795
|
+
async uploadPreShip(payLoad) {
|
|
796
|
+
const access_token = await this.getAccessToken()
|
|
797
|
+
const url = util.format(uploadPreShipUrl, access_token)
|
|
798
|
+
|
|
799
|
+
const result = await axios
|
|
800
|
+
.post(url, {
|
|
801
|
+
...payLoad,
|
|
802
|
+
})
|
|
803
|
+
.then((res) => res.data)
|
|
804
|
+
if (result.errcode) {
|
|
805
|
+
if (result.errcode === 40001) {
|
|
806
|
+
cache.reset()
|
|
807
|
+
return await this.uploadPreShip(payLoad)
|
|
808
|
+
}
|
|
809
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
810
|
+
}
|
|
811
|
+
return result
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
async getShipOrderList(payLoad) {
|
|
815
|
+
const access_token = await this.getAccessToken()
|
|
816
|
+
const url = util.format(getShipOrderListUrl, access_token)
|
|
817
|
+
|
|
818
|
+
const result = await axios
|
|
819
|
+
.post(url, {
|
|
820
|
+
...payLoad,
|
|
821
|
+
})
|
|
822
|
+
.then((res) => res.data)
|
|
823
|
+
if (result.errcode) {
|
|
824
|
+
if (result.errcode === 40001) {
|
|
825
|
+
cache.reset()
|
|
826
|
+
return await this.getShipOrderList(payLoad)
|
|
827
|
+
}
|
|
828
|
+
throw new Error(`${result.errcode};${result.errmsg}`)
|
|
829
|
+
}
|
|
830
|
+
return result
|
|
831
|
+
}
|
|
832
|
+
|
|
789
833
|
async uploadImage(payLoad) {
|
|
790
834
|
const access_token = await this.getAccessToken()
|
|
791
835
|
const { upload_type, resp_type, ...rest } = payLoad
|