Authored by 陈峰

Merge branch 'feature/activity-image-upload' into 'master'

Feature/activity image upload

增加中奖用户管理

See merge request !22
... ... @@ -27,6 +27,7 @@ const userController = {
* @param res
*/
userListPage(req, res) {
res.render('user/list', {
bodyClass: 'nav-md',
module: 'admin',
... ... @@ -47,6 +48,14 @@ const userController = {
});
},
prizeUsersListPage(req, res) {
res.render('user/prize-users-list', {
bodyClass: 'nav-md',
module: 'admin',
page: 'prize-users-list'
});
},
/**
* 用户列表
* @param req
... ... @@ -126,6 +135,44 @@ const userController = {
},
/**
* 中奖用户列表
* @param req
* @param res
* @param next
*/
prizeUsersList(req, res, next) {
const pageNo = req.query.pageNo || 1;
const pageSize = req.query.pageSize || 20;
req.ctx(UserModel).prizeUsersList(pageNo, pageSize).then(list => {
let result = [];
_.each(list, item => {
let data = {};
_.each(item, (val, key) => {
data[camelcase(key)] = val;
});
result.push(data);
});
return result;
}).then(list => {
req.ctx(UserModel).allInfoUsersNum().then(totalCount => {
res.json({
code: 200,
data: list,
pageNo: +pageNo,
pageSize: +pageSize,
totalCount,
totalPage: Math.ceil(totalCount / pageSize),
message: GET_SUCCESS
});
});
}).catch(next);
},
/**
* 用户删除
* @param req
* @param res
... ... @@ -162,6 +209,23 @@ const userController = {
},
/**
* 抽奖用户删除
* @param req
* @param res
* @param next
*/
deletePrizeUsers(req, res, next) {
const userId = req.body.userId;
req.ctx(UserModel).deletePrizeUser(userId).then(() => {
res.json({
code: 200,
message: DO_SUCCESS
});
}).catch(next);
},
/**
* 用户列表导出
* @param req
* @param res
... ... @@ -258,8 +322,6 @@ const userController = {
_.each(result, item => {
temp = [];
console.log(item);
temp.push(item.id);
temp.push(item.user_name);
temp.push(moment(item.user_birthday).format('YYYY-MM-DD'));
... ... @@ -278,6 +340,55 @@ const userController = {
res.end(exportFile, 'binary');
}).catch(next);
},
exportPrizeUserList(req, res, next) {
let conf = {
name: 'myInfoSheet',
cols: [
{
caption: '用户ID',
type: 'number'
},
{
caption: '昵称',
type: 'string'
},
{
caption: '手机号',
type: 'string'
},
{
caption: '地址',
type: 'string'
},
{
caption: '鞋码',
type: 'number'
}
],
rows: []
};
req.ctx(UserModel).exportPrizeUserList().then(result => {
let temp = [];
_.each(result, item => {
temp = [];
temp.push(item.id);
temp.push(item.user_name);
temp.push(item.user_phone);
temp.push(item.user_address);
temp.push(item.user_shoes_size);
conf.rows.push(temp);
});
let exportFile = excelExport.execute(conf);
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader('Content-Disposition', 'attachment; filename=userInfoList.xlsx');
res.end(exportFile, 'binary');
}).catch(next);
},
userLoginLog(req, res) {
res.render('user/login-log', {
bodyClass: 'nav-md',
... ...
... ... @@ -10,6 +10,7 @@ const _ = require('lodash');
const TABLE_USER = 'user';
const TABLE_USER_INFO = 'act_user_detail_info';
const TABLE_USER_LOGIN_LOG = 'act_login_user_log';
const TABLE_USER_PRIZE_LOG = 'act_prize_user_log';
class UserModel extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -47,6 +48,20 @@ class UserModel extends global.yoho.BaseModel {
}
/**
* 中奖用户信息列表
*/
prizeUsersList(pageNo, pageSize) {
let strSql = `select * from ${TABLE_USER_PRIZE_LOG} where is_get = 1
order by create_time desc
limit :start, :page;`;
return mysqlCli.query(strSql, {
start: (pageNo - 1) * pageSize,
page: _.parseInt(pageSize)
});
}
/**
* 用户总数
* @returns {*}
*/
... ... @@ -71,6 +86,18 @@ class UserModel extends global.yoho.BaseModel {
}
/**
* 中奖用户总数
*/
allPrizeUsersNum() {
let strSql = `select count(*) as total from ${TABLE_USER_PRIZE_LOG} where is_get = 1;`;
return mysqlCli.query(strSql)
.then(res => {
return res[0].total;
});
}
/**
* 导出用户列表
* @returns {*}
*/
... ... @@ -91,6 +118,16 @@ class UserModel extends global.yoho.BaseModel {
}
/**
* 导出中奖用户列表
* @returns {*}
*/
exportPrizeUserList() {
return mysqlCli.query(
`select * from ${TABLE_USER_PRIZE_LOG} where is_get = 1;`
);
}
/**
* 用户删除
* @returns {*}
*/
... ... @@ -116,6 +153,19 @@ class UserModel extends global.yoho.BaseModel {
}
/**
* 中奖用户删除
* @param userId
* @returns {*}
*/
deletePrizeUser(userId) {
return mysqlCli.delete(
`delete from ${TABLE_USER_PRIZE_LOG} where id = :userId;`, {
userId
}
);
}
/**
* 导出用户登录日志
* @returns {*}
*/
... ...
... ... @@ -21,6 +21,7 @@ router.get('/activity/createArticle', activity.createArticlePage);
// 用户管理[page]
router.get('/user/list', user.userListPage);
router.get('/user/users_list', user.usersListPage);
router.get('/user/prize_users_list', user.prizeUsersListPage);
// 用户登录日志[page]
router.get('/user/login-log', user.userLoginLog);
... ... @@ -46,9 +47,12 @@ router.post('/api/activity/createArticle', activity.createArticle);
// 用户管理[ajax]
router.post('/api/user/delete', user.deleteUser);
router.post('/api/user/deleteInfoUser', user.deleteInfoUsers);
router.post('/api/user/deletePrizeUser', user.deletePrizeUsers);
router.get('/api/user/list', user.userList);
router.get('/api/user/users_list', user.usersList);
router.get('/api/user/prize_users_list', user.prizeUsersList);
router.get('/api/user/exportUserList', user.exportUserList);
router.get('/api/user/exportPrizeUserList', user.exportPrizeUserList);
router.get('/api/user/exportInfoUserList', user.exportInfoUserList);
module.exports = router;
... ...
<!-- 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-user-list" data-id="{{id}}">导出用户列表</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="10%" class="column-title">ID</th>
<th width="15%" class="column-title">昵称</th>
<th width="15%" class="column-title">手机号</th>
<th width="30%" class="column-title">地址</th>
<th width="10%" class="column-title">鞋码</th>
<th width="20%" class="column-title">操作</th>
</tr>
</thead>
<tbody class="user-list">
</tbody>
</table>
</div>
<div class="table-pagination user-pagination pull-right"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /page content -->
... ...
... ... @@ -57,6 +57,7 @@
<ul class="nav child_menu">
<li><a href="/admin/user/list">用户列表</a></li>
<li><a href="/admin/user/users_list">用户信息收集</a></li>
<li><a href="/admin/user/prize_users_list">中奖用户信息</a></li>
<li><a href="/admin/user/login-log">用户登录日志</a></li>
</ul>
</li>
... ...
require('admin/user.page.css');
require('bootpag/lib/jquery.bootpag.min');
const _ = require('lodash');
const moment = require('moment');
function bind_delete_user() {
const deleteFn = function() {
const userId = $(this).data('id');
$.ajax({
method: 'post',
url: '/admin/api/user/deletePrizeUser',
data: {
userId
}
})
.then(() => {
location.reload();
});
};
$(document).on('click', '.btn-delete-user', deleteFn);
}
function bind_export_user_list() {
const exportFn = function() {
window.open('/admin/api/user/exportPrizeUserList', '_blank');
};
$('.btn-export-user-list').on('click', exportFn);
}
function bind_table_pagination() {
const $ul = $('.user-list');
const $up = $('.user-pagination');
const fetchRender = (pageNo, pageSize) => {
$.ajax({
url: '/admin/api/user/prize_users_list',
data: {
pageNo,
pageSize
}
})
.then(result => {
console.log(result);
const list = result.data;
const totalPage = result.totalPage;
let html = '';
_.each(list, item => {
item.userBirthday = moment(item.userBirthday).format('YYYY-MM-DD');
item.userGender = ['男', '女'][item.userGender];
html += `
<tr class="even pointer">
<td class="">${item.id}</td>
<td class="">${item.userName}</td>
<td class="">${item.userPhone}</td>
<td class="">${item.userAddress}</td>
<td class="">${item.userShoesSize}</td>
<td class="">
<button class="btn btn-danger btn-delete-user" data-id="${item.id}">删除用户
</button>
</td>
</tr>`;
});
$ul.html(html);
if (pageNo === 1) {
$up.bootpag({
total: totalPage,
page: 1,
maxVisible: 10,
}).on('page', function(event, num) {
fetchRender(num, 20);
});
}
});
};
fetchRender(1, 20);
}
(function() {
bind_delete_user();
bind_export_user_list();
bind_table_pagination();
}());
... ...