shawenguan před 2 roky
rodič
revize
07ddb39af0
2 změnil soubory, kde provedl 178 přidání a 82 odebrání
  1. 176 80
      Scripts/gandart/gandartGrab.js
  2. 2 2
      Scripts/gandart/gandartPay.js

+ 176 - 80
Scripts/gandart/gandartGrab.js

@@ -36,6 +36,9 @@ const GandartConstKey = {
 
     IsCollectionMaxNumLimit: 'lkGandartIsCollectionMaxNumLimit',
     CollectionLockMaxNum: 'lkGandartCollectionLockMaxNum',
+
+    PasswordPlainText: 'lkGandartPasswordPlainText',
+    PrivPayWalletList: 'lkGandartPrivPayWalletList',
     // -----抢首发相关的-----
     NewCastingId: 'lkGandartNewCollectionCastingId',
 };
@@ -98,8 +101,17 @@ function getCollectionLockMaxNum() {
     return Number(num);
 }
 
-function getCurWalletListInUse() {
-    let str = lk.getVal(GandartConstKey.PrivWalletListInUse);
+function getMyPasswordPlainText() {
+    let str = lk.getVal(GandartConstKey.PasswordPlainText);
+    let ret = '';
+    if (!lk.isEmpty(str)) {
+        ret = str;
+    }
+    return ret;
+}
+
+function getMyPayWalletList() {
+    let str = lk.getVal(GandartConstKey.PrivPayWalletList);
     let ret = 'A,B,C';
     if (!lk.isEmpty(str)) {
         ret = str;
@@ -125,22 +137,47 @@ async function all() {
             }
         }
         if (isPass) {
-            let price = lk.getVal(GandartConstKey.LimitPrice, 0);
-            price = Number(price);
-            if (castingId <= 0) {
-                lk.prependNotifyInfo('⚠️请设置光予产品品类');
-                hasNeedSendNotify = true;
-            } else if (price <= 0) {
-                lk.prependNotifyInfo('⚠️请设置光予监控价格');
-                hasNeedSendNotify = true;
-            } else {
-                gandartWalletList = getCurWalletListInUse();
-                let itemLst = await refreshLstOnSale(castingId, price);
-                if (itemLst && itemLst.length > 0) {
-                    hasNeedSendNotify = await checkToBuyAll(itemLst);
+            let castingItem = await getNewCollectionCastingData();
+            if (castingItem) {
+                let userInfo = await getUser();
+                let stockNum = await getStock(castingItem.id, castingItem.collectionName);
+                if (stockNum > 0) {
+                    gandartWalletList = getMyPayWalletList();
+                    let myWalletList = await getMyWalletListDetail();
+                    let usedWalletInfo = myWalletList[0];
+                    for (let i = myWalletList.length - 1; i >= 0; i--) {
+                        let walletInfo = myWalletList[i];
+                        if (checkIsInPrivWalletList(walletInfo) && walletInfo.availableMoney >= castingItem.price) {
+                            usedWalletInfo = walletInfo;
+                            break;
+                        }
+                    }
+                    if (usedWalletInfo) {
+                        await generate();
+                        await submitOrder();
+                        let maxQueryCnt = 10;
+                        let startNum = 0;
+                        while (startNum < maxQueryCnt) {
+                            let ret = await getIsCreateOrder();
+                            if (ret && ret.success) {
+                                if (Number(ret.code) == 1) {
+                                    break;
+                                } else {
+                                    lk.log(ret.msg);
+                                }
+                            }
+                            startNum++;
+                        }
+                    } else {
+                        lk.log('无匹配钱包进行支付');
+                    }
                 } else {
-                    hasNeedSendNotify = false;
+                    lk.log('产品库存不足');
                 }
+                hasNeedSendNotify = true;
+            } else {
+                lk.log('暂无匹配的首发产品发售');
+                hasNeedSendNotify = false;
             }
         }
     }
@@ -150,6 +187,17 @@ async function all() {
     lk.done();
 }
 
+
+function checkIsInPrivWalletList(walletInfo) {
+    // if (gandartWalletList.indexOf(walletInfo.channel) > -1) {
+    //     return true;
+    // }
+    // return false;
+    return true;
+}
+
+
+
 async function getNewCollectionCastingData() {
     let newCastingId = lk.getVal(GandartConstKey.NewCastingId, 0);
     newCastingId = Number(newCastingId);
@@ -157,19 +205,31 @@ async function getNewCollectionCastingData() {
         lk.log(`没有指定首发产品铸造ID,进行自动匹配合适的首发产品`);
     }
     let nftSeriers = await findAllFirstNftSeriers();
+    let tNftCollection;
+    let allMateCollections = [];
     if (nftSeriers) {
         let nowDate = new Date();
         for (let i = 0; i < nftSeriers.length; i++) {
             let nftSerier = nftSeriers[i];
             let startDate = new Date(nftSerier.startDate);
-            if (nowDate.getTime() >= startDate.getTime() - 1000) {
-
+            if (nowDate.getTime() >= startDate.getTime() - 1000 && nftSerier.status == 1) {
+                let castingList = nftSerier.castingList;
+                for (let cItem of castingList) {
+                    if (cItem.id == newCastingId) {
+                        tNftCollection = cItem;
+                        break;
+                    }
+                    allMateCollections.push(cItem);
+                }
             }
         }
     } else {
         newCastingId = 0;
     }
-    return newCastingId;
+    if (tNftCollection) {
+        return tNftCollection;
+    }
+    return allMateCollections[0];
 }
 
 async function getNftOrderList(status, orderType = 0, page = 1, pageSize = 6) {
@@ -218,7 +278,7 @@ async function findAllFirstNftSeriers(page = 1, pageSize = 5) {
     return new Promise((resolve, _reject) => {
         try {
             const headers = GCommonGandartHeads;
-            headers.Host = "api2.gandart.com";
+            headers.Host = "api.gandart.com";
             let body = `page=${page}&pageSize=${pageSize}`;
             let url = {
                 url: `${config.BASE_API}/casting/nftseriers/findAll`,
@@ -257,101 +317,137 @@ async function findAllFirstNftSeriers(page = 1, pageSize = 5) {
     });
 }
 
-async function refreshLstOnSale(castingId, price, pageSize = 15, page = 1) {
+async function getUser() {
     return new Promise((resolve, _reject) => {
         try {
             const headers = GCommonGandartHeads;
-            headers.Host = "api2.gandart.com";
-            let signData = getSign();
-            signData.castingId = castingId;
-            signData.page = page;
-            signData.pageSize = pageSize;
-            signData.sort = 2;// 1=编号,2=价格
-            signData.transactionStatus = 2;
-            let body = lk.objToQueryStr(signData);
+            headers.Host = "api.gandart.com";
+            let body = ``;
             let url = {
-                url: `${config.RESALE_API_V2}/resaleManage/resale/onSale`,
+                url: `${config.BASE_API}/user/getUser`,
                 headers: headers,
                 body: body
             };
-            let collectionName = getCollectionNameById(castingId);
-            lk.log(`请求产品[${collectionName}(${castingId})]寄售列表:${body}`);
+            collectionName = collectionName || getCollectionNameById(castingId);
+            lk.log(`请求用户信息:${body}`);
             lk.post(url, async (error, _response, data) => {
-                let retItemLst = [];
+                let userInfo;
                 try {
                     if (error) {
-                        lk.log(`获取寄售列表数据发生错误`);
+                        lk.log(`获取用户信息发生错误`);
                         lk.execFail();
-                        lk.appendNotifyInfo(`❌获取寄售列表失败,请稍后再试`);
                     } else {
                         let ret = JSON.parse(data);
-                        let minPrice = 99999;
                         if (ret.success) {
+                            lk.log(`获取用户信息成功`);
                             let obj = ret.obj;
-                            let lst = obj.list;
-                            for (let d of lst) {
-                                if (d.transactionStatus == 2) {//2=可购买,4=支付中
-                                    const resalePrice = Number(d.resalePrice);
-                                    if (minPrice > resalePrice) {
-                                        minPrice = resalePrice;
-                                    }
-                                    if (price >= resalePrice) {
-                                        retItemLst.push(d);
-                                    }
-                                }
-                            }
-                            if (retItemLst.length > 0) {
-                                const one = retItemLst[0];
-                                lk.appendNotifyInfo(`🎉成功匹配产品[${one.collectionName}#${one.viewSort}](<=${price}),数量: ${retItemLst.length},最低价格:${one.resalePrice}`);
-                            } else {
-                                lk.log(`无匹配的价格(<=${price}),当前[${collectionName}]最低价:${minPrice}`);
-                            }
+                            userInfo = obj.user;
                         } else {
-                            lk.log(`获取寄售列表失败,响应:${data}`);
+                            lk.log(`获取用户信息失败,响应:${data}`);
                         }
                     }
                 } catch (e) {
-                    lk.log(`GandartLocker发生错误`);
+                    lk.log(`获取用户信息发生错误`);
                     lk.logErr(e);
                     lk.execFail();
                 } finally {
-                    resolve(retItemLst);
+                    resolve(userInfo);
                 }
             });
         } catch (e) {
-            lk.log(`获取寄售列表数据发生错误`);
+            lk.log(`获取用户信息发生错误`);
             lk.logErr(e);
             resolve();
         }
     });
 }
 
-
-function checkIsInPrivWalletList(item) {
-    let walletList = item.walletList;
-    for (let w of walletList) {
-        if (gandartWalletList.indexOf(w) > -1) {
-            return true;
+async function getStock(castingId, collectionName) {
+    return new Promise((resolve, _reject) => {
+        try {
+            const headers = GCommonGandartHeads;
+            headers.Host = "api2.gandart.com";
+            let body = `ids=${castingId}`;
+            let url = {
+                url: `${config.BASE_API}/casting/nftseries/getStock`,
+                headers: headers,
+                body: body
+            };
+            collectionName = collectionName || getCollectionNameById(castingId);
+            lk.log(`请求产品[${collectionName}(${castingId})]库存:${body}`);
+            lk.post(url, async (error, _response, data) => {
+                let stockNum = 0;
+                try {
+                    if (error) {
+                        lk.log(`获取产品库存发生错误`);
+                        lk.execFail();
+                        lk.appendNotifyInfo(`❌获取产品库存失败,请稍后再试`);
+                    } else {
+                        let ret = JSON.parse(data);
+                        if (ret.success) {
+                            lk.log(`获取产品库存成功,响应:${data}`);
+                            let obj = ret.obj;
+                            stockNum = Number(obj[castingId] || 0);
+                        } else {
+                            lk.log(`获取产品库存失败,响应:${data}`);
+                        }
+                    }
+                } catch (e) {
+                    lk.log(`获取产品库存发生错误`);
+                    lk.logErr(e);
+                    lk.execFail();
+                } finally {
+                    resolve(stockNum);
+                }
+            });
+        } catch (e) {
+            lk.log(`获取产品库存发生错误`);
+            lk.logErr(e);
+            resolve(0);
         }
-    }
-    return false;
+    });
 }
 
-async function checkToBuyAll(itemLst) {
-    let ret = false;
-    let count = Math.min(1, itemLst.length);
-    for (let i = 0; i < count; i++) {
-        const info = itemLst[i];
-        if (checkIsInPrivWalletList(info)) {
-            let succItem = await checkToBuyCollection(info);
-            if (succItem) {
-                ret = true;
-            }
-        } else {
-            lk.log(`[${info.collectionName}#${info.viewSort}]收款钱包(${item.walletList.join(',')})不匹配下单支付钱包(${gandartWalletList})`);
+async function getMyWalletListDetail() {
+    return new Promise((resolve, _reject) => {
+        try {
+            const headers = GCommonGandartHeads;
+            headers.Host = "api.gandart.com";
+            const body = ``;
+            let url = {
+                url: `${config.WALLET_API}/v2/wallet/list?`,
+                headers: headers,
+                body: body
+            };
+            lk.log(`请求个人钱包列表数据`);
+            lk.post(url, async (error, _response, data) => {
+                let ret;
+                try {
+                    if (error) {
+                        lk.log(`请求个人钱包列表数据发生错误`);
+                        lk.execFail();
+                    } else {
+                        let info = JSON.parse(data);
+                        if (info.success) {
+                            ret = info.obj;
+                        } else {
+                            lk.log(`请求个人钱包列表数据失败,响应:${data}`);
+                        }
+                    }
+                } catch (e) {
+                    lk.log(`请求个人钱包列表数据发生错误`);
+                    lk.logErr(e);
+                    lk.execFail();
+                } finally {
+                    resolve(ret);
+                }
+            });
+        } catch (e) {
+            lk.log(`请求个人钱包列表数据发生错误`);
+            lk.logErr(e);
+            resolve();
         }
-    }
-    return ret;
+    });
 }
 
 function checkToBuyCollection(item) {

+ 2 - 2
Scripts/gandart/gandartPay.js

@@ -167,7 +167,7 @@ async function checkPay(orderNum, orderTotal) {
         if (new Date().getTime() < endDate.getTime()) {
             lk.log('开始检查钱包是否匹配支付');
             let tranWalletList = await transactionWalletList();
-            let myWalletList = await getMyWalletList();
+            let myWalletList = await getMyWalletListDetail();
             if (tranWalletList && myWalletList) {
                 let isMateWallet = false;
                 let isPaySuccess = false;
@@ -284,7 +284,7 @@ async function transactionWalletList(orderNum) {
     });
 }
 
-async function getMyWalletList() {
+async function getMyWalletListDetail() {
     return new Promise((resolve, _reject) => {
         try {
             const headers = GCommonGandartHeads;