shish 3 سال پیش
والد
کامیت
9272d3936d
1فایلهای تغییر یافته به همراه7 افزوده شده و 3 حذف شده
  1. 7 3
      app-ghs/controllers/LabelController.php

+ 7 - 3
app-ghs/controllers/LabelController.php

@@ -22,17 +22,21 @@ class LabelController extends BaseController
         if (empty($ptItemId)) {
         if (empty($ptItemId)) {
             util::fail('没有花材信息');
             util::fail('没有花材信息');
         }
         }
-print_r($arr);die;
+
         $list = LabelClass::getAllByCondition(['mainId' => $this->mainId, 'use' => 0], null, '*');
         $list = LabelClass::getAllByCondition(['mainId' => $this->mainId, 'use' => 0], null, '*');
-        $has = [];
         if (!empty($list)) {
         if (!empty($list)) {
             $has = array_column($list, 'epc');
             $has = array_column($list, 'epc');
+            $common = array_intersect($arr, $has);
+            if (!empty($common)) {
+                $currentLabel = $common[0] ?? '';
+                util::fail('标签已经添加过了:' . $currentLabel);
+            }
         }
         }
         $connection = Yii::$app->db;//事务处理
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         $transaction = $connection->beginTransaction();
         try {
         try {
             foreach ($arr as $epc) {
             foreach ($arr as $epc) {
-
+                LabelClass::add(['mainId' => $this->mainId, 'epc' => $epc, 'itemId' => $ptItemId]);
             }
             }
             $transaction->commit();
             $transaction->commit();
             util::complete('操作成功');
             util::complete('操作成功');