Skip to content

Commit

Permalink
bugfix: state状态才是可购买状态
Browse files Browse the repository at this point in the history
  • Loading branch information
meooxx committed Nov 30, 2020
1 parent 9d19da0 commit ff660e4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
79 changes: 45 additions & 34 deletions jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,21 @@ async function submitOrderFromShoppingCart(date, skuId, areaId) {
const shopId = text.match(/shopId:'(.*?)',/i)[1];
const paramJson = text.match(/paramJson:\s*'(.*?)'/i)[1];

const stock = await helper.getItemStock(skuId, area);
const item = stock[skuId];
// const stock = await helper.getItemStock(skuId, area);
// const item = stock[skuId];
// IsPurchase: 是否可以购买, false 可以购买, true 不可以
// StockState:
// 33 现货,
// 40 可配货
// 0,34 无货
// 36 采购中
//skuState # 商品是否上架
const { /*IsPurchase,*/ StockState, StockStateName, skuState } = item;
console.log('库存状态:', StockStateName);
if ([0, 34, 36].includes(StockState)) {
console.log(`狗东耍猴呢!溜了~`);
process.exit();
}
// const { /*IsPurchase,*/ StockState, StockStateName, skuState } = item;
// console.log('库存状态:', StockStateName);
// if ([0, 34, 36].includes(StockState)) {
// console.log(`狗东耍猴呢!溜了~`);
// process.exit();
// }

timer(date, async () => {
let i = 10;
Expand All @@ -133,47 +133,58 @@ async function submitOrderFromShoppingCart(date, skuId, areaId) {
paramJson,
num: 1,
});
// type === 4 此时可以添加购物车抢购
if (yuyue.yuyueInfo.type == '4') {
// type 5 plus 专用
// state === 4 抢购, 此时可以添加购物车
const { yuyueInfo = {}, stockInfo = {} } = yuyue;
const isStock =
[33, 40].includes(stockInfo.stockState) && stockInfo.isStock;
if (yuyueInfo.state == '4' && isStock) {
console.log('准备提交购物车');
isAvalibal = true;
break;
} else {
// 还剩多少时间
console.log(yuyue.yuyueInfo.cdPrefix, yuyue.yuyueInfo.countdown);
console.log(
// yuyueInfo.state,
stockInfo.stockDesc,
yuyueInfo.cdPrefix,
yuyueInfo.countdown
);
}
} catch (e) {
console.log('查询预约信息失败:', i, e);
}
await new Promise(r => setTimeout(r, 200));
}

if (!isAvalibal) {
console.log('哈哈又被耍猴了!');
process.exit();
}
// 有货哦
if (isAvalibal) {
const result = await helper.addItemToCart(skuId);
// 已经跳转至购物车页面
// 当前sku 是套装商品
console.log('添加成功,', result);
if (!result.isCartPage) {
await helper.requestCartPage(skuId);
console.log('访问购物车页面成功');
await helper.requestCheckoutPage();
console.log('访问购物车结算页面成功');
let i = 10;
while (i--) {
try {
const res = await helper.submitCartOrder();
if (res.success) {
const text = `订单提交成功!订单号:${res.order_id}`;
console.log(text);
helper.sendToWechat(text);
process.exit();
}
} catch (e) {
console.log('抢购失败:', i, e);
const result = await helper.addItemToCart(skuId);
// 已经跳转至购物车页面
// 当前sku 是套装商品
console.log('添加成功,', result);
if (!result.isCartPage) {
await helper.requestCartPage(skuId);
console.log('访问购物车页面成功');
await helper.requestCheckoutPage();
console.log('访问购物车结算页面成功');
let i = 10;
while (i--) {
try {
const res = await helper.submitCartOrder();
if (res.success) {
const text = `订单提交成功!订单号:${res.order_id}`;
console.log(text);
helper.sendToWechat(text);
process.exit();
}
await new Promise(r => setTimeout(r, 200));
} catch (e) {
console.log('抢购失败:', i, e);
}
await new Promise(r => setTimeout(r, 200));
}
}
});
Expand Down
12 changes: 4 additions & 8 deletions tasks-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@

// 修改使用的时间
// 2020/3/3 10:00:00.400
const dd1 = new Date(2020, 2, 3, 10, 0, 0, 400).getTime();
// 2020/3/3 20:00:00.400
const dd2 = new Date(2020, 2, 3, 20, 0, 0, 400).getTime();
// 2020/3/3 21:00:00.400
const dd3 = new Date(2020, 2, 3, 21, 0, 0, 400).getTime();
const dd1 = new Date(2020, 10, 30, 13, 59, 59, 400).getTime();

// 修改这里, 添加skuId, 和抢购时间 date, 需要更改 月/日 时:分:秒:毫秒
// skuId 获取方法, 打开任意一个商品详情页如 `https://item.jd.com/100011521400.html`, 则 `100011521400` 就是其skuId
export const pool = [
// { skuId: '100011521400', date: dd1 },
exports.pool = [
{ skuId: '100016642488', date: dd1, areaId: '2_2825_51936' },
// { skuId: '100006394713', date: dd2 },
// { skuId: '100011621642', date: dd2 },
];

export const forceLogin = false;
exports.forceLogin = false;

0 comments on commit ff660e4

Please sign in to comment.