|
@@ -15,54 +15,54 @@ class TradeService extends CrudService {
|
|
|
/**
|
|
|
* 检测是否可以购买该物品
|
|
|
* @param {Object} param 查询条件
|
|
|
- * @param param.shop_id 商店id
|
|
|
- * @param param.goods_id 商品id
|
|
|
- * @param param.goodsSpec_id 商品规格id
|
|
|
+ * @param param.shop 商店id
|
|
|
+ * @param param.goods 商品id
|
|
|
+ * @param param.goodsSpec 商品规格id
|
|
|
* @param param.num 购买数量
|
|
|
*/
|
|
|
- async checkCanBuy({ shop_id, goods_id, goodsSpec_id, num }) {
|
|
|
- assert(shop_id, '缺少店铺信息');
|
|
|
- assert(goods_id, '缺少商品信息');
|
|
|
- assert(goodsSpec_id, '缺少商品规格信息');
|
|
|
+ async checkCanBuy({ shop, goods, goodsSpec, num }) {
|
|
|
+ assert(shop, '缺少店铺信息');
|
|
|
+ assert(goods, '缺少商品信息');
|
|
|
+ assert(goodsSpec, '缺少商品规格信息');
|
|
|
assert(num, '缺少购买数量');
|
|
|
const result = { result: true };
|
|
|
// 1.检查商店是否正常运行
|
|
|
- const shop = await this.shopModel.findById(shop_id);
|
|
|
- if (!shop) {
|
|
|
+ const shopData = await this.shopModel.findById(shop);
|
|
|
+ if (!shopData) {
|
|
|
result.msg = '未找到店铺';
|
|
|
result.result = false;
|
|
|
return result;
|
|
|
}
|
|
|
- if (shop.status !== '1') {
|
|
|
+ if (shopData.status !== '1') {
|
|
|
result.msg = '店铺不处于营业状态';
|
|
|
result.result = false;
|
|
|
return result;
|
|
|
}
|
|
|
// 2.检查商品是否可以购买
|
|
|
- const goods = await this.goodsModel.findById(goods_id);
|
|
|
- if (!goods) {
|
|
|
+ const goodsData = await this.goodsModel.findById(goods);
|
|
|
+ if (!goodsData) {
|
|
|
result.msg = '未找到商品';
|
|
|
result.result = false;
|
|
|
return result;
|
|
|
}
|
|
|
- if (goods.status === '0') {
|
|
|
+ if (goodsData.status === '0') {
|
|
|
result.msg = '该商品已下架';
|
|
|
result.result = false;
|
|
|
return result;
|
|
|
}
|
|
|
// 3.检验该规格是否可以购买
|
|
|
- const goodsSpec = await this.goodsSpecModel.findById(goodsSpec_id);
|
|
|
- if (!goodsSpec) {
|
|
|
+ const goodsSpecData = await this.goodsSpecModel.findById(goodsSpec);
|
|
|
+ if (!goodsSpecData) {
|
|
|
result.msg = '未找到商品的指定规格';
|
|
|
result.result = false;
|
|
|
return result;
|
|
|
}
|
|
|
- if (goods.status !== '0') {
|
|
|
+ if (goodsSpecData.status !== '0') {
|
|
|
result.msg = '该规格的商品已下架';
|
|
|
result.result = false;
|
|
|
return result;
|
|
|
}
|
|
|
- if (goods.num < num) {
|
|
|
+ if (goodsSpecData.num < num) {
|
|
|
result.msg = '库存量不足';
|
|
|
result.result = false;
|
|
|
return result;
|