MCPcopy Create free account
hub / github.com/Semporia/Scripts / algorithm

Function algorithm

jd_jdfactory.js:116–245  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

114 })
115}
116async function algorithm() {
117 // 当心仪的商品存在,并且收集起来的电量满足当前商品所需,就投入
118 return new Promise(resolve => {
119 $.post(taskPostUrl('jdfactory_getHomeData'), async (err, resp, data) => {
120 try {
121 if (err) {
122 console.log(`${JSON.stringify(err)}`)
123 console.log(`${$.name} API请求失败,请检查网路重试`)
124 } else {
125 if (safeGet(data)) {
126 data = JSON.parse(data);
127 if (data.data.bizCode === 0) {
128 $.haveProduct = data.data.result.haveProduct;
129 $.userName = data.data.result.userName;
130 $.newUser = data.data.result.newUser;
131 wantProduct = $.isNode() ? (process.env.FACTORAY_WANTPRODUCT_NAME ? process.env.FACTORAY_WANTPRODUCT_NAME : wantProduct) : ($.getdata('FACTORAY_WANTPRODUCT_NAME') ? $.getdata('FACTORAY_WANTPRODUCT_NAME') : wantProduct);
132 if (data.data.result.factoryInfo) {
133 let { totalScore, useScore, produceScore, remainScore, couponCount, name } = data.data.result.factoryInfo
134 console.log(`\n已选商品:${name}`);
135 console.log(`当前已投入电量/所需电量:${useScore}/${totalScore}`);
136 console.log(`已选商品剩余量:${couponCount}`);
137 console.log(`当前总电量:${remainScore * 1 + useScore * 1}`);
138 console.log(`当前完成度:${((remainScore * 1 + useScore * 1)/(totalScore * 1)).toFixed(2) * 100}%\n`);
139 message += `京东账号${$.index} ${$.nickName}\n`;
140 message += `已选商品:${name}\n`;
141 message += `当前已投入电量/所需电量:${useScore}/${totalScore}\n`;
142 message += `已选商品剩余量:${couponCount}\n`;
143 message += `当前总电量:${remainScore * 1 + useScore * 1}\n`;
144 message += `当前完成度:${((remainScore * 1 + useScore * 1)/(totalScore * 1)).toFixed(2) * 100}%\n`;
145 if (wantProduct) {
146 console.log(`BoxJs或环境变量提供的心仪商品:${wantProduct}\n`);
147 await jdfactory_getProductList(true);
148 let wantProductSkuId = '';
149 for (let item of $.canMakeList) {
150 if (item.name.indexOf(wantProduct) > - 1) {
151 totalScore = item['fullScore'] * 1;
152 couponCount = item.couponCount;
153 name = item.name;
154 }
155 if (item.name.indexOf(wantProduct) > - 1 && item.couponCount > 0) {
156 wantProductSkuId = item.skuId;
157 }
158 }
159 // console.log(`\n您心仪商品${name}\n当前数量为:${couponCount}\n兑换所需电量为:${totalScore}\n您当前总电量为:${remainScore * 1 + useScore * 1}\n`);
160 if (wantProductSkuId && ((remainScore * 1 + useScore * 1) >= (totalScore * 1 + 100000))) {
161 console.log(`\n提供的心仪商品${name}目前数量:${couponCount},且当前总电量为:${remainScore * 1 + useScore * 1},【满足】兑换此商品所需总电量:${totalScore + 100000}`);
162 console.log(`请去活动页面更换成心仪商品并手动投入电量兑换\n`);
163 $.msg($.name, '', `京东账号${$.index}${$.nickName}\n您提供的心仪商品${name}目前数量:${couponCount}\n当前总电量为:${remainScore * 1 + useScore * 1}\n【满足】兑换此商品所需总电量:${totalScore}\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'});
164 if ($.isNode()) await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName}`, `【京东账号${$.index}】${$.nickName}\n您提供的心仪商品${name}目前数量:${couponCount}\n当前总电量为:${remainScore * 1 + useScore * 1}\n【满足】兑换此商品所需总电量:${totalScore}\n请去活动页面更换成心仪商品并手动投入电量兑换`);
165 } else {
166 console.log(`您心仪商品${name}\n当前数量为:${couponCount}\n兑换所需电量为:${totalScore}\n您当前总电量为:${remainScore * 1 + useScore * 1}\n不满足兑换心仪商品的条件\n`)
167 }
168 } else {
169 console.log(`BoxJs或环境变量暂未提供心仪商品\n如需兑换心仪商品,请提供心仪商品名称,否则满足条件后会为您兑换当前所选商品:${name}\n`);
170 if (((remainScore * 1 + useScore * 1) >= totalScore * 1 + 100000) && (couponCount * 1 > 0)) {
171 console.log(`\n所选商品${name}目前数量:${couponCount},且当前总电量为:${remainScore * 1 + useScore * 1},【满足】兑换此商品所需总电量:${totalScore}`);
172 console.log(`BoxJs或环境变量暂未提供心仪商品,下面为您目前选的${name} 发送提示通知\n`);
173 // await jdfactory_addEnergy();

Callers 1

jdFactoryFunction · 0.85

Calls 9

jdfactory_getProductListFunction · 0.85
taskPostUrlFunction · 0.70
safeGetFunction · 0.70
postMethod · 0.45
logMethod · 0.45
isNodeMethod · 0.45
getdataMethod · 0.45
msgMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected