-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path马帮缺货商品状态抓取脚本.txt
86 lines (75 loc) · 2.74 KB
/
马帮缺货商品状态抓取脚本.txt
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//http://www.mabangerp.com/index.php?mod=order.list&Order_orderStatus=2,订单Tab中点击配货中,注意页数选择50.
var page = 1; //第几页开始
var maxPage = 377; //第几页结束,此值可以设置,如果需要爬取完全可以设置
var startDate=new Date("2018/04/01");
var myDate = new Date();
var endDate=myDate.toLocaleString().split(" ")[0];//当前时间
var gapDate=6;//设置间隔时间,一般是7天
var checkGap=(Date.parse(endDate) -Date.parse(startDate)) / 1000 / 60 / 60 / 24-gapDate;//得到当前日期-7天之后,再减去起始日期的时间间隔。
var content = "\uFEFF";
//给EXCEL加标题
//content += (["" + "仓库名", "销售记录编号","库存sku", "quantity", "支付时间", "是否有货"].join(','));
// content += "\n";
function todo() {
try {
$.get("http://www.mabangerp.com/index.php?mod=order.orderSearch", {
"page": page
}, function(data, status) {
const theData = JSON.parse(data);
console.log("加载第", page, "页数据", ",共" + (theData.pageCount / 50) + "页", status);
//之前的条件是status == "success"
const orders = theData.orderDataList;
orders.forEach(function(order) {
order.orderItem_data_list.forEach(function(sku) {
var productDate = order.paidTime;
var productStatus = sku.hasGoods;
if (timeScope(productDate) && isLackProduct(productStatus)) {
if (sku.warehouseName == "上海自建仓-澄建路" ||sku.warehouseName =="马帮自建仓-九新公路") {
content += (["" + sku.warehouseName, order.salesRecordNumber, sku.stockSku, sku.quantity, order.paidTime, sku.hasGoods == 1 ? '有货' : '没货'].join(','));
content += "\n";
}
}
});
});
if (page < maxPage) {
page++;
todo();
} else {
console.log("数据抓取完成,开始下载文件")
var csvData = new Blob([content], {
type: 'text/csv'
});
var a = document.createElement('a');
a.href = URL.createObjectURL(csvData);
a.target = '_blank';
a.download = 'info.csv';
document.body.appendChild(a);
console.log(a);
a.click();
document.body.removeChild(a);
}
})
} catch (e) {
console.log(e);
}
}
//时间范围判断
function timeScope(productDate) {
var myDate = new Date();
var beginval = productDate.split(" ")[0]; //这个时间可以是日期控件选择的,也可以是其他的任何日期时间
var date1 = new Date(beginval);
var curVal = (Date.parse(date1) - Date.parse(startDate)) / 1000 / 60 / 60 / 24;//当前产品日期减去起始日期
if (curVal <= checkGap&&curVal>=0) {
return true;
} else {
return false;
}
}
//是否有货判断
function isLackProduct(productStatus) {
if (productStatus == 1) {
return false; //有货
}
return true;//不为1,缺货
}
todo();