shawenguan há 1 ano atrás
pai
commit
5e5fa34501
1 ficheiros alterados com 33 adições e 5 exclusões
  1. 33 5
      Scripts/wubian/wubianRevokeEntrust.js

+ 33 - 5
Scripts/wubian/wubianRevokeEntrust.js

@@ -76,7 +76,7 @@ async function Main() {
         checkHandleRequest();
     } else {
         updateHeaders();
-        await tryTRevokeEntrust();
+        await tryRevokeEntrust();
     }
     magicJS.notification.msg('');
     if (gRetBody) {
@@ -103,9 +103,11 @@ function getRevokeEntrustName() {
     return magicJS.data.read(WuBianConstKey.RevokeEntrustName, '');
 }
 
-async function tryTRevokeEntrust() {
+async function tryRevokeEntrust() {
     let name = getRevokeEntrustName();
     let page = 1;
+    let optOrderNum = 0;
+    let entrustOrderTotal = 0;
     while (page < 100) {
         let retOrder = await getOrderList(0, page);
         if (retOrder && retOrder.code == 200) {
@@ -118,13 +120,31 @@ async function tryTRevokeEntrust() {
                 // 8=空投订单
                 // 9=委托订单
                 if (orderInfo.orderType == 9 && orderInfo.title.indexOf(name) > -1) {
+                    if (orderInfo.state == -1) {//已取消
+                        continue;
+                    }
+                    if (orderInfo.state == -4) {//已退款
+                        continue;
+                    }
+                    if (orderInfo.state == 1) {//商品转入成功
+                        continue;
+                    }
+                    if (orderInfo.state == 9) {//已支付
+
+                    }
+                    entrustOrderTotal += 1;
                     let retDetail = await getOrderInfo(orderInfo.orderSn);
                     if (retDetail && retDetail.code == 200) {
-                        // let ret = await revokeEntrust(orderInfo.orderSn);
-                        // if (ret && ret.code == 200) {
+                        optOrderNum += 1;
                         let baseInfo = retDetail.data.baseInfo;
+                        let artInfo = retDetail.data.artInfo;
+                        magicJS.logger.info(`[${orderInfo.title}委托购买数量:${orderInfo.num},已完成:${artInfo.num}`);
                         let retOpt = await cancelEntrustOrder(baseInfo.orderSn);
-                        magicJS.notification.msg(`撤销委托成功!`);
+                        if (retOpt && retOpt.code == 200) {
+                            magicJS.notification.appendNotifyInfo(`[${orderInfo.title}x${orderInfo.num}]¥${orderInfo.price}委托单撤销成功!`);
+                        } else {
+                            magicJS.notification.appendNotifyInfo(`[${orderInfo.title}x${orderInfo.num}]¥${orderInfo.price}委托单撤销失败,原因:${retOpt.msg}!`);
+                        }
                     }
                 }
             }
@@ -135,6 +155,14 @@ async function tryTRevokeEntrust() {
             }
         }
     }
+    magicJS.logger.info(`共检测到历史总共${entrustOrderTotal}个委托单,需处理的委托单数:${optOrderNum}`);
+    if (optOrderNum == 0) {
+        if (name && name.length > 0) {
+            magicJS.notification.appendNotifyInfo(`不存在购买[${name}]未完成的委托单!`);
+        } else {
+            magicJS.notification.appendNotifyInfo(`不存在任何未完成的委托单!`);
+        }
+    }
 }
 
 /**