|
@@ -126,7 +126,7 @@ class OrderService extends CrudService {
|
|
|
for (const i of list) {
|
|
|
const goodsSpec = await this.goodsSpecModel.findById(i._id, { num: 1 });
|
|
|
if (!goodsSpec) continue;
|
|
|
- const newNum = (parseInt(goodsSpec.num) || 0) + (parseInt(i.buy_num) || 0);
|
|
|
+ const newNum = this.ctx.plus(goodsSpec.num, i.buy_num);
|
|
|
this.tran.update('GoodsSpec', i._id, { num: newNum });
|
|
|
}
|
|
|
}
|
|
@@ -144,14 +144,13 @@ class OrderService extends CrudService {
|
|
|
await this.tran.run();
|
|
|
} catch (error) {
|
|
|
await this.tran.rollback();
|
|
|
- console.log(error);
|
|
|
+ console.error(error);
|
|
|
throw new BusinessError(ErrorCode.SERVICE_FAULT, '订单取消失败');
|
|
|
} finally {
|
|
|
this.tran.clean();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 减库存,删除购物车
|
|
|
* @param {Array} list 商品
|
|
@@ -161,7 +160,7 @@ class OrderService extends CrudService {
|
|
|
for (const g of i.goods) {
|
|
|
const { _id, buy_num, cart_id } = g;
|
|
|
const goodsSpec = await this.goodsSpecModel.findById(_id);
|
|
|
- const newNum = parseInt(goodsSpec.num - buy_num);
|
|
|
+ const newNum = this.ctx.minus(goodsSpec.num, buy_num);
|
|
|
this.tran.update('GoodsSpec', _id, { num: newNum });
|
|
|
if (cart_id) this.tran.remove('Cart', cart_id);
|
|
|
}
|
|
@@ -221,14 +220,8 @@ class OrderService extends CrudService {
|
|
|
*/
|
|
|
computedShopTotal(list) {
|
|
|
for (const i of list) {
|
|
|
- i.goods_total = _.floor(
|
|
|
- i.goods.reduce((p, n) => p + (n.money || 0) * (n.num || 0), 0),
|
|
|
- 2
|
|
|
- );
|
|
|
- i.freight_total = _.floor(
|
|
|
- i.goods.reduce((p, n) => p + (n.freight || 0) * (n.num || 0), 0),
|
|
|
- 2
|
|
|
- );
|
|
|
+ i.goods_total = i.goods.reduce((p, n) => this.ctx.plus(p, this.ctx.multiply(n.money, n.num)), 0);
|
|
|
+ i.freight_total = i.goods.reduce((p, n) => this.ctx.plus(p, this.ctx.multiply(n.freight, n.num)), 0);
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
@@ -239,14 +232,8 @@ class OrderService extends CrudService {
|
|
|
*/
|
|
|
computedAllTotal(list) {
|
|
|
const obj = {
|
|
|
- goods_total: _.floor(
|
|
|
- list.reduce((p, n) => p + (n.goods_total || 0), 0),
|
|
|
- 2
|
|
|
- ),
|
|
|
- freight_total: _.floor(
|
|
|
- list.reduce((p, n) => p + (n.freight_total || 0), 0),
|
|
|
- 2
|
|
|
- ),
|
|
|
+ goods_total: list.reduce((p, n) => this.ctx.plus(p, n.goods_total), 0),
|
|
|
+ freight_total: list.reduce((p, n) => this.ctx.plus(p, n.freight_total), 0),
|
|
|
};
|
|
|
return obj;
|
|
|
}
|