WIN-2308041133\Administrator 4 months ago
parent
commit
f3287656b4
2 changed files with 50 additions and 0 deletions
  1. 41 0
      app/admin/controller/store/StoreProduct.php
  2. 9 0
      app/models/store/StoreCart.php

+ 41 - 0
app/admin/controller/store/StoreProduct.php

@@ -290,6 +290,47 @@ class StoreProduct extends AuthController
                 $data['activity'][$k] = 3;
             }
         }
+//        $is_type_num = 0;
+//        if ($data['is_inclusive'] ==1){
+//            $is_type_num = $is_type_num + 1;
+//        }
+//        if ($data['is_points'] ==1){
+//            $is_type_num = $is_type_num + 1;
+//        }
+//        if ($data['is_explosive'] ==1){
+//            $is_type_num = $is_type_num + 1;
+//        }
+//        if ($data['is_health'] ==1){
+//            $is_type_num = $is_type_num + 1;
+//        }
+//        if ($data['is_life'] ==1){
+//            $is_type_num = $is_type_num + 1;
+//        }
+//        if ($is_type_num > 1){
+//            return Json::fail('普惠商品,积分商品,报单商品,健康生活商品,生活商品商品类型不能同时选择');
+//        }
+        $typeMap = [
+            'is_inclusive' => '普惠商品',
+            'is_points'    => '积分商品',
+            'is_explosive' => '报单商品',
+            'is_health'    => '健康生活商品',
+            'is_life'      => '生活商品'
+        ];
+
+        $selectedTypes = [];  // 存储选中的类型名称
+
+// 检查每个类型是否被选中
+        foreach ($typeMap as $field => $name) {
+            if (!empty($data[$field])) {  // 使用更安全的判断条件
+                $selectedTypes[] = $name;
+            }
+        }
+
+// 验证选择数量
+        if (count($selectedTypes) > 1) {
+            $errorMsg = implode(',', $selectedTypes) . '不能同时选择';
+            return Json::fail($errorMsg);
+        }
 
         $data['description'] = $this->request->post('description', '');
         $data['activity'] = implode(',', $data['activity']);

+ 9 - 0
app/models/store/StoreCart.php

@@ -90,6 +90,15 @@ class StoreCart extends BaseModel
             $product = StoreProduct::get($product_id);
             if ($product['store_type'] == 2 && !$is_new) return self::setErrorInfo('虚拟商品不可加入购物车');
         }
+//        普惠商品,积分商品,报单商品不能加入购物车
+        $product_info = StoreProduct::get($product_id);
+        if ($product_info['is_inclusive']==1){
+            return self::setErrorInfo('普惠商品不能加入购物车');
+        }elseif ($product_info['is_points']==1){
+            return self::setErrorInfo('积分商品不能加入购物车');
+        }elseif ($product_info['is_explosive']==1){
+            return self::setErrorInfo('报单商品不能加入购物车');
+        }
         if ($cart = self::where('type', $type)->where('uid', $uid)->where('product_id', $product_id)->where('product_attr_unique', $product_attr_unique)->where('is_new', $is_new)->where('is_pay', 0)->where('is_del', 0)->where('combination_id', $combination_id)->where('bargain_id', $bargain_id)->where('seckill_id', $seckill_id)->find()) {
             if ($is_new)
                 $cart->cart_num = $cart_num;