shish 2 rokov pred
rodič
commit
95efe11d7f

+ 26 - 1
app-pt/controllers/PtItemCatRelateController.php

@@ -2,6 +2,9 @@
 
 namespace pt\controllers;
 
+use biz\item\classes\PtItemCatClass;
+use biz\item\classes\PtItemCatRelateClass;
+use biz\item\classes\PtItemClass;
 use  Yii;
 use common\components\util;
 
@@ -10,7 +13,29 @@ class PtItemCatRelateController extends BaseController
     //批量设置为建议花材 sssh 20240127
     public function actionBatchSet()
     {
+        $post = Yii::$app->request->post();
+        $str = $post['ids'] ?? '';
+        $classId = $post['classId'] ?? 0;
+        $class = PtItemCatClass::getById($classId, true);
+        if (empty($class)) {
+            util::fail('没有找到分类');
+        }
+        $ids = json_decode($str, true);
+        if (empty($ids)) {
+            util::fail('请选择花材');
+        }
+        $list = PtItemClass::getByIds($ids);
+        if (empty($list)) {
+            util::fail('没有花材');
+        }
+        foreach ($list as $item) {
+            $id = $item['id'] ?? 0;
+            $has = PtItemCatRelateClass::getByCondition(['catId' => $classId, 'itemId' => $id], true);
+            if (empty($has)) {
+                PtItemCatRelateClass::add(['catId' => $classId, 'itemId' => $id], true);
+            }
+        }
         util::complete();
     }
 
-}
+}