|
@@ -13,6 +13,8 @@ class CartService extends CrudService {
|
|
this.platformActModel = this.ctx.model.System.PlatformAct;
|
|
this.platformActModel = this.ctx.model.System.PlatformAct;
|
|
this.gjaModel = this.ctx.model.Shop.GoodsJoinAct;
|
|
this.gjaModel = this.ctx.model.Shop.GoodsJoinAct;
|
|
this.setModel = this.ctx.model.Shop.GoodsSet;
|
|
this.setModel = this.ctx.model.Shop.GoodsSet;
|
|
|
|
+ this.shopModel = this.ctx.model.Shop.Shop;
|
|
|
|
+ this.goodsModel = this.ctx.model.Shop.Goods;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -111,7 +113,7 @@ class CartService extends CrudService {
|
|
data.num = buyNum;
|
|
data.num = buyNum;
|
|
await data.save();
|
|
await data.save();
|
|
} else {
|
|
} else {
|
|
- const { enough, msg } = await this.checkSetGoodsNum(data, num);
|
|
|
|
|
|
+ const { enough, msg } = await this.checkSetGoodsNum(body, num);
|
|
if (!enough) throw new BusinessError(ErrorCode.SERVICE_FAULT, msg);
|
|
if (!enough) throw new BusinessError(ErrorCode.SERVICE_FAULT, msg);
|
|
await this.model.create({ num, ...body });
|
|
await this.model.create({ num, ...body });
|
|
}
|
|
}
|
|
@@ -130,9 +132,11 @@ class CartService extends CrudService {
|
|
const stockList = [];
|
|
const stockList = [];
|
|
for (const sd of set) {
|
|
for (const sd of set) {
|
|
const { shop, goods, spec, set_num } = sd;
|
|
const { shop, goods, spec, set_num } = sd;
|
|
- const shopRes = this.ctx.service.util.trade.checkShop(shop);
|
|
|
|
|
|
+ const shopData = await this.shopModel.findById(shop);
|
|
|
|
+ const shopRes = this.ctx.service.util.trade.checkShop(shopData);
|
|
if (shopRes.result !== true) throw new BusinessError(ErrorCode.DATA_INVALID, shopRes.msg);
|
|
if (shopRes.result !== true) throw new BusinessError(ErrorCode.DATA_INVALID, shopRes.msg);
|
|
- const goodsRes = this.ctx.service.util.trade.checkGoods(goods);
|
|
|
|
|
|
+ const goodsData = await this.goodsModel.findById(goods);
|
|
|
|
+ const goodsRes = this.ctx.service.util.trade.checkGoods(goodsData);
|
|
if (goodsRes.result !== true) throw new BusinessError(ErrorCode.DATA_INVALID, goodsRes.msg);
|
|
if (goodsRes.result !== true) throw new BusinessError(ErrorCode.DATA_INVALID, goodsRes.msg);
|
|
if (single_stock === '1') {
|
|
if (single_stock === '1') {
|
|
const goodsSpecData = await this.goodsSpecModel.findById(spec);
|
|
const goodsSpecData = await this.goodsSpecModel.findById(spec);
|
|
@@ -140,7 +144,9 @@ class CartService extends CrudService {
|
|
const gsRes = this.ctx.service.util.trade.checkGoodsSpec(goodsSpecData, setGoodsNum, '0');
|
|
const gsRes = this.ctx.service.util.trade.checkGoodsSpec(goodsSpecData, setGoodsNum, '0');
|
|
if (gsRes.result !== true) throw new BusinessError(ErrorCode.DATA_INVALID, gsRes.msg);
|
|
if (gsRes.result !== true) throw new BusinessError(ErrorCode.DATA_INVALID, gsRes.msg);
|
|
const { num: gsnum = 0 } = goodsSpecData;
|
|
const { num: gsnum = 0 } = goodsSpecData;
|
|
- stockList.push(gsnum);
|
|
|
|
|
|
+ // 应该用 库存/每套的件数 向下取整作为库存量
|
|
|
|
+ const stock_num = _.floor(this.ctx.divide(gsnum, set_num));
|
|
|
|
+ stockList.push(stock_num);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (single_stock !== '1') {
|
|
if (single_stock !== '1') {
|