|
@@ -63,40 +63,68 @@ class OrderDetailService extends CrudService {
|
|
|
let noTimes = 1;
|
|
|
// const list = [];
|
|
|
const ids = [];
|
|
|
- for (const s of shopGoods) {
|
|
|
- const { is_set = '1' } = s;
|
|
|
- if (is_set === '1') {
|
|
|
- const shop = _.get(s, 'shop');
|
|
|
- const remarks = _.get(s, 'remarks');
|
|
|
- const goodsList = _.get(s, 'goods', []);
|
|
|
- const detailNo = `${no}-${noTimes}`;
|
|
|
- const total_detail = shopMoneyDetail[shop];
|
|
|
- // 优惠部分分割
|
|
|
- if (_.get(otd, 'discount_detail')) {
|
|
|
- // 如果有优惠部分,那就得找,优惠里面有没有对应的商品规格
|
|
|
- const discount_detail = this.getGoodsListDiscountDetail(goodsList, _.get(otd, 'discount_detail'));
|
|
|
- total_detail.discount_detail = discount_detail;
|
|
|
+ const groupShop = _.groupBy(shopGoods, 'shop');
|
|
|
+ for (const shop in groupShop) {
|
|
|
+ const list = groupShop[shop];
|
|
|
+ const detailNo = `${no}-${noTimes}`;
|
|
|
+ const total_detail = shopMoneyDetail[shop];
|
|
|
+ const newGoodsList = [];
|
|
|
+ for (const s of list) {
|
|
|
+ const { is_set = '1' } = s;
|
|
|
+ if (is_set === '1') {
|
|
|
+ const goodsList = _.get(s, 'goods', []);
|
|
|
+ // 优惠部分分割
|
|
|
+ if (_.get(otd, 'discount_detail')) {
|
|
|
+ // 如果有优惠部分,那就得找,优惠里面有没有对应的商品规格
|
|
|
+ const discount_detail = this.getGoodsListDiscountDetail(goodsList, _.get(otd, 'discount_detail'));
|
|
|
+ total_detail.discount_detail = discount_detail;
|
|
|
+ }
|
|
|
+ noTimes++;
|
|
|
+ newGoodsList.push(...goodsList);
|
|
|
+ } else {
|
|
|
+ const g = _.pick(s, [ 'name', 'buy_num', 'freight', 'is_set', 'is_use', 'meta', 'sell_money', 'set_id', 'goods' ]);
|
|
|
+ g._id = g.set_id;
|
|
|
+ newGoodsList.push(g);
|
|
|
}
|
|
|
- noTimes++;
|
|
|
- const obj = { ...orderDetailData, shop, goods: goodsList, no: detailNo, total_detail, remarks };
|
|
|
- obj.status = '1';
|
|
|
- // list.push(obj);
|
|
|
- const od_id = tran.insert('OrderDetail', obj);
|
|
|
- ids.push(od_id);
|
|
|
- } else {
|
|
|
- const shop = _.get(s, 'shop');
|
|
|
- const detailNo = `${no}-${noTimes}`;
|
|
|
- const total_detail = shopMoneyDetail[shop];
|
|
|
- const remarks = _.get(s, 'remarks');
|
|
|
- const g = _.pick(s, [ 'name', 'buy_num', 'freight', 'is_set', 'is_use', 'meta', 'sell_money', 'set_id', 'goods' ]);
|
|
|
- g._id = g.set_id;
|
|
|
- const obj = { ...orderDetailData, shop, goods: g, no: detailNo, total_detail, remarks, status: '1' };
|
|
|
- const od_id = tran.insert('OrderDetail', obj);
|
|
|
- ids.push(od_id);
|
|
|
}
|
|
|
+ const obj = { ...orderDetailData, shop, no: detailNo, total_detail, goods: newGoodsList };
|
|
|
+ const od_id = tran.insert('OrderDetail', obj);
|
|
|
+ ids.push(od_id);
|
|
|
}
|
|
|
+
|
|
|
+ // for (const s of shopGoods) {
|
|
|
+ // const { is_set = '1' } = s;
|
|
|
+ // if (is_set === '1') {
|
|
|
+ // const shop = _.get(s, 'shop');
|
|
|
+ // const remarks = _.get(s, 'remarks');
|
|
|
+ // const goodsList = _.get(s, 'goods', []);
|
|
|
+ // const detailNo = `${no}-${noTimes}`;
|
|
|
+ // const total_detail = shopMoneyDetail[shop];
|
|
|
+ // // 优惠部分分割
|
|
|
+ // if (_.get(otd, 'discount_detail')) {
|
|
|
+ // // 如果有优惠部分,那就得找,优惠里面有没有对应的商品规格
|
|
|
+ // const discount_detail = this.getGoodsListDiscountDetail(goodsList, _.get(otd, 'discount_detail'));
|
|
|
+ // total_detail.discount_detail = discount_detail;
|
|
|
+ // }
|
|
|
+ // noTimes++;
|
|
|
+ // const obj = { ...orderDetailData, shop, goods: goodsList, no: detailNo, total_detail, remarks };
|
|
|
+ // obj.status = '1';
|
|
|
+ // // list.push(obj);
|
|
|
+ // const od_id = tran.insert('OrderDetail', obj);
|
|
|
+ // ids.push(od_id);
|
|
|
+ // } else {
|
|
|
+ // const shop = _.get(s, 'shop');
|
|
|
+ // const detailNo = `${no}-${noTimes}`;
|
|
|
+ // const total_detail = shopMoneyDetail[shop];
|
|
|
+ // const remarks = _.get(s, 'remarks');
|
|
|
+ // const g = _.pick(s, [ 'name', 'buy_num', 'freight', 'is_set', 'is_use', 'meta', 'sell_money', 'set_id', 'goods' ]);
|
|
|
+ // g._id = g.set_id;
|
|
|
+ // const obj = { ...orderDetailData, shop, goods: g, no: detailNo, total_detail, remarks, status: '1' };
|
|
|
+ // const od_id = tran.insert('OrderDetail', obj);
|
|
|
+ // ids.push(od_id);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
return ids;
|
|
|
- // await this.model.insertMany(list);
|
|
|
}
|
|
|
|
|
|
/**
|