Showing
7 changed files
with
107 additions
and
32 deletions
@@ -7,17 +7,13 @@ const zerobuyModel = require('../models/zero-buy'); | @@ -7,17 +7,13 @@ const zerobuyModel = require('../models/zero-buy'); | ||
7 | 7 | ||
8 | module.exports = { | 8 | module.exports = { |
9 | list(req, res, next) { | 9 | list(req, res, next) { |
10 | - if (req.isAdmin) { | ||
11 | - req.query.noCache = true; | ||
12 | - } | 10 | + req.query.noCache = false; |
13 | 11 | ||
14 | req.ctx(zerobuyModel).getList(req.query.status, req.query.page, req.query) | 12 | req.ctx(zerobuyModel).getList(req.query.status, req.query.page, req.query) |
15 | .then(res.json).catch(next); | 13 | .then(res.json).catch(next); |
16 | }, | 14 | }, |
17 | content(req, res, next) { | 15 | content(req, res, next) { |
18 | - if (req.isAdmin) { | ||
19 | - req.query.noCache = true; | ||
20 | - } | 16 | + req.query.noCache = false; |
21 | 17 | ||
22 | req.ctx(zerobuyModel).getContent(req.query.actPrizeId, req.query) | 18 | req.ctx(zerobuyModel).getContent(req.query.actPrizeId, req.query) |
23 | .then(res.json).catch(next); | 19 | .then(res.json).catch(next); |
@@ -40,6 +36,10 @@ module.exports = { | @@ -40,6 +36,10 @@ module.exports = { | ||
40 | req.ctx(zerobuyModel).getCodeMine(uid, actPrizeId) | 36 | req.ctx(zerobuyModel).getCodeMine(uid, actPrizeId) |
41 | .then(res.json).catch(next); | 37 | .then(res.json).catch(next); |
42 | }, | 38 | }, |
39 | + joinNum(req, res, next) { | ||
40 | + req.ctx(zerobuyModel).getUserJoinNum(req.query.actPrizeId) | ||
41 | + .then(res.json).catch(next); | ||
42 | + }, | ||
43 | codeGain(req, res, next) { | 43 | codeGain(req, res, next) { |
44 | let params = req.body; | 44 | let params = req.body; |
45 | 45 | ||
@@ -50,7 +50,7 @@ module.exports = { | @@ -50,7 +50,7 @@ module.exports = { | ||
50 | }); | 50 | }); |
51 | } | 51 | } |
52 | 52 | ||
53 | - req.ctx(zerobuyModel).getPrizeCode(req.query) | 53 | + req.ctx(zerobuyModel).getPrizeCode(params.uid, params.actPrizeId, params) |
54 | .then(res.json).catch(next); | 54 | .then(res.json).catch(next); |
55 | } | 55 | } |
56 | }; | 56 | }; |
@@ -58,12 +58,19 @@ module.exports = class extends global.yoho.BaseModel { | @@ -58,12 +58,19 @@ module.exports = class extends global.yoho.BaseModel { | ||
58 | status = parseInt(status, 10); | 58 | status = parseInt(status, 10); |
59 | page = parseInt(page, 10) || 1; | 59 | page = parseInt(page, 10) || 1; |
60 | 60 | ||
61 | - status = _.isNaN(status) ? '> 0' : `= ${status}`; | 61 | + if (_.isNaN(status)) { |
62 | + status = '> 0'; | ||
63 | + } else if (status < 0) { | ||
64 | + status = '>= 0'; | ||
65 | + } else { | ||
66 | + status = `= ${status}`; | ||
67 | + } | ||
62 | 68 | ||
63 | let limit = `${(page - 1) * pageSize},${page * pageSize}`; | 69 | let limit = `${(page - 1) * pageSize},${page * pageSize}`; |
64 | 70 | ||
65 | return mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT} | 71 | return mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT} |
66 | - where act_id = :actId and status ${status} limit ${limit}`, { | 72 | + where act_id = :actId and status ${status} |
73 | + order by sort desc limit ${limit}`, { | ||
67 | actId | 74 | actId |
68 | }, { | 75 | }, { |
69 | cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES | 76 | cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES |
@@ -103,7 +110,8 @@ module.exports = class extends global.yoho.BaseModel { | @@ -103,7 +110,8 @@ module.exports = class extends global.yoho.BaseModel { | ||
103 | actPrizeId = parseInt(actPrizeId, 10) || 0; | 110 | actPrizeId = parseInt(actPrizeId, 10) || 0; |
104 | 111 | ||
105 | return mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT} | 112 | return mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT} |
106 | - where act_id = :actId and id > :actPrizeId and status > 0 limit 5`, { | 113 | + where act_id = :actId and id > :actPrizeId and status > 0 |
114 | + order by sort desc limit 5`, { | ||
107 | actId, | 115 | actId, |
108 | actPrizeId: actPrizeId - 3 | 116 | actPrizeId: actPrizeId - 3 |
109 | }, { | 117 | }, { |
@@ -183,6 +191,21 @@ module.exports = class extends global.yoho.BaseModel { | @@ -183,6 +191,21 @@ module.exports = class extends global.yoho.BaseModel { | ||
183 | } | 191 | } |
184 | 192 | ||
185 | /** | 193 | /** |
194 | + * 0元购单个活动参与人数 | ||
195 | + * @param actPrizeId | ||
196 | + * @param noCache | ||
197 | + * @returns {*} | ||
198 | + */ | ||
199 | + getUserJoinNum(actPrizeId, noCache) { | ||
200 | + return mysqlCli.query(`select count(distinct uid) as join_num from ${TABLE_ACT_PRIZE_PRODUCT_USER} | ||
201 | + where act_prize_id = :actPrizeId;`, { | ||
202 | + actPrizeId | ||
203 | + }, { | ||
204 | + cache: noCache ? 0 : MINUTE_TIMES / 6 | ||
205 | + }).then(handelResult); | ||
206 | + } | ||
207 | + | ||
208 | + /** | ||
186 | * 0元购获取抽奖码 | 209 | * 0元购获取抽奖码 |
187 | * @param uid | 210 | * @param uid |
188 | * @param actPrizeId | 211 | * @param actPrizeId |
@@ -195,8 +218,9 @@ module.exports = class extends global.yoho.BaseModel { | @@ -195,8 +218,9 @@ module.exports = class extends global.yoho.BaseModel { | ||
195 | let info = await Promise.all([ | 218 | let info = await Promise.all([ |
196 | mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT} | 219 | mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT} |
197 | where id = :actPrizeId limit 1;`, {actPrizeId}, {cache: MINUTE_TIMES / 2}), | 220 | where id = :actPrizeId limit 1;`, {actPrizeId}, {cache: MINUTE_TIMES / 2}), |
198 | - mysqlCli.query(`select count(distinct uid) as join_num from ${TABLE_ACT_PRIZE_PRODUCT_USER} | ||
199 | - where act_prize_id = :actPrizeId;`, {actPrizeId}) | 221 | + this.getUserJoinNum(actPrizeId, true).then(result => { |
222 | + return result.data; | ||
223 | + }) | ||
200 | ]); | 224 | ]); |
201 | 225 | ||
202 | const errorData = { | 226 | const errorData = { |
@@ -21,8 +21,9 @@ router.get('/zerobuy/list', zeroBuy.list); // 0元购活动列表 | @@ -21,8 +21,9 @@ router.get('/zerobuy/list', zeroBuy.list); // 0元购活动列表 | ||
21 | router.get('/zerobuy/list/mine', zeroBuy.listMine); // 0元购用户参与列表 | 21 | router.get('/zerobuy/list/mine', zeroBuy.listMine); // 0元购用户参与列表 |
22 | router.get('/zerobuy/list/recommend', zeroBuy.listRecommend); // 0元购活动推荐列表 | 22 | router.get('/zerobuy/list/recommend', zeroBuy.listRecommend); // 0元购活动推荐列表 |
23 | router.get('/zerobuy/content', zeroBuy.content); // 0元购详情 | 23 | router.get('/zerobuy/content', zeroBuy.content); // 0元购详情 |
24 | +router.get('/zerobuy/join/sum', zeroBuy.joinNum); // 0元购抽奖码最近获取记录 | ||
24 | router.get('/zerobuy/code/recent', zeroBuy.codeRecent); // 0元购抽奖码最近获取记录 | 25 | router.get('/zerobuy/code/recent', zeroBuy.codeRecent); // 0元购抽奖码最近获取记录 |
25 | -router.get('/zerobuy/code/mine', zeroBuy.codeMine); // 0元购用户单个活动抽奖码 | 26 | +router.get('/zerobuy/code/mine', zeroBuy.codeMine); // 0元购用户单个活动获取的抽奖码 |
26 | router.post('/zerobuy/code/gain', zeroBuy.codeGain); // 0元购获取抽奖码 | 27 | router.post('/zerobuy/code/gain', zeroBuy.codeGain); // 0元购获取抽奖码 |
27 | 28 | ||
28 | module.exports = router; | 29 | module.exports = router; |
@@ -21,6 +21,19 @@ const timeFormat = (time) => { | @@ -21,6 +21,19 @@ const timeFormat = (time) => { | ||
21 | return moment(time).format('YYYY-MM-DD HH:mm:ss'); | 21 | return moment(time).format('YYYY-MM-DD HH:mm:ss'); |
22 | }; | 22 | }; |
23 | 23 | ||
24 | +const zeroBuy = { | ||
25 | + zeroBuyList(req, res, next) { | ||
26 | + req.ctx(ActivityModel).getZerobuyList().then(result => { | ||
27 | + res.render('activity/zero-buy-list', { | ||
28 | + bodyClass: 'nav-md', | ||
29 | + list: result, | ||
30 | + module: 'admin', | ||
31 | + page: 'activity' | ||
32 | + }); | ||
33 | + }).catch(next); | ||
34 | + } | ||
35 | +}; | ||
36 | + | ||
24 | const activity = { | 37 | const activity = { |
25 | /** | 38 | /** |
26 | * 活动列表 | 39 | * 活动列表 |
@@ -550,7 +563,8 @@ const activity = { | @@ -550,7 +563,8 @@ const activity = { | ||
550 | }) | 563 | }) |
551 | .catch(next); | 564 | .catch(next); |
552 | 565 | ||
553 | - } | 566 | + }, |
567 | + ...zeroBuy | ||
554 | }; | 568 | }; |
555 | 569 | ||
556 | 570 |
@@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
6 | 6 | ||
7 | const mysqlCli = global.yoho.utils.mysqlCli; | 7 | const mysqlCli = global.yoho.utils.mysqlCli; |
8 | const _ = require('lodash'); | 8 | const _ = require('lodash'); |
9 | +const zerobuyModel = require('../../activity/models/zero-buy'); | ||
9 | 10 | ||
10 | const TB_USER = 'user'; | 11 | const TB_USER = 'user'; |
11 | const TB_ACTIVITY = 'activity'; | 12 | const TB_ACTIVITY = 'activity'; |
@@ -28,7 +29,7 @@ class AdminModel extends global.yoho.BaseModel { | @@ -28,7 +29,7 @@ class AdminModel extends global.yoho.BaseModel { | ||
28 | */ | 29 | */ |
29 | createActivity({title, startTime, endTime, repeat_limit, vote_limit}) { | 30 | createActivity({title, startTime, endTime, repeat_limit, vote_limit}) { |
30 | return mysqlCli.insert( | 31 | return mysqlCli.insert( |
31 | - `insert into ${TB_ACTIVITY} (title, start_time, end_time, repeat_limit, vote_limit) | 32 | + `insert into ${TB_ACTIVITY} (title, start_time, end_time, repeat_limit, vote_limit) |
32 | values (:title, :startTime, :endTime, :repeat_limit, :vote_limit);`, | 33 | values (:title, :startTime, :endTime, :repeat_limit, :vote_limit);`, |
33 | { | 34 | { |
34 | title, | 35 | title, |
@@ -46,7 +47,7 @@ class AdminModel extends global.yoho.BaseModel { | @@ -46,7 +47,7 @@ class AdminModel extends global.yoho.BaseModel { | ||
46 | */ | 47 | */ |
47 | activityList() { | 48 | activityList() { |
48 | return mysqlCli.query( | 49 | return mysqlCli.query( |
49 | - `select id, title, start_time startTime, end_time endTime, create_time createTime, | 50 | + `select id, title, start_time startTime, end_time endTime, create_time createTime, |
50 | repeat_limit repeatLimit, vote_limit voteLimit from ${TB_ACTIVITY};` | 51 | repeat_limit repeatLimit, vote_limit voteLimit from ${TB_ACTIVITY};` |
51 | ); | 52 | ); |
52 | } | 53 | } |
@@ -78,12 +79,12 @@ class AdminModel extends global.yoho.BaseModel { | @@ -78,12 +79,12 @@ class AdminModel extends global.yoho.BaseModel { | ||
78 | 79 | ||
79 | return mysqlCli.query( | 80 | return mysqlCli.query( |
80 | `select taa.id, taai.img_url imgUrl, taa.content, taa.create_time createTime, taa.good_count goodCount, | 81 | `select taa.id, taai.img_url imgUrl, taa.content, taa.create_time createTime, taa.good_count goodCount, |
81 | - taa.user_name userName, tu.user_phone phone | 82 | + taa.user_name userName, tu.user_phone phone |
82 | from ${TB_ACT_ARTICLE} taa | 83 | from ${TB_ACT_ARTICLE} taa |
83 | left join ${TB_USER} tu | 84 | left join ${TB_USER} tu |
84 | - on taa.user_id = tu.id | ||
85 | - left join ${TB_ACT_ARTICLE_IMG} taai | ||
86 | - on taai.article_id = taa.id | 85 | + on taa.user_id = tu.id |
86 | + left join ${TB_ACT_ARTICLE_IMG} taai | ||
87 | + on taai.article_id = taa.id | ||
87 | where act_id = :actId | 88 | where act_id = :actId |
88 | ${orderSql} ${limitSql};`, { | 89 | ${orderSql} ${limitSql};`, { |
89 | actId, | 90 | actId, |
@@ -101,10 +102,10 @@ class AdminModel extends global.yoho.BaseModel { | @@ -101,10 +102,10 @@ class AdminModel extends global.yoho.BaseModel { | ||
101 | exportActArticleList(actId) { | 102 | exportActArticleList(actId) { |
102 | return mysqlCli.query( | 103 | return mysqlCli.query( |
103 | `select taa.id, taa.content, taa.create_time createTime, taa.good_count goodCount, | 104 | `select taa.id, taa.content, taa.create_time createTime, taa.good_count goodCount, |
104 | - tu.user_name userName, tu.user_phone phone | 105 | + tu.user_name userName, tu.user_phone phone |
105 | from ${TB_ACT_ARTICLE} taa | 106 | from ${TB_ACT_ARTICLE} taa |
106 | left join ${TB_USER} tu | 107 | left join ${TB_USER} tu |
107 | - on taa.user_id = tu.id | 108 | + on taa.user_id = tu.id |
108 | where act_id = :actId;`, { | 109 | where act_id = :actId;`, { |
109 | actId | 110 | actId |
110 | } | 111 | } |
@@ -132,8 +133,8 @@ class AdminModel extends global.yoho.BaseModel { | @@ -132,8 +133,8 @@ class AdminModel extends global.yoho.BaseModel { | ||
132 | */ | 133 | */ |
133 | async createArticle({actId, userName, content, createTime}) { | 134 | async createArticle({actId, userName, content, createTime}) { |
134 | return mysqlCli.insert( | 135 | return mysqlCli.insert( |
135 | - `insert into ${TB_ACT_ARTICLE} | ||
136 | - (act_id, user_name, content, create_time) values | 136 | + `insert into ${TB_ACT_ARTICLE} |
137 | + (act_id, user_name, content, create_time) values | ||
137 | (:actId, :userName, :content, :createTime);`, | 138 | (:actId, :userName, :content, :createTime);`, |
138 | { | 139 | { |
139 | actId, | 140 | actId, |
@@ -164,10 +165,10 @@ class AdminModel extends global.yoho.BaseModel { | @@ -164,10 +165,10 @@ class AdminModel extends global.yoho.BaseModel { | ||
164 | */ | 165 | */ |
165 | async createY100Article(actId, articleId, headUrl, imageUrl, index, name, tag, style, career, interest, skns, desc, | 166 | async createY100Article(actId, articleId, headUrl, imageUrl, index, name, tag, style, career, interest, skns, desc, |
166 | top, createTime) { | 167 | top, createTime) { |
167 | - let strSQL = `INSERT INTO ${TB_ACT_ARTICLE_Y100} | ||
168 | - (act_id, article_id, head_url, img_url, \`index\`, name, tag, style, career, interest, skns, \`desc\`, | ||
169 | - \`top\`, create_time) | ||
170 | - VALUES | 168 | + let strSQL = `INSERT INTO ${TB_ACT_ARTICLE_Y100} |
169 | + (act_id, article_id, head_url, img_url, \`index\`, name, tag, style, career, interest, skns, \`desc\`, | ||
170 | + \`top\`, create_time) | ||
171 | + VALUES | ||
171 | (:actId, :articleId, :headUrl, :imageUrl, :index, :name, :tag, :style, :career, :interest, :skns, :desc, | 172 | (:actId, :articleId, :headUrl, :imageUrl, :index, :name, :tag, :style, :career, :interest, :skns, :desc, |
172 | :top, :createTime);`; | 173 | :top, :createTime);`; |
173 | 174 | ||
@@ -206,8 +207,8 @@ class AdminModel extends global.yoho.BaseModel { | @@ -206,8 +207,8 @@ class AdminModel extends global.yoho.BaseModel { | ||
206 | page: _.parseInt(pageSize) | 207 | page: _.parseInt(pageSize) |
207 | }; | 208 | }; |
208 | let sql = ` | 209 | let sql = ` |
209 | - SELECT | ||
210 | - AA.id, | 210 | + SELECT |
211 | + AA.id, | ||
211 | AA.good_count, | 212 | AA.good_count, |
212 | AA.create_time, | 213 | AA.create_time, |
213 | AAY.name, | 214 | AAY.name, |
@@ -239,7 +240,7 @@ class AdminModel extends global.yoho.BaseModel { | @@ -239,7 +240,7 @@ class AdminModel extends global.yoho.BaseModel { | ||
239 | * @returns {Promise.<*>} | 240 | * @returns {Promise.<*>} |
240 | */ | 241 | */ |
241 | async getY100ArticleNums(actId) { | 242 | async getY100ArticleNums(actId) { |
242 | - let strSQL = `SELECT COUNT(*) AS total_count FROM ${TB_ACT_ARTICLE_Y100} | 243 | + let strSQL = `SELECT COUNT(*) AS total_count FROM ${TB_ACT_ARTICLE_Y100} |
243 | WHERE act_id = :actId;`; | 244 | WHERE act_id = :actId;`; |
244 | 245 | ||
245 | let params = { | 246 | let params = { |
@@ -258,7 +259,7 @@ class AdminModel extends global.yoho.BaseModel { | @@ -258,7 +259,7 @@ class AdminModel extends global.yoho.BaseModel { | ||
258 | */ | 259 | */ |
259 | createArticleImg(artId, imgUrl, createTime) { | 260 | createArticleImg(artId, imgUrl, createTime) { |
260 | return mysqlCli.insert( | 261 | return mysqlCli.insert( |
261 | - `insert into ${TB_ACT_ARTICLE_IMG} | 262 | + `insert into ${TB_ACT_ARTICLE_IMG} |
262 | (article_id, img_url, create_time) values (:artId, :imgUrl, :createTime);`, | 263 | (article_id, img_url, create_time) values (:artId, :imgUrl, :createTime);`, |
263 | { | 264 | { |
264 | artId, | 265 | artId, |
@@ -361,6 +362,14 @@ class AdminModel extends global.yoho.BaseModel { | @@ -361,6 +362,14 @@ class AdminModel extends global.yoho.BaseModel { | ||
361 | } | 362 | } |
362 | ); | 363 | ); |
363 | } | 364 | } |
365 | + | ||
366 | + getZerobuyList(page) { | ||
367 | + return this.ctx.req.ctx(zerobuyModel).getList(-1, page, { | ||
368 | + noCache: true | ||
369 | + }).then(result => { | ||
370 | + return result.data; | ||
371 | + }); | ||
372 | + } | ||
364 | } | 373 | } |
365 | 374 | ||
366 | module.exports = AdminModel; | 375 | module.exports = AdminModel; |
@@ -20,6 +20,7 @@ router.get('/activity/createArticle', activity.createArticlePage); | @@ -20,6 +20,7 @@ router.get('/activity/createArticle', activity.createArticlePage); | ||
20 | router.get('/activity/createY100Article', activity.createY100ArticlePage); | 20 | router.get('/activity/createY100Article', activity.createY100ArticlePage); |
21 | router.get('/activity/y100Article', activity.actY100ArticleListPage); | 21 | router.get('/activity/y100Article', activity.actY100ArticleListPage); |
22 | router.get('/activity/upload_excel', activity.uploadExcelPage); | 22 | router.get('/activity/upload_excel', activity.uploadExcelPage); |
23 | +router.get('/activity/zerobuy', activity.zeroBuyList); | ||
23 | 24 | ||
24 | // 用户管理[page] | 25 | // 用户管理[page] |
25 | router.get('/user/list', user.userListPage); | 26 | router.get('/user/list', user.userListPage); |
1 | +<!-- page content --> | ||
2 | +<div class="right_col" role="main"> | ||
3 | + <div class="col-md-12 col-sm-12 col-xs-12"> | ||
4 | + <div class="x_panel"> | ||
5 | + <table class="table table-bordered"> | ||
6 | + <thead> | ||
7 | + <tr class="headings"> | ||
8 | + <th width="7%" class="column-title text-center">活动ID</th> | ||
9 | + <th width="12%" class="clolumn-title text-center">商品名称</th> | ||
10 | + <th width="12%" class="column-title text-center">活动状态</th> | ||
11 | + <th width="10%" class="column-title text-center">活动有效时间</th> | ||
12 | + <th width="10%" class="column-title text-center">开奖需要人数</th> | ||
13 | + <th width="10%" class="column-title text-center">活动排序</th> | ||
14 | + <th width="20%" class="column-title text-center">封面图</th> | ||
15 | + <th width="29%" class="column-title text-center">操作</th> | ||
16 | + </tr> | ||
17 | + </thead> | ||
18 | + | ||
19 | + <tbody class="article-list"> | ||
20 | + </tbody> | ||
21 | + </table> | ||
22 | + <div class="table-pagination article-pagination pull-right"></div> | ||
23 | + </div> | ||
24 | + </div> | ||
25 | +</div> | ||
26 | +<!-- /page content --> |
-
Please register or login to post a comment