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.
Files changed (116) hide show
  1. package/core/app.js +1813 -0
  2. package/core/config.js +124 -0
  3. package/core/file/plugins/administrator/config.js +17 -0
  4. package/core/file/plugins/administrator/controller.js +264 -0
  5. package/core/file/plugins/administrator/model.js +53 -0
  6. package/core/file/plugins/administrator/validate.js +41 -0
  7. package/core/file/plugins/alipay/controller.js +68 -0
  8. package/core/file/plugins/alipay/validate.js +9 -0
  9. package/core/file/plugins/cache/service.js +16 -0
  10. package/core/file/plugins/cloudfunction/config.js +4 -0
  11. package/core/file/plugins/cloudfunction/model.js +15 -0
  12. package/core/file/plugins/common/controller.js +398 -0
  13. package/core/file/plugins/common/validate.js +47 -0
  14. package/core/file/plugins/douyin/config.js +3 -0
  15. package/core/file/plugins/douyin/controller.js +521 -0
  16. package/core/file/plugins/douyin/validate.js +40 -0
  17. package/core/file/plugins/douyin_user/config.js +15 -0
  18. package/core/file/plugins/douyin_user/model.js +72 -0
  19. package/core/file/plugins/good_sku/controller.js +80 -0
  20. package/core/file/plugins/h5_user/config.js +19 -0
  21. package/core/file/plugins/h5_user/model.js +71 -0
  22. package/core/file/plugins/lang/config.js +4 -0
  23. package/core/file/plugins/lang/model.js +15 -0
  24. package/core/file/plugins/language/config.js +5 -0
  25. package/core/file/plugins/language/model.js +54 -0
  26. package/core/file/plugins/log/config.js +25 -0
  27. package/core/file/plugins/log/controller.js +31 -0
  28. package/core/file/plugins/log/model.js +51 -0
  29. package/core/file/plugins/model/config.js +12 -0
  30. package/core/file/plugins/model/controller.js +69 -0
  31. package/core/file/plugins/model/model.js +169 -0
  32. package/core/file/plugins/model/service.js +218 -0
  33. package/core/file/plugins/model/validate.js +42 -0
  34. package/core/file/plugins/model_attributes/config.js +12 -0
  35. package/core/file/plugins/model_attributes/model.js +114 -0
  36. package/core/file/plugins/mp_user/config.js +19 -0
  37. package/core/file/plugins/mp_user/model.js +59 -0
  38. package/core/file/plugins/permission/config.js +15 -0
  39. package/core/file/plugins/permission/model.js +91 -0
  40. package/core/file/plugins/role/config.js +27 -0
  41. package/core/file/plugins/role/controller.js +26 -0
  42. package/core/file/plugins/role/model.js +58 -0
  43. package/core/file/plugins/role_permission/config.js +12 -0
  44. package/core/file/plugins/role_permission/controller.js +27 -0
  45. package/core/file/plugins/role_permission/model.js +24 -0
  46. package/core/file/plugins/routes/config.js +17 -0
  47. package/core/file/plugins/routes/controller.js +153 -0
  48. package/core/file/plugins/routes/model.js +70 -0
  49. package/core/file/plugins/routes/service.js +22 -0
  50. package/core/file/plugins/setting/afterExecute.js +14 -0
  51. package/core/file/plugins/setting/config.js +14 -0
  52. package/core/file/plugins/setting/controller.js +50 -0
  53. package/core/file/plugins/setting/model.js +118 -0
  54. package/core/file/plugins/setting/validate.js +42 -0
  55. package/core/file/plugins/system/controller.js +501 -0
  56. package/core/file/plugins/system/service.js +148 -0
  57. package/core/file/plugins/system/validate.js +40 -0
  58. package/core/file/plugins/todolist/config.js +31 -0
  59. package/core/file/plugins/todolist/model.js +69 -0
  60. package/core/file/plugins/toutiao/controller.js +201 -0
  61. package/core/file/plugins/toutiao_user/config.js +15 -0
  62. package/core/file/plugins/toutiao_user/model.js +66 -0
  63. package/core/file/plugins/user/afterExecute.js +38 -0
  64. package/core/file/plugins/user/config.js +9 -0
  65. package/core/file/plugins/user/controller.js +329 -0
  66. package/core/file/plugins/user/model.js +96 -0
  67. package/core/file/plugins/user/test.js +71 -0
  68. package/core/file/plugins/user/validate.js +44 -0
  69. package/core/file/plugins/video/config.js +3 -0
  70. package/core/file/plugins/video/controller.js +15 -0
  71. package/core/file/plugins/video/validate.js +12 -0
  72. package/core/file/plugins/weixin/config.js +3 -0
  73. package/core/file/plugins/weixin/controller.js +994 -0
  74. package/core/file/plugins/weixin/service.js +105 -0
  75. package/core/file/plugins/weixin/validate.js +111 -0
  76. package/core/file/services/aliSms.js +45 -0
  77. package/core/file/services/alipay.js +123 -0
  78. package/core/file/services/amap.js +95 -0
  79. package/core/file/services/card.js +24 -0
  80. package/core/file/services/config.js +38 -0
  81. package/core/file/services/douyin.js +151 -0
  82. package/core/file/services/email.js +45 -0
  83. package/core/file/services/express.js +37 -0
  84. package/core/file/services/geo.js +71 -0
  85. package/core/file/services/qqVideo.js +64 -0
  86. package/core/file/services/toutiao.js +102 -0
  87. package/core/file/services/weixin.js +79 -0
  88. package/core/file/services/weixinArticle.js +53 -0
  89. package/core/file/services/weixinCrypt.js +34 -0
  90. package/core/file/services/weixinMP.js +435 -0
  91. package/core/file/services/weixinPay.js +35 -0
  92. package/core/file/services/xml.js +33 -0
  93. package/core/file/task/shop/index.js +589 -0
  94. package/core/file/task/shop/static/562e45760a44632de6fa7219bab78cce.png +0 -0
  95. package/core/file/task/shop/static/d7aeaeb6bfd68f71a00a83c0f5548363.png +0 -0
  96. package/core/file/utils/index.js +61 -0
  97. package/core/middlewares.js +120 -0
  98. package/core/restc/.npminstall.done +1 -0
  99. package/core/restc/LICENSE +21 -0
  100. package/core/restc/README.md +48 -0
  101. package/core/restc/faas/index.html +1112 -0
  102. package/core/restc/faas/index.txt +31 -0
  103. package/core/restc/faas/install_production.sh +6 -0
  104. package/core/restc/index.d.ts +7 -0
  105. package/core/restc/index.js +9 -0
  106. package/core/restc/lib/express.js +7 -0
  107. package/core/restc/lib/hapi.js +17 -0
  108. package/core/restc/lib/hapiLegacy.js +15 -0
  109. package/core/restc/lib/index.js +46 -0
  110. package/core/restc/lib/koa.js +9 -0
  111. package/core/restc/lib/koa2.js +9 -0
  112. package/core/restc/lib/utils/gateway.js +51 -0
  113. package/core/restc/package.json +41 -0
  114. package/core/validator.js +15 -0
  115. package/index.js +1 -0
  116. package/package.json +65 -0
@@ -0,0 +1,69 @@
1
+ const { Sequelize, Random } = require('multiple-quick-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.desc = {
14
+ type: Sequelize.TEXT,
15
+ comment: '详细描述',
16
+ allowNull: false,
17
+ is_mock: true,
18
+ defaultValue: '',
19
+ sortOrder: 2,
20
+ mock: () => Random.csentence(),
21
+ }
22
+
23
+ exports.image_list = {
24
+ type: Sequelize.JSON,
25
+ comment: '相关图片',
26
+ allowNull: false,
27
+ is_mock: true,
28
+ defaultValue: [],
29
+ sortOrder: 3,
30
+ mock: () =>
31
+ Random.range(5).map((item, index) =>
32
+ Random.image('200x200', Random.color(), Random.cword())
33
+ ),
34
+ extra: {
35
+ tableWidth: 0,
36
+ },
37
+ }
38
+
39
+ exports.status = {
40
+ type: Sequelize.ENUM('待定', '待完成', '已完成'),
41
+ comment: '状态',
42
+ allowNull: false,
43
+ is_mock: true,
44
+ defaultValue: '待定',
45
+ sortOrder: 4,
46
+ mock: () => ['待定', '待完成', '已完成'][Random.integer(0, 2)],
47
+ }
48
+
49
+ exports.type = {
50
+ type: Sequelize.ENUM('需求', 'bug'),
51
+ comment: '类型',
52
+ allowNull: false,
53
+ is_mock: true,
54
+ defaultValue: '需求',
55
+ sortOrder: 5,
56
+ mock: () => ['需求', 'bug'][Random.integer(0, 1)],
57
+ }
58
+
59
+ exports.important_rate = {
60
+ type: Sequelize.TINYINT,
61
+ comment: '重要级',
62
+ allowNull: false,
63
+ is_mock: false,
64
+ defaultValue: 0,
65
+ sortOrder: 6,
66
+ extra: {
67
+ tableWidth: 180,
68
+ },
69
+ }
@@ -0,0 +1,201 @@
1
+ const {
2
+ getAppByCtx,
3
+ getConfig,
4
+ getService,
5
+ lodash,
6
+ } = require('multiple-quick-koa')
7
+
8
+ const util = require('util')
9
+ const axios = require('axios')
10
+ const qr = require('qr-image')
11
+ const path = require('path')
12
+ const TOUTIAO = getService('toutiao')
13
+
14
+ const utils = require('../../utils')
15
+
16
+ exports.initData = async (ctx) => {
17
+ const { app, appName } = getAppByCtx(ctx)
18
+ if (app.cache.get('initData')) {
19
+ return ctx.SUCCESS(app.cache.get('initData'))
20
+ } else {
21
+ return ctx.SUCCESS(null)
22
+ }
23
+ }
24
+ exports.qr_code = async (ctx) => {
25
+ const { app } = getAppByCtx(ctx)
26
+ const { page = 'pages/index/index', type = 'douyin', item } = ctx.request.body
27
+
28
+ const appConfig = getConfig(app)
29
+ // const { app_id, app_secrect } = await appConfig.getObject('toutiao')
30
+
31
+ const { site_host } = await appConfig.getObject('base')
32
+
33
+ const toutiaoService = new TOUTIAO({
34
+ appid: item.appid,
35
+ secrect: item.secrect,
36
+ targetPath: `${path.resolve(__dirname, `${process.cwd()}/public/upload`)}`,
37
+ })
38
+
39
+ toutiaoService.init()
40
+
41
+ const result = await toutiaoService.createQR({
42
+ path: encodeURIComponent(page),
43
+ appname: type,
44
+ filename: utils.hashFn(item.key + page + type),
45
+ })
46
+ console.log(`qr,${item.key},${page},${type}`)
47
+ const qr_image = `https://${site_host || 'api.kuashou.com'}/upload/${result}`
48
+
49
+ // const qr_image = `http://localhost:3001/upload/${result}`;
50
+ // await app.model.user.upsert({
51
+ // id: lodash.get(ctx.request, `${appName}-user.id`, null),
52
+ // qr_image
53
+ // })
54
+
55
+ ctx.SUCCESS(qr_image)
56
+ }
57
+
58
+ exports.getCode = async (ctx) => {
59
+ const { app, appName } = getAppByCtx(ctx)
60
+
61
+ // let url = req.query.url
62
+ // let img = qr.image(url, { size: 10 })
63
+ // res.writeHead(200, {
64
+ // 'Content-Type': 'image/png'
65
+ // })
66
+ // img.pipe(res)
67
+
68
+ const appConfig = getConfig(app)
69
+ const { app_id, app_secrect } = await appConfig.getObject('toutiao')
70
+
71
+ const url =
72
+ 'https://open.douyin.com/platform/oauth/connect?client_key=awbzmjjjcusg3hg1&redirect_uri=http://wxdy.592web.com/douyin/auth_redirect&response_type=code&scope=aweme.share,user_info,fans.data,renew_refresh_token,micapp.is_legal,following.list,video.comment,im&state=1613f649-7e6c-4d86-945b-eea62ea00b09'
73
+
74
+ // const result = await axios.get(url, {
75
+ // client_key: app_id,
76
+ // }).then(res => res.data)
77
+
78
+ const img = qr.image(url, {
79
+ size: 10,
80
+ })
81
+ ctx.type = 'image/png'
82
+ ctx.body = img
83
+
84
+ // ctx.SUCCESS(result)
85
+ }
86
+
87
+ exports.login = async (ctx) => {
88
+ const { app, appName } = getAppByCtx(ctx)
89
+
90
+ const { code, anonymousCode, ...rest } = ctx.request.body
91
+
92
+ const appConfig = getConfig(app)
93
+ const { app_id, app_secrect } = await appConfig.getObject('toutiao')
94
+
95
+ const loginUrl =
96
+ 'https://developer.toutiao.com/api/apps/jscode2session?appid=%s&secret=%s&code=%s&anonymous_code=%s'
97
+
98
+ const url = util.format(loginUrl, app_id, app_secrect, code, anonymousCode)
99
+
100
+ const res = await axios.get(url).then((res) => res.data)
101
+
102
+ const { openid } = res
103
+
104
+ if (!openid) {
105
+ const msg = `找不到openid, errcode:${res.errcode} app_id:${app_id} app_secrect:${app_secrect}`
106
+ console.log(msg)
107
+ throw new Error('头条登录失败')
108
+ }
109
+
110
+ const post = lodash.pickBy(
111
+ {
112
+ nick_name: lodash.get(rest, 'nickName', null),
113
+ avatar: lodash.get(rest, 'avatarUrl', null),
114
+ country: lodash.get(rest, 'country', null),
115
+ city: lodash.get(rest, 'city', null),
116
+ province: lodash.get(rest, 'province', null),
117
+ gender: lodash.get(rest, 'gender', null),
118
+ openid,
119
+ user_id: lodash.get(ctx.request, `${appName}-user.id`, null),
120
+ },
121
+ (item) => item !== null
122
+ )
123
+
124
+ const openIdUser = await app.model.toutiao_user.findOne({
125
+ where: {
126
+ openid: post.openid,
127
+ },
128
+ })
129
+
130
+ let uid
131
+ if (openIdUser) {
132
+ await app.model.toutiao_user.update(post, {
133
+ where: {
134
+ openid: post.openid,
135
+ },
136
+ })
137
+ uid = openIdUser.user_id
138
+ } else {
139
+ if (post.user_id) {
140
+ uid = post.user_id
141
+ } else {
142
+ const user = await app.model.user.create()
143
+ uid = user.id
144
+ }
145
+
146
+ await app.model.toutiao_user.create({
147
+ ...post,
148
+ user_id: uid,
149
+ })
150
+ }
151
+
152
+ const result = await app.model.user.findOne({
153
+ where: {
154
+ id: uid,
155
+ },
156
+ include: [
157
+ {
158
+ model: app.model.h5_user,
159
+ },
160
+ {
161
+ model: app.model.mp_user,
162
+ },
163
+ {
164
+ model: app.model.toutiao_user,
165
+ },
166
+ ...app.include.user,
167
+ ],
168
+ })
169
+
170
+ console.log('result', result, app.include.user)
171
+
172
+ const tokenResult = {
173
+ id: result.id,
174
+ name: result.name,
175
+ mobile: result.mobile,
176
+ h5_user: result.h5_user
177
+ ? {
178
+ openid: result.h5_user && result.h5_user.openid,
179
+ }
180
+ : null,
181
+ mp_user: result.mp_user
182
+ ? {
183
+ openid: result.mp_user && result.mp_user.openid,
184
+ }
185
+ : null,
186
+ toutiao_user: result.toutiao_user
187
+ ? {
188
+ openid: result.toutiao_user && result.toutiao_user.openid,
189
+ }
190
+ : null,
191
+ }
192
+
193
+ const token = await app.sign({
194
+ user: tokenResult,
195
+ })
196
+
197
+ return ctx.SUCCESS({
198
+ token,
199
+ user: result,
200
+ })
201
+ }
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ name: '头条小程序用户',
3
+ belongs: 'page',
4
+ multiple: false,
5
+ availableSort: false,
6
+ order: ["created_at"],
7
+ select: [{"key":"user_id"},{"key":"nick_name"}],
8
+ excludes: [],
9
+ limit: 20,
10
+ defaultOrder: [{ sort: 'descending', type: 'id' }],
11
+ comment: {"created_at":"创建时间"},
12
+ sortOrder: 1,
13
+ reference: [],
14
+ excludeAuth: [],
15
+ }
@@ -0,0 +1,66 @@
1
+ const { Sequelize } = require('multiple-quick-koa')
2
+
3
+ exports.openid = {
4
+ type: Sequelize.STRING,
5
+ comment: 'openid',
6
+ allowNull: false,
7
+ unique: true,
8
+ }
9
+
10
+ exports.nick_name = {
11
+ type: Sequelize.STRING,
12
+ comment: '昵称',
13
+ allowNull: false,
14
+ defaultValue: '',
15
+ }
16
+
17
+ exports.gender = {
18
+ type: Sequelize.INTEGER(11),
19
+ allowNull: false,
20
+ defaultValue: 1,
21
+ comment: '性别',
22
+ }
23
+
24
+ exports.city = {
25
+ type: Sequelize.STRING,
26
+ comment: '城市',
27
+ allowNull: false,
28
+ defaultValue: '',
29
+ }
30
+
31
+ exports.province = {
32
+ type: Sequelize.STRING,
33
+ comment: '省份',
34
+ allowNull: false,
35
+ defaultValue: '',
36
+ }
37
+
38
+ exports.country = {
39
+ type: Sequelize.STRING,
40
+ comment: '国家',
41
+ allowNull: false,
42
+ defaultValue: '',
43
+ }
44
+
45
+ exports.avatar = {
46
+ type: Sequelize.STRING(1000),
47
+ comment: '头像',
48
+ allowNull: false,
49
+ defaultValue: '',
50
+ }
51
+
52
+ exports.name = {
53
+ type: Sequelize.VIRTUAL,
54
+ comment: '名字',
55
+ get: function () {
56
+ return this.getDataValue('nick_name')
57
+ },
58
+ }
59
+
60
+ exports.user_id = {
61
+ type: Sequelize.INTEGER(11),
62
+ allowNull: false,
63
+ defaultValue: 0,
64
+ comment: '用户',
65
+ hasOne: true,
66
+ }
@@ -0,0 +1,38 @@
1
+ const {
2
+ getAppByCtx,
3
+ getConfig,
4
+ } = require('multiple-quick-koa');
5
+
6
+ exports.destroy = async (ctx) => {
7
+ const {
8
+ app,
9
+ } = getAppByCtx(ctx);
10
+
11
+ const {
12
+ id,
13
+ } = ctx.request.body;
14
+
15
+ app.model.mp_user && app.model.mp_user.destroy({
16
+ where: {
17
+ user_id: id,
18
+ },
19
+ }).then(() => {
20
+ console.log(`删除${id}`);
21
+ }).catch(console.log);
22
+
23
+ app.model.h5_user && app.model.h5_user.destroy({
24
+ where: {
25
+ user_id: id,
26
+ },
27
+ }).then(() => {
28
+ console.log(`删除${id}`);
29
+ }).catch(console.log);
30
+
31
+ app.model.toutiao_user && app.model.toutiao_user.destroy({
32
+ where: {
33
+ user_id: id,
34
+ },
35
+ }).then(() => {
36
+ console.log(`删除${id}`);
37
+ }).catch(console.log);
38
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ name: '用户',
3
+ order: ['created_at', 'code'],
4
+ comment: {
5
+ created_at: {
6
+ comment: '注册时间',
7
+ },
8
+ },
9
+ }