Authored by 陈峰

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

Feature/activity image upload

增加中奖用户管理

See merge request !22
@@ -27,6 +27,7 @@ const userController = { @@ -27,6 +27,7 @@ const userController = {
27 * @param res 27 * @param res
28 */ 28 */
29 userListPage(req, res) { 29 userListPage(req, res) {
  30 +
30 res.render('user/list', { 31 res.render('user/list', {
31 bodyClass: 'nav-md', 32 bodyClass: 'nav-md',
32 module: 'admin', 33 module: 'admin',
@@ -47,6 +48,14 @@ const userController = { @@ -47,6 +48,14 @@ const userController = {
47 }); 48 });
48 }, 49 },
49 50
  51 + prizeUsersListPage(req, res) {
  52 + res.render('user/prize-users-list', {
  53 + bodyClass: 'nav-md',
  54 + module: 'admin',
  55 + page: 'prize-users-list'
  56 + });
  57 + },
  58 +
50 /** 59 /**
51 * 用户列表 60 * 用户列表
52 * @param req 61 * @param req
@@ -126,6 +135,44 @@ const userController = { @@ -126,6 +135,44 @@ const userController = {
126 }, 135 },
127 136
128 /** 137 /**
  138 + * 中奖用户列表
  139 + * @param req
  140 + * @param res
  141 + * @param next
  142 + */
  143 + prizeUsersList(req, res, next) {
  144 + const pageNo = req.query.pageNo || 1;
  145 + const pageSize = req.query.pageSize || 20;
  146 +
  147 + req.ctx(UserModel).prizeUsersList(pageNo, pageSize).then(list => {
  148 +
  149 + let result = [];
  150 +
  151 + _.each(list, item => {
  152 + let data = {};
  153 +
  154 + _.each(item, (val, key) => {
  155 + data[camelcase(key)] = val;
  156 + });
  157 + result.push(data);
  158 + });
  159 + return result;
  160 + }).then(list => {
  161 + req.ctx(UserModel).allInfoUsersNum().then(totalCount => {
  162 + res.json({
  163 + code: 200,
  164 + data: list,
  165 + pageNo: +pageNo,
  166 + pageSize: +pageSize,
  167 + totalCount,
  168 + totalPage: Math.ceil(totalCount / pageSize),
  169 + message: GET_SUCCESS
  170 + });
  171 + });
  172 + }).catch(next);
  173 + },
  174 +
  175 + /**
129 * 用户删除 176 * 用户删除
130 * @param req 177 * @param req
131 * @param res 178 * @param res
@@ -162,6 +209,23 @@ const userController = { @@ -162,6 +209,23 @@ const userController = {
162 }, 209 },
163 210
164 /** 211 /**
  212 + * 抽奖用户删除
  213 + * @param req
  214 + * @param res
  215 + * @param next
  216 + */
  217 + deletePrizeUsers(req, res, next) {
  218 + const userId = req.body.userId;
  219 +
  220 + req.ctx(UserModel).deletePrizeUser(userId).then(() => {
  221 + res.json({
  222 + code: 200,
  223 + message: DO_SUCCESS
  224 + });
  225 + }).catch(next);
  226 + },
  227 +
  228 + /**
165 * 用户列表导出 229 * 用户列表导出
166 * @param req 230 * @param req
167 * @param res 231 * @param res
@@ -258,8 +322,6 @@ const userController = { @@ -258,8 +322,6 @@ const userController = {
258 _.each(result, item => { 322 _.each(result, item => {
259 temp = []; 323 temp = [];
260 324
261 - console.log(item);  
262 -  
263 temp.push(item.id); 325 temp.push(item.id);
264 temp.push(item.user_name); 326 temp.push(item.user_name);
265 temp.push(moment(item.user_birthday).format('YYYY-MM-DD')); 327 temp.push(moment(item.user_birthday).format('YYYY-MM-DD'));
@@ -278,6 +340,55 @@ const userController = { @@ -278,6 +340,55 @@ const userController = {
278 res.end(exportFile, 'binary'); 340 res.end(exportFile, 'binary');
279 }).catch(next); 341 }).catch(next);
280 }, 342 },
  343 + exportPrizeUserList(req, res, next) {
  344 + let conf = {
  345 + name: 'myInfoSheet',
  346 + cols: [
  347 + {
  348 + caption: '用户ID',
  349 + type: 'number'
  350 + },
  351 + {
  352 + caption: '昵称',
  353 + type: 'string'
  354 + },
  355 + {
  356 + caption: '手机号',
  357 + type: 'string'
  358 + },
  359 + {
  360 + caption: '地址',
  361 + type: 'string'
  362 + },
  363 + {
  364 + caption: '鞋码',
  365 + type: 'number'
  366 + }
  367 + ],
  368 + rows: []
  369 + };
  370 +
  371 + req.ctx(UserModel).exportPrizeUserList().then(result => {
  372 + let temp = [];
  373 +
  374 + _.each(result, item => {
  375 + temp = [];
  376 +
  377 + temp.push(item.id);
  378 + temp.push(item.user_name);
  379 + temp.push(item.user_phone);
  380 + temp.push(item.user_address);
  381 + temp.push(item.user_shoes_size);
  382 + conf.rows.push(temp);
  383 + });
  384 +
  385 + let exportFile = excelExport.execute(conf);
  386 +
  387 + res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  388 + res.setHeader('Content-Disposition', 'attachment; filename=userInfoList.xlsx');
  389 + res.end(exportFile, 'binary');
  390 + }).catch(next);
  391 + },
281 userLoginLog(req, res) { 392 userLoginLog(req, res) {
282 res.render('user/login-log', { 393 res.render('user/login-log', {
283 bodyClass: 'nav-md', 394 bodyClass: 'nav-md',
@@ -10,6 +10,7 @@ const _ = require('lodash'); @@ -10,6 +10,7 @@ const _ = require('lodash');
10 const TABLE_USER = 'user'; 10 const TABLE_USER = 'user';
11 const TABLE_USER_INFO = 'act_user_detail_info'; 11 const TABLE_USER_INFO = 'act_user_detail_info';
12 const TABLE_USER_LOGIN_LOG = 'act_login_user_log'; 12 const TABLE_USER_LOGIN_LOG = 'act_login_user_log';
  13 +const TABLE_USER_PRIZE_LOG = 'act_prize_user_log';
13 14
14 class UserModel extends global.yoho.BaseModel { 15 class UserModel extends global.yoho.BaseModel {
15 constructor(ctx) { 16 constructor(ctx) {
@@ -47,6 +48,20 @@ class UserModel extends global.yoho.BaseModel { @@ -47,6 +48,20 @@ class UserModel extends global.yoho.BaseModel {
47 } 48 }
48 49
49 /** 50 /**
  51 + * 中奖用户信息列表
  52 + */
  53 + prizeUsersList(pageNo, pageSize) {
  54 + let strSql = `select * from ${TABLE_USER_PRIZE_LOG} where is_get = 1
  55 + order by create_time desc
  56 + limit :start, :page;`;
  57 +
  58 + return mysqlCli.query(strSql, {
  59 + start: (pageNo - 1) * pageSize,
  60 + page: _.parseInt(pageSize)
  61 + });
  62 + }
  63 +
  64 + /**
50 * 用户总数 65 * 用户总数
51 * @returns {*} 66 * @returns {*}
52 */ 67 */
@@ -71,6 +86,18 @@ class UserModel extends global.yoho.BaseModel { @@ -71,6 +86,18 @@ class UserModel extends global.yoho.BaseModel {
71 } 86 }
72 87
73 /** 88 /**
  89 + * 中奖用户总数
  90 + */
  91 + allPrizeUsersNum() {
  92 + let strSql = `select count(*) as total from ${TABLE_USER_PRIZE_LOG} where is_get = 1;`;
  93 +
  94 + return mysqlCli.query(strSql)
  95 + .then(res => {
  96 + return res[0].total;
  97 + });
  98 + }
  99 +
  100 + /**
74 * 导出用户列表 101 * 导出用户列表
75 * @returns {*} 102 * @returns {*}
76 */ 103 */
@@ -91,6 +118,16 @@ class UserModel extends global.yoho.BaseModel { @@ -91,6 +118,16 @@ class UserModel extends global.yoho.BaseModel {
91 } 118 }
92 119
93 /** 120 /**
  121 + * 导出中奖用户列表
  122 + * @returns {*}
  123 + */
  124 + exportPrizeUserList() {
  125 + return mysqlCli.query(
  126 + `select * from ${TABLE_USER_PRIZE_LOG} where is_get = 1;`
  127 + );
  128 + }
  129 +
  130 + /**
94 * 用户删除 131 * 用户删除
95 * @returns {*} 132 * @returns {*}
96 */ 133 */
@@ -116,6 +153,19 @@ class UserModel extends global.yoho.BaseModel { @@ -116,6 +153,19 @@ class UserModel extends global.yoho.BaseModel {
116 } 153 }
117 154
118 /** 155 /**
  156 + * 中奖用户删除
  157 + * @param userId
  158 + * @returns {*}
  159 + */
  160 + deletePrizeUser(userId) {
  161 + return mysqlCli.delete(
  162 + `delete from ${TABLE_USER_PRIZE_LOG} where id = :userId;`, {
  163 + userId
  164 + }
  165 + );
  166 + }
  167 +
  168 + /**
119 * 导出用户登录日志 169 * 导出用户登录日志
120 * @returns {*} 170 * @returns {*}
121 */ 171 */
@@ -21,6 +21,7 @@ router.get('/activity/createArticle', activity.createArticlePage); @@ -21,6 +21,7 @@ router.get('/activity/createArticle', activity.createArticlePage);
21 // 用户管理[page] 21 // 用户管理[page]
22 router.get('/user/list', user.userListPage); 22 router.get('/user/list', user.userListPage);
23 router.get('/user/users_list', user.usersListPage); 23 router.get('/user/users_list', user.usersListPage);
  24 +router.get('/user/prize_users_list', user.prizeUsersListPage);
24 25
25 // 用户登录日志[page] 26 // 用户登录日志[page]
26 router.get('/user/login-log', user.userLoginLog); 27 router.get('/user/login-log', user.userLoginLog);
@@ -46,9 +47,12 @@ router.post('/api/activity/createArticle', activity.createArticle); @@ -46,9 +47,12 @@ router.post('/api/activity/createArticle', activity.createArticle);
46 // 用户管理[ajax] 47 // 用户管理[ajax]
47 router.post('/api/user/delete', user.deleteUser); 48 router.post('/api/user/delete', user.deleteUser);
48 router.post('/api/user/deleteInfoUser', user.deleteInfoUsers); 49 router.post('/api/user/deleteInfoUser', user.deleteInfoUsers);
  50 +router.post('/api/user/deletePrizeUser', user.deletePrizeUsers);
49 router.get('/api/user/list', user.userList); 51 router.get('/api/user/list', user.userList);
50 router.get('/api/user/users_list', user.usersList); 52 router.get('/api/user/users_list', user.usersList);
  53 +router.get('/api/user/prize_users_list', user.prizeUsersList);
51 router.get('/api/user/exportUserList', user.exportUserList); 54 router.get('/api/user/exportUserList', user.exportUserList);
  55 +router.get('/api/user/exportPrizeUserList', user.exportPrizeUserList);
52 router.get('/api/user/exportInfoUserList', user.exportInfoUserList); 56 router.get('/api/user/exportInfoUserList', user.exportInfoUserList);
53 57
54 module.exports = router; 58 module.exports = router;
  1 +<!-- page content -->
  2 +<div class="right_col" role="main">
  3 + <div class="">
  4 + <div class="row">
  5 + <div class="col-md-12 col-sm-12 col-xs-12">
  6 + <div class="x_panel">
  7 + <div class="x_title">
  8 + <button class="btn btn-primary btn-export-user-list" data-id="{{id}}">导出用户列表</button>
  9 + <div class="clearfix"></div>
  10 + </div>
  11 + <div class="x_content">
  12 + <div class="table-responsive">
  13 + <table class="table table-bordered">
  14 + <thead>
  15 + <tr class="headings">
  16 + <th width="10%" class="column-title">ID</th>
  17 + <th width="15%" class="column-title">昵称</th>
  18 + <th width="15%" class="column-title">手机号</th>
  19 + <th width="30%" class="column-title">地址</th>
  20 + <th width="10%" class="column-title">鞋码</th>
  21 + <th width="20%" class="column-title">操作</th>
  22 + </tr>
  23 + </thead>
  24 +
  25 + <tbody class="user-list">
  26 + </tbody>
  27 + </table>
  28 + </div>
  29 + <div class="table-pagination user-pagination pull-right"></div>
  30 + </div>
  31 + </div>
  32 + </div>
  33 + </div>
  34 + </div>
  35 +</div>
  36 +<!-- /page content -->
@@ -57,6 +57,7 @@ @@ -57,6 +57,7 @@
57 <ul class="nav child_menu"> 57 <ul class="nav child_menu">
58 <li><a href="/admin/user/list">用户列表</a></li> 58 <li><a href="/admin/user/list">用户列表</a></li>
59 <li><a href="/admin/user/users_list">用户信息收集</a></li> 59 <li><a href="/admin/user/users_list">用户信息收集</a></li>
  60 + <li><a href="/admin/user/prize_users_list">中奖用户信息</a></li>
60 <li><a href="/admin/user/login-log">用户登录日志</a></li> 61 <li><a href="/admin/user/login-log">用户登录日志</a></li>
61 </ul> 62 </ul>
62 </li> 63 </li>
  1 +require('admin/user.page.css');
  2 +require('bootpag/lib/jquery.bootpag.min');
  3 +
  4 +const _ = require('lodash');
  5 +const moment = require('moment');
  6 +
  7 +function bind_delete_user() {
  8 + const deleteFn = function() {
  9 + const userId = $(this).data('id');
  10 +
  11 + $.ajax({
  12 + method: 'post',
  13 + url: '/admin/api/user/deletePrizeUser',
  14 + data: {
  15 + userId
  16 + }
  17 + })
  18 + .then(() => {
  19 + location.reload();
  20 + });
  21 + };
  22 +
  23 + $(document).on('click', '.btn-delete-user', deleteFn);
  24 +}
  25 +
  26 +function bind_export_user_list() {
  27 + const exportFn = function() {
  28 + window.open('/admin/api/user/exportPrizeUserList', '_blank');
  29 + };
  30 +
  31 + $('.btn-export-user-list').on('click', exportFn);
  32 +}
  33 +
  34 +function bind_table_pagination() {
  35 + const $ul = $('.user-list');
  36 + const $up = $('.user-pagination');
  37 +
  38 + const fetchRender = (pageNo, pageSize) => {
  39 + $.ajax({
  40 + url: '/admin/api/user/prize_users_list',
  41 + data: {
  42 + pageNo,
  43 + pageSize
  44 + }
  45 + })
  46 + .then(result => {
  47 + console.log(result);
  48 + const list = result.data;
  49 + const totalPage = result.totalPage;
  50 +
  51 + let html = '';
  52 +
  53 + _.each(list, item => {
  54 + item.userBirthday = moment(item.userBirthday).format('YYYY-MM-DD');
  55 + item.userGender = ['男', '女'][item.userGender];
  56 + html += `
  57 + <tr class="even pointer">
  58 + <td class="">${item.id}</td>
  59 + <td class="">${item.userName}</td>
  60 + <td class="">${item.userPhone}</td>
  61 + <td class="">${item.userAddress}</td>
  62 + <td class="">${item.userShoesSize}</td>
  63 + <td class="">
  64 + <button class="btn btn-danger btn-delete-user" data-id="${item.id}">删除用户
  65 + </button>
  66 + </td>
  67 + </tr>`;
  68 + });
  69 +
  70 + $ul.html(html);
  71 +
  72 + if (pageNo === 1) {
  73 + $up.bootpag({
  74 + total: totalPage,
  75 + page: 1,
  76 + maxVisible: 10,
  77 + }).on('page', function(event, num) {
  78 + fetchRender(num, 20);
  79 + });
  80 + }
  81 + });
  82 + };
  83 +
  84 + fetchRender(1, 20);
  85 +}
  86 +
  87 +(function() {
  88 + bind_delete_user();
  89 + bind_export_user_list();
  90 + bind_table_pagination();
  91 +}());
  92 +
  93 +