guhongwei 2 years ago
parent
commit
f2cb50edba
3 changed files with 54 additions and 34 deletions
  1. 1 0
      .gitignore
  2. 39 24
      app/controller/shop/config/.goodsJoinAct.js
  3. 14 10
      app/service/shop/goodsJoinAct.js

+ 1 - 0
.gitignore

@@ -12,3 +12,4 @@ run/
 typings/
 .nyc_output/
 .vscode/
+.history

+ 39 - 24
app/controller/shop/config/.goodsJoinAct.js

@@ -1,47 +1,62 @@
 module.exports = {
   create: {
-    requestBody: ['platform_act', 'spec', 'platform_act_type', 'shop', 'goods', 'config', 'status'],
+    requestBody: [
+      "platform_act",
+      "spec",
+      "platform_act_type",
+      "shop",
+      "goods",
+      "config",
+      "status",
+    ],
   },
   destroy: {
-    params: ['!id'],
-    service: 'delete',
+    params: ["!id"],
+    service: "delete",
   },
   update: {
-    params: ['!id'],
-    requestBody: ['platform_act', 'platform_act_type', 'shop', 'config', 'status'],
+    params: ["!id"],
+    requestBody: [
+      "platform_act",
+      "platform_act_type",
+      "shop",
+      "config",
+      "status",
+    ],
   },
   show: {
     parameters: {
-      params: ['!id'],
+      params: ["!id"],
     },
-    service: 'fetch',
+    service: "fetch",
   },
   index: {
     parameters: {
       query: {
-        'meta.createdAt@start': 'meta.createdAt@start',
-        'meta.createdAt@end': 'meta.createdAt@end',
-        platform_act: 'platform_act',
-        platform_act_type: 'platform_act_type',
-        shop: 'shop',
-        shop_name: 'shop_name',
-        goods: 'goods',
-        goods_name: 'goods_name',
-        spec: 'spec',
-        spec_name: 'spec_name',
-        status: 'status',
-        tags: 'tags',
-        act_tags: 'act_tags',
-        goods_type: 'goods_type',
+        "meta.createdAt@start": "meta.createdAt@start",
+        "meta.createdAt@end": "meta.createdAt@end",
+        platform_act: "platform_act",
+        platform_act_type: "platform_act_type",
+        shop: "shop",
+        shop_name: "shop_name",
+        goods: "goods",
+        goods_name: "goods_name",
+        goods_status: "goods_status",
+        spec: "spec",
+        spec_name: "spec_name",
+        status: "status",
+        tags: "tags",
+        act_tags: "act_tags",
+        goods_type: "goods_type",
       },
       // options: {
       //   "meta.state": 0 // 默认条件
       // },
     },
-    service: 'query',
+    service: "query",
     options: {
-      query: ['skip', 'limit'],
-      sort: ['meta.createdAt'],
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
       desc: true,
       count: true,
     },

+ 14 - 10
app/service/shop/goodsJoinAct.js

@@ -64,13 +64,14 @@ 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, 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 = {};
     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 (spec) mq.spec = spec;
     if (spec_name) mq['spec.name'] = new RegExp(spec_name);
     if (status) mq.status = status;
@@ -108,15 +109,16 @@ class GoodsJoinActService extends CrudService {
       $project: {
         meta: 1,
         shop: 1,
-        shop_name: { $first: '$shopInfo.name' },
-        goods: '$goods._id',
-        goods_name: '$goods.name',
-        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' },
+        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" },
         platform_act_type: 1,
         platform_act: 1,
         config: 1,
@@ -127,6 +129,8 @@ class GoodsJoinActService extends CrudService {
     qPipeline.push({ $sort: { 'meta.createdAt': -1 } });
     if (parseInt(skip)) qPipeline.push({ $skip: parseInt(skip) });
     if (parseInt(limit)) qPipeline.push({ $limit: parseInt(limit) });
+    console.log(qPipeline);
+        console.log("functi");
     const res = await this.model.aggregate(qPipeline);
     const tPipeline = _.cloneDeep(pipeline);
     tPipeline.push({ $count: 'total' });