Authored by 李奇

文章列表修改

... ... @@ -10,6 +10,14 @@ const AdminModel = require('../models/admin');
const POST_SUCCESS = '操作成功';
const INVALID_PARAMS = '参数错误';
const timeFormat = (time) => {
if (_.isNumber(time)) {
time = moment.unix(time);
}
return moment(time).format('YYYY-MM-DD HH:mm:ss');
};
const article = {
/**
* 首页
... ... @@ -124,20 +132,14 @@ const article = {
* @param next
*/
activityListPage(req, res, next) {
const _timeFormat = (time) => {
if (_.isNumber(time)) {
time = moment.unix(time);
}
return moment(time).format('YYYY-MM-DD HH:mm:ss');
};
req.ctx(AdminModel).activityList()
.then(result => {
_.each(result, item => {
item.endTime = _timeFormat(item.endTime);
item.startTime = _timeFormat(item.startTime);
item.createTime = _timeFormat(item.createTime);
item.endTime = timeFormat(item.endTime);
item.startTime = timeFormat(item.startTime);
item.createTime = timeFormat(item.createTime);
});
res.render('activity/list', {
... ... @@ -234,6 +236,9 @@ const article = {
req.ctx(AdminModel).actArticleList(actId)
.then(result => {
_.each(result, item => {
item.createTime = timeFormat(item.createTime);
});
res.render('activity/article-list', {
bodyClass: 'nav-md',
articleList: result,
... ...
... ... @@ -63,7 +63,8 @@ class AdminModel extends global.yoho.BaseModel {
*/
actArticleList(actId) {
return mysqlCli.query(
`select taa.id, taa.content, taa.good_count goodCount, tu.user_name userName
`select taa.id, taa.create_time createTime, taa.good_count goodCount,
tu.user_name userName, tu.user_phone phone
from ${TABLE_ACT_ARTICLE} taa
inner join ${TABLE_USER} tu
on taa.user_id = tu.id
... ...
... ... @@ -15,9 +15,10 @@
<thead>
<tr class="headings">
<th class="column-title">文章ID</th>
<th class="column-title">文章内容</th>
<th class="column-title">文章赞数</th>
<th class="column-title">文章发布者</th>
<th class="column-title">赞数</th>
<th class="column-title">发布者</th>
<th class="column-title">手机号</th>
<th class="column-title">创建时间</th>
<th class="column-title">操作</th>
</tr>
</thead>
... ... @@ -26,9 +27,10 @@
{{#each articleList}}
<tr class="even pointer">
<td>{{id}}</td>
<td>{{content}}</td>
<td>{{goodCount}}</td>
<td>{{userName}}</td>
<td>{{phone}}</td>
<td>{{createTime}}</td>
<td>
<button class="btn btn-danger btn-delete-article" data-id="{{id}}">删除文章
</button>
... ...
... ... @@ -159,7 +159,7 @@ class ArticleModel extends global.yoho.BaseModel {
*/
insertLikeDetail(actId, articleId) {
const userId = _.get(this.ctx.req.session, 'user.id', 0);
const ip = this.header['X-Forwarded-For'] || this.ctx.req.connection.remoteAddress;
const ip = this.header['X-Forwarded-For'] || this.ctx.req.ip || this.ctx.req.connection.remoteAddress;
return mysqlCli.insert(
`INSERT INTO ${TABLE_ACT_ARTICLE_GOOD} (act_id, article_id, user_id, ip)
... ...