Authored by yyq

save

... ... @@ -7,17 +7,13 @@ const zerobuyModel = require('../models/zero-buy');
module.exports = {
list(req, res, next) {
if (req.isAdmin) {
req.query.noCache = true;
}
req.query.noCache = false;
req.ctx(zerobuyModel).getList(req.query.status, req.query.page, req.query)
.then(res.json).catch(next);
},
content(req, res, next) {
if (req.isAdmin) {
req.query.noCache = true;
}
req.query.noCache = false;
req.ctx(zerobuyModel).getContent(req.query.actPrizeId, req.query)
.then(res.json).catch(next);
... ... @@ -40,6 +36,10 @@ module.exports = {
req.ctx(zerobuyModel).getCodeMine(uid, actPrizeId)
.then(res.json).catch(next);
},
joinNum(req, res, next) {
req.ctx(zerobuyModel).getUserJoinNum(req.query.actPrizeId)
.then(res.json).catch(next);
},
codeGain(req, res, next) {
let params = req.body;
... ... @@ -50,7 +50,7 @@ module.exports = {
});
}
req.ctx(zerobuyModel).getPrizeCode(req.query)
req.ctx(zerobuyModel).getPrizeCode(params.uid, params.actPrizeId, params)
.then(res.json).catch(next);
}
};
... ...
... ... @@ -58,12 +58,19 @@ module.exports = class extends global.yoho.BaseModel {
status = parseInt(status, 10);
page = parseInt(page, 10) || 1;
status = _.isNaN(status) ? '> 0' : `= ${status}`;
if (_.isNaN(status)) {
status = '> 0';
} else if (status < 0) {
status = '>= 0';
} else {
status = `= ${status}`;
}
let limit = `${(page - 1) * pageSize},${page * pageSize}`;
return mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
where act_id = :actId and status ${status} limit ${limit}`, {
where act_id = :actId and status ${status}
order by sort desc limit ${limit}`, {
actId
}, {
cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES
... ... @@ -103,7 +110,8 @@ module.exports = class extends global.yoho.BaseModel {
actPrizeId = parseInt(actPrizeId, 10) || 0;
return mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
where act_id = :actId and id > :actPrizeId and status > 0 limit 5`, {
where act_id = :actId and id > :actPrizeId and status > 0
order by sort desc limit 5`, {
actId,
actPrizeId: actPrizeId - 3
}, {
... ... @@ -183,6 +191,21 @@ module.exports = class extends global.yoho.BaseModel {
}
/**
* 0元购单个活动参与人数
* @param actPrizeId
* @param noCache
* @returns {*}
*/
getUserJoinNum(actPrizeId, noCache) {
return mysqlCli.query(`select count(distinct uid) as join_num from ${TABLE_ACT_PRIZE_PRODUCT_USER}
where act_prize_id = :actPrizeId;`, {
actPrizeId
}, {
cache: noCache ? 0 : MINUTE_TIMES / 6
}).then(handelResult);
}
/**
* 0元购获取抽奖码
* @param uid
* @param actPrizeId
... ... @@ -195,8 +218,9 @@ module.exports = class extends global.yoho.BaseModel {
let info = await Promise.all([
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
where id = :actPrizeId limit 1;`, {actPrizeId}, {cache: MINUTE_TIMES / 2}),
mysqlCli.query(`select count(distinct uid) as join_num from ${TABLE_ACT_PRIZE_PRODUCT_USER}
where act_prize_id = :actPrizeId;`, {actPrizeId})
this.getUserJoinNum(actPrizeId, true).then(result => {
return result.data;
})
]);
const errorData = {
... ...
... ... @@ -21,8 +21,9 @@ router.get('/zerobuy/list', zeroBuy.list); // 0元购活动列表
router.get('/zerobuy/list/mine', zeroBuy.listMine); // 0元购用户参与列表
router.get('/zerobuy/list/recommend', zeroBuy.listRecommend); // 0元购活动推荐列表
router.get('/zerobuy/content', zeroBuy.content); // 0元购详情
router.get('/zerobuy/join/sum', zeroBuy.joinNum); // 0元购抽奖码最近获取记录
router.get('/zerobuy/code/recent', zeroBuy.codeRecent); // 0元购抽奖码最近获取记录
router.get('/zerobuy/code/mine', zeroBuy.codeMine); // 0元购用户单个活动抽奖码
router.get('/zerobuy/code/mine', zeroBuy.codeMine); // 0元购用户单个活动获取的抽奖码
router.post('/zerobuy/code/gain', zeroBuy.codeGain); // 0元购获取抽奖码
module.exports = router;
... ...
... ... @@ -21,6 +21,19 @@ const timeFormat = (time) => {
return moment(time).format('YYYY-MM-DD HH:mm:ss');
};
const zeroBuy = {
zeroBuyList(req, res, next) {
req.ctx(ActivityModel).getZerobuyList().then(result => {
res.render('activity/zero-buy-list', {
bodyClass: 'nav-md',
list: result,
module: 'admin',
page: 'activity'
});
}).catch(next);
}
};
const activity = {
/**
* 活动列表
... ... @@ -550,7 +563,8 @@ const activity = {
})
.catch(next);
}
},
...zeroBuy
};
... ...
... ... @@ -6,6 +6,7 @@
const mysqlCli = global.yoho.utils.mysqlCli;
const _ = require('lodash');
const zerobuyModel = require('../../activity/models/zero-buy');
const TB_USER = 'user';
const TB_ACTIVITY = 'activity';
... ... @@ -28,7 +29,7 @@ class AdminModel extends global.yoho.BaseModel {
*/
createActivity({title, startTime, endTime, repeat_limit, vote_limit}) {
return mysqlCli.insert(
`insert into ${TB_ACTIVITY} (title, start_time, end_time, repeat_limit, vote_limit)
`insert into ${TB_ACTIVITY} (title, start_time, end_time, repeat_limit, vote_limit)
values (:title, :startTime, :endTime, :repeat_limit, :vote_limit);`,
{
title,
... ... @@ -46,7 +47,7 @@ class AdminModel extends global.yoho.BaseModel {
*/
activityList() {
return mysqlCli.query(
`select id, title, start_time startTime, end_time endTime, create_time createTime,
`select id, title, start_time startTime, end_time endTime, create_time createTime,
repeat_limit repeatLimit, vote_limit voteLimit from ${TB_ACTIVITY};`
);
}
... ... @@ -78,12 +79,12 @@ class AdminModel extends global.yoho.BaseModel {
return mysqlCli.query(
`select taa.id, taai.img_url imgUrl, taa.content, taa.create_time createTime, taa.good_count goodCount,
taa.user_name userName, tu.user_phone phone
taa.user_name userName, tu.user_phone phone
from ${TB_ACT_ARTICLE} taa
left join ${TB_USER} tu
on taa.user_id = tu.id
left join ${TB_ACT_ARTICLE_IMG} taai
on taai.article_id = taa.id
on taa.user_id = tu.id
left join ${TB_ACT_ARTICLE_IMG} taai
on taai.article_id = taa.id
where act_id = :actId
${orderSql} ${limitSql};`, {
actId,
... ... @@ -101,10 +102,10 @@ class AdminModel extends global.yoho.BaseModel {
exportActArticleList(actId) {
return mysqlCli.query(
`select taa.id, taa.content, taa.create_time createTime, taa.good_count goodCount,
tu.user_name userName, tu.user_phone phone
tu.user_name userName, tu.user_phone phone
from ${TB_ACT_ARTICLE} taa
left join ${TB_USER} tu
on taa.user_id = tu.id
on taa.user_id = tu.id
where act_id = :actId;`, {
actId
}
... ... @@ -132,8 +133,8 @@ class AdminModel extends global.yoho.BaseModel {
*/
async createArticle({actId, userName, content, createTime}) {
return mysqlCli.insert(
`insert into ${TB_ACT_ARTICLE}
(act_id, user_name, content, create_time) values
`insert into ${TB_ACT_ARTICLE}
(act_id, user_name, content, create_time) values
(:actId, :userName, :content, :createTime);`,
{
actId,
... ... @@ -164,10 +165,10 @@ class AdminModel extends global.yoho.BaseModel {
*/
async createY100Article(actId, articleId, headUrl, imageUrl, index, name, tag, style, career, interest, skns, desc,
top, createTime) {
let strSQL = `INSERT INTO ${TB_ACT_ARTICLE_Y100}
(act_id, article_id, head_url, img_url, \`index\`, name, tag, style, career, interest, skns, \`desc\`,
\`top\`, create_time)
VALUES
let strSQL = `INSERT INTO ${TB_ACT_ARTICLE_Y100}
(act_id, article_id, head_url, img_url, \`index\`, name, tag, style, career, interest, skns, \`desc\`,
\`top\`, create_time)
VALUES
(:actId, :articleId, :headUrl, :imageUrl, :index, :name, :tag, :style, :career, :interest, :skns, :desc,
:top, :createTime);`;
... ... @@ -206,8 +207,8 @@ class AdminModel extends global.yoho.BaseModel {
page: _.parseInt(pageSize)
};
let sql = `
SELECT
AA.id,
SELECT
AA.id,
AA.good_count,
AA.create_time,
AAY.name,
... ... @@ -239,7 +240,7 @@ class AdminModel extends global.yoho.BaseModel {
* @returns {Promise.<*>}
*/
async getY100ArticleNums(actId) {
let strSQL = `SELECT COUNT(*) AS total_count FROM ${TB_ACT_ARTICLE_Y100}
let strSQL = `SELECT COUNT(*) AS total_count FROM ${TB_ACT_ARTICLE_Y100}
WHERE act_id = :actId;`;
let params = {
... ... @@ -258,7 +259,7 @@ class AdminModel extends global.yoho.BaseModel {
*/
createArticleImg(artId, imgUrl, createTime) {
return mysqlCli.insert(
`insert into ${TB_ACT_ARTICLE_IMG}
`insert into ${TB_ACT_ARTICLE_IMG}
(article_id, img_url, create_time) values (:artId, :imgUrl, :createTime);`,
{
artId,
... ... @@ -361,6 +362,14 @@ class AdminModel extends global.yoho.BaseModel {
}
);
}
getZerobuyList(page) {
return this.ctx.req.ctx(zerobuyModel).getList(-1, page, {
noCache: true
}).then(result => {
return result.data;
});
}
}
module.exports = AdminModel;
... ...
... ... @@ -20,6 +20,7 @@ router.get('/activity/createArticle', activity.createArticlePage);
router.get('/activity/createY100Article', activity.createY100ArticlePage);
router.get('/activity/y100Article', activity.actY100ArticleListPage);
router.get('/activity/upload_excel', activity.uploadExcelPage);
router.get('/activity/zerobuy', activity.zeroBuyList);
// 用户管理[page]
router.get('/user/list', user.userListPage);
... ...
<!-- page content -->
<div class="right_col" role="main">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<table class="table table-bordered">
<thead>
<tr class="headings">
<th width="7%" class="column-title text-center">活动ID</th>
<th width="12%" class="clolumn-title text-center">商品名称</th>
<th width="12%" class="column-title text-center">活动状态</th>
<th width="10%" class="column-title text-center">活动有效时间</th>
<th width="10%" class="column-title text-center">开奖需要人数</th>
<th width="10%" class="column-title text-center">活动排序</th>
<th width="20%" class="column-title text-center">封面图</th>
<th width="29%" class="column-title text-center">操作</th>
</tr>
</thead>
<tbody class="article-list">
</tbody>
</table>
<div class="table-pagination article-pagination pull-right"></div>
</div>
</div>
</div>
<!-- /page content -->
... ...