Parcourir la source

fix 商户二级分类无法发布商品

stanley-king il y a 3 ans
Parent
commit
d02ff55b98
2 fichiers modifiés avec 32 ajouts et 31 suppressions
  1. 2 1
      admin/control/store.php
  2. 30 30
      shop/control/store_goods_add.php

+ 2 - 1
admin/control/store.php

@@ -296,7 +296,8 @@ class storeControl extends SystemControl{
     /**
      * 添加经营类目
      */
-    public function store_bind_class_addOp() {
+    public function store_bind_class_addOp()
+    {
         $store_id = intval($_POST['store_id']);
         $commis_rate = intval($_POST['commis_rate']);
         if($commis_rate < 0 || $commis_rate > 100) {

+ 30 - 30
shop/control/store_goods_add.php

@@ -52,6 +52,27 @@ class store_goods_addControl extends BaseSellerControl
         Tpl::showpage('store_goods_add.step1');
     }
 
+    private function class_level($goods_class, $gc_id)
+    {
+        $result[] = $gc_id;
+        do {
+            $parent_id = $goods_class[$gc_id]['gc_parent_id'];
+            if ($parent_id > 0) {
+                $result[] = $parent_id;
+                $gc_id = $parent_id;
+            } else {
+                break;
+            }
+
+        } while (true);
+
+        $result = array_reverse($result);
+        while (count($result) < 3) {
+            $result[] = 0;
+        }
+
+        return $result;
+    }
     /**
      * 添加商品
      */
@@ -79,35 +100,14 @@ class store_goods_addControl extends BaseSellerControl
             $model_bind_class = Model('store_bind_class');
             $goods_class = Model('goods_class')->getGoodsClassForCacheModel();
             $where['store_id'] = $_SESSION['store_id'];
-            $class_2 = $goods_class[$gc_id]['gc_parent_id'];
-            $class_1 = $goods_class[$class_2]['gc_parent_id'];
-            $where['class_1'] =  $class_1;
-            $where['class_2'] =  $class_2;
-            $where['class_3'] =  $gc_id;
-            $bind_info = $model_bind_class->getStoreBindClassInfo($where);
-            if (empty($bind_info))
-            {
-                $where['class_3'] =  0;
-                $bind_info = $model_bind_class->getStoreBindClassInfo($where);
-                if (empty($bind_info))
-                {
-                    $where['class_2'] =  0;
-                    $where['class_3'] =  0;
-                    $bind_info = $model_bind_class->getStoreBindClassInfo($where);
-                    if (empty($bind_info))
-                    {
-                        $where['class_1'] =  0;
-                        $where['class_2'] =  0;
-                        $where['class_3'] =  0;
-                        $bind_info = Model('store_bind_class')->getStoreBindClassInfo($where);
-                        if (empty($bind_info))
-                        {
-                            showDialog(L('store_goods_index_again_choose_category2'));
-                        }
-                    }
-
-                }
+            [$class_1, $class_2, $gc_id] = $this->class_level($goods_class, $gc_id);
 
+            $where['class_1'] = $class_1;
+            $where['class_2'] = $class_2;
+            $where['class_3'] = $gc_id;
+            $bind_info = $model_bind_class->getStoreBindClassInfo($where);
+            if (empty($bind_info)) {
+                showDialog(L('store_goods_index_again_choose_category2'));
             }
         }
 
@@ -118,7 +118,7 @@ class store_goods_addControl extends BaseSellerControl
 
         // 获取类型相关数据
         $typeinfo = Model('type')->getAttr($goods_class['type_id'], $_SESSION['store_id'], $gc_id);
-        list($spec_json, $spec_list, $attr_list, $brand_list) = $typeinfo;
+        [$spec_json, $spec_list, $attr_list, $brand_list] = $typeinfo;
         Tpl::output('sign_i', count($spec_list));
         Tpl::output('spec_list', $spec_list);
         Tpl::output('attr_list', $attr_list);
@@ -566,7 +566,7 @@ class store_goods_addControl extends BaseSellerControl
         $img_path = $upload->getSysSetPath() . $upload->file_name;
 
         // 取得图像大小
-        list($width, $height, $type, $attr) = getimagesize(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS . '/' . $_SESSION['store_id'] . DS . $img_path);
+        [$width, $height, $type, $attr] = getimagesize(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS . '/' . $_SESSION['store_id'] . DS . $img_path);
 
         // 存入相册
         $image = explode('.', $_FILES[$_POST['name']]["name"]);