|
@@ -32,7 +32,7 @@ class CartService extends CrudService {
|
|
|
let data = await this.model.find({ customer });
|
|
|
if (data.length > 0) {
|
|
|
data = JSON.parse(JSON.stringify(data));
|
|
|
- data = data.map((i) => ({ ...i, cart_id: i._id }));
|
|
|
+ data = data.map(i => ({ ...i, cart_id: i._id }));
|
|
|
}
|
|
|
data = await this.getCartGoodsAct(data);
|
|
|
const actList = await this.ctx.service.trade.order.getActList(data);
|
|
@@ -44,10 +44,10 @@ class CartService extends CrudService {
|
|
|
* @param {Array} data 购物车商品
|
|
|
*/
|
|
|
async getCartGoodsAct(data) {
|
|
|
- data = data.map((i) => ({ ...i, act: [] }));
|
|
|
+ data = data.map(i => ({ ...i, act: [] }));
|
|
|
// 实时匹配活动问题
|
|
|
const platformActList = await this.platformActModel.find({ is_use: '0' });
|
|
|
- const platform_act = platformActList.map((i) => ObjectId(i._id).toString());
|
|
|
+ const platform_act = platformActList.map(i => ObjectId(i._id).toString());
|
|
|
for (const cart of data) {
|
|
|
const { goodsSpec: spec_id, goods: goods_id, act = [], is_set = '1', set_id } = cart;
|
|
|
if (is_set === '1' || !set_id) {
|
|
@@ -88,7 +88,7 @@ class CartService extends CrudService {
|
|
|
} else assert(set_id, '缺少套装id');
|
|
|
if (is_set === '1') {
|
|
|
// 非套装 添加购物车
|
|
|
- const query = _.pick(body, ['customer', 'shop', 'goods', 'goodsSpec']);
|
|
|
+ const query = _.pick(body, [ 'customer', 'shop', 'goods', 'goodsSpec' ]);
|
|
|
const data = await this.model.findOne(query);
|
|
|
if (data) {
|
|
|
const buyNum = this.ctx.plus(data.num, num);
|
|
@@ -103,7 +103,7 @@ class CartService extends CrudService {
|
|
|
}
|
|
|
} else {
|
|
|
// 套装添加购物车
|
|
|
- const query = _.pick(body, ['customer', 'set_id']);
|
|
|
+ const query = _.pick(body, [ 'customer', 'set_id' ]);
|
|
|
const data = await this.model.findOne(query);
|
|
|
if (data) {
|
|
|
// 计算套装购买数量
|
|
@@ -113,9 +113,9 @@ class CartService extends CrudService {
|
|
|
data.num = buyNum;
|
|
|
await data.save();
|
|
|
} else {
|
|
|
- const { enough, msg } = await this.checkSetGoodsNum(body, num);
|
|
|
+ const { enough, msg, shop } = await this.checkSetGoodsNum(body, num);
|
|
|
if (!enough) throw new BusinessError(ErrorCode.SERVICE_FAULT, msg);
|
|
|
- await this.model.create({ num, ...body });
|
|
|
+ await this.model.create({ shop, num, ...body });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -149,7 +149,7 @@ class CartService extends CrudService {
|
|
|
stockList.push(stock_num);
|
|
|
}
|
|
|
const total = _.min(stockList);
|
|
|
- return { enough: true, total };
|
|
|
+ return { enough: true, total, shop };
|
|
|
}
|
|
|
|
|
|
/**
|