|
|
@@ -15,6 +15,8 @@ const WuBianConstKey = {
|
|
|
ActivityTagName: 'WubianActivityActivityTagName',
|
|
|
ActivityIndexName: 'WubianActivityIndexName',
|
|
|
ActivityId: 'WubianActivityId',
|
|
|
+ SynthesisConcurrentMode: 'WubianSynthesisConcurrentMode',
|
|
|
+ SynthesisRunsPerSecond: 'WubianSynthesisRunsPerSecond',
|
|
|
};
|
|
|
|
|
|
const gUserAgent = `Mozilla/5.0 (iPhone; CPU iPhone OS 16_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Html5Plus/1.0 (Immersed/20) uni-app`;
|
|
|
@@ -35,6 +37,8 @@ const gCommonHeaders = {
|
|
|
|
|
|
let gRetBody;
|
|
|
|
|
|
+let gSynthesizeResultList = [];
|
|
|
+
|
|
|
async function Main() {
|
|
|
if (magicJS.isStrictRequest) {
|
|
|
magicJS.checkRecordRequestBody();
|
|
|
@@ -191,6 +195,16 @@ function getActivityWillCount() {
|
|
|
return 99999;
|
|
|
}
|
|
|
|
|
|
+function isConcurrentMode() {
|
|
|
+ let flag = magicJS.data.read(WuBianConstKey.SynthesisConcurrentMode, true);
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function getRunsPreSecond() {
|
|
|
+ let runs = magicJS.data.read(WuBianConstKey.SynthesisRunsPerSecond, 5);
|
|
|
+ return runs;
|
|
|
+}
|
|
|
+
|
|
|
async function getWillActivityData() {
|
|
|
let tagName = getWillActivityTagName();
|
|
|
let indexName = getWillActivityIndexName();
|
|
|
@@ -239,25 +253,68 @@ async function trySynthesize() {
|
|
|
magicJS.logger.info(`combinationLst=${JSON.stringify(combinationLst)}`);
|
|
|
let nExcuteCount = Math.min(willCount, combinationLst.length);
|
|
|
let tipsText = `[${activityData.activityType}]${activityData.name},执行结果如下:\n`;
|
|
|
- for (let i = 0; i < nExcuteCount; i++) {
|
|
|
- let oneCombination = combinationLst[i];
|
|
|
- let goodsList = getCombinationGoodsList(oneCombination);
|
|
|
- let retData = null;
|
|
|
- if (activityData.type == 0) {
|
|
|
- retData = await doCreateCompositeOrder(activityId, goodsList);
|
|
|
- } else if (activityData.type == 1) {
|
|
|
- retData = await doCreateConvertOrder(activityId, goodsList);
|
|
|
- }
|
|
|
- let errMsg = '';
|
|
|
- if (retData && retData.code == 200) {
|
|
|
- errMsg = `序号[${+1}]使用材料[${getCombinationGoodsLstText(oneCombination)}]兑换成功`;
|
|
|
- } else {
|
|
|
- errMsg = `序号[${i + 1}]使用材料[${getCombinationGoodsLstText(oneCombination)}]${retData?.msg || '兑换失败'}`;
|
|
|
- }
|
|
|
- tipsText += `${errMsg}\n`;
|
|
|
- }
|
|
|
+
|
|
|
+ let nRuns = getRunsPreSecond();
|
|
|
+ let ctrlMillSec = 1000 / nRuns;
|
|
|
+ let isConcurrentExcute = isConcurrentMode();
|
|
|
if (nExcuteCount == 0) {
|
|
|
tipsText += `缺少可执行的材料组合,请检查活动配置`;
|
|
|
+ } else {
|
|
|
+ if (isConcurrentExcute) {
|
|
|
+ for (let n = 0; n < nRuns; n++) {
|
|
|
+ let startTime = Date.now();
|
|
|
+ for (let i = 0; i < nExcuteCount; i++) {
|
|
|
+ let oneCombination = combinationLst[i];
|
|
|
+ let goodsList = getCombinationGoodsList(oneCombination);
|
|
|
+ if (activityData.type == 0) {
|
|
|
+ doCreateCompositeOrder(activityId, goodsList);
|
|
|
+ } else if (activityData.type == 1) {
|
|
|
+ doCreateConvertOrder(activityId, goodsList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let costTime = Date.now() - startTime;
|
|
|
+ if (costTime < ctrlMillSec) {
|
|
|
+ await magicJS.sleep(ctrlMillSec - costTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let nSuccCount = 0;
|
|
|
+ let nFailCount = 0;
|
|
|
+ for (let retData of gSynthesizeResultList) {
|
|
|
+ if (retData && retData.code == 200) {
|
|
|
+ nSuccCount += 1;
|
|
|
+ } else {
|
|
|
+ nFailCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tipsText += `成功兑换次数:${nSuccCount}\n`;
|
|
|
+ tipsText += `失败兑换次数:${nFailCount}\n`;
|
|
|
+ tipsText += `未知结果次数:${nExcuteCount - nSuccCount - nFailCount}\n`;
|
|
|
+ } else {
|
|
|
+ for (let n = 0; n < nRuns; n++) {
|
|
|
+ let startTime = Date.now();
|
|
|
+ for (let i = 0; i < nExcuteCount; i++) {
|
|
|
+ let oneCombination = combinationLst[i];
|
|
|
+ let goodsList = getCombinationGoodsList(oneCombination);
|
|
|
+ let retData = null;
|
|
|
+ if (activityData.type == 0) {
|
|
|
+ retData = await doCreateCompositeOrder(activityId, goodsList);
|
|
|
+ } else if (activityData.type == 1) {
|
|
|
+ retData = await doCreateConvertOrder(activityId, goodsList);
|
|
|
+ }
|
|
|
+ let errMsg = '';
|
|
|
+ if (retData && retData.code == 200) {
|
|
|
+ errMsg = `序号[${+1}]使用材料[${getCombinationGoodsLstText(oneCombination)}]兑换成功`;
|
|
|
+ } else {
|
|
|
+ errMsg = `序号[${i + 1}]使用材料[${getCombinationGoodsLstText(oneCombination)}]${retData?.msg || '兑换失败'}`;
|
|
|
+ }
|
|
|
+ tipsText += `${errMsg}\n`;
|
|
|
+ }
|
|
|
+ let costTime = Date.now() - startTime;
|
|
|
+ if (costTime < ctrlMillSec) {
|
|
|
+ await magicJS.sleep(ctrlMillSec - costTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
magicJS.notification.appendNotifyInfo(tipsText);
|
|
|
}
|
|
|
@@ -496,6 +553,7 @@ async function doCreateConvertOrder(activityId, goodsList) {
|
|
|
try {
|
|
|
let rspData = response.body;
|
|
|
magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
|
|
|
+ gSynthesizeResultList.push(rspData);
|
|
|
return rspData;
|
|
|
} catch (e) {
|
|
|
magicJS.logger.error(e);
|
|
|
@@ -522,6 +580,7 @@ async function doCreateCompositeOrder(activityId, goodsList) {
|
|
|
try {
|
|
|
let rspData = response.body;
|
|
|
magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
|
|
|
+ gSynthesizeResultList.push(rspData);
|
|
|
return rspData;
|
|
|
} catch (e) {
|
|
|
magicJS.logger.error(e);
|