Authored by 邱骏

y100管理后台

... ... @@ -182,6 +182,22 @@ const activity = {
});
},
/**
* Y100活动文章列表页面
* @param req
* @param res
*/
actY100ArticleListPage(req, res) {
const actId = req.query.actId;
res.render('activity/article-y100-list', {
actId,
bodyClass: 'nav-md',
module: 'admin',
page: 'activity'
});
},
/**
* 活动文章创建
... ... @@ -202,6 +218,24 @@ const activity = {
},
/**
* y100活动文章创建页面
* @param req
* @param res
*/
createY100ArticlePage(req, res) {
const actId = req.query.actId;
let date = new Date();
res.render('activity/create-y100-article', {
actId,
date: moment(date.getTime()).format('YYYY-MM-DD HH:mm:ss'),
bodyClass: 'nav-md',
module: 'admin',
page: 'activity'
});
},
/**
* 活动文章创建
* @param req
* @param res
... ... @@ -232,6 +266,64 @@ const activity = {
},
/**
* 创建Y100文章
* @param req
* @param res
* @param next
*/
async createY100Article(req, res, next) {
const {
actId,
content = '',
imgUrl,
createTime = moment().format('YYYY-MM-DD hh:mm:ss'),
career,
interest,
name = '',
style,
tag,
skns
} = req.body;
if (!actId || !imgUrl || !career || !interest || !name || !style || !tag || !skns) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
try {
// 先创建一个普通文章
const articleId = await req.ctx(ActivityModel).createArticle({
actId,
name,
content,
createTime
});
// 获取到目前y100文章的总数
const numResult = await req.ctx(ActivityModel).getY100ArticleNums(actId);
// 向y100表中插入一条新记录
const y100ArticleId = await req.ctx(ActivityModel).createY100Article(
actId, articleId, imgUrl, numResult[0].total_count + 1, name, tag, style, career, skns, createTime
);
return res.json({
code: 200,
data: y100ArticleId
});
} catch (err) {
console.log(err);
return next(err);
}
},
/**
* 活动文章列表
* @param req
* @param res
... ... @@ -272,6 +364,34 @@ const activity = {
},
/**
* y100活动文章列表
* @param req
* @param res
* @param next
* @returns {Promise.<void>}
*/
async actY100ArticleList(req, res, next) {
const {
actId,
pageNo = 1,
pageSize = 20
} = req.query;
try {
const result = await req.ctx(ActivityModel).y100ArticleList(actId, pageNo, pageSize);
return res.json({
code: 200,
data: result
});
} catch (err) {
return next(err);
}
},
/**
* 删除文章
* @param req
* @param res
... ...
... ... @@ -12,6 +12,7 @@ const TB_ACTIVITY = 'activity';
const TB_ACT_ARTICLE = 'act_article';
const TB_ACT_ARTICLE_IMG = 'act_article_img';
const TB_ACT_ARTICLE_GOOD = 'act_article_good';
const TB_ACT_ARTICLE_Y100 = 'act_article_y100';
class AdminModel extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -144,6 +145,90 @@ class AdminModel extends global.yoho.BaseModel {
}
/**
* 创建Y100文章
* @param actId
* @param articleId
* @param imageUrl
* @param index
* @param name
* @param tag
* @param style
* @param career
* @param skns
* @param createTime
* @returns {Promise.<*>}
*/
async createY100Article(actId, articleId, imageUrl, index, name, tag, style, career, skns, createTime) {
let strSQL = `INSERT INTO ${TB_ACT_ARTICLE_Y100}
(act_id, article_id, img_url, \`index\`, name, tag, style, career, skns, create_time)
VALUES
(:actId, :articleId, :imageUrl, :index, :name, :tag, :style, :career, :skns, :createTime);`;
console.log(strSQL, {actId, articleId, imageUrl, index, name, tag, style, career, skns, createTime});
return mysqlCli.insert(strSQL, {
actId,
articleId,
imageUrl,
index,
name,
tag,
style,
career,
skns,
createTime
});
}
/**
* Y100文章列表
* @param actId
* @param pageNo
* @param pageSize
* @param tag
* @returns {Promise.<*>}
*/
async y100ArticleList(actId, pageNo, pageSize) {
const params = {
actId,
start: (pageNo - 1) * pageSize,
page: _.parseInt(pageSize)
};
let sql = `
SELECT
AA.id,
AA.good_count,
AA.create_time,
AAY.name,
AAY.img_url
FROM ${TB_ACT_ARTICLE} AA
INNER JOIN ${TB_ACT_ARTICLE_Y100} AAY ON AA.id = AAY.article_id
WHERE AA.act_id = :actId`;
sql += ' ORDER BY AA.create_time DESC';
sql += ' LIMIT :start, :page';
return mysqlCli.query(sql, params);
}
/**
* 获取Y100文章总数
* @param actId
* @returns {Promise.<*>}
*/
async getY100ArticleNums(actId) {
let strSQL = `SELECT COUNT(*) AS total_count FROM ${TB_ACT_ARTICLE_Y100}
WHERE act_id = :actId;`;
let params = {
actId: actId
};
return mysqlCli.query(strSQL, params);
}
/**
* 创建文章图片
* @param id 文章ID
* @returns {*}
... ...
... ... @@ -17,6 +17,8 @@ router.get('/activity/list', activity.activityListPage);
router.get('/activity/create', activity.createActivityPage);
router.get('/activity/article', activity.actArticleListPage);
router.get('/activity/createArticle', activity.createArticlePage);
router.get('/activity/createY100Article', activity.createY100ArticlePage);
router.get('/activity/y100Article', activity.actY100ArticleListPage);
// 用户管理[page]
router.get('/user/list', user.userListPage);
... ... @@ -38,10 +40,13 @@ router.post('/api/activity/create', activity.createActivity);
router.post('/api/activity/delete', activity.deleteActivity);
router.get('/api/activity/article', activity.actArticleList);
router.get('/api/activity/y100Article', activity.actY100ArticleList);
router.post('/api/activity/deleteArticle', activity.deleteArticle);
router.post('/api/activity/modifyArticle', activity.modifyArticle);
router.get('/api/activity/exportArticleList', activity.exportArticleList);
router.post('/api/activity/createArticle', activity.createArticle);
router.post('/api/activity/createY100Article', activity.createY100Article);
// 用户管理[ajax]
... ...
<!-- page content -->
<div class="right_col" role="main">
<div class="">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<button class="btn btn-primary btn-export-article" style="display: none;" data-id="{{actId}}" data-type="y100">导出文章列表</button>
<div class="clearfix"></div>
</div>
<div class="x_content">
<div class="table-responsive">
<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="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>
<div class="table-pagination article-pagination pull-right"></div>
</div>
</div>
</div>
</div>
<div class="msg_container">
</div>
</div>
</div>
<!-- /page content -->
... ...
<!-- page content -->
<div class="right_col" role="main">
<div class="">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>y100文章创建</h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<form id="createArticleForm" class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">姓名<span
class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="name" required="required"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">内容<span
class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="content" required="required"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">职业<span
class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="career" required="required"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">爱好<span
class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="interest" required="required"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">风格<span
class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="style" required="required"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">标签<span
class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="tag" required="required"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">推荐商品<span
class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="skns" required="required"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">图片<span
class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="upload-box form-control" >
<a id="browser-btn">+上传图片</a>
<div class="img-preview">
<span class="delete">x</span>
<img src="">
</div>
<input type="hidden" name="imgUrl">
<input type="hidden" name="actId" value="{{actId}}">
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">创建时间
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="createTime" required="required"
class="form-control col-md-7 col-xs-12" value="{{date}}">
</div>
</div>
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<button type="button" class="btn btn-success article-create-btn-y100">创建</button>
</div>
</div>
</form>
<p style="color: red;text-align: center;" id="message"></p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /page content -->
... ...
... ... @@ -36,8 +36,10 @@
<td class="text-center">{{createTime}}</td>
<td class="text-center">
<a class="btn btn-info" href="/admin/activity/article?actId={{id}}">文章列表</a>
<a class="btn btn-info" href="/admin/activity/y100Article?actId={{id}}">y100文章列表</a>
<a class="btn btn-primary" href="/admin/activity/createArticle?actId={{id}}">
创建文章</a>
<a class="btn btn-primary" href="/admin/activity/createY100Article?actId={{id}}">创建y100文章</a>
<button class="btn btn-danger btn-delete" data-id="{{id}}">删除活动
</button>
</td>
... ...
... ... @@ -480,7 +480,7 @@ class ArticleModel extends global.yoho.BaseModel {
* 获取Y100列表
* @returns {*}
*/
articleY100List({actId, pageNo, pageSize, tag}) {
async articleY100List({actId, pageNo, pageSize, tag}) {
const params = {
actId,
start: (pageNo - 1) * pageSize,
... ...
... ... @@ -186,10 +186,13 @@ function bind_table_pagination() {
const $al = $('.article-list');
const $ap = $('.article-pagination');
const actId = $('.btn-export-article').data('id');
const type = $('.btn-export-article').data('type') || '';
let url = type === 'y100' ? '/admin/api/activity/y100Article' : '/admin/api/activity/article';
const fetchRender = (pageNo, pageSize) => {
$.ajax({
url: '/admin/api/activity/article',
url: url,
data: {
actId,
pageNo,
... ... @@ -197,12 +200,27 @@ function bind_table_pagination() {
}
})
.then(result => {
console.log(result);
const list = result.data;
const totalPage = result.totalPage;
let html = '';
_.each(list, item => {
if (type === 'y100') {
html += `
<tr class="even pointer">
<td>${item.id}</td>
<td><img src="${item.img_url}" style="width: 100px"></td>
<td><input id="${('txt_goodCount' + item.id)}" type="text" value="${item.good_count}"></td>
<td>${item.name || '-'}</td>
<td>${item.create_time}</td>
<td>
<button class="btn btn-danger btn-delete-article" data-id="${item.id}">删除文章</button>
<button class="btn btn-warning btn-modify-article" data-id="${item.id}">修改赞数</button>
</td>
</tr>`;
} else {
html += `
<tr class="even pointer">
<td>${item.id}</td>
... ... @@ -217,6 +235,8 @@ function bind_table_pagination() {
<button class="btn btn-warning btn-modify-article" data-id="${item.id}">修改赞数</button>
</td>
</tr>`;
}
});
$al.html(html);
... ... @@ -336,6 +356,37 @@ function bind_qiniu_upload() {
}
});
$('.article-create-btn-y100').on('click', function() {
let $form = $('#createArticleForm');
let userName = $form[0].name.value;
let content = $form[0].content.value;
let career = $form[0].career.value;
let interest = $form[0].interest.value;
let style = $form[0].style.value;
let tag = $form[0].tag.value;
let skns = $form[0].skns.value;
let imgUrl = $form[0].imgUrl.value;
let actId = $form[0].actId.value;
let createTime = $form[0].createTime.value;
console.log(userName, content, career, interest, style, tag, skns, imgUrl, actId, createTime);
if (!userName || !imgUrl || !actId) {
$('#messages').text('请填写完整信息');
} else {
$('#message').text('');
$.ajax({
method: 'post',
url: '/admin/api/activity/createY100Article',
data: $form.serialize()
}).then(res => {
console.log(res);
location.reload();
});
}
});
}
... ...