lrf 2 jaren geleden
bovenliggende
commit
af8df3d6de
3 gewijzigde bestanden met toevoegingen van 30 en 4 verwijderingen
  1. 4 0
      app/service/shop/goodsJoinAct.js
  2. 24 3
      app/service/system/platformAct.js
  3. 2 1
      app/service/view/goods.js

+ 4 - 0
app/service/shop/goodsJoinAct.js

@@ -13,6 +13,10 @@ class GoodsJoinActService extends CrudService {
     this.goodsModel = this.ctx.model.Shop.Goods;
     this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
   }
+  // TODO 需要接口: 检测商品/规格 是否已经处于同种优惠方式的活动中,有就不能添加;
+  // 可以存在多个不同种优惠方式的活动中: 满减,满折,赠品=> √; 满折,满折 => ×
+  // 需要检查活动是否处于活动中,如果在活动中的,则不能添加
+
   async create(data) {
     assert(data);
     const { goods, spec, shop, platform_act } = data;

+ 24 - 3
app/service/system/platformAct.js

@@ -27,15 +27,36 @@ class PlatformActService extends CrudService {
     rs = await this.afterQuery(filter, rs);
     return rs;
   }
-
-  getActText(data) {
+  /**
+   * 获取设置
+   * @param {PlatformAct} data 活动数据
+   * @param {Goods} goods 商品数据
+   */
+  async getActText(data, goods) {
     const { type } = data;
     let tag = '';
     let text = '';
+    const aboutList = [];
     if (type === '2') {
       tag = '赠品';
+      // 寻找赠品信息
+      const list = await this.gjaModel.find({ platform_act: data._id, 'goods._id': goods._id });
+      for (const i of list) {
+        const gift = _.get(i, 'config.gift', []);
+        const goods = _.get(i, 'goods._id');
+        const spec = _.get(i, 'spec._id');
+        aboutList.push({ goods, spec, gift });
+      }
     } else if (type === '3') {
       tag = '特价';
+      // 寻找商品的特价
+      const list = await this.gjaModel.find({ platform_act: data._id, 'goods._id': goods._id });
+      for (const i of list) {
+        const goods = _.get(i, 'goods._id');
+        const spec = _.get(i, 'spec._id');
+        const price = _.get(i, 'config.sp_price');
+        aboutList.push({ goods, spec, price });
+      }
     } else if (type === '4') {
       tag = '加价购';
     } else if (type === '5') {
@@ -57,7 +78,7 @@ class PlatformActService extends CrudService {
     } else if (type === '7') {
       tag = '套装';
     }
-    return { tag, text };
+    return { tag, text, aboutList };
   }
 
   async beforeUpdate(filter, update) {

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

@@ -140,9 +140,10 @@ class GoodsService extends CrudService {
       data.goods.tags = nt;
     }
     for (const d of data.act) {
-      const { tag, text } = this.ctx.service.system.platformAct.getActText(d);
+      const { tag, text, aboutList } = await this.ctx.service.system.platformAct.getActText(d, data.goods);
       d.text = text;
       d.tag = tag;
+      d.list = aboutList;
     }
     data.act = _.uniqBy(data.act, '_id');
     return data;