|
|
@@ -48,8 +48,6 @@ if (!lk.isExecComm) {
|
|
|
if (lk.isRequest()) {
|
|
|
checkHanldeRequest();
|
|
|
lk.done();
|
|
|
- } else {
|
|
|
- all();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -58,7 +56,6 @@ function checkHanldeRequest() {
|
|
|
const path = $request.path;
|
|
|
lk.log(`请求url=${url}#${$request.method}`);
|
|
|
lk.log(`请求body=${lk.getRequestBody()}`);
|
|
|
- lk.log(`path=${path}`);
|
|
|
if ($request && $request.method != 'OPTIONS') {
|
|
|
switch (path) {
|
|
|
case '/base/auth/verifyCodeLogin':
|
|
|
@@ -88,7 +85,7 @@ function handleVerifyCodeLogin() {
|
|
|
if (!data) {
|
|
|
return;
|
|
|
}
|
|
|
- lk.log(`开始获取Token`);
|
|
|
+ lk.log(`正在获取Token`);
|
|
|
data = JSON.parse(data);
|
|
|
if (data.success) {
|
|
|
let jwktoken = data.obj.token;
|
|
|
@@ -111,7 +108,7 @@ function handleFindAllIsOpenResale() {
|
|
|
if (!data) {
|
|
|
return;
|
|
|
}
|
|
|
- lk.log(`获取最新产品开放在售列表`);
|
|
|
+ lk.log(`获取产品在售列表`);
|
|
|
data = JSON.parse(data);
|
|
|
if (data.success) {
|
|
|
let obj = data.obj;
|
|
|
@@ -135,7 +132,7 @@ function handleSelectRecord() {
|
|
|
if (!data) {
|
|
|
return;
|
|
|
}
|
|
|
- lk.log(`获取收藏的产品列表`);
|
|
|
+ lk.log(`获取产品收藏列表`);
|
|
|
data = JSON.parse(data);
|
|
|
if (data.success) {
|
|
|
let obj = data.obj;
|
|
|
@@ -182,15 +179,19 @@ function handleTradingMarket() {
|
|
|
}
|
|
|
|
|
|
function checkFixLimitPrice(castingId, info, lastCastingId) {
|
|
|
- // 检查预设价格
|
|
|
+ // 检查预设捡漏价格
|
|
|
+ let resalePrice = Number(info.resalePrice);
|
|
|
if (lastCastingId == castingId) {
|
|
|
let floatInterval = lk.getVal(GandartConstKey.FloatPriceIntaval, 5);
|
|
|
let price = Number(lk.getVal(GandartConstKey.LimitPrice, 0));
|
|
|
- if (price - floatInterval > Number(info.resalePrice)) {
|
|
|
+ if (resalePrice > 0 && price - floatInterval > resalePrice) {
|
|
|
lk.setVal(GandartConstKey.LimitPrice, info.resalePrice);
|
|
|
}
|
|
|
} else {
|
|
|
- lk.setVal(GandartConstKey.LimitPrice, info.resalePrice);
|
|
|
+ if (resalePrice > 0) {
|
|
|
+ resalePrice -= 10;
|
|
|
+ }
|
|
|
+ lk.setVal(GandartConstKey.LimitPrice, String(resalePrice));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -200,7 +201,7 @@ function handleCollectionDetailsByCastingId() {
|
|
|
if (!data) {
|
|
|
return;
|
|
|
}
|
|
|
- lk.log(`开始获取产品信息`);
|
|
|
+ lk.log(`获取产品详情信息`);
|
|
|
data = JSON.parse(data);
|
|
|
if (data.success) {
|
|
|
let obj = data.obj;
|
|
|
@@ -277,6 +278,7 @@ function checkAppendCollectionItemsDiff(cLst, pageLst) {
|
|
|
}
|
|
|
return newLst;
|
|
|
}
|
|
|
+
|
|
|
function getCollectionMInfoById(castingId) {
|
|
|
let ret;
|
|
|
try {
|
|
|
@@ -302,173 +304,6 @@ function getCollectionNameById(castingId) {
|
|
|
return name;
|
|
|
}
|
|
|
|
|
|
-async function all() {
|
|
|
- let hasNeedSendNotify = true;
|
|
|
- if (gandartToken == '') {
|
|
|
- lk.execFail();
|
|
|
- lk.appendNotifyInfo(`⚠️请先打开光予登录获取token`);
|
|
|
- } else {
|
|
|
- let castingId = lk.getVal(GandartConstKey.CastingId, 0);
|
|
|
- castingId = Number(castingId);
|
|
|
- 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 {
|
|
|
- let itemLst = await refreshLstOnSale(castingId, price);
|
|
|
- if (itemLst && itemLst.length > 0) {
|
|
|
- hasNeedSendNotify = await checkToBuyAll(itemLst);
|
|
|
- } else {
|
|
|
- hasNeedSendNotify = false;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (hasNeedSendNotify) {
|
|
|
- lk.msg(``);
|
|
|
- }
|
|
|
- lk.done();
|
|
|
-}
|
|
|
-
|
|
|
-async function refreshLstOnSale(castingId, price) {
|
|
|
- return new Promise((resolve, _reject) => {
|
|
|
- try {
|
|
|
- const headers = GCommonGandartHeads;
|
|
|
- headers.Host = "api2.gandart.com";
|
|
|
- let signData = getSign();
|
|
|
- signData.castingId = castingId;
|
|
|
- signData.page = 1;
|
|
|
- signData.pageSize = 15;
|
|
|
- signData.sort = 2;// 1=编号,2=价格
|
|
|
- signData.transactionStatus = 2;
|
|
|
- let body = lk.objToQueryStr(signData);
|
|
|
- let url = {
|
|
|
- url: `${config.RESALE_API_V2}/resaleManage/resale/onSale`,
|
|
|
- headers: headers,
|
|
|
- body: body
|
|
|
- };
|
|
|
- let collectionName = getCollectionNameById(castingId)
|
|
|
- lk.log(`请求产品[${collectionName}(${castingId})]寄售列表:${body}`);
|
|
|
- lk.post(url, async (error, _response, data) => {
|
|
|
- let retItemLst = [];
|
|
|
- try {
|
|
|
- if (error) {
|
|
|
- lk.log(`获取寄售列表信息发生错误`);
|
|
|
- lk.execFail();
|
|
|
- lk.appendNotifyInfo(`❌获取寄售列表失败,请稍后再试`);
|
|
|
- } else {
|
|
|
- let ret = JSON.parse(data);
|
|
|
- let minPrice = 99999;
|
|
|
- if (ret.success) {
|
|
|
- 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}`);
|
|
|
- }
|
|
|
- } else {
|
|
|
- lk.execFail();
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
- lk.log(`获取寄售列表信息失败`);
|
|
|
- lk.logErr(e);
|
|
|
- lk.execFail();
|
|
|
- } finally {
|
|
|
- resolve(retItemLst);
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (e) {
|
|
|
- lk.log(`获取寄售列表信息发生错误`);
|
|
|
- lk.logErr(e);
|
|
|
- resolve();
|
|
|
- }
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-async function checkToBuyAll(itemLst) {
|
|
|
- let ret = false;
|
|
|
- let count = Math.min(1, itemLst.length);
|
|
|
- for (let i = 0; i < count; i++) {
|
|
|
- let succItem = await checkToBuyCollection(itemLst[i]);
|
|
|
- if (succItem) {
|
|
|
- ret = true;
|
|
|
- }
|
|
|
- }
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-function checkToBuyCollection(item) {
|
|
|
- return new Promise((resolve, _reject) => {
|
|
|
- try {
|
|
|
- const id = item.id;
|
|
|
- const viewSort = item.viewSort || 0;
|
|
|
- const headers = GCommonGandartHeads;
|
|
|
- headers.Host = "api.gandart.com";
|
|
|
- const body = `transactionRecordId=${id}`;
|
|
|
- let url = {
|
|
|
- url: `${config.BASE_API}/v2/resaleManage/resale/buy/v2`,
|
|
|
- headers: headers,
|
|
|
- body: body
|
|
|
- };
|
|
|
- lk.log(`请求购买产品[${item.collectionName}#${viewSort}]=${body}`);
|
|
|
- // resolve(1);
|
|
|
- const collectionName = item.collectionName;
|
|
|
- lk.post(url, async (error, _response, data) => {
|
|
|
- let retItem;
|
|
|
- try {
|
|
|
- if (error) {
|
|
|
- lk.log(`无法下单产品[${collectionName}#${viewSort}]`);
|
|
|
- lk.execFail();
|
|
|
- lk.appendNotifyInfo(`❌购买失败,请稍后再试`);
|
|
|
- } else {
|
|
|
- lk.log(data);
|
|
|
- let retBuyInfo = JSON.parse(data);
|
|
|
- if (retBuyInfo.success) {
|
|
|
- let obj = retBuyInfo.obj;
|
|
|
- let orderNum = obj.orderNum;
|
|
|
- if (orderNum && orderNum.length > 0) {
|
|
|
- retItem = retBuyInfo;
|
|
|
- lk.log(`成功下单产品[${obj.collectionName}#${viewSort}],价格:${item.resalePrice},订单号:${obj.orderNum}`);
|
|
|
- lk.appendNotifyInfo(`🎉成功下单产品[${obj.collectionName}#${viewSort}],价格:${item.resalePrice},订单号:${obj.orderNum}`);
|
|
|
- }
|
|
|
- } else {
|
|
|
- lk.log(`产品[${collectionName}#${viewSort}]下单失败`);
|
|
|
- lk.execFail();
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
- lk.log(`下单产品[${collectionName}#${viewSort}]发生错误`);
|
|
|
- lk.logErr(e);
|
|
|
- lk.execFail();
|
|
|
- } finally {
|
|
|
- resolve(retItem);
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (e) {
|
|
|
- lk.log(`下单产品[${item.collectionName}#${item.viewSort}]发生错误`);
|
|
|
- lk.logErr(e);
|
|
|
- resolve();
|
|
|
- }
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
function getSign() {
|
|
|
const now = new Date().getTime();
|
|
|
const s1 = now - 20000;
|