db->createCommand($sql)->execute(); util::complete(); } //批量添加电子标 ssh 20230821 public function actionBatchAddLabel() { $post = Yii::$app->request->post(); $data = $post['data'] ?? ''; $arr = json_decode($data, true); if (empty($arr)) { util::fail('没有电子标'); } $ptItemId = $post['ptItemId'] ?? 0; if (empty($ptItemId)) { util::fail('没有花材信息'); } $list = LabelClass::getAllByCondition(['mainId' => $this->mainId, 'use' => 0], null, '*'); 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('操作成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("保存失败原因:" . $e->getMessage()); util::fail('保存失败'); } } //获取我没有使用的电子标 ssh 20230817 public function actionGetMyLabelList() { $mainId = $this->mainId; $list = LabelClass::getMyUnUseLabelList($mainId); util::success(['list' => $list]); } }