From 43386c2cdfd326733bb9251fd8eca3dcc2374197 Mon Sep 17 00:00:00 2001 From: superq <13815865+meooxx@users.noreply.github.com> Date: Sat, 13 Mar 2021 20:45:50 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BF=AE=E6=AD=A3=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=98=AF=E9=A2=84=E7=BA=A6=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jobs.js | 22 ++++++++++------------ package.json | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/jobs.js b/jobs.js index 08361eb..eab5ab1 100644 --- a/jobs.js +++ b/jobs.js @@ -168,6 +168,7 @@ async function submitOrderFromShoppingCart( } const notInCartIds = await isSkuInCart(skuIds, area); const skuIdsSet = new Set(skuIds); + const yuyueSkuSet = new Set(); for (let i = 0; i < skuIds.length; i++) { const skuId = skuIds[i]; try { @@ -178,7 +179,7 @@ async function submitOrderFromShoppingCart( }); if (yuyueInfo && yuyueInfo.yuyue) { // eslint-disable-next-line no-param-reassign - params[skuId].yuyue = true; + yuyueSkuSet.add(skuId); } console.log( skuId, @@ -219,11 +220,10 @@ async function submitOrderFromShoppingCart( } let skuData = []; - const isYuyue = params.yuyue; - if (isYuyue) { + if (yuyueSkuSet.size > 0) { try { - const data = await getSkusData(skuIds, area); - skuData = [...skuIdsSet].map(s => data.get(s)); + const data = await getSkusData(area); + skuData = [...yuyueSkuSet].map(s => data.get(s)); if (skuData.length === 0) { throw Error('空的购物车数据'); } @@ -234,15 +234,15 @@ async function submitOrderFromShoppingCart( } await timer(date, async () => { - if (isYuyue) { + if (yuyueSkuSet.size > 0) { const d = Date.now(); - const validIds = [...skuIdsSet]; + const validIds = [...yuyueSkuSet]; const [success] = await helper.checkSkus(skuData, validIds, area); - console.log(`使用${Date.now() - d}ms, 已勾选${validIds}`); if (!success) { console.log('勾选失败'); process.exit(); } + console.log(`使用${Date.now() - d}ms, 已勾选${validIds}`); } let isAvailable = false; @@ -358,15 +358,14 @@ async function isSkuInCart(skuId, areaId) { * @param {*} areadId * 购物车中sku的数据 */ -async function getSkusData(skuId, areaId) { - const skuIds = Array.isArray(skuId) ? skuId : [skuId]; +async function getSkusData(areaId) { // 获取购物车数据 const res = await helper.getCartData(areaId); const data = new Map(); if (res.success) { let allskus = []; - if (!res.resultData.cartInfo) return skuIds; + if (!res.resultData.cartInfo) return data; res.resultData.cartInfo.vendors.forEach(v => { allskus = allskus.concat(v.sorted); }); @@ -378,7 +377,6 @@ async function getSkusData(skuId, areaId) { } data.set(String(s.item.Id), s); }); - return data; } return data; } diff --git a/package.json b/package.json index c569b81..242993e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jd-yuyue", - "version": "1.0.0", + "version": "1.2.1", "description": "", "main": "index.js", "scripts": {