shish hace 3 años
padre
commit
9272d3936d
Se han modificado 1 ficheros con 7 adiciones y 3 borrados
  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)) {
             util::fail('没有花材信息');
         }
-print_r($arr);die;
+
         $list = LabelClass::getAllByCondition(['mainId' => $this->mainId, 'use' => 0], null, '*');
-        $has = [];
         if (!empty($list)) {
             $has = array_column($list, 'epc');
+            $common = array_intersect($arr, $has);
+            if (!empty($common)) {
+                $currentLabel = $common[0] ?? '';
+                util::fail('标签已经添加过了:' . $currentLabel);
+            }
         }
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {
             foreach ($arr as $epc) {
-
+                LabelClass::add(['mainId' => $this->mainId, 'epc' => $epc, 'itemId' => $ptItemId]);
             }
             $transaction->commit();
             util::complete('操作成功');