From d65ad2232fa22476de404e4c139812c33a36c31b Mon Sep 17 00:00:00 2001 From: devil Date: Tue, 31 Dec 2019 16:08:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A3=E9=99=A4=E5=BA=93=E5=AD=98=E5=89=8D?= =?UTF-8?q?=E5=86=8D=E6=AC=A1=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/service/BuyService.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/application/service/BuyService.php b/application/service/BuyService.php index 0b04b15fb..2f5169da8 100755 --- a/application/service/BuyService.php +++ b/application/service/BuyService.php @@ -1384,6 +1384,13 @@ class BuyService $goods = Db::name('Goods')->field('is_deduction_inventory,inventory')->find($v['goods_id']); if(isset($goods['is_deduction_inventory']) && $goods['is_deduction_inventory'] == 1) { + // 先判断商品库存是否不足 + $inventory = Db::name('Goods')->where(['id'=>$v['goods_id']])->value('inventory'); + if($inventory < $v['buy_number']) + { + return DataReturn('商品库存不足['.$inventory.'<'.$v['buy_number'].']', -10); + } + // 扣除操作 if(!Db::name('Goods')->where(['id'=>$v['goods_id']])->setDec('inventory', $v['buy_number'])) { @@ -1395,6 +1402,13 @@ class BuyService $base = GoodsService::GoodsSpecDetail(['id'=>$v['goods_id'], 'spec'=>$spec]); if($base['code'] == 0) { + // 先判断商品规格库存是否不足 + $inventory = Db::name('GoodsSpecBase')->where(['id'=>$base['data']['spec_base']['id'], 'goods_id'=>$v['goods_id']])->value('inventory'); + if($inventory < $v['buy_number']) + { + return DataReturn('商品规格库存不足['.$inventory.'<'.$v['buy_number'].']', -10); + } + // 扣除规格操作 if(!Db::name('GoodsSpecBase')->where(['id'=>$base['data']['spec_base']['id'], 'goods_id'=>$v['goods_id']])->setDec('inventory', $v['buy_number'])) {