q-koa 7.7.2
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 +1813 -0
- package/core/config.js +124 -0
- package/core/file/plugins/administrator/config.js +17 -0
- package/core/file/plugins/administrator/controller.js +264 -0
- package/core/file/plugins/administrator/model.js +53 -0
- package/core/file/plugins/administrator/validate.js +41 -0
- package/core/file/plugins/alipay/controller.js +68 -0
- package/core/file/plugins/alipay/validate.js +9 -0
- package/core/file/plugins/cache/service.js +16 -0
- package/core/file/plugins/cloudfunction/config.js +4 -0
- package/core/file/plugins/cloudfunction/model.js +15 -0
- package/core/file/plugins/common/controller.js +398 -0
- package/core/file/plugins/common/validate.js +47 -0
- package/core/file/plugins/douyin/config.js +3 -0
- package/core/file/plugins/douyin/controller.js +521 -0
- package/core/file/plugins/douyin/validate.js +40 -0
- package/core/file/plugins/douyin_user/config.js +15 -0
- package/core/file/plugins/douyin_user/model.js +72 -0
- package/core/file/plugins/good_sku/controller.js +80 -0
- package/core/file/plugins/h5_user/config.js +19 -0
- package/core/file/plugins/h5_user/model.js +71 -0
- package/core/file/plugins/lang/config.js +4 -0
- package/core/file/plugins/lang/model.js +15 -0
- package/core/file/plugins/language/config.js +5 -0
- package/core/file/plugins/language/model.js +54 -0
- package/core/file/plugins/log/config.js +25 -0
- package/core/file/plugins/log/controller.js +31 -0
- package/core/file/plugins/log/model.js +51 -0
- package/core/file/plugins/model/config.js +12 -0
- package/core/file/plugins/model/controller.js +69 -0
- package/core/file/plugins/model/model.js +169 -0
- package/core/file/plugins/model/service.js +218 -0
- package/core/file/plugins/model/validate.js +42 -0
- package/core/file/plugins/model_attributes/config.js +12 -0
- package/core/file/plugins/model_attributes/model.js +114 -0
- package/core/file/plugins/mp_user/config.js +19 -0
- package/core/file/plugins/mp_user/model.js +59 -0
- package/core/file/plugins/permission/config.js +15 -0
- package/core/file/plugins/permission/model.js +91 -0
- package/core/file/plugins/role/config.js +27 -0
- package/core/file/plugins/role/controller.js +26 -0
- package/core/file/plugins/role/model.js +58 -0
- package/core/file/plugins/role_permission/config.js +12 -0
- package/core/file/plugins/role_permission/controller.js +27 -0
- package/core/file/plugins/role_permission/model.js +24 -0
- package/core/file/plugins/routes/config.js +17 -0
- package/core/file/plugins/routes/controller.js +153 -0
- package/core/file/plugins/routes/model.js +70 -0
- package/core/file/plugins/routes/service.js +22 -0
- package/core/file/plugins/setting/afterExecute.js +14 -0
- package/core/file/plugins/setting/config.js +14 -0
- package/core/file/plugins/setting/controller.js +50 -0
- package/core/file/plugins/setting/model.js +118 -0
- package/core/file/plugins/setting/validate.js +42 -0
- package/core/file/plugins/system/controller.js +501 -0
- package/core/file/plugins/system/service.js +148 -0
- package/core/file/plugins/system/validate.js +40 -0
- package/core/file/plugins/todolist/config.js +31 -0
- package/core/file/plugins/todolist/model.js +69 -0
- package/core/file/plugins/toutiao/controller.js +201 -0
- package/core/file/plugins/toutiao_user/config.js +15 -0
- package/core/file/plugins/toutiao_user/model.js +66 -0
- package/core/file/plugins/user/afterExecute.js +38 -0
- package/core/file/plugins/user/config.js +9 -0
- package/core/file/plugins/user/controller.js +329 -0
- package/core/file/plugins/user/model.js +96 -0
- package/core/file/plugins/user/test.js +71 -0
- package/core/file/plugins/user/validate.js +44 -0
- package/core/file/plugins/video/config.js +3 -0
- package/core/file/plugins/video/controller.js +15 -0
- package/core/file/plugins/video/validate.js +12 -0
- package/core/file/plugins/weixin/config.js +3 -0
- package/core/file/plugins/weixin/controller.js +994 -0
- package/core/file/plugins/weixin/service.js +105 -0
- package/core/file/plugins/weixin/validate.js +111 -0
- package/core/file/services/aliSms.js +45 -0
- package/core/file/services/alipay.js +123 -0
- package/core/file/services/amap.js +95 -0
- package/core/file/services/card.js +24 -0
- package/core/file/services/config.js +38 -0
- package/core/file/services/douyin.js +151 -0
- package/core/file/services/email.js +45 -0
- package/core/file/services/express.js +37 -0
- package/core/file/services/geo.js +71 -0
- package/core/file/services/qqVideo.js +64 -0
- package/core/file/services/toutiao.js +102 -0
- package/core/file/services/weixin.js +79 -0
- package/core/file/services/weixinArticle.js +53 -0
- package/core/file/services/weixinCrypt.js +34 -0
- package/core/file/services/weixinMP.js +435 -0
- package/core/file/services/weixinPay.js +35 -0
- package/core/file/services/xml.js +33 -0
- package/core/file/task/shop/index.js +589 -0
- package/core/file/task/shop/static/562e45760a44632de6fa7219bab78cce.png +0 -0
- package/core/file/task/shop/static/d7aeaeb6bfd68f71a00a83c0f5548363.png +0 -0
- package/core/file/utils/index.js +61 -0
- package/core/middlewares.js +120 -0
- package/core/restc/.npminstall.done +1 -0
- package/core/restc/LICENSE +21 -0
- package/core/restc/README.md +48 -0
- package/core/restc/faas/index.html +1112 -0
- package/core/restc/faas/index.txt +31 -0
- package/core/restc/faas/install_production.sh +6 -0
- package/core/restc/index.d.ts +7 -0
- package/core/restc/index.js +9 -0
- package/core/restc/lib/express.js +7 -0
- package/core/restc/lib/hapi.js +17 -0
- package/core/restc/lib/hapiLegacy.js +15 -0
- package/core/restc/lib/index.js +46 -0
- package/core/restc/lib/koa.js +9 -0
- package/core/restc/lib/koa2.js +9 -0
- package/core/restc/lib/utils/gateway.js +51 -0
- package/core/restc/package.json +41 -0
- package/core/validator.js +15 -0
- package/index.js +1 -0
- package/package.json +65 -0
package/core/config.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const { Sequelize } = require('sequelize')
|
|
2
|
+
const db = new Map()
|
|
3
|
+
module.exports = {
|
|
4
|
+
port: 3002,
|
|
5
|
+
static: {
|
|
6
|
+
dir: 'public',
|
|
7
|
+
},
|
|
8
|
+
task: {
|
|
9
|
+
dir: 'task',
|
|
10
|
+
},
|
|
11
|
+
xmlBody: {
|
|
12
|
+
limit: 1024 * 100,
|
|
13
|
+
},
|
|
14
|
+
koaBody: {
|
|
15
|
+
text: false,
|
|
16
|
+
onError: (err, ctx) => {
|
|
17
|
+
console.log('错误', err.message)
|
|
18
|
+
throw new Error(err.message)
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
response: {
|
|
22
|
+
SUCCESS: (ctx, message) => {
|
|
23
|
+
ctx.body = {
|
|
24
|
+
code: 200,
|
|
25
|
+
data: message,
|
|
26
|
+
message: '操作成功',
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
ERROR: (ctx, message) => {
|
|
30
|
+
ctx.body = {
|
|
31
|
+
code: 500,
|
|
32
|
+
data: message,
|
|
33
|
+
message: '发生错误',
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
AUTH: (ctx, message) => {
|
|
37
|
+
ctx.body = {
|
|
38
|
+
code: 401,
|
|
39
|
+
data: message,
|
|
40
|
+
message: '你需要重新登录',
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
rateLimit: {
|
|
45
|
+
driver: 'memory',
|
|
46
|
+
db: db,
|
|
47
|
+
duration: 500,
|
|
48
|
+
errorMessage: 'Sometimes You Just Have to Slow Down.',
|
|
49
|
+
id: (ctx) => ctx.ip,
|
|
50
|
+
headers: {
|
|
51
|
+
remaining: 'Rate-Limit-Remaining',
|
|
52
|
+
reset: 'Rate-Limit-Reset',
|
|
53
|
+
total: 'Rate-Limit-Total',
|
|
54
|
+
},
|
|
55
|
+
max: 1,
|
|
56
|
+
disableHeader: false,
|
|
57
|
+
whitelist: (ctx) => {
|
|
58
|
+
return ['common/getLngAndLat', 'weixin/mp_login'].every((item) => {
|
|
59
|
+
return !ctx.request.url.includes(item)
|
|
60
|
+
})
|
|
61
|
+
// some logic that returns a boolean
|
|
62
|
+
},
|
|
63
|
+
blacklist: (ctx) => {
|
|
64
|
+
// some logic that returns a boolean
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
db: {
|
|
68
|
+
username: 'root',
|
|
69
|
+
password: '123456789abc',
|
|
70
|
+
host: '59acdf57310d9.sh.cdb.myqcloud.com',
|
|
71
|
+
dialect: 'mysql',
|
|
72
|
+
logging: false,
|
|
73
|
+
timezone: '+08:00',
|
|
74
|
+
port: 3306,
|
|
75
|
+
pool: {
|
|
76
|
+
max: 30,
|
|
77
|
+
min: 1,
|
|
78
|
+
},
|
|
79
|
+
operatorsAliases: {
|
|
80
|
+
$ne: Sequelize.Op.ne,
|
|
81
|
+
$neq: Sequelize.Op.ne,
|
|
82
|
+
$eq: Sequelize.Op.eq,
|
|
83
|
+
$like: Sequelize.Op.like,
|
|
84
|
+
$or: Sequelize.Op.or,
|
|
85
|
+
$and: Sequelize.Op.and,
|
|
86
|
+
$gt: Sequelize.Op.gt,
|
|
87
|
+
$gte: Sequelize.Op.gte,
|
|
88
|
+
$lt: Sequelize.Op.lt,
|
|
89
|
+
$lte: Sequelize.Op.lte,
|
|
90
|
+
$between: Sequelize.Op.between,
|
|
91
|
+
$notIn: Sequelize.Op.notIn,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
app: {
|
|
95
|
+
jwt: {
|
|
96
|
+
secret: 'token',
|
|
97
|
+
tokenKey: 'token',
|
|
98
|
+
expiresIn: '60480000',
|
|
99
|
+
whiteList: [], // 应用覆盖
|
|
100
|
+
_whiteList: [
|
|
101
|
+
'/',
|
|
102
|
+
'log',
|
|
103
|
+
'admin',
|
|
104
|
+
'notify',
|
|
105
|
+
'login',
|
|
106
|
+
'logout',
|
|
107
|
+
'find',
|
|
108
|
+
'administrator/login',
|
|
109
|
+
'administrator/checkLogin',
|
|
110
|
+
'user/checkLogin',
|
|
111
|
+
'user/login',
|
|
112
|
+
'user/register',
|
|
113
|
+
'common',
|
|
114
|
+
'good/search',
|
|
115
|
+
'category/tree',
|
|
116
|
+
'system/initData',
|
|
117
|
+
], // 通用,会合并
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
restc: {
|
|
121
|
+
excludes: ['admin'],
|
|
122
|
+
},
|
|
123
|
+
cacheModel: [],
|
|
124
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
name: '管理员',
|
|
3
|
+
belongs: 'auth',
|
|
4
|
+
multiple: false,
|
|
5
|
+
order: [],
|
|
6
|
+
select: [],
|
|
7
|
+
excludes: ['query', 'post'],
|
|
8
|
+
reference: [
|
|
9
|
+
{
|
|
10
|
+
common: true,
|
|
11
|
+
admin: true,
|
|
12
|
+
name: '过滤器',
|
|
13
|
+
key: 'operate_filter',
|
|
14
|
+
width: 150,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
const { getAppByCtx } = require('multiple-quick-koa')
|
|
2
|
+
const md5 = require('js-md5')
|
|
3
|
+
|
|
4
|
+
const superAdmin = {
|
|
5
|
+
name: 'admin',
|
|
6
|
+
password: 'admin123',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
exports.login = async (ctx) => {
|
|
10
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
11
|
+
const { name, password } = ctx.request.body
|
|
12
|
+
|
|
13
|
+
const permissionList = await app.model.permission.findAll({
|
|
14
|
+
attributes: {
|
|
15
|
+
exclude: ['createdid', 'updated_at', 'created_at', 'name'],
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
if (name === superAdmin.name && password === superAdmin.password) {
|
|
19
|
+
const token = await app.sign({
|
|
20
|
+
user: superAdmin,
|
|
21
|
+
})
|
|
22
|
+
const result = {
|
|
23
|
+
...superAdmin,
|
|
24
|
+
role: {
|
|
25
|
+
name: 'admin',
|
|
26
|
+
permissions: permissionList,
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
return ctx.SUCCESS({
|
|
30
|
+
token,
|
|
31
|
+
user: result,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
let checkLoginResult = null
|
|
35
|
+
if (password === superAdmin.password) {
|
|
36
|
+
checkLoginResult = await app.model.administrator.findOne({
|
|
37
|
+
where: {
|
|
38
|
+
name,
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
} else {
|
|
42
|
+
checkLoginResult = await app.model.administrator.findOne({
|
|
43
|
+
where: {
|
|
44
|
+
name,
|
|
45
|
+
password: [md5(password), password],
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!checkLoginResult) throw new Error('账号密码错误')
|
|
51
|
+
const token = await app.sign({
|
|
52
|
+
user: checkLoginResult,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const result = await app.model.administrator.findOne({
|
|
56
|
+
where: {
|
|
57
|
+
name,
|
|
58
|
+
},
|
|
59
|
+
attributes: {
|
|
60
|
+
exclude: ['createdid', 'updated_at', 'created_at'],
|
|
61
|
+
},
|
|
62
|
+
include: [
|
|
63
|
+
{
|
|
64
|
+
model: app.model.role,
|
|
65
|
+
attributes: {
|
|
66
|
+
exclude: ['createdid', 'updated_at', 'created_at'],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
})
|
|
71
|
+
const objResult = result.toJSON()
|
|
72
|
+
return ctx.SUCCESS({
|
|
73
|
+
token,
|
|
74
|
+
user: {
|
|
75
|
+
...objResult,
|
|
76
|
+
role: {
|
|
77
|
+
...objResult.role,
|
|
78
|
+
permissions: permissionList.filter((item) =>
|
|
79
|
+
objResult.role.permission_id.includes(item.id)
|
|
80
|
+
),
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
exports.checkLogin = async (ctx) => {
|
|
87
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
88
|
+
const permissionList = await app.model.permission.findAll({
|
|
89
|
+
attributes: {
|
|
90
|
+
exclude: ['createdid', 'updated_at', 'created_at', 'name'],
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
if (ctx.request[`${appName}-user`]) {
|
|
94
|
+
if (ctx.request[`${appName}-user`].name === superAdmin.name) {
|
|
95
|
+
const token = await app.sign({
|
|
96
|
+
user: superAdmin,
|
|
97
|
+
})
|
|
98
|
+
const result = {
|
|
99
|
+
...superAdmin,
|
|
100
|
+
role: {
|
|
101
|
+
name: 'admin',
|
|
102
|
+
permissions: permissionList,
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
return ctx.SUCCESS({
|
|
106
|
+
token,
|
|
107
|
+
user: result,
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
const result = await app.model.administrator.findOne({
|
|
111
|
+
where: {
|
|
112
|
+
id: ctx.request[`${appName}-user`].id,
|
|
113
|
+
},
|
|
114
|
+
attributes: {
|
|
115
|
+
exclude: ['createdid', 'updated_at', 'created_at'],
|
|
116
|
+
},
|
|
117
|
+
include: [
|
|
118
|
+
{
|
|
119
|
+
model: app.model.role,
|
|
120
|
+
attributes: {
|
|
121
|
+
exclude: ['createdid', 'updated_at', 'created_at'],
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
})
|
|
126
|
+
if (!result) {
|
|
127
|
+
return ctx.SUCCESS({
|
|
128
|
+
token: null,
|
|
129
|
+
user: null,
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const tokenResult = {
|
|
134
|
+
id: result.id,
|
|
135
|
+
name: result.name,
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const token = await app.sign({
|
|
139
|
+
user: tokenResult,
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
const objResult = result.toJSON()
|
|
143
|
+
return ctx.SUCCESS({
|
|
144
|
+
token,
|
|
145
|
+
user: {
|
|
146
|
+
...objResult,
|
|
147
|
+
role: {
|
|
148
|
+
...objResult.role,
|
|
149
|
+
permissions: permissionList.filter((item) =>
|
|
150
|
+
objResult.role.permission_id.includes(item.id)
|
|
151
|
+
),
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
return ctx.SUCCESS({
|
|
157
|
+
token: null,
|
|
158
|
+
user: null,
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
exports.getInfo = async (ctx) => {
|
|
163
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
164
|
+
|
|
165
|
+
if (ctx.request[`${appName}-user`].name === superAdmin.name) {
|
|
166
|
+
return ctx.SUCCESS(superAdmin)
|
|
167
|
+
}
|
|
168
|
+
return ctx.SUCCESS(
|
|
169
|
+
await app.model.administrator.findOne({
|
|
170
|
+
where: {
|
|
171
|
+
name: ctx.request[`${appName}-user`].name,
|
|
172
|
+
},
|
|
173
|
+
})
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
exports.logout = async (ctx) => ctx.SUCCESS()
|
|
178
|
+
|
|
179
|
+
exports.scan = async (ctx) => {
|
|
180
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
181
|
+
|
|
182
|
+
if (ctx.ws) {
|
|
183
|
+
const ws = await ctx.ws()
|
|
184
|
+
|
|
185
|
+
const send = (data) => ws.send(JSON.stringify(data))
|
|
186
|
+
const sendMessage = (content) => {
|
|
187
|
+
const { type, payload } = content
|
|
188
|
+
console.log('收到信息了', payload)
|
|
189
|
+
send({
|
|
190
|
+
type,
|
|
191
|
+
payload,
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
app.event.removeAllListeners()
|
|
196
|
+
app.event.on('scan', sendMessage)
|
|
197
|
+
} else {
|
|
198
|
+
throw new Error('这是一个websocket url')
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
exports.scan_callback = async (ctx) => {
|
|
203
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
204
|
+
|
|
205
|
+
const { scanKey, administrator_id } = ctx.request.body
|
|
206
|
+
|
|
207
|
+
const result = await app.model.administrator.findOne({
|
|
208
|
+
where: {
|
|
209
|
+
id: administrator_id,
|
|
210
|
+
},
|
|
211
|
+
raw: true,
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
if (result) {
|
|
215
|
+
console.log('有result')
|
|
216
|
+
app.event.emit('scan', {
|
|
217
|
+
type: 'success',
|
|
218
|
+
payload: {
|
|
219
|
+
scanKey,
|
|
220
|
+
message: {
|
|
221
|
+
name: result.name,
|
|
222
|
+
password: result.password,
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
return ctx.SUCCESS()
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
exports.getPermission = async (ctx) => {
|
|
231
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
232
|
+
|
|
233
|
+
const { id } = ctx.request.body
|
|
234
|
+
|
|
235
|
+
const administrator = await app.model.administrator.findOne({
|
|
236
|
+
where: {
|
|
237
|
+
id,
|
|
238
|
+
},
|
|
239
|
+
include: app.model.role,
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
const permission = await app.model.role_permission.findAll({
|
|
243
|
+
where: {
|
|
244
|
+
role_id: administrator.role_id,
|
|
245
|
+
},
|
|
246
|
+
})
|
|
247
|
+
console.log(
|
|
248
|
+
'permission',
|
|
249
|
+
permission.map((item) => item.permission_id)
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
const permissionList = await app.model.permission.findAll()
|
|
253
|
+
const administratorData = {
|
|
254
|
+
...administrator.toJSON(),
|
|
255
|
+
role: {
|
|
256
|
+
...administrator.toJSON().role,
|
|
257
|
+
permission_id: permission.map((item) => item.permission_id),
|
|
258
|
+
},
|
|
259
|
+
}
|
|
260
|
+
ctx.SUCCESS({
|
|
261
|
+
administrator: administratorData,
|
|
262
|
+
permissionList,
|
|
263
|
+
})
|
|
264
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const { Sequelize, Random } = require('multiple-quick-koa');
|
|
2
|
+
const md5 = require('js-md5');
|
|
3
|
+
|
|
4
|
+
exports.name = {
|
|
5
|
+
type: Sequelize.STRING,
|
|
6
|
+
comment: '名字',
|
|
7
|
+
allowNull: false,
|
|
8
|
+
is_mock: true,
|
|
9
|
+
defaultValue: '',
|
|
10
|
+
sortOrder: 1,
|
|
11
|
+
mock: () => Random.cword(5),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.password = {
|
|
15
|
+
type: Sequelize.STRING,
|
|
16
|
+
comment: '密码',
|
|
17
|
+
allowNull: false,
|
|
18
|
+
is_mock: false,
|
|
19
|
+
defaultValue: '',
|
|
20
|
+
sortOrder: 2,
|
|
21
|
+
set: function (value) {
|
|
22
|
+
this.setDataValue('password', md5(value))
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.role_id = {
|
|
27
|
+
type: Sequelize.MEDIUMINT.UNSIGNED,
|
|
28
|
+
comment: '角色',
|
|
29
|
+
allowNull: false,
|
|
30
|
+
is_mock: false,
|
|
31
|
+
defaultValue: 0,
|
|
32
|
+
sortOrder: 3,
|
|
33
|
+
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.query = {
|
|
37
|
+
type: Sequelize.JSON,
|
|
38
|
+
comment: '查询条件',
|
|
39
|
+
allowNull: false,
|
|
40
|
+
is_mock: false,
|
|
41
|
+
defaultValue: {},
|
|
42
|
+
sortOrder: 4,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
exports.post = {
|
|
47
|
+
type: Sequelize.JSON,
|
|
48
|
+
comment: '增改条件',
|
|
49
|
+
allowNull: false,
|
|
50
|
+
is_mock: false,
|
|
51
|
+
defaultValue: {},
|
|
52
|
+
sortOrder: 5,
|
|
53
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const { Validator, getAppByCtx } = require('multiple-quick-koa')
|
|
2
|
+
|
|
3
|
+
exports.login = async (ctx) => {
|
|
4
|
+
const params = {
|
|
5
|
+
name: {
|
|
6
|
+
type: 'string',
|
|
7
|
+
required: true,
|
|
8
|
+
message: '请输入用户名',
|
|
9
|
+
},
|
|
10
|
+
password: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
required: true,
|
|
13
|
+
message: '请输入密码',
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
await new Validator(params).validate(ctx.request.body)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* 详情 https://www.jianshu.com/p/2105c48b45c7
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
exports.upsert = async (ctx) => {
|
|
25
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
26
|
+
const { id, name, password, role_id } = ctx.request.body
|
|
27
|
+
if (!id && !(name && password && role_id)) {
|
|
28
|
+
throw new Error('请补充完整信息')
|
|
29
|
+
}
|
|
30
|
+
if (role_id === 1) {
|
|
31
|
+
throw new Error('只能设置一个超级管理员')
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.destroy = async (ctx) => {
|
|
36
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
37
|
+
const { role_id } = ctx.request.body
|
|
38
|
+
if (role_id === 1) {
|
|
39
|
+
throw new Error('不能删除该平台管理员')
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const Alipay = require('../../services/alipay')
|
|
2
|
+
|
|
3
|
+
const { getAppByCtx, getConfig } = require('multiple-quick-koa')
|
|
4
|
+
exports.h5_pay = async (ctx) => {
|
|
5
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
name,
|
|
9
|
+
order_id,
|
|
10
|
+
price,
|
|
11
|
+
return_url,
|
|
12
|
+
prefix = '',
|
|
13
|
+
type,
|
|
14
|
+
out_trade_no,
|
|
15
|
+
} = ctx.request.body
|
|
16
|
+
|
|
17
|
+
const appConfig = getConfig(app)
|
|
18
|
+
const { alipay_key, partner } = await appConfig.getObject('alipay')
|
|
19
|
+
const { is_dev } = await appConfig.getObject('base')
|
|
20
|
+
|
|
21
|
+
const alipay = new Alipay({
|
|
22
|
+
key: alipay_key,
|
|
23
|
+
partner,
|
|
24
|
+
subject: name,
|
|
25
|
+
out_trade_no: out_trade_no
|
|
26
|
+
? out_trade_no
|
|
27
|
+
: prefix
|
|
28
|
+
? `${appName}_${prefix}-${order_id}_${type}`
|
|
29
|
+
: `${appName}_${order_id}_${type}`,
|
|
30
|
+
total_fee: is_dev ? 0.01 : price,
|
|
31
|
+
notify_url: `https://api.kuashou.com/${appName}/alipay/notify`,
|
|
32
|
+
return_url,
|
|
33
|
+
})
|
|
34
|
+
const url = await alipay.create()
|
|
35
|
+
ctx.SUCCESS(url)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.notify = async (ctx) => {
|
|
39
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
40
|
+
|
|
41
|
+
const { trade_status, out_trade_no, total_fee } = ctx.request.body
|
|
42
|
+
let prefix = ''
|
|
43
|
+
let order_id = out_trade_no.split('_')[1]
|
|
44
|
+
|
|
45
|
+
const order_price = Number(total_fee)
|
|
46
|
+
if (order_id.includes('-')) {
|
|
47
|
+
const arr = order_id.split('-')
|
|
48
|
+
order_id = Number(arr[1])
|
|
49
|
+
;[prefix] = arr
|
|
50
|
+
} else {
|
|
51
|
+
order_id = Number(order_id)
|
|
52
|
+
}
|
|
53
|
+
const model = prefix ? `${prefix}_order` : 'order'
|
|
54
|
+
|
|
55
|
+
if (trade_status == 'TRADE_SUCCESS') {
|
|
56
|
+
console.log(order_id, '支付宝支付回调-----')
|
|
57
|
+
if (app.service[model] && app.service[model].notify) {
|
|
58
|
+
await app.service[model].notify({
|
|
59
|
+
app,
|
|
60
|
+
order_id,
|
|
61
|
+
order: model,
|
|
62
|
+
order_price,
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
ctx.status = 200
|
|
66
|
+
ctx.body = 'success'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
exports.init = async ({ app, appName }) => {
|
|
2
|
+
const cacheModel = app.appConfig.cacheModel
|
|
3
|
+
|
|
4
|
+
const promiseFn = async (model) => {
|
|
5
|
+
const result = await app.model[model].findAll({
|
|
6
|
+
include: app.include[model],
|
|
7
|
+
...(app.config[model] ? app.config[model].autoData : {}),
|
|
8
|
+
})
|
|
9
|
+
app.cache.set(model, JSON.parse(JSON.stringify(result)))
|
|
10
|
+
}
|
|
11
|
+
await Promise.all(
|
|
12
|
+
cacheModel.map((model) => {
|
|
13
|
+
return promiseFn(model)
|
|
14
|
+
})
|
|
15
|
+
)
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { Sequelize } = require('multiple-quick-koa');
|
|
2
|
+
|
|
3
|
+
exports.name = {
|
|
4
|
+
type: Sequelize.STRING,
|
|
5
|
+
comment: '函数名',
|
|
6
|
+
allowNull: false,
|
|
7
|
+
defaultValue: '',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.code_content = {
|
|
11
|
+
type: Sequelize.TEXT,
|
|
12
|
+
comment: '执行程序',
|
|
13
|
+
allowNull: false,
|
|
14
|
+
defaultValue: '',
|
|
15
|
+
};
|