|
@@ -13,6 +13,7 @@ class OrderService extends CrudService {
|
|
|
this.gjaModel = this.ctx.model.Shop.GoodsJoinAct;
|
|
|
this.goodsModel = this.ctx.model.Shop.Goods;
|
|
|
this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
|
|
|
+ this.goodsSetService = this.ctx.service.shop.goodsSet;
|
|
|
}
|
|
|
|
|
|
// #region 下单前计算函数
|
|
@@ -90,18 +91,25 @@ class OrderService extends CrudService {
|
|
|
let goods_total = 0,
|
|
|
freight_total = 0,
|
|
|
discount = 0;
|
|
|
- for (const g of i.goods) {
|
|
|
- // 如果有特价,那就使用特价,没有特价就是用正常销售价
|
|
|
- goods_total = this.ctx.plus(goods_total, this.ctx.multiply(_.get(g, 'price'), _.get(g, 'buy_num')));
|
|
|
- freight_total = this.ctx.plus(freight_total, this.ctx.multiply(_.get(g, 'freight'), _.get(g, 'num')));
|
|
|
- if (_.isArray(g.act)) {
|
|
|
- const actDiscount = g.act.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
|
|
|
- discount = this.ctx.plus(discount, actDiscount);
|
|
|
+ const { is_set = '1' } = i;
|
|
|
+ if (is_set === '1') {
|
|
|
+ for (const g of i.goods) {
|
|
|
+ // 如果有特价,那就使用特价,没有特价就是用正常销售价
|
|
|
+ goods_total = this.ctx.plus(goods_total, this.ctx.multiply(_.get(g, 'price'), _.get(g, 'buy_num')));
|
|
|
+ freight_total = this.ctx.plus(freight_total, this.ctx.multiply(_.get(g, 'freight'), _.get(g, 'num')));
|
|
|
+ if (_.isArray(g.act)) {
|
|
|
+ const actDiscount = g.act.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
|
|
|
+ discount = this.ctx.plus(discount, actDiscount);
|
|
|
+ }
|
|
|
}
|
|
|
+ i.goods_total = goods_total;
|
|
|
+ i.freight_total = freight_total;
|
|
|
+ i.discount = this.ctx.minus(0, discount);
|
|
|
+ } else {
|
|
|
+ const { sell_money, num, freight } = i;
|
|
|
+ i.goods_total = this.ctx.multiply(num, sell_money);
|
|
|
+ i.freight_total = this.ctx.multiply(num, freight);
|
|
|
}
|
|
|
- i.goods_total = goods_total;
|
|
|
- i.freight_total = freight_total;
|
|
|
- i.discount = this.ctx.minus(0, discount);
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
@@ -209,36 +217,46 @@ class OrderService extends CrudService {
|
|
|
goodsSpecs = [],
|
|
|
goodsData = [];
|
|
|
for (const i of goods) {
|
|
|
- const { goods: goodsList, ...others } = i;
|
|
|
+ const { goods: goodsList, is_set = '1', set_id, ...others } = i;
|
|
|
const qp = [];
|
|
|
- for (const g of goodsList) {
|
|
|
- const { goodsSpec_id, goods_id } = g;
|
|
|
- // 需要的订单数据
|
|
|
- const orderNeedData = _.pick(g, [ 'act', 'price', 'sp_price', 'num', 'cart_id', 'gift' ]);
|
|
|
- if (orderNeedData.num) {
|
|
|
- orderNeedData.buy_num = orderNeedData.num;
|
|
|
- delete orderNeedData.num;
|
|
|
- }
|
|
|
- let goodsSpec = await this.goodsSpecModel.findById(goodsSpec_id);
|
|
|
- if (!goodsSpec) continue;
|
|
|
- goodsSpec = JSON.parse(JSON.stringify(goodsSpec));
|
|
|
- const goods = await this.goodsModel.findById(goods_id);
|
|
|
- if (goods) goodsSpec.goods = JSON.parse(JSON.stringify(goods));
|
|
|
- goodsSpec = { ...goodsSpec, ...orderNeedData };
|
|
|
- qp.push(goodsSpec);
|
|
|
- const ogs = _.pick(goodsSpec, [ '_id', 'buy_num', 'sell_money', 'price' ]);
|
|
|
- if (ogs._id) {
|
|
|
- ogs.id = ogs._id;
|
|
|
- delete ogs._id;
|
|
|
+ if (is_set === '1') {
|
|
|
+ for (const g of goodsList) {
|
|
|
+ const { goodsSpec_id, goods_id } = g;
|
|
|
+ // 需要的订单数据
|
|
|
+ const orderNeedData = _.pick(g, [ 'act', 'price', 'sp_price', 'num', 'cart_id', 'gift' ]);
|
|
|
+ if (orderNeedData.num) {
|
|
|
+ orderNeedData.buy_num = orderNeedData.num;
|
|
|
+ delete orderNeedData.num;
|
|
|
+ }
|
|
|
+ let goodsSpec = await this.goodsSpecModel.findById(goodsSpec_id);
|
|
|
+ if (!goodsSpec) continue;
|
|
|
+ goodsSpec = JSON.parse(JSON.stringify(goodsSpec));
|
|
|
+ const goods = await this.goodsModel.findById(goods_id);
|
|
|
+ if (goods) goodsSpec.goods = JSON.parse(JSON.stringify(goods));
|
|
|
+ goodsSpec = { ...goodsSpec, ...orderNeedData };
|
|
|
+ qp.push(goodsSpec);
|
|
|
+ const ogs = _.pick(goodsSpec, [ '_id', 'buy_num', 'sell_money', 'price' ]);
|
|
|
+ if (ogs._id) {
|
|
|
+ ogs.id = ogs._id;
|
|
|
+ delete ogs._id;
|
|
|
+ }
|
|
|
+ goodsSpecs.push({ ...ogs });
|
|
|
+ // 将活动提取出来:只需要满减/折;买赠和特价跟着规格走,计算过程中已经处理;加价购是外面处理
|
|
|
+ const { act = [] } = goodsSpec;
|
|
|
+ let gAct = act.filter(f => f.platform_act_type === '5' || f.platform_act_type === '6');
|
|
|
+ gAct = gAct.map(i => ({ ...i, goodsSpec_id: goodsSpec._id }));
|
|
|
+ actList.push(...gAct);
|
|
|
}
|
|
|
- goodsSpecs.push({ ...ogs });
|
|
|
- // 将活动提取出来:只需要满减/折;买赠和特价跟着规格走,计算过程中已经处理;加价购是外面处理
|
|
|
- const { act = [] } = goodsSpec;
|
|
|
- let gAct = act.filter(f => f.platform_act_type === '5' || f.platform_act_type === '6');
|
|
|
- gAct = gAct.map(i => ({ ...i, goodsSpec_id: goodsSpec._id }));
|
|
|
- actList.push(...gAct);
|
|
|
+ goodsData.push({ ...others, goods: qp });
|
|
|
+ } else {
|
|
|
+ const data = await this.goodsSetService.getSnapshot(set_id);
|
|
|
+ data.cart_id = i.cart_id;
|
|
|
+ data.buy_num = i.num;
|
|
|
+ data.is_set = '0';
|
|
|
+ data.set_id = i.set_id;
|
|
|
+ goodsData.push(data);
|
|
|
}
|
|
|
- goodsData.push({ ...others, goods: qp });
|
|
|
+
|
|
|
}
|
|
|
return { actList, goodsSpecs, goodsData };
|
|
|
}
|