lrf 2 rokov pred
rodič
commit
3edd4aa99a

+ 30 - 0
app/service/system/platformAct.js

@@ -23,6 +23,36 @@ class PlatformActService extends CrudService {
     rs = await this.afterQuery(filter, rs);
     return rs;
   }
+
+  getActText(data) {
+    const { type } = data;
+    let text = '';
+    if (type === '2') {
+      text = '赠品';
+    } else if (type === '3') {
+      text = '特价';
+    } else if (type === '4') {
+      text = '加价购';
+    } else if (type === '5') {
+      const discount = _.get(data, 'config.discount', []);
+      for (const i of discount) {
+        const { limit, number } = i;
+        text = `${text}满${limit}减${number};`;
+      }
+    } else if (type === '6') {
+      const discount = _.get(data, 'config.discount', []);
+      for (const i of discount) {
+        const { limit, number, max } = i;
+        text = `满${limit}打${number}折`;
+        if (max) text = `${text}(最多减免${max}元)`;
+        text = `${text};`;
+      }
+    } else if (type === '7') {
+      text = '套装';
+    }
+    return text;
+  }
+
 }
 
 module.exports = PlatformActService;

+ 8 - 2
app/service/view/goods.js

@@ -91,7 +91,7 @@ class GoodsService extends CrudService {
           },
           { $unwind: '$act' },
           { $replaceRoot: { newRoot: '$act' } },
-          { $project: { act_time: 1, config: 1 } },
+          { $project: { act_time: 1, config: 1, type: 1 } },
         ],
         as: 'act',
       },
@@ -116,7 +116,13 @@ class GoodsService extends CrudService {
       },
     });
     const res = await this.goodsModel.aggregate(pipeline);
-    return _.head(res);
+    let data = _.head(res);
+    if (data) data = JSON.parse(JSON.stringify(data));
+    for (const d of data.act) {
+      const text = this.ctx.service.system.platformAct.getActText(d);
+      d.text = text;
+    }
+    return data;
   }