东东工厂添加判断,减少部分用户获取的数据不全导致脚本出错

This commit is contained in:
lxk0301
2021-01-04 12:35:46 +08:00
parent feaf414776
commit 8b160136e9
11 changed files with 32 additions and 28 deletions

View File

@@ -283,7 +283,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取${randomCount}个码放到您固定的互助码后面`) console.log(`随机取${randomCount}个码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }

View File

@@ -498,7 +498,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取${randomCount}个码放到您固定的互助码后面`) console.log(`随机取${randomCount}个码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }

View File

@@ -330,7 +330,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取${randomCount}个码放到您固定的互助码后面`) console.log(`随机取${randomCount}个码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }

View File

@@ -666,7 +666,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取${randomCount}个码放到您固定的互助码后面`) console.log(`随机取${randomCount}个码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }

View File

@@ -1305,7 +1305,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取${randomCount}个码放到您固定的互助码后面`) console.log(`随机取${randomCount}个码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }

View File

@@ -1239,7 +1239,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取个${randomCount}码放到您固定的互助码后面`) console.log(`随机取个${randomCount}码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }

View File

@@ -265,7 +265,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取${randomCount}个码放到您固定的互助码后面`) console.log(`随机取${randomCount}个码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }

View File

@@ -108,8 +108,8 @@ function showMsg() {
} else { } else {
$.log(`京东账号${$.index}${$.nickName}\n${message}`); $.log(`京东账号${$.index}${$.nickName}\n${message}`);
} }
if (new Date().getHours() === 23) { if (new Date().getHours() === 12) {
$.msg($.name, '', `京东账号${$.index}${$.nickName}\n${message}`); $.msg($.name, '', `${message}`);
} }
resolve() resolve()
}) })
@@ -181,6 +181,7 @@ async function algorithm() {
} }
} else { } else {
console.log(`\n此账号${$.index}${$.nickName}暂未选择商品\n`); console.log(`\n此账号${$.index}${$.nickName}暂未选择商品\n`);
message += `京东账号${$.index} ${$.nickName}\n`;
message += `已选商品:暂无\n`; message += `已选商品:暂无\n`;
message += `心仪商品:${wantProduct ? wantProduct : '暂无'}\n`; message += `心仪商品:${wantProduct ? wantProduct : '暂无'}\n`;
if (wantProduct) { if (wantProduct) {
@@ -216,17 +217,17 @@ async function algorithm() {
} else { } else {
console.log(`BoxJs或环境变量暂未提供心仪商品\n如需兑换心仪商品,请提供心仪商品名称\n`); console.log(`BoxJs或环境变量暂未提供心仪商品\n如需兑换心仪商品,请提供心仪商品名称\n`);
await jdfactory_getProductList(true); await jdfactory_getProductList(true);
message += `当前剩余最多商品:${$.canMakeList[0].name}\n`; message += `当前剩余最多商品:${$.canMakeList[0] && $.canMakeList[0].name}\n`;
message += `兑换所需电量:${$.canMakeList[0].fullScore}\n`; message += `兑换所需电量:${$.canMakeList[0] && $.canMakeList[0].fullScore}\n`;
message += `您当前总电量:${$.batteryValue * 1}\n`; message += `您当前总电量:${$.batteryValue * 1}\n`;
if ($.canMakeList[0].couponCount > 0 && $.batteryValue * 1 >= $.canMakeList[0].fullScore) { if ($.canMakeList[0] && $.canMakeList[0].couponCount > 0 && $.batteryValue * 1 >= $.canMakeList[0] && $.canMakeList[0].fullScore) {
let nowTimes = new Date(new Date().getTime() + new Date().getTimezoneOffset()*60*1000 + 8*60*60*1000); let nowTimes = new Date(new Date().getTime() + new Date().getTimezoneOffset()*60*1000 + 8*60*60*1000);
if (new Date(nowTimes).getHours() === 12) { if (new Date(nowTimes).getHours() === 12) {
$.msg($.name, '', `京东账号${$.index}${$.nickName}\n${message}【满足】兑换${$.canMakeList[0].name}所需总电量:${$.canMakeList[0].fullScore}\n请点击弹窗直达活动页面\n选择此心仪商品并手动投入电量兑换`, {'open-url': 'openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%20%22des%22:%20%22m%22,%20%22url%22:%20%22https://h5.m.jd.com/babelDiy/Zeus/2uSsV2wHEkySvompfjB43nuKkcHp/index.html%22%20%7D'}); $.msg($.name, '', `京东账号${$.index}${$.nickName}\n${message}【满足】兑换${$.canMakeList[0] && $.canMakeList[0] && [0].name}所需总电量:${$.canMakeList[0] && $.canMakeList[0].fullScore}\n请点击弹窗直达活动页面\n选择此心仪商品并手动投入电量兑换`, {'open-url': 'openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%20%22des%22:%20%22m%22,%20%22url%22:%20%22https://h5.m.jd.com/babelDiy/Zeus/2uSsV2wHEkySvompfjB43nuKkcHp/index.html%22%20%7D'});
if ($.isNode()) await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName}`, `【京东账号${$.index}${$.nickName}\n${message}【满足】兑换${$.canMakeList[0].name}所需总电量:${$.canMakeList[0].fullScore}\n请速去活动页面查看`); if ($.isNode()) await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName}`, `【京东账号${$.index}${$.nickName}\n${message}【满足】兑换${$.canMakeList[0] && $.canMakeList[0].name}所需总电量:${$.canMakeList[0].fullScore}\n请速去活动页面查看`);
} }
} else { } else {
console.log(`\n目前电量${$.batteryValue * 1},不满足兑换 ${$.canMakeList[0].name}所需的 ${$.canMakeList[0].fullScore}电量\n`) console.log(`\n目前电量${$.batteryValue * 1},不满足兑换 ${$.canMakeList[0] && $.canMakeList[0].name}所需的 ${$.canMakeList[0] && $.canMakeList[0].fullScore}电量\n`)
} }
} }
} }
@@ -535,17 +536,20 @@ function jdfactory_getProductList(flag = false) {
if (safeGet(data)) { if (safeGet(data)) {
data = JSON.parse(data); data = JSON.parse(data);
if (data.data.bizCode === 0) { if (data.data.bizCode === 0) {
$.canMakeList = [];
$.canMakeList = data.data.result.canMakeList;//当前可选商品列表 sellOut:1为已抢光0为目前可选择 $.canMakeList = data.data.result.canMakeList;//当前可选商品列表 sellOut:1为已抢光0为目前可选择
$.canMakeList.sort(sortCouponCount); if ($.canMakeList && $.canMakeList.length > 0) {
console.log(`商品名称 可选状态 剩余量`) $.canMakeList.sort(sortCouponCount);
for (let item of $.canMakeList) { console.log(`商品名称 可选状态 剩余量`)
console.log(`${item.name.slice(-4)} ${item.sellOut === 1 ? '已抢光':'可 选'} ${item.couponCount}`);
}
if (!flag) {
for (let item of $.canMakeList) { for (let item of $.canMakeList) {
if (item.name.indexOf(wantProduct) > -1 && item.couponCount > 0 && item.sellOut === 0) { console.log(`${item.name.slice(-4)} ${item.sellOut === 1 ? '已抢光':'可 选'} ${item.couponCount}`);
await jdfactory_makeProduct(item.skuId); }
break if (!flag) {
for (let item of $.canMakeList) {
if (item.name.indexOf(wantProduct) > -1 && item.couponCount > 0 && item.sellOut === 0) {
await jdfactory_makeProduct(item.skuId);
break
}
} }
} }
} }
@@ -624,7 +628,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取${randomCount}个码放到您固定的互助码后面`) console.log(`随机取${randomCount}个码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }

View File

@@ -343,7 +343,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取${randomCount}个码放到您固定的互助码后面`) console.log(`随机取${randomCount}个码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }

View File

@@ -442,7 +442,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取个${randomCount}码放到您固定的互助码后面`) console.log(`随机取个${randomCount}码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }

View File

@@ -521,7 +521,7 @@ function readShareCode() {
console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
console.log(`随机取个${randomCount}码放到您固定的互助码后面`) console.log(`随机取个${randomCount}码放到您固定的互助码后面(不影响已有固定互助)`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }