Bläddra i källkod

批量设置采购人

shish 2 år sedan
förälder
incheckning
c14477e7ad
1 ändrade filer med 43 tillägg och 0 borttagningar
  1. 43 0
      app-ghs/controllers/ProductController.php

+ 43 - 0
app-ghs/controllers/ProductController.php

@@ -1498,6 +1498,49 @@ class ProductController extends BaseController
         }
     }
 
+    //批量修改采购人 ssh 20240609
+    public function actionBatchModifyCgStaff()
+    {
+        $post = Yii::$app->request->post();
+        $staffId = $post['staffId'] ?? 0;
+        $staff = ShopAdminClass::getById($staffId, true);
+        if (empty($staff)) {
+            util::fail('没有找到这个员工');
+        }
+        if ($staff->mainId != $this->mainId) {
+            util::fail('不是你的员工');
+        }
+        $staffName = $staff->name ?? '';
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $idsList = $post['ids'] ?? '';
+            $ids = json_decode($idsList, true);
+            if (empty($ids)) {
+                util::fail('请选择花材');
+            }
+            $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
+            if (empty($list)) {
+                util::fail('请选择花材');
+            }
+            foreach ($list as $item) {
+                $name = $item->name ?? '';
+                if ($item->mainId != $this->mainId) {
+                    util::fail($name . '不是您的花材');
+                }
+                $item->cgStaffId = $staffId;
+                $item->cgStaffName = $staffName;
+                $item->save();
+            }
+            $transaction->commit();
+            util::complete('修改成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("修改失败原因:" . $e->getMessage());
+            util::fail('修改失败');
+        }
+    }
+
     //修改属于成本还是收入选项 ssh 20240514
     public function actionChangeBelongCost()
     {