shawenguan 1 năm trước cách đây
mục cha
commit
cc5031268f
2 tập tin đã thay đổi với 120 bổ sung9 xóa
  1. 28 0
      Scripts/wubian/wubianHelper.js
  2. 92 9
      Scripts/wubian/wubianSynthesis.js

+ 28 - 0
Scripts/wubian/wubianHelper.js

@@ -138,6 +138,11 @@ function checkHandleRequest() {
                 break;
             case '/vmf/app/synthesis/createConvertOrder':
                 break;
+            case '/vmf/app/synthesis/compositeGoodsList':
+                handleCompositeGoodsList();
+                break;
+            case '/vmf/app/synthesis/createCompositeOrder':
+                break;
             default:
                 break;
         }
@@ -280,6 +285,7 @@ function handleActivityList() {
         // endTiem
         // hashId
         // activityType
+        // type 0=合成 1=兑换或置换
         const hashId = item.hashId;
         dataDict[hashId] = item;
         item.status = 1;
@@ -310,6 +316,7 @@ function handleCvtGoodsList() {
     if (isActivityTaskCaptureEnabled()) {
         magicJS.data.write(WuBianConstKey.ActivityId, activityId);
         let activityInfo = rspData.data.activityInfo;
+        activityInfo.type = 1;
         magicJS.notification.appendNotifyInfo(`🎉[${activityInfo.name}]数据采集成功!`);
     }
     let key = `${WuBianConstKey.ActivityCvtGoodsList}#${activityId}`;
@@ -317,6 +324,27 @@ function handleCvtGoodsList() {
 }
 
 
+function handleCompositeGoodsList() {
+    let rspData = getResponsePlainData();
+    if (!rspData) {
+        return;
+    }
+
+    if (rspData.code != 200) {
+        return;
+    }
+    let reqData = getRequestPlainData();
+    let activityId = reqData.activityId || 'default';
+    if (isActivityTaskCaptureEnabled()) {
+        magicJS.data.write(WuBianConstKey.ActivityId, activityId);
+        let activityInfo = rspData.data.activityInfo;
+        activityInfo.type = 0;
+        magicJS.notification.appendNotifyInfo(`🎉[${activityInfo.name}]数据采集成功!`);
+    }
+    let key = `${WuBianConstKey.ActivityCvtGoodsList}#${activityId}`;
+    magicJS.data.write(key, rspData.data);
+}
+
 Main().catch((e) => magicJS.logger.log(`-\n ${e}`)).finally(() => magicJS.done());
 
 

+ 92 - 9
Scripts/wubian/wubianSynthesis.js

@@ -223,7 +223,12 @@ async function trySynthesize() {
         return;
     }
     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)}`);
     if (!retCvtData) {
         return;
@@ -236,7 +241,12 @@ async function trySynthesize() {
     for (let i = 0; i < nExcuteCount; i++) {
         let oneCombination = combinationLst[i];
         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 = '';
         if (retData && retData.code == 200) {
             errMsg = `序号[${+1}]使用材料[${getCombinationGoodsLstText(oneCombination)}]兑换成功`;
@@ -266,19 +276,25 @@ function getCombinationGoodsLstText(combination) {
 function getSynthesizeCombination(retCvtData) {
     let goodsList = retCvtData.goodsList;
     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 isContinus = true;
     while (isContinus) {
         let retOneList = [];
-        magicJS.logger.info(`limitCountArr:${JSON.stringify(limitCountArr)}`);
+        magicJS.logger.info(`ruleList${JSON.stringify(ruleList)}`);
         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 limitCount = limitCountArr[i];
+            let limitCount = ruleList[i].num;
             magicJS.logger.info(`oneData${JSON.stringify(oneData)}`);
             magicJS.logger.info(`limitCount:${limitCount}`);
             if (oneData && oneData.verList && limitCount <= oneData.verList.length) {
@@ -395,6 +411,8 @@ async function getCvtGoodsList(activityId, noCache) {
     return data;
 }
 
+
+
 async function queryCvtGoodsList(activityId) {
     const url = `https://api.wubian.pro/vmf/app/synthesis/convertGoodsList`;
     const reqData = {
@@ -414,7 +432,46 @@ async function queryCvtGoodsList(activityId) {
             magicJS.logger.error(e);
         }
     }).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);
     });
     return result;
@@ -446,6 +503,32 @@ async function doCreateConvertOrder(activityId, goodsList) {
     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());