Browse Source

添加分类成功

shish 3 năm trước cách đây
mục cha
commit
4ffddf905a
2 tập tin đã thay đổi với 28 bổ sung2 xóa
  1. 2 2
      app-hd/controllers/KindController.php
  2. 26 0
      biz-hd/goods/classes/KindClass.php

+ 2 - 2
app-hd/controllers/KindController.php

@@ -34,8 +34,8 @@ class KindController extends BaseController
         $post = Yii::$app->request->post();
         $post['sjId'] = $this->sjId;
         $post['mainId'] = $this->mainId;
-        $cat = CategoryService::addCategory($post);
-        util::success(['id' => $cat['id']]);
+        KindClass::addData($post);
+        util::complete();
     }
 
     //更新品类 ssh 20220404

+ 26 - 0
biz-hd/goods/classes/KindClass.php

@@ -13,6 +13,32 @@ class KindClass extends BaseClass
 
     public static $baseFile = '\bizHd\goods\models\Kind';
 
+    public static function addData($post)
+    {
+        $name = $post['name'] ?? '';
+        $name = trim($name);
+        $mainId = $post['mainId'] ?? 0;
+        $list = self::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
+        if (!empty($list)) {
+            $has = false;
+            foreach ($list as $item) {
+                $hasName = $item->name ?? '';
+                if ($hasName == $name) {
+                    $delStatus = $item->delStatus ?? 0;
+                    if ($delStatus == 0) {
+                        util::fail('名称已经存在');
+                    }
+                    $item->delStatus = 0;
+                    $item->save();
+                    $has = true;
+                }
+            }
+            if ($has == false) {
+                self::add($post, true);
+            }
+        }
+    }
+
     public static function getKindList($mainId)
     {
         $where = ['mainId' => $mainId, 'delStatus' => 0];