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

Function doTask

jd_plantBean.js:235–384  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

233 }
234}
235async function doTask() {
236 if ($.taskList && $.taskList.length > 0) {
237 for (let item of $.taskList) {
238 if (item.isFinished === 1) {
239 console.log(`${item.taskName} 任务已完成\n`);
240 continue;
241 } else {
242 if (item.taskType === 8) {
243 console.log(`\n【${item.taskName}】任务未完成,需自行手动去京东APP完成,${item.desc}营养液\n`)
244 } else {
245 console.log(`\n【${item.taskName}】任务未完成,${item.desc}营养液\n`)
246 }
247 }
248 if (item.dailyTimes === 1 && item.taskType !== 8) {
249 console.log(`\n开始做 ${item.taskName}任务`);
250 // $.receiveNutrientsTaskRes = await receiveNutrientsTask(item.taskType);
251 await receiveNutrientsTask(item.taskType);
252 console.log(`做 ${item.taskName}任务结果:${JSON.stringify($.receiveNutrientsTaskRes)}\n`);
253 }
254 if (item.taskType === 3) {
255 //浏览店铺
256 console.log(`开始做 ${item.taskName}任务`);
257 let unFinishedShopNum = item.totalNum - item.gainedNum;
258 if (unFinishedShopNum === 0) {
259 continue
260 }
261 await shopTaskList();
262 const { data } = $.shopTaskListRes;
263 let goodShopListARR = [], moreShopListARR = [], shopList = [];
264 const { goodShopList, moreShopList } = data;
265 for (let i of goodShopList) {
266 if (i.taskState === '2') {
267 goodShopListARR.push(i);
268 }
269 }
270 for (let j of moreShopList) {
271 if (j.taskState === '2') {
272 moreShopListARR.push(j);
273 }
274 }
275 shopList = goodShopListARR.concat(moreShopListARR);
276 for (let shop of shopList) {
277 const { shopId, shopTaskId } = shop;
278 const body = {
279 "monitor_refer": "plant_shopNutrientsTask",
280 "shopId": shopId,
281 "shopTaskId": shopTaskId
282 }
283 const shopRes = await requestGet('shopNutrientsTask', body);
284 console.log(`shopRes结果:${JSON.stringify(shopRes)}`);
285 if (shopRes && shopRes.code === '0') {
286 if (shopRes.data && shopRes.data.nutrState && shopRes.data.nutrState === '1') {
287 unFinishedShopNum --;
288 }
289 }
290 if (unFinishedShopNum <= 0) {
291 console.log(`${item.taskName}任务已做完\n`)
292 break;

Callers 1

jdPlantBeanFunction · 0.70

Calls 6

receiveNutrientsTaskFunction · 0.85
shopTaskListFunction · 0.85
requestGetFunction · 0.85
productTaskListFunction · 0.85
plantChannelTaskListFunction · 0.85
logMethod · 0.45

Tested by

no test coverage detected