1 | const Response = require('../util/response') |
||
2 | const Validate = require('../util/validate') |
||
3 | const Uuid = require('../util/uuid') |
||
4 | const ModelUser = require('../model/users') |
||
5 | const Redis = require('../libraries/redis') |
||
6 | |||
7 | module.exports = { |
||
8 | |||
9 | test: async function (ctx) { |
||
10 | |||
11 | console.log('controller input') |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
12 | console.log(ctx.input) |
||
13 | console.log(ctx.params) |
||
14 | |||
15 | let conflict = [] |
||
16 | let tmpNo = 'none' |
||
17 | let orderNo = [] |
||
18 | for (let index = 0; index < 100; index++) { |
||
19 | let genNo = await Uuid.genOrderNo() |
||
20 | orderNo[index] = genNo |
||
21 | if (genNo === tmpNo) { |
||
22 | conflict.push(genNo) |
||
23 | } |
||
24 | tmpNo = genNo |
||
25 | } |
||
26 | orderNo.reverse() |
||
27 | |||
28 | let orderResult = { |
||
29 | "conflict": conflict, |
||
30 | "order": orderNo |
||
31 | } |
||
32 | |||
33 | let rules = { |
||
34 | 'uid': 'numeric|in:"0","3","4"', |
||
35 | 'filter': 'in:1,2,3', |
||
36 | } |
||
37 | |||
38 | let message = { |
||
39 | 'uid.required': 'kkkk', |
||
40 | 'uid.numeric': '数字数字', |
||
41 | 'uid.in': 'uid 必须在xxx范围内' |
||
42 | } |
||
43 | |||
44 | Validate(ctx, rules, message) |
||
45 | |||
46 | Redis.set('testkey', JSON.stringify(message)) |
||
47 | Redis.expire('testkey', 86400 * 30) |
||
48 | |||
49 | let insertData = [ |
||
0 ignored issues
–
show
|
|||
50 | { |
||
51 | 'name': 'te', |
||
52 | 'user_id': 1, |
||
53 | 'description': 'uni * 2' |
||
54 | }, |
||
55 | { |
||
56 | 'name': 'test2', |
||
57 | 'user_id': 2, |
||
58 | 'description': 'test2' |
||
59 | }, |
||
60 | ] |
||
61 | |||
62 | let sigleData = { |
||
0 ignored issues
–
show
|
|||
63 | 'name': '测试', |
||
64 | 'user_id': 2, |
||
65 | 'description': 'test4' |
||
66 | } |
||
67 | |||
68 | let realInsertData = { |
||
0 ignored issues
–
show
|
|||
69 | 'openid': 'test' + new Date().getTime() |
||
70 | } |
||
71 | // insertData = await ModelUser.addUser(realInsertData) |
||
72 | |||
73 | return Response.output(ctx, orderResult) |
||
74 | }, |
||
75 | |||
76 | edit: async function (ctx) { |
||
77 | console.log(ctx.params) |
||
0 ignored issues
–
show
|
|||
78 | let updateData = { |
||
79 | 'name': '更新', |
||
80 | 'description': '更新测试' |
||
81 | } |
||
82 | |||
83 | let where = { |
||
84 | 'user_id': 2, |
||
85 | 'name': ['test', 'test2', 'test3'] |
||
86 | } |
||
87 | |||
88 | let notWhere = { |
||
89 | 'description': ['test4', 'test3'] |
||
90 | } |
||
91 | |||
92 | let data = await ModelUser.editUser(updateData, where, notWhere) |
||
93 | |||
94 | return Response.output(ctx, data) |
||
95 | }, |
||
96 | |||
97 | } |