Parcourir la source

bugfix:商品下架时下单报错

kevin_zhangl il y a 3 ans
Parent
commit
456b899041

+ 3 - 0
common/models/forms/DeclarationLoopForm.php

@@ -123,6 +123,9 @@ class DeclarationLoopForm extends Model
                  */
                 if (isset($value['packageId']) && $value['packageId']){
                     $packagedata = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $value['packageId']]);
+                    if (!$packagedata) {
+                        throw new Exception('商品不存在');
+                    }
                     //var_dump($packagedata['ID']);
                     if($packagedata['STORE_NUMS']<=0){
                         throw new Exception($packagedata['PACKAGE_NAME'].'库存不足');

+ 6 - 1
common/models/forms/DeclarationUpgradeForm.php

@@ -148,6 +148,9 @@ class DeclarationUpgradeForm extends Model
                 foreach ($this->goodsNum as $k => $v) {
                     if ($v) {
                         $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
+                        if (!$goods) {
+                            throw new Exception('商品不存在');
+                        }
                         if($goods['STORE_NUMS']>0){
                             $totalAmount += $goods['SELL_PRICE'] * intval($v);
                             $totalPv += $goods['PRICE_PV'] * intval($v);
@@ -281,7 +284,9 @@ class DeclarationUpgradeForm extends Model
             foreach ($this->goodsNum as $k => $v) {
                 if ($v) {
                     $goods = ShopGoods::findOneAsArray('ID=:ID',[':ID'=> $this->goodsId[$k]]);
-
+                    if (!$goods) {
+                        throw new Exception('商品不存在');
+                    }
                     $storenums = $goods['STORE_NUMS'] - $this->goodsNum[$k];
                     if($goods['STATUS']==1){
                         if($goods['STORE_NUMS'] >=$this->goodsNum[$k]){

+ 6 - 0
common/models/forms/OrderForm.php

@@ -313,6 +313,9 @@ class OrderForm extends Model
         foreach ($this->goodsNum as $k => $v) {
             if ($v) {
                 $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
+                if (!$goods) {
+                    throw new Exception('商品不存在');
+                }
                 if($goods['STORE_NUMS']>0){
                     $discount = $goods['SELL_DISCOUNT'];
                     $realPrice = $goods['SELL_PRICE'] * $discount;
@@ -381,6 +384,9 @@ class OrderForm extends Model
             foreach ($this->goodsNum as $k => $v){
                 if ($v){
                     $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
+                    if (!$goods) {
+                        throw new Exception('商品不存在');
+                    }
                     if ($goods['STORE_NUMS'] >= $this->goodsNum[$k]){
                         $data = ShopGoods::find()->where(['ID' => $ids[$k]])->one();
                         $goods_store_nums = $data->STORE_NUMS - $this->goodsNum[$k];