|
@@ -223,7 +223,12 @@ async function trySynthesize() {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
let activityId = activityData.hashId || activityData.activityId;
|
|
let activityId = activityData.hashId || activityData.activityId;
|
|
|
- let retCvtData = await getCvtGoodsList(activityId, true);
|
|
|
|
|
|
|
+ let retCvtData = null;
|
|
|
|
|
+ if (activityData.type == 0) {
|
|
|
|
|
+ retCvtData = await getCompositeGoodsList(activityId, true);
|
|
|
|
|
+ } else if (activityData.type == 1) {
|
|
|
|
|
+ retCvtData = await getCvtGoodsList(activityId, true);
|
|
|
|
|
+ }
|
|
|
magicJS.logger.info(`retCvtData=${JSON.stringify(retCvtData)}`);
|
|
magicJS.logger.info(`retCvtData=${JSON.stringify(retCvtData)}`);
|
|
|
if (!retCvtData) {
|
|
if (!retCvtData) {
|
|
|
return;
|
|
return;
|
|
@@ -236,7 +241,12 @@ async function trySynthesize() {
|
|
|
for (let i = 0; i < nExcuteCount; i++) {
|
|
for (let i = 0; i < nExcuteCount; i++) {
|
|
|
let oneCombination = combinationLst[i];
|
|
let oneCombination = combinationLst[i];
|
|
|
let goodsList = getCombinationGoodsList(oneCombination);
|
|
let goodsList = getCombinationGoodsList(oneCombination);
|
|
|
- let retData = await doCreateConvertOrder(activityId, goodsList);
|
|
|
|
|
|
|
+ let retData = null;
|
|
|
|
|
+ if (activityData.type == 0) {
|
|
|
|
|
+ retData = await doCreateCompositeOrder(activityId, goodsList);
|
|
|
|
|
+ } else if (activityData.type == 1) {
|
|
|
|
|
+ retData = await doCreateConvertOrder(activityId, goodsList);
|
|
|
|
|
+ }
|
|
|
let errMsg = '';
|
|
let errMsg = '';
|
|
|
if (retData && retData.code == 200) {
|
|
if (retData && retData.code == 200) {
|
|
|
errMsg = `序号[${+1}]使用材料[${getCombinationGoodsLstText(oneCombination)}]兑换成功`;
|
|
errMsg = `序号[${+1}]使用材料[${getCombinationGoodsLstText(oneCombination)}]兑换成功`;
|
|
@@ -266,19 +276,25 @@ function getCombinationGoodsLstText(combination) {
|
|
|
function getSynthesizeCombination(retCvtData) {
|
|
function getSynthesizeCombination(retCvtData) {
|
|
|
let goodsList = retCvtData.goodsList;
|
|
let goodsList = retCvtData.goodsList;
|
|
|
let activityInfo = retCvtData.activityInfo;
|
|
let activityInfo = retCvtData.activityInfo;
|
|
|
- let limitCountArr = activityInfo.limit;
|
|
|
|
|
- if (typeof limitCountArr == 'number') {
|
|
|
|
|
- limitCountArr = [limitCountArr];
|
|
|
|
|
|
|
+ let ruleList = retCvtData.ruleList;
|
|
|
|
|
+ if (!ruleList) {
|
|
|
|
|
+ if (typeof activityInfo.limit == 'number') {
|
|
|
|
|
+ ruleList = [{
|
|
|
|
|
+ num: activityInfo.limit,
|
|
|
|
|
+ desc: '',
|
|
|
|
|
+ matchArtIdList: [activityInfo.articleId],
|
|
|
|
|
+ }];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
let retAllList = [];
|
|
let retAllList = [];
|
|
|
let isContinus = true;
|
|
let isContinus = true;
|
|
|
while (isContinus) {
|
|
while (isContinus) {
|
|
|
let retOneList = [];
|
|
let retOneList = [];
|
|
|
- magicJS.logger.info(`limitCountArr:${JSON.stringify(limitCountArr)}`);
|
|
|
|
|
|
|
+ magicJS.logger.info(`ruleList${JSON.stringify(ruleList)}`);
|
|
|
magicJS.logger.info(`goodsList:${JSON.stringify(goodsList)}`);
|
|
magicJS.logger.info(`goodsList:${JSON.stringify(goodsList)}`);
|
|
|
- for (let i = 0; i < limitCountArr.length; i++) {
|
|
|
|
|
|
|
+ for (let i = 0; i < ruleList.length; i++) {
|
|
|
let oneData = goodsList[i];
|
|
let oneData = goodsList[i];
|
|
|
- let limitCount = limitCountArr[i];
|
|
|
|
|
|
|
+ let limitCount = ruleList[i].num;
|
|
|
magicJS.logger.info(`oneData${JSON.stringify(oneData)}`);
|
|
magicJS.logger.info(`oneData${JSON.stringify(oneData)}`);
|
|
|
magicJS.logger.info(`limitCount:${limitCount}`);
|
|
magicJS.logger.info(`limitCount:${limitCount}`);
|
|
|
if (oneData && oneData.verList && limitCount <= oneData.verList.length) {
|
|
if (oneData && oneData.verList && limitCount <= oneData.verList.length) {
|
|
@@ -395,6 +411,8 @@ async function getCvtGoodsList(activityId, noCache) {
|
|
|
return data;
|
|
return data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
async function queryCvtGoodsList(activityId) {
|
|
async function queryCvtGoodsList(activityId) {
|
|
|
const url = `https://api.wubian.pro/vmf/app/synthesis/convertGoodsList`;
|
|
const url = `https://api.wubian.pro/vmf/app/synthesis/convertGoodsList`;
|
|
|
const reqData = {
|
|
const reqData = {
|
|
@@ -414,7 +432,46 @@ async function queryCvtGoodsList(activityId) {
|
|
|
magicJS.logger.error(e);
|
|
magicJS.logger.error(e);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
- const msg = `请求消耗产品列表异常\n${JSON.stringify(err)}`;
|
|
|
|
|
|
|
+ const msg = `请求兑换消耗产品列表异常\n${JSON.stringify(err)}`;
|
|
|
|
|
+ magicJS.logger.error(msg);
|
|
|
|
|
+ });
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async function getCompositeGoodsList(activityId, noCache) {
|
|
|
|
|
+ let key = `${WuBianConstKey.ActivityCvtGoodsList}#${activityId}`;
|
|
|
|
|
+ let data = magicJS.data.read(key, null);
|
|
|
|
|
+ if (!data || noCache) {
|
|
|
|
|
+ let ret = await queryCompositeGoodsList(activityId);
|
|
|
|
|
+ if (ret.code == 200) {
|
|
|
|
|
+ data = ret.data;
|
|
|
|
|
+ magicJS.data.write(key, data);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return data;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function queryCompositeGoodsList(activityId) {
|
|
|
|
|
+ const url = `https://api.wubian.pro/vmf/app/synthesis/compositeGoodsList`;
|
|
|
|
|
+ const reqData = {
|
|
|
|
|
+ id: activityId,
|
|
|
|
|
+ };
|
|
|
|
|
+ let options = {
|
|
|
|
|
+ url: url,
|
|
|
|
|
+ headers: gCommonHeaders,
|
|
|
|
|
+ body: JSON.stringify(reqData),
|
|
|
|
|
+ };
|
|
|
|
|
+ let result = await magicJS.http.post(options).then(response => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ let rspData = response.body;
|
|
|
|
|
+ magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
|
|
|
|
|
+ return rspData;
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ magicJS.logger.error(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(err => {
|
|
|
|
|
+ const msg = `请求合成消耗产品列表异常\n${JSON.stringify(err)}`;
|
|
|
magicJS.logger.error(msg);
|
|
magicJS.logger.error(msg);
|
|
|
});
|
|
});
|
|
|
return result;
|
|
return result;
|
|
@@ -446,6 +503,32 @@ async function doCreateConvertOrder(activityId, goodsList) {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function doCreateCompositeOrder() {
|
|
|
|
|
+ const url = `https://api.wubian.pro/vmf/app/synthesis/createCompositeOrder`;
|
|
|
|
|
+ const reqData = {
|
|
|
|
|
+ activityId: activityId,
|
|
|
|
|
+ goodsList: goodsList,
|
|
|
|
|
+ };
|
|
|
|
|
+ let options = {
|
|
|
|
|
+ url: url,
|
|
|
|
|
+ headers: gCommonHeaders,
|
|
|
|
|
+ body: JSON.stringify(reqData),
|
|
|
|
|
+ };
|
|
|
|
|
+ let result = await magicJS.http.post(options).then(response => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ let rspData = response.body;
|
|
|
|
|
+ magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
|
|
|
|
|
+ return rspData;
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ magicJS.logger.error(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(err => {
|
|
|
|
|
+ const msg = `请求合成异常\n${JSON.stringify(err)}`;
|
|
|
|
|
+ magicJS.logger.error(msg);
|
|
|
|
|
+ });
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
Main().catch((e) => magicJS.logger.log(`-\n ${e}`)).finally(() => magicJS.done());
|
|
Main().catch((e) => magicJS.logger.log(`-\n ${e}`)).finally(() => magicJS.done());
|
|
|
|
|
|
|
|
|
|
|