guhongwei 2 年之前
父节点
当前提交
afd141463e
共有 1 个文件被更改,包括 24 次插入11 次删除
  1. 24 11
      app/service/shop/goodsJoinAct.js

+ 24 - 11
app/service/shop/goodsJoinAct.js

@@ -64,14 +64,15 @@ class GoodsJoinActService extends CrudService {
   }
 
   async query(filter, { skip = 0, limit, sort, desc, projection } = {}) {
-    const { platform_act, platform_act_type, shop, shop_name, goods, goods_name,goods_status, spec, spec_name, status, goods_type = 'basic' } = filter;
+    const { platform_act, platform_act_type, shop, shop_name, goods, goods_name, goods_status, spec, spec_name, status, goods_type = 'basic' } = filter;
     const mq = {};
+    const goodsMq = { status: '1' };
     if (platform_act) mq.platform_act = platform_act;
     if (platform_act_type) mq.platform_act_type = platform_act_type;
     if (shop) mq.shop = shop;
     if (goods) mq.goods = goods;
     if (goods_name) mq['goods.name'] = new RegExp(goods_name);
-    if (goods_status) mq["goods.status"] = new RegExp(goods_status);
+    if (goods_status) goodsMq.status = new RegExp(goods_status);
     if (spec) mq.spec = spec;
     if (spec_name) mq['spec.name'] = new RegExp(spec_name);
     if (status) mq.status = status;
@@ -105,20 +106,32 @@ class GoodsJoinActService extends CrudService {
         as: 'shopInfo',
       },
     });
+    // 检查商品的实时状态及上架状态
+    pipeline.push({ $addFields: { goods_id: { $toObjectId: '$goods._id' } } });
+    pipeline.push({
+      $lookup: {
+        from: 'goods',
+        localField: 'goods_id',
+        foreignField: '_id',
+        pipeline: [{ $match: goodsMq }],
+        as: 'goods_prototype',
+      },
+    });
+    pipeline.push({ $match: { 'goods_prototype.length': { $gt: 0 } } });
     pipeline.push({
       $project: {
         meta: 1,
         shop: 1,
-        shop_name: { $first: "$shopInfo.name" },
-        goods: "$goods._id",
-        goods_name: "$goods.name",
+        shop_name: { $first: '$shopInfo.name' },
+        goods: '$goods._id',
+        goods_name: '$goods.name',
         // goods_status: "$goods.status",
-        act_tags: "$goods.act_tags",
-        spec: "$spec._id",
-        spec_name: "$spec.name",
-        file: "$goods.file",
-        sell_money: { $toString: "$spec.sell_money" },
-        flow_money: { $toString: "$spec.flow_money" },
+        act_tags: '$goods.act_tags',
+        spec: '$spec._id',
+        spec_name: '$spec.name',
+        file: '$goods.file',
+        sell_money: { $toString: '$spec.sell_money' },
+        flow_money: { $toString: '$spec.flow_money' },
         platform_act_type: 1,
         platform_act: 1,
         config: 1,