-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
70 lines (62 loc) · 1.65 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const Koa = require('koa')
const app = new Koa()
const axios = require('axios')
const Excel = require('exceljs')
// 查询数据
async function queryData() {
let dataList = [];
for (let i = 0; i < 12 * 4; i += 12) {
let url = `https://www.iqianjin.com/plan/detail/buyRecord?planId=12180&sid=bc90eb04f9&pageIndex=${i}&pageSize=12&_=1543920341612`
console.log(url)
let data = await axios.get(url)
dataList = dataList.concat(data.data.bean.list)
}
makeExcel(dataList)
}
//计算总金额
function countAmount(data) {
let amount = 0;
data.forEach((item, index) => {
amount += item.amount;
})
return amount.toFixed(0)
}
// 生成表格
async function makeExcel(dataList) {
let amount = await countAmount(dataList)
//create a workbook
let workbook = new Excel.Workbook()
//add header
let ws = workbook.addWorksheet("aqj")
ws.columns = [{
header: '用户名',
key: 'name',
width: 30
},
{
header: `金额${amount}元`,
key: 'amount',
width: 30
},
{
header: '创建时间',
key: 'time',
width: 50
}
]
ws.getColumn('amount').alignment = { horizontal: 'left' }
dataList.forEach((item, index) => {
ws.addRow([item.userName, item.amount, item.createTime]);
})
workbook.xlsx.writeFile('爱钱进.xlsx')
.then(() => {
console.log('生成 xlsx');
})
.catch(error => {
console.log(error);
})
}
queryData()
app.listen(3000, () => {
console.log('listen on 3000');
})