Showing
6 changed files
with
522 additions
and
236 deletions
@@ -654,102 +654,6 @@ const article = { | @@ -654,102 +654,6 @@ const article = { | ||
654 | return res.json(result); | 654 | return res.json(result); |
655 | }).catch(next); | 655 | }).catch(next); |
656 | }, | 656 | }, |
657 | - | ||
658 | - /** | ||
659 | - * Y100文章列表 | ||
660 | - * @param req | ||
661 | - * @param res | ||
662 | - * @param next | ||
663 | - */ | ||
664 | - async y100List(req, res, next) { | ||
665 | - const {actId, pageNo = 1, pageSize = 10, tag = ''} = req.query; | ||
666 | - | ||
667 | - if (!actId) { | ||
668 | - return res.json({ | ||
669 | - code: 400, | ||
670 | - message: INVALID_PARAMS | ||
671 | - }); | ||
672 | - } | ||
673 | - | ||
674 | - try { | ||
675 | - const result = await req.ctx(ArticleModel).articleY100List({ | ||
676 | - actId, | ||
677 | - pageNo, | ||
678 | - pageSize, | ||
679 | - tag | ||
680 | - }); | ||
681 | - | ||
682 | - return res.json({ | ||
683 | - code: 200, | ||
684 | - data: result, | ||
685 | - pageNo: +pageNo, | ||
686 | - pageSize: +pageSize, | ||
687 | - message: GET_SUCCESS | ||
688 | - }); | ||
689 | - } catch (err) { | ||
690 | - return next(err); | ||
691 | - } | ||
692 | - }, | ||
693 | - | ||
694 | - /** | ||
695 | - * Y100文章列表-随机 | ||
696 | - * @param req | ||
697 | - * @param res | ||
698 | - * @param next | ||
699 | - */ | ||
700 | - async y100RandomList(req, res, next) { | ||
701 | - const {actId, num} = req.query; | ||
702 | - | ||
703 | - if (!actId || num > 100) { | ||
704 | - return res.json({ | ||
705 | - code: 400, | ||
706 | - message: INVALID_PARAMS | ||
707 | - }); | ||
708 | - } | ||
709 | - | ||
710 | - try { | ||
711 | - const result = await req.ctx(ArticleModel).articleY100RandomList({ | ||
712 | - actId, | ||
713 | - num | ||
714 | - }); | ||
715 | - | ||
716 | - return res.json({ | ||
717 | - code: 200, | ||
718 | - data: result, | ||
719 | - message: GET_SUCCESS | ||
720 | - }); | ||
721 | - } catch (err) { | ||
722 | - return next(err); | ||
723 | - } | ||
724 | - }, | ||
725 | - | ||
726 | - /** | ||
727 | - * Y100详情 | ||
728 | - * @param req | ||
729 | - * @param res | ||
730 | - * @param next | ||
731 | - */ | ||
732 | - async y100Detail(req, res, next) { | ||
733 | - const {id} = req.query; | ||
734 | - | ||
735 | - if (!id) { | ||
736 | - return res.json({ | ||
737 | - code: 400, | ||
738 | - message: INVALID_PARAMS | ||
739 | - }); | ||
740 | - } | ||
741 | - | ||
742 | - try { | ||
743 | - const result = await req.ctx(ArticleModel).articleY100Detail(id); | ||
744 | - | ||
745 | - return res.json({ | ||
746 | - code: 200, | ||
747 | - data: result, | ||
748 | - }); | ||
749 | - } catch (err) { | ||
750 | - return next(err); | ||
751 | - } | ||
752 | - }, | ||
753 | }; | 657 | }; |
754 | 658 | ||
755 | 659 |
apps/article/controllers/y100.js
0 → 100644
1 | +const Y100Model = require('../models/y100'); | ||
2 | + | ||
3 | +const GET_SUCCESS = '获取成功'; | ||
4 | +const INVALID_PARAMS = '参数错误'; | ||
5 | + | ||
6 | +const y100 = { | ||
7 | + /** | ||
8 | + * Y100文章列表 | ||
9 | + * @param req | ||
10 | + * @param res | ||
11 | + * @param next | ||
12 | + */ | ||
13 | + async y100List(req, res, next) { | ||
14 | + const {actId, pageNo = 1, pageSize = 10, tag = ''} = req.query; | ||
15 | + | ||
16 | + if (!actId) { | ||
17 | + return res.json({ | ||
18 | + code: 400, | ||
19 | + message: INVALID_PARAMS | ||
20 | + }); | ||
21 | + } | ||
22 | + | ||
23 | + try { | ||
24 | + const result = await req.ctx(Y100Model).articleY100List({ | ||
25 | + actId, | ||
26 | + pageNo, | ||
27 | + pageSize, | ||
28 | + tag | ||
29 | + }); | ||
30 | + | ||
31 | + return res.json({ | ||
32 | + code: 200, | ||
33 | + data: result, | ||
34 | + pageNo: +pageNo, | ||
35 | + pageSize: +pageSize, | ||
36 | + message: GET_SUCCESS | ||
37 | + }); | ||
38 | + } catch (err) { | ||
39 | + return next(err); | ||
40 | + } | ||
41 | + }, | ||
42 | + | ||
43 | + /** | ||
44 | + * Y100文章列表-随机 | ||
45 | + * @param req | ||
46 | + * @param res | ||
47 | + * @param next | ||
48 | + */ | ||
49 | + async y100RandomList(req, res, next) { | ||
50 | + const {actId, num} = req.query; | ||
51 | + | ||
52 | + if (!actId || num > 100) { | ||
53 | + return res.json({ | ||
54 | + code: 400, | ||
55 | + message: INVALID_PARAMS | ||
56 | + }); | ||
57 | + } | ||
58 | + | ||
59 | + try { | ||
60 | + const result = await req.ctx(Y100Model).articleY100RandomList({ | ||
61 | + actId, | ||
62 | + num | ||
63 | + }); | ||
64 | + | ||
65 | + return res.json({ | ||
66 | + code: 200, | ||
67 | + data: result, | ||
68 | + message: GET_SUCCESS | ||
69 | + }); | ||
70 | + } catch (err) { | ||
71 | + return next(err); | ||
72 | + } | ||
73 | + }, | ||
74 | + | ||
75 | + /** | ||
76 | + * Y100详情 | ||
77 | + * @param req | ||
78 | + * @param res | ||
79 | + * @param next | ||
80 | + */ | ||
81 | + async y100Detail(req, res, next) { | ||
82 | + const {id} = req.query; | ||
83 | + | ||
84 | + if (!id) { | ||
85 | + return res.json({ | ||
86 | + code: 400, | ||
87 | + message: INVALID_PARAMS | ||
88 | + }); | ||
89 | + } | ||
90 | + | ||
91 | + try { | ||
92 | + const result = await req.ctx(Y100Model).articleY100Detail(id); | ||
93 | + | ||
94 | + return res.json({ | ||
95 | + code: 200, | ||
96 | + data: result, | ||
97 | + }); | ||
98 | + } catch (err) { | ||
99 | + return next(err); | ||
100 | + } | ||
101 | + }, | ||
102 | + async y100DeviceScan(req, res, next) { | ||
103 | + const {openId, avatar, deviceNo, actId, userName} = req.body; | ||
104 | + | ||
105 | + if (!deviceNo || !openId) { | ||
106 | + return res.json({ | ||
107 | + code: 400 | ||
108 | + }); | ||
109 | + } | ||
110 | + | ||
111 | + try { | ||
112 | + const result = await req.ctx(Y100Model).deviceUse({openId, avatar, deviceNo, actId, userName}); | ||
113 | + | ||
114 | + return res.json(result); | ||
115 | + } catch (err) { | ||
116 | + return next(err); | ||
117 | + } | ||
118 | + }, | ||
119 | + async y100DevicePost(req, res, next) { | ||
120 | + const {openId, deviceNo, actId, userImage, userLabel} = req.body; | ||
121 | + | ||
122 | + if (!deviceNo || !openId) { | ||
123 | + return res.json({ | ||
124 | + code: 400 | ||
125 | + }); | ||
126 | + } | ||
127 | + try { | ||
128 | + const result = await req.ctx(Y100Model).devicePost({openId, deviceNo, actId, userImage, userLabel}); | ||
129 | + | ||
130 | + return res.json(result); | ||
131 | + } catch (err) { | ||
132 | + return next(err); | ||
133 | + } | ||
134 | + }, | ||
135 | + async checkDeviceStatus(req, res, next) { | ||
136 | + const {deviceNo, actId} = req.query; | ||
137 | + | ||
138 | + if (!deviceNo || !actId) { | ||
139 | + return res.json({ | ||
140 | + code: 400 | ||
141 | + }); | ||
142 | + } | ||
143 | + try { | ||
144 | + const result = await req.ctx(Y100Model).checkDeviceStatus({deviceNo, actId}); | ||
145 | + | ||
146 | + return res.json(result); | ||
147 | + } catch (err) { | ||
148 | + return next(err); | ||
149 | + } | ||
150 | + } | ||
151 | +}; | ||
152 | + | ||
153 | +module.exports = y100; |
@@ -9,7 +9,6 @@ const mysqlCli = global.yoho.utils.mysqlCli; | @@ -9,7 +9,6 @@ const mysqlCli = global.yoho.utils.mysqlCli; | ||
9 | 9 | ||
10 | const TABLE_USER = 'user'; | 10 | const TABLE_USER = 'user'; |
11 | const TABLE_ACT_ARTICLE = 'act_article'; | 11 | const TABLE_ACT_ARTICLE = 'act_article'; |
12 | -const TABLE_ACT_ARTICLE_Y100 = 'act_article_y100'; | ||
13 | const TABLE_ACT_ARTICLE_IMG = 'act_article_img'; | 12 | const TABLE_ACT_ARTICLE_IMG = 'act_article_img'; |
14 | const TABLE_ACT_ARTICLE_GOOD = 'act_article_good'; | 13 | const TABLE_ACT_ARTICLE_GOOD = 'act_article_good'; |
15 | 14 | ||
@@ -475,141 +474,6 @@ class ArticleModel extends global.yoho.BaseModel { | @@ -475,141 +474,6 @@ class ArticleModel extends global.yoho.BaseModel { | ||
475 | ); | 474 | ); |
476 | } | 475 | } |
477 | 476 | ||
478 | - | ||
479 | - /** | ||
480 | - * 获取Y100列表 | ||
481 | - * @returns {*} | ||
482 | - */ | ||
483 | - articleY100List({actId, pageNo, pageSize, tag}) { | ||
484 | - const params = { | ||
485 | - actId, | ||
486 | - start: (pageNo - 1) * pageSize, | ||
487 | - page: _.parseInt(pageSize) | ||
488 | - }; | ||
489 | - let sql = ` | ||
490 | - SELECT | ||
491 | - AA.id, | ||
492 | - AA.good_count, | ||
493 | - AA.create_time, | ||
494 | - AAY.name, | ||
495 | - AAY.img_url | ||
496 | - FROM ${TABLE_ACT_ARTICLE} AA | ||
497 | - INNER JOIN ${TABLE_ACT_ARTICLE_Y100} AAY ON AA.id = AAY.article_id | ||
498 | - WHERE AA.act_id = :actId`; | ||
499 | - | ||
500 | - if (tag) { | ||
501 | - sql += ' and AAY.tag like :tag'; | ||
502 | - params.tag = `%${tag}%`; | ||
503 | - } | ||
504 | - sql += ' ORDER BY AA.good_count DESC'; | ||
505 | - sql += ' LIMIT :start, :page'; | ||
506 | - | ||
507 | - | ||
508 | - return mysqlCli.query(sql, params); | ||
509 | - } | ||
510 | - | ||
511 | - /** | ||
512 | - * 获取Y100列表-随机 | ||
513 | - * @returns {*} | ||
514 | - */ | ||
515 | - async articleY100RandomList({actId, num}) { | ||
516 | - const params = { | ||
517 | - actId, | ||
518 | - }; | ||
519 | - let maxSql = ` | ||
520 | - SELECT | ||
521 | - max(\`index\`) as maxIndex | ||
522 | - FROM ${TABLE_ACT_ARTICLE_Y100} AAY | ||
523 | - WHERE AAy.act_id = :actId`; | ||
524 | - | ||
525 | - const maxResult = await mysqlCli.query(maxSql, params); | ||
526 | - let maxIndex = maxResult[0].maxIndex; | ||
527 | - | ||
528 | - if (num > maxIndex) { | ||
529 | - throw '随机数量超过数据库大小'; | ||
530 | - } | ||
531 | - const ids = [], | ||
532 | - selectIds = []; | ||
533 | - | ||
534 | - for (let i = 0; i <= maxIndex; i++) { | ||
535 | - ids.push(i); | ||
536 | - } | ||
537 | - | ||
538 | - for (let i = 0; i < num; i++) { | ||
539 | - const index = parseInt(Math.random() * ids.length, 10); | ||
540 | - | ||
541 | - selectIds.push(ids[index]); | ||
542 | - ids.splice(index, 1); | ||
543 | - } | ||
544 | - | ||
545 | - let sql = ` | ||
546 | - SELECT | ||
547 | - AA.id, | ||
548 | - AA.good_count, | ||
549 | - AA.create_time, | ||
550 | - AAY.name, | ||
551 | - AAY.img_url | ||
552 | - FROM ${TABLE_ACT_ARTICLE} AA | ||
553 | - INNER JOIN ${TABLE_ACT_ARTICLE_Y100} AAY ON AA.id = AAY.article_id | ||
554 | - WHERE AA.act_id = :actId`; | ||
555 | - | ||
556 | - sql += ` and AAY.index in (${selectIds.join(',')})`; | ||
557 | - sql += ` order by field(AAY.index,${selectIds.join(',')});`; | ||
558 | - | ||
559 | - return mysqlCli.query(sql, params); | ||
560 | - } | ||
561 | - | ||
562 | - /** | ||
563 | - * 获取Y100详情 | ||
564 | - * @returns {*} | ||
565 | - */ | ||
566 | - async articleY100Detail(id) { | ||
567 | - let sql = ` | ||
568 | - SELECT | ||
569 | - AAY.id, | ||
570 | - AAY.act_id, | ||
571 | - AAY.article_id, | ||
572 | - AAY.img_url, | ||
573 | - AAY.tag, | ||
574 | - AAY.name, | ||
575 | - AAY.career, | ||
576 | - AAY.style, | ||
577 | - AAY.interest, | ||
578 | - AAY.skns, | ||
579 | - AAY.create_time, | ||
580 | - AA.good_count | ||
581 | - FROM ${TABLE_ACT_ARTICLE_Y100} AAY | ||
582 | - INNER JOIN ${TABLE_ACT_ARTICLE} AA ON AAY.article_id = AA.id | ||
583 | - where AAY.id = :id`; | ||
584 | - | ||
585 | - const query = await mysqlCli.query(sql, { | ||
586 | - id | ||
587 | - }); | ||
588 | - | ||
589 | - if (query.length === 1) { | ||
590 | - const result = query[0]; | ||
591 | - const {skns} = query[0]; | ||
592 | - | ||
593 | - if (skns) { | ||
594 | - const productsResult = await this.get({ | ||
595 | - data: { | ||
596 | - method: 'h5.product.batch', | ||
597 | - limit: skns.split(',').length, | ||
598 | - productSkn: skns, | ||
599 | - contain_all: 'Y' | ||
600 | - }, | ||
601 | - param: { | ||
602 | - cache: true | ||
603 | - } | ||
604 | - }); | ||
605 | - | ||
606 | - if (productsResult.code === 200 && productsResult.data) { | ||
607 | - result.products = productsResult.data.product_list; | ||
608 | - } | ||
609 | - } | ||
610 | - return result; | ||
611 | - } | ||
612 | - } | ||
613 | } | 477 | } |
614 | 478 | ||
615 | module.exports = ArticleModel; | 479 | module.exports = ArticleModel; |
apps/article/models/y100.js
0 → 100644
1 | +const _ = require('lodash'); | ||
2 | +const mysqlCli = global.yoho.utils.mysqlCli; | ||
3 | + | ||
4 | +const TABLE_ACT_ARTICLE = 'act_article'; | ||
5 | +const TABLE_ACT_ARTICLE_Y100 = 'act_article_y100'; | ||
6 | +const playExpireTime = 45 * 1000; | ||
7 | +const showExpireTime = 30 * 1000; | ||
8 | + | ||
9 | +class Y100Model extends global.yoho.BaseModel { | ||
10 | + constructor(ctx) { | ||
11 | + super(ctx); | ||
12 | + } | ||
13 | + | ||
14 | + | ||
15 | + /** | ||
16 | + * 获取Y100列表 | ||
17 | + * @returns {*} | ||
18 | + */ | ||
19 | + articleY100List({actId, pageNo, pageSize, tag}) { | ||
20 | + const params = { | ||
21 | + actId, | ||
22 | + start: (pageNo - 1) * pageSize, | ||
23 | + page: _.parseInt(pageSize) | ||
24 | + }; | ||
25 | + let sql = ` | ||
26 | + SELECT | ||
27 | + AA.id, | ||
28 | + AA.good_count, | ||
29 | + AA.create_time, | ||
30 | + AAY.name, | ||
31 | + AAY.img_url | ||
32 | + FROM ${TABLE_ACT_ARTICLE} AA | ||
33 | + INNER JOIN ${TABLE_ACT_ARTICLE_Y100} AAY ON AA.id = AAY.article_id | ||
34 | + WHERE AA.act_id = :actId`; | ||
35 | + | ||
36 | + if (tag) { | ||
37 | + sql += ' and AAY.tag like :tag'; | ||
38 | + params.tag = `%${tag}%`; | ||
39 | + } | ||
40 | + sql += ' ORDER BY AA.good_count DESC'; | ||
41 | + sql += ' LIMIT :start, :page'; | ||
42 | + | ||
43 | + | ||
44 | + return mysqlCli.query(sql, params); | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * 获取Y100列表-随机 | ||
49 | + * @returns {*} | ||
50 | + */ | ||
51 | + async articleY100RandomList({actId, num}) { | ||
52 | + const params = { | ||
53 | + actId, | ||
54 | + }; | ||
55 | + let maxSql = ` | ||
56 | + SELECT | ||
57 | + max(\`index\`) as maxIndex | ||
58 | + FROM ${TABLE_ACT_ARTICLE_Y100} AAY | ||
59 | + WHERE AAy.act_id = :actId`; | ||
60 | + | ||
61 | + const maxResult = await mysqlCli.query(maxSql, params); | ||
62 | + let maxIndex = maxResult[0].maxIndex; | ||
63 | + | ||
64 | + if (num > maxIndex) { | ||
65 | + throw '随机数量超过数据库大小'; | ||
66 | + } | ||
67 | + const ids = [], | ||
68 | + selectIds = []; | ||
69 | + | ||
70 | + for (let i = 0; i <= maxIndex; i++) { | ||
71 | + ids.push(i); | ||
72 | + } | ||
73 | + | ||
74 | + for (let i = 0; i < num; i++) { | ||
75 | + const index = parseInt(Math.random() * ids.length, 10); | ||
76 | + | ||
77 | + selectIds.push(ids[index]); | ||
78 | + ids.splice(index, 1); | ||
79 | + } | ||
80 | + | ||
81 | + let sql = ` | ||
82 | + SELECT | ||
83 | + AA.id, | ||
84 | + AA.good_count, | ||
85 | + AA.create_time, | ||
86 | + AAY.name, | ||
87 | + AAY.img_url | ||
88 | + FROM ${TABLE_ACT_ARTICLE} AA | ||
89 | + INNER JOIN ${TABLE_ACT_ARTICLE_Y100} AAY ON AA.id = AAY.article_id | ||
90 | + WHERE AA.act_id = :actId`; | ||
91 | + | ||
92 | + sql += ` and AAY.index in (${selectIds.join(',')})`; | ||
93 | + sql += ` order by field(AAY.index,${selectIds.join(',')});`; | ||
94 | + | ||
95 | + return mysqlCli.query(sql, params); | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * 获取Y100详情 | ||
100 | + * @returns {*} | ||
101 | + */ | ||
102 | + async articleY100Detail(id) { | ||
103 | + let sql = ` | ||
104 | + SELECT | ||
105 | + AAY.id, | ||
106 | + AAY.act_id, | ||
107 | + AAY.article_id, | ||
108 | + AAY.img_url, | ||
109 | + AAY.tag, | ||
110 | + AAY.name, | ||
111 | + AAY.career, | ||
112 | + AAY.style, | ||
113 | + AAY.interest, | ||
114 | + AAY.skns, | ||
115 | + AAY.create_time, | ||
116 | + AA.good_count | ||
117 | + FROM ${TABLE_ACT_ARTICLE_Y100} AAY | ||
118 | + INNER JOIN ${TABLE_ACT_ARTICLE} AA ON AAY.article_id = AA.id | ||
119 | + where AAY.id = :id`; | ||
120 | + | ||
121 | + const query = await mysqlCli.query(sql, { | ||
122 | + id | ||
123 | + }); | ||
124 | + | ||
125 | + if (query.length === 1) { | ||
126 | + const result = query[0]; | ||
127 | + const {skns} = query[0]; | ||
128 | + | ||
129 | + if (skns) { | ||
130 | + const productsResult = await this.get({ | ||
131 | + data: { | ||
132 | + method: 'h5.product.batch', | ||
133 | + limit: skns.split(',').length, | ||
134 | + productSkn: skns, | ||
135 | + contain_all: 'Y' | ||
136 | + }, | ||
137 | + param: { | ||
138 | + cache: true | ||
139 | + } | ||
140 | + }); | ||
141 | + | ||
142 | + if (productsResult.code === 200 && productsResult.data) { | ||
143 | + result.products = productsResult.data.product_list; | ||
144 | + } | ||
145 | + } | ||
146 | + return result; | ||
147 | + } | ||
148 | + } | ||
149 | + | ||
150 | + /** | ||
151 | + * 使用设备更新用户信息 | ||
152 | + * @returns {*} | ||
153 | + */ | ||
154 | + async deviceUse({openId, userName, avatar, deviceNo, actId}) { | ||
155 | + const deviceQuery = await mysqlCli.query( | ||
156 | + `SELECT | ||
157 | + user_id, | ||
158 | + user_name, | ||
159 | + user_avatar, | ||
160 | + user_image, | ||
161 | + user_label, | ||
162 | + expire_time, | ||
163 | + status | ||
164 | + FROM | ||
165 | + act_devices_y100 | ||
166 | + WHERE | ||
167 | + act_id = :actId | ||
168 | + AND | ||
169 | + device_no = :deviceNo`, | ||
170 | + { | ||
171 | + deviceNo, | ||
172 | + actId, | ||
173 | + }); | ||
174 | + | ||
175 | + if (deviceQuery.length !== 1) { | ||
176 | + return { | ||
177 | + code: 400, | ||
178 | + message: '设备信息错误' | ||
179 | + }; | ||
180 | + } | ||
181 | + const device = _.head(deviceQuery); | ||
182 | + | ||
183 | + if (device.expire_time && device.expire_time > Date.now()) { | ||
184 | + return { | ||
185 | + code: 401, | ||
186 | + message: `用户${device.user_name}正在使用大屏,请稍等一会` | ||
187 | + }; | ||
188 | + } | ||
189 | + const expireTime = Date.now() + playExpireTime; | ||
190 | + | ||
191 | + await mysqlCli.update(` | ||
192 | + UPDATE | ||
193 | + act_devices_y100 | ||
194 | + SET | ||
195 | + user_id = :openId, | ||
196 | + user_name = :userName, | ||
197 | + user_avatar = :avatar, | ||
198 | + user_image = '', | ||
199 | + user_label = '', | ||
200 | + expire_time = :expireTime, | ||
201 | + status = 0 | ||
202 | + WHERE | ||
203 | + act_id = :actId | ||
204 | + AND | ||
205 | + device_no = :deviceNo`, { | ||
206 | + openId, | ||
207 | + userName, | ||
208 | + avatar, | ||
209 | + expireTime, | ||
210 | + actId, | ||
211 | + deviceNo | ||
212 | + }); | ||
213 | + return { | ||
214 | + code: 200, | ||
215 | + message: '扫描成功', | ||
216 | + data: { | ||
217 | + expireTime | ||
218 | + } | ||
219 | + }; | ||
220 | + } | ||
221 | + | ||
222 | + /** | ||
223 | + * 使用设备更新用户信息 | ||
224 | + * @returns {*} | ||
225 | + */ | ||
226 | + async devicePost({openId, deviceNo, actId, userImage, userLabel}) { | ||
227 | + const deviceQuery = await mysqlCli.query( | ||
228 | + `SELECT | ||
229 | + user_id, | ||
230 | + user_name, | ||
231 | + user_avatar, | ||
232 | + user_image, | ||
233 | + user_label, | ||
234 | + expire_time, | ||
235 | + status | ||
236 | + FROM | ||
237 | + act_devices_y100 | ||
238 | + WHERE | ||
239 | + act_id = :actId | ||
240 | + AND | ||
241 | + device_no = :deviceNo`, | ||
242 | + { | ||
243 | + deviceNo, | ||
244 | + actId, | ||
245 | + }); | ||
246 | + | ||
247 | + if (deviceQuery.length !== 1) { | ||
248 | + return { | ||
249 | + code: 400, | ||
250 | + message: '设备信息错误' | ||
251 | + }; | ||
252 | + } | ||
253 | + const device = _.head(deviceQuery); | ||
254 | + | ||
255 | + if (device.expire_time <= Date.now()) { | ||
256 | + return { | ||
257 | + code: 400, | ||
258 | + message: '提交超时请再玩一次吧' | ||
259 | + }; | ||
260 | + } | ||
261 | + | ||
262 | + if (device.user_id !== openId) { | ||
263 | + return { | ||
264 | + code: 401, | ||
265 | + message: `用户${device.user_name}正在使用大屏,请稍等一会` | ||
266 | + }; | ||
267 | + } | ||
268 | + const expireTime = Date.now() + showExpireTime; | ||
269 | + | ||
270 | + await mysqlCli.update(` | ||
271 | + UPDATE | ||
272 | + act_devices_y100 | ||
273 | + SET | ||
274 | + user_image = :userImage, | ||
275 | + user_label = :userLabel, | ||
276 | + expire_time = :expireTime, | ||
277 | + status = 1 | ||
278 | + WHERE | ||
279 | + act_id = :actId | ||
280 | + AND | ||
281 | + device_no = :deviceNo`, { | ||
282 | + openId, | ||
283 | + expireTime, | ||
284 | + userImage, | ||
285 | + userLabel, | ||
286 | + actId, | ||
287 | + deviceNo | ||
288 | + }); | ||
289 | + return { | ||
290 | + code: 200, | ||
291 | + message: '提交成功', | ||
292 | + }; | ||
293 | + } | ||
294 | + | ||
295 | + /** | ||
296 | + * 检查设备状态 | ||
297 | + * @returns {*} | ||
298 | + */ | ||
299 | + async checkDeviceStatus({deviceNo, actId}) { | ||
300 | + const deviceQuery = await mysqlCli.query( | ||
301 | + `SELECT | ||
302 | + user_id, | ||
303 | + user_name, | ||
304 | + user_avatar, | ||
305 | + user_image, | ||
306 | + user_label, | ||
307 | + expire_time, | ||
308 | + status | ||
309 | + FROM | ||
310 | + act_devices_y100 | ||
311 | + WHERE | ||
312 | + act_id = :actId | ||
313 | + AND | ||
314 | + device_no = :deviceNo`, | ||
315 | + { | ||
316 | + deviceNo, | ||
317 | + actId, | ||
318 | + }); | ||
319 | + | ||
320 | + if (deviceQuery.length !== 1) { | ||
321 | + return { | ||
322 | + code: 400, | ||
323 | + message: '设备信息错误' | ||
324 | + }; | ||
325 | + } | ||
326 | + const device = _.head(deviceQuery); | ||
327 | + | ||
328 | + if (device.expire_time > Date.now()) { | ||
329 | + if (device.status === 0) { | ||
330 | + return { | ||
331 | + code: 1002, | ||
332 | + message: 'playing', | ||
333 | + data: { | ||
334 | + openId: device.user_id, | ||
335 | + userName: device.user_name, | ||
336 | + avatar: device.user_avatar, | ||
337 | + expireTime: device.expire_time | ||
338 | + } | ||
339 | + }; | ||
340 | + } | ||
341 | + if (device.status === 1) { | ||
342 | + return { | ||
343 | + code: 10003, | ||
344 | + message: 'show image', | ||
345 | + data: { | ||
346 | + openId: device.user_id, | ||
347 | + userName: device.user_name, | ||
348 | + avatar: device.user_avatar, | ||
349 | + userImage: device.user_image, | ||
350 | + userLabel: device.user_label, | ||
351 | + expireTime: device.expire_time | ||
352 | + } | ||
353 | + }; | ||
354 | + } | ||
355 | + } | ||
356 | + return { | ||
357 | + code: 1001, | ||
358 | + message: 'show qrcode' | ||
359 | + }; | ||
360 | + } | ||
361 | +} | ||
362 | + | ||
363 | +module.exports = Y100Model; |
@@ -7,12 +7,13 @@ const express = require('express'); | @@ -7,12 +7,13 @@ const express = require('express'); | ||
7 | const router = express.Router(); // eslint-disable-line | 7 | const router = express.Router(); // eslint-disable-line |
8 | const auth = require('../../doraemon/middleware/auth'); | 8 | const auth = require('../../doraemon/middleware/auth'); |
9 | const article = require('./controllers/article'); | 9 | const article = require('./controllers/article'); |
10 | +const y100 = require('./controllers/y100'); | ||
10 | 11 | ||
11 | router.post('/like', article.like); | 12 | router.post('/like', article.like); |
12 | router.get('/list', article.list); | 13 | router.get('/list', article.list); |
13 | -router.get('/y100list', article.y100List); | ||
14 | -router.get('/y100randomlist', article.y100RandomList); | ||
15 | -router.get('/y100detail', article.y100Detail); | 14 | +router.get('/y100list', y100.y100List); |
15 | +router.get('/y100randomlist', y100.y100RandomList); | ||
16 | +router.get('/y100detail', y100.y100Detail); | ||
16 | router.get('/listNoImg', article.listNoImg); | 17 | router.get('/listNoImg', article.listNoImg); |
17 | router.get('/listNoUser', article.listNoUser); | 18 | router.get('/listNoUser', article.listNoUser); |
18 | router.post('/publish', auth, article.publish); | 19 | router.post('/publish', auth, article.publish); |
@@ -28,10 +28,11 @@ CREATE TABLE IF NOT EXISTS act_devices_y100 ( | @@ -28,10 +28,11 @@ CREATE TABLE IF NOT EXISTS act_devices_y100 ( | ||
28 | `act_id` int(8) NOT NULL DEFAULT 0, | 28 | `act_id` int(8) NOT NULL DEFAULT 0, |
29 | `device_no` varchar(200) DEFAULT '', | 29 | `device_no` varchar(200) DEFAULT '', |
30 | `user_id` varchar(200) DEFAULT '', | 30 | `user_id` varchar(200) DEFAULT '', |
31 | + `user_name` varchar(200) DEFAULT '', | ||
31 | `user_avatar` varchar(200) DEFAULT '', | 32 | `user_avatar` varchar(200) DEFAULT '', |
32 | `user_image` varchar(200) DEFAULT '', | 33 | `user_image` varchar(200) DEFAULT '', |
33 | `user_label` varchar(200) DEFAULT '', | 34 | `user_label` varchar(200) DEFAULT '', |
34 | - `expire_time` timestamp NOT NULL, | 35 | + `expire_time` bigint NOT NULL, |
35 | `status` TINYINT DEFAULT 0, | 36 | `status` TINYINT DEFAULT 0, |
36 | `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP | 37 | `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP |
37 | ) DEFAULT CHARSET=utf8; | 38 | ) DEFAULT CHARSET=utf8; |
-
Please register or login to post a comment