|
@@ -17,6 +17,15 @@ class OrderService extends CrudService {
|
|
|
|
|
|
this.cartModel = this.ctx.model.Trade.Cart;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建订单
|
|
|
+ * 1.检测商品是否可以购买
|
|
|
+ * 2.
|
|
|
+ * @param {Object} body
|
|
|
+ */
|
|
|
+ async create(body) {}
|
|
|
+
|
|
|
/**
|
|
|
* 进入下单页面
|
|
|
* @param {Object} body 请求参数
|
|
@@ -27,7 +36,6 @@ class OrderService extends CrudService {
|
|
|
let data = await this.redis.get(key);
|
|
|
if (!data) throw new BusinessError(ErrorCode.SERVICE_FAULT, '请求超时,请重新进入下单页');
|
|
|
data = JSON.parse(data);
|
|
|
- console.log(data);
|
|
|
let specsData = [];
|
|
|
if (_.isArray(data)) {
|
|
|
// 购物车来的: 1.循环校验 规格商品; 2.按店铺分组
|
|
@@ -67,8 +75,8 @@ class OrderService extends CrudService {
|
|
|
*/
|
|
|
computedShopTotal(list) {
|
|
|
for (const i of list) {
|
|
|
- i.goods_total = i.goods.reduce((p, n) => p + (n.money || 0) * (n.num || 0), 0);
|
|
|
- i.freight_total = i.goods.reduce((p, n) => p + (n.freight || 0) * (n.num || 0), 0);
|
|
|
+ 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);
|
|
|
console.log(i);
|
|
|
}
|
|
|
return list;
|
|
@@ -80,8 +88,8 @@ class OrderService extends CrudService {
|
|
|
*/
|
|
|
computedAllTotal(list) {
|
|
|
const obj = {
|
|
|
- goods_total: list.reduce((p, n) => p + (n.goods_total || 0), 0),
|
|
|
- freight_total: list.reduce((p, n) => p + (n.freight_total || 0), 0),
|
|
|
+ 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),
|
|
|
};
|
|
|
return obj;
|
|
|
}
|
|
@@ -144,27 +152,6 @@ class OrderService extends CrudService {
|
|
|
}
|
|
|
return arr;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 重组购物车商品
|
|
|
- * @param {Object} goods 商品
|
|
|
- * @param {Object} goodsSpec 商品规格
|
|
|
- * @param {Object} data 购物车数据
|
|
|
- */
|
|
|
- setCartGoodsData(data) {
|
|
|
- const { goods, goodsSpec, _id, num = 1 } = data;
|
|
|
- const obj = {};
|
|
|
- obj.cart_id = _id;
|
|
|
- obj.goods_id = _.get(goods, '_id');
|
|
|
- obj.goods_name = _.get(goods, 'name');
|
|
|
- obj.goodsSpec_id = _.get(goodsSpec, '_id');
|
|
|
- obj.goodsSpec_name = _.get(goodsSpec, 'name');
|
|
|
- obj.freight = _.get(goodsSpec, 'freight');
|
|
|
- obj.money = _.get(goodsSpec, 'sell_money');
|
|
|
- obj.num = num;
|
|
|
- obj.file = _.get(goods, 'file');
|
|
|
- return obj;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
module.exports = OrderService;
|