Browse Source

更新种类

shish 3 năm trước cách đây
mục cha
commit
2607417e13
2 tập tin đã thay đổi với 25 bổ sung17 xóa
  1. 22 5
      app-hd/controllers/KindController.php
  2. 3 12
      biz-hd/goods/classes/KindClass.php

+ 22 - 5
app-hd/controllers/KindController.php

@@ -38,14 +38,31 @@ class KindController extends BaseController
         util::complete();
     }
 
-    //更新品类 ssh 20220404
+    //更新种类 ssh 20230220
     public function actionUpdate()
     {
         $post = Yii::$app->request->post();
-        $categoryId = isset($post['categoryId']) ? $post['categoryId'] : 0;
-        $category = CategoryService::getById($categoryId);
-        CategoryService::valid($category, $this->mainId);
-        CategoryService::updateCategory($category, $post);
+        $kindId = isset($post['kindId']) ? $post['kindId'] : 0;
+        $kind = KindClass::getById($kindId, true);
+        if (empty($kind)) {
+            util::fail('没有找到种类');
+        }
+        if ($kind->mainId != $this->mainId) {
+            util::fail('没有权限');
+        }
+        $inTurn = $post['inTurn'] ?? 0;
+        $name = $post['name'] ?? '';
+        $name = trim($name);
+        $list = KindClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, '*', true);
+        foreach ($list as $key => $item) {
+            $currentName = $item->name ?? '';
+            if ($currentName == $name && $item->id != $kind->id) {
+                util::fail('名称已经存在了');
+            }
+        }
+        $kind->inTurn = $inTurn;
+        $kind->name = $name;
+        $kind->save();
         util::complete('修改成功');
     }
 

+ 3 - 12
biz-hd/goods/classes/KindClass.php

@@ -18,25 +18,16 @@ class KindClass extends BaseClass
         $name = $post['name'] ?? '';
         $name = trim($name);
         $mainId = $post['mainId'] ?? 0;
-        $list = self::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
-        $has = false;
+        $list = self::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, '*', null, true);
         if (!empty($list)) {
             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;
+                    util::fail('名称已经存在');
                 }
             }
         }
-        if ($has == false) {
-            self::add($post, true);
-        }
+        self::add($post, true);
     }
 
     public static function getKindList($mainId)