lrf 2 년 전
부모
커밋
fae16de4f0
1개의 변경된 파일12개의 추가작업 그리고 12개의 파일을 삭제
  1. 12 12
      app/service/trade/cart.js

+ 12 - 12
app/service/trade/cart.js

@@ -3,7 +3,7 @@ const { CrudService } = require('naf-framework-mongoose-free/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const assert = require('assert');
-
+const { ObjectId } = require('mongoose').Types;
 //
 class CartService extends CrudService {
   constructor(ctx) {
@@ -43,19 +43,19 @@ class CartService extends CrudService {
   async getCartGoodsAct(data) {
     // 实时匹配活动问题
     const platformActList = await this.platformActModel.find({ is_use: '0' });
+    const platform_act = platformActList.map(i => ObjectId(i._id).toString());
     for (const cart of data) {
-      const { goodsSpec: spec } = cart;
-      const actList = [];
-      for (const act of platformActList) {
-        const { _id: platform_act } = act;
-        const gjaNum = await this.gjaModel.count({
-          platform_act,
-          'spec._id': spec,
-          $or: [{ platform_act_type: '4', 'config.goods_type': 'basic' }, { platform_act_type: { $ne: '4' } }],
-        });
-        if (gjaNum > 0) actList.push(platform_act);
+      const { goodsSpec: spec_id, goods: goods_id, act = [] } = cart;
+      const gjaList = await this.gjaModel.find({ platform_act, 'goods._id': ObjectId(goods_id).toString(), 'spec._id': ObjectId(spec_id).toString() });
+      for (const gja of gjaList) {
+        const { platform_act_type: type, platform_act } = gja;
+        // 加价购需要额外判断是否是基础商品
+        if (type === '4') {
+          const goods_type = _.get(gja, 'config.goods_type');
+          if (goods_type === 'basic') act.push(platform_act);
+        } else act.push(platform_act);
       }
-      cart.act = actList;
+      cart.act = _.uniq(act);
     }
   }