kevin_zhangl пре 3 година
родитељ
комит
a9af3b8fb2
2 измењених фајлова са 8 додато и 3 уклоњено
  1. 1 1
      common/models/forms/ApproachOrderForm.php
  2. 7 2
      common/models/forms/OrderForm.php

+ 1 - 1
common/models/forms/ApproachOrderForm.php

@@ -206,7 +206,7 @@ class ApproachOrderForm extends Model
             return;
         }
         $goodsCategoryType = array_unique(array_column($goods, 'CATEGORY_TYPE'));
-        if (count($goodsCategoryType) != 1) {
+        if (count($goodsCategoryType) > 1) {
             $this->addError($attribute, 'Order cannot contain multiple product categories');//订单不能包含多种商品分类
             return;
         }

+ 7 - 2
common/models/forms/OrderForm.php

@@ -215,6 +215,7 @@ class OrderForm extends Model
     /**
      * 判断支付方式
      * @param $attribute
+     * @throws Exception
      */
     public function isPayType($attribute){
         if(!array_key_exists($this->payType, ShopGoods::payTypes())){
@@ -224,9 +225,13 @@ class OrderForm extends Model
 
         // 一个订单只能包含一类商品
         $goods = ShopGoods::find()->select('ID,CATEGORY_TYPE')->where(['in', 'ID', $this->goodsId])->andWhere(['STATUS' => 1])->asArray()->all();
+        if (!$goods) {
+            throw new Exception('Products does not exists!');
+            return;
+        }
         $goodsCategoryType = array_unique(array_column($goods, 'CATEGORY_TYPE'));
-        if (count($goodsCategoryType) != 1) {
-            $this->addError($attribute, '订单不能包含多种商品分类');
+        if (count($goodsCategoryType) > 1) {
+            $this->addError($attribute, 'Order cannot contain multiple product categories'); // 订单不能包含多种商品分类
             return;
         }