|
|
@@ -99,6 +99,11 @@ async function all() {
|
|
|
} else {
|
|
|
viewSort = 0;
|
|
|
}
|
|
|
+ let collectionName = '未知';
|
|
|
+ if (castingId > 0) {
|
|
|
+ collectionName = getCollectionNameById(castingId);
|
|
|
+ lk.setVal(GandartConstKey.LLockCollectionName, collectionName);
|
|
|
+ }
|
|
|
if (castingId <= 0) {
|
|
|
lk.prependNotifyInfo('⚠️请设置光予产品品类');
|
|
|
hasNeedSendNotify = true;
|
|
|
@@ -106,10 +111,37 @@ async function all() {
|
|
|
lk.prependNotifyInfo('⚠️请设置光予产品编号');
|
|
|
hasNeedSendNotify = true;
|
|
|
} else {
|
|
|
- let itemLst = await refreshLstOnSale(castingId, price);
|
|
|
- if (itemLst && itemLst.length > 0) {
|
|
|
- hasNeedSendNotify = await checkToBuyAll(itemLst);
|
|
|
+ // 流通量
|
|
|
+ let collectionCirculation = 100000;
|
|
|
+ let pageSize = 15;
|
|
|
+ let totalPage = Math.ceil(collectionCirculation / pageSize);
|
|
|
+ let curPage = 1;
|
|
|
+ let collectionItem;
|
|
|
+ while (curPage <= totalPage) {
|
|
|
+ let ret = await refreshLstOnSale(castingId, viewSort);
|
|
|
+ if (ret && ret.success) {
|
|
|
+ if (ret.collectionItem) {
|
|
|
+ collectionItem = ret.collectionItem;
|
|
|
+ break
|
|
|
+ }
|
|
|
+ totalPage = ret.totalPage;
|
|
|
+ curPage += 1;
|
|
|
+ if (curPage > totalPage) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (collectionItem) {
|
|
|
+ if (collectionItem.transactionStatus == 2) {//2=可购买,4=支付中
|
|
|
+ hasNeedSendNotify = await checkToBuyCollection(collectionItem);
|
|
|
+ } else {
|
|
|
+ let tipsText = `产品${collectionItem.collectionName}#${collectionItem.viewSort}已被锁定,状态=${collectionItem.transactionStatus}`;
|
|
|
+ lk.log(tipsText);
|
|
|
+ }
|
|
|
} else {
|
|
|
+ lk.log(`请求锁定的产品[${collectionName}#${viewSort}]不在寄售中`);
|
|
|
hasNeedSendNotify = false;
|
|
|
}
|
|
|
}
|
|
|
@@ -120,17 +152,16 @@ async function all() {
|
|
|
lk.done();
|
|
|
}
|
|
|
|
|
|
-async function getItemOnSale(castingId, price, pageSize = 15) {
|
|
|
+async function refreshLstOnSale(castingId, viewSort, pageSize = 15, page = 1) {
|
|
|
return new Promise((resolve, _reject) => {
|
|
|
try {
|
|
|
- let page = 1;
|
|
|
const headers = GCommonGandartHeads;
|
|
|
headers.Host = "api2.gandart.com";
|
|
|
let signData = getSign();
|
|
|
signData.castingId = castingId;
|
|
|
signData.page = page;
|
|
|
signData.pageSize = pageSize;
|
|
|
- signData.sort = 1;// 1=编号,2=价格
|
|
|
+ signData.sort = 2;// 1=编号,2=价格
|
|
|
signData.transactionStatus = 2;
|
|
|
let body = lk.objToQueryStr(signData);
|
|
|
let url = {
|
|
|
@@ -141,45 +172,42 @@ async function getItemOnSale(castingId, price, pageSize = 15) {
|
|
|
let collectionName = getCollectionNameById(castingId);
|
|
|
lk.log(`请求产品[${collectionName}(${castingId})]寄售列表:${body}`);
|
|
|
lk.post(url, async (error, _response, data) => {
|
|
|
- let retItemLst = [];
|
|
|
+ let finalRet = {
|
|
|
+ success: false,
|
|
|
+ collectionItem: null,
|
|
|
+ };
|
|
|
try {
|
|
|
if (error) {
|
|
|
lk.log(`获取寄售列表信息发生错误`);
|
|
|
lk.execFail();
|
|
|
lk.appendNotifyInfo(`❌获取寄售列表失败,请稍后再试`);
|
|
|
} else {
|
|
|
+ finalRet.success = true;
|
|
|
let ret = JSON.parse(data);
|
|
|
- let minPrice = 99999;
|
|
|
if (ret.success) {
|
|
|
let obj = ret.obj;
|
|
|
+ k.log(`获取到产品[${collectionName}]${obj.page}页寄售列表`);
|
|
|
+ finalRet.totalPage = Math.floor(obj.total / obj.page_size);
|
|
|
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 (d.viewSort == viewSort) {
|
|
|
+ finalRet.collectionItem = 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}`);
|
|
|
+ if (finalRet.collectionItem) {
|
|
|
+ lk.log(`搜寻到产品[${collectionName}#${viewSort}]`);
|
|
|
}
|
|
|
} else {
|
|
|
-
|
|
|
+ lk.log(`获取寄售列表失败,响应:${data}`);
|
|
|
+ finalRet.success = false;
|
|
|
}
|
|
|
}
|
|
|
} catch (e) {
|
|
|
- lk.log(`获取寄售列表信息失败`);
|
|
|
+ lk.log(`获取寄售列表信息发生错误`);
|
|
|
lk.logErr(e);
|
|
|
lk.execFail();
|
|
|
} finally {
|
|
|
- resolve(retItemLst);
|
|
|
+ resolve(finalRet);
|
|
|
}
|
|
|
});
|
|
|
} catch (e) {
|