|
@@ -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);
|
|
|
}
|
|
|
}
|
|
|
|