Authored by huangyi

修改api

... ... @@ -5,8 +5,8 @@
*/
const _ = require('lodash');
const moment = require('moment');
const excelExport = require('excel-export');
const ActivityModel = require('../models/activity');
const {excel_export} = require('../../../utils/excel');
const DO_SUCCESS = '操作成功';
const DO_FAILED = '操作失败!';
... ... @@ -80,10 +80,14 @@ const zeroBuy = {
}
req.ctx(ActivityModel).getZerobuyExportList(req.query.id)
.then(result => {
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader('Content-Disposition', `attachment; filename=zerobuy_${id}_${new Date().getTime()}.xlsx`);
res.end(excelExport.execute(result), 'binary');
.then(conf => {
return excel_export({
title: conf.cols,
data: conf.rows,
fileName: `zerobuy_${id}_${new Date().getTime()}`,
sheetName: conf.name,
res
});
}).catch(next);
},
zeroBuyEdit(req, res, next) {
... ... @@ -579,32 +583,7 @@ const activity = {
let conf = {
name: 'mysheet',
cols: [
{
caption: '文章ID',
type: 'number'
},
{
caption: '内容',
type: 'string'
},
{
caption: '赞数',
type: 'number'
},
{
caption: '发布者',
type: 'string'
},
{
caption: '手机号',
type: 'string'
},
{
caption: '创建时间',
type: 'string'
}
],
cols: ['文章ID', '内容', '赞数', '发布者', '手机号', '创建时间'],
rows: []
};
... ... @@ -623,11 +602,13 @@ const activity = {
conf.rows.push(temp);
});
let exportFile = excelExport.execute(conf);
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader('Content-Disposition', 'attachment; filename=articleList.xlsx');
res.end(exportFile, 'binary');
return excel_export({
title: conf.cols,
data: conf.rows,
fileName: 'articleList',
sheetName: conf.name,
res
});
})
.catch(next);
... ...
... ... @@ -7,13 +7,11 @@
const _ = require('lodash');
const CouponModel = require('../models/coupon');
const moment = require('moment');
const excelExport = require('excel-export');
const INVALID_PARAMS = '参数错误';
const xlsx = require('xlsx');
const DO_SUCCESS = '操作成功';
const GET_SUCCESS = '获取成功';
const {excel_export} = require('../../../utils/excel');
let loadExcel = function(path) {
let workbook = xlsx.readFile(path);
... ... @@ -147,22 +145,13 @@ const couponController = {
}
},
downloadTpl(req, res) {
let conf = {
name: 'mysheet',
cols: [
{
caption: 'couponNo',
type: 'String'
}
],
rows: [['c3236233105'], ['c3236233105']]
};
let exportFile = excelExport.execute(conf);
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader('Content-Disposition', 'attachment; filename=couponNoTpl.xlsx');
res.end(exportFile, 'binary');
return excel_export({
title: ['couponNo'],
data: [['c3236233105'], ['c3236233105']],
fileName: 'couponNoTpl',
sheetName: '优惠券',
res
});
},
downloadNoList(req, res, next) {
const couponId = req.query.id;
... ... @@ -178,24 +167,7 @@ const couponController = {
let conf = {
name: 'mysheet',
cols: [
{
caption: '券ID',
type: 'number'
},
{
caption: '券码',
type: 'string'
},
{
caption: '用户id',
type: 'number'
},
{
caption: '领取时间',
type: 'string'
}
],
cols: ['券ID', '券码', '用户id', '领取时间'],
rows: []
};
... ... @@ -215,12 +187,13 @@ const couponController = {
}
conf.rows.push(temp);
});
let exportFile = excelExport.execute(conf);
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader('Content-Disposition', 'attachment; filename=couponList.xlsx');
res.end(exportFile, 'binary');
return excel_export({
title: conf.cols,
data: conf.rows,
fileName: 'couponList',
sheetName: conf.name,
res
});
})
.catch(next);
... ...
... ... @@ -5,9 +5,9 @@
*/
const _ = require('lodash');
const moment = require('moment');
const excelExport = require('excel-export');
const UserModel = require('../models/user');
const camelcase = require('camelcase');
const {excel_export} = require('../../../utils/excel');
const DO_SUCCESS = '操作成功';
const GET_SUCCESS = '获取成功';
... ... @@ -70,29 +70,29 @@ const userController = {
pageNo,
pageSize
})
.then(list => {
.then(list => {
_.each(list, item => {
item.createTime = timeFmt(item.createTime);
});
_.each(list, item => {
item.createTime = timeFmt(item.createTime);
});
return list;
})
.then(list => {
req.ctx(UserModel).allUsersNum()
.then(totalCount => {
res.json({
code: 200,
data: list,
pageNo: +pageNo,
pageSize: +pageSize,
totalCount,
totalPage: Math.ceil(totalCount / pageSize),
message: GET_SUCCESS
return list;
})
.then(list => {
req.ctx(UserModel).allUsersNum()
.then(totalCount => {
res.json({
code: 200,
data: list,
pageNo: +pageNo,
pageSize: +pageSize,
totalCount,
totalPage: Math.ceil(totalCount / pageSize),
message: GET_SUCCESS
});
});
});
})
.catch(next);
})
.catch(next);
},
/**
... ... @@ -235,24 +235,7 @@ const userController = {
exportUserList(req, res, next) {
let conf = {
name: 'mysheet',
cols: [
{
caption: '用户ID',
type: 'number'
},
{
caption: '昵称',
type: 'string'
},
{
caption: '手机号',
type: 'string'
},
{
caption: '创建时间',
type: 'string'
}
],
cols: ['用户ID', '昵称', '手机号', '创建时间'],
rows: []
};
... ... @@ -269,11 +252,13 @@ const userController = {
conf.rows.push(temp);
});
let exportFile = excelExport.execute(conf);
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader('Content-Disposition', 'attachment; filename=userList.xlsx');
res.end(exportFile, 'binary');
return excel_export({
title: conf.cols,
data: conf.rows,
fileName: 'userList',
sheetName: conf.name,
res
});
})
.catch(next);
},
... ... @@ -281,39 +266,14 @@ const userController = {
let conf = {
name: 'myInfoSheet',
cols: [
{
caption: '用户ID',
type: 'number'
},
{
caption: '昵称',
type: 'string'
},
{
caption: '生日',
type: 'string'
},
{
caption: '性别',
type: 'string'
},
{
caption: '手机号',
type: 'string'
},
{
caption: 'email',
type: 'string'
},
{
caption: '省份',
type: 'string'
},
{
caption: '城市',
type: 'string'
},
],
'用户ID',
'昵称',
'生日',
'性别',
'手机号',
'email',
'省份',
'城市'],
rows: []
};
... ... @@ -334,38 +294,24 @@ const userController = {
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');
return excel_export({
title: conf.cols,
data: conf.rows,
fileName: 'userInfoList',
sheetName: conf.name,
res
});
}).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'
}
],
'用户ID',
'昵称',
'手机号',
'地址',
'鞋码'],
rows: []
};
... ... @@ -383,11 +329,13 @@ const userController = {
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');
return excel_export({
title: conf.cols,
data: conf.rows,
fileName: 'prizeUserList',
sheetName: conf.name,
res
});
}).catch(next);
},
userLoginLog(req, res) {
... ... @@ -404,28 +352,7 @@ const userController = {
let conf = {
name: 'mysheet',
cols: [
{
caption: '用户id',
type: 'string'
},
{
caption: '登录时间',
type: 'string'
},
{
caption: '平台',
type: 'string'
},
{
caption: '地址',
type: 'string'
},
{
caption: 'ip',
type: 'string'
}
],
cols: ['用户id', '登录时间', '平台', '地址', 'ip'],
rows: []
};
... ... @@ -443,11 +370,13 @@ const userController = {
conf.rows.push(temp);
});
let exportFile = excelExport.execute(conf);
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader('Content-Disposition', 'attachment; filename=user-login-log.xlsx');
res.end(exportFile, 'binary');
return excel_export({
title: conf.cols,
data: conf.rows,
fileName: 'user-login-log',
sheetName: conf.name,
res
});
})
.catch(next);
}
... ...
... ... @@ -558,36 +558,7 @@ class AdminModel extends global.yoho.BaseModel {
return {
name: 'sheet',
cols: [
{
caption: '编号',
type: 'number'
},
{
caption: 'UID',
type: 'number'
},
{
caption: '昵称',
type: 'string'
},
{
caption: '抽奖码',
type: 'string'
},
{
caption: '是否分享获得',
type: 'string'
},
{
caption: '邀请者',
type: 'string'
},
{
caption: '获得时间',
type: 'string'
}
],
cols: ['编号', 'UID', '昵称', '抽奖码', '是否分享获得', '邀请者', '获得时间'],
rows
};
});
... ...