LabelController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\item\classes\LabelClass;
  4. use common\components\util;
  5. use Yii;
  6. class LabelController extends BaseController
  7. {
  8. //批量添加电子标 ssh 20230821
  9. public function actionBatchAddLabel()
  10. {
  11. $post = Yii::$app->request->post();
  12. $data = $post['data'] ?? '';
  13. $arr = json_decode($data, true);
  14. if (empty($arr)) {
  15. util::fail('没有电子标');
  16. }
  17. $ptItemId = $post['ptItemId'] ?? 0;
  18. if (empty($ptItemId)) {
  19. util::fail('没有花材信息');
  20. }
  21. print_r($arr);die;
  22. $list = LabelClass::getAllByCondition(['mainId' => $this->mainId, 'use' => 0], null, '*');
  23. $has = [];
  24. if (!empty($list)) {
  25. $has = array_column($list, 'epc');
  26. }
  27. $connection = Yii::$app->db;//事务处理
  28. $transaction = $connection->beginTransaction();
  29. try {
  30. foreach ($arr as $epc) {
  31. }
  32. $transaction->commit();
  33. util::complete('操作成功');
  34. } catch (\Exception $e) {
  35. $transaction->rollBack();
  36. Yii::info("保存失败原因:" . $e->getMessage());
  37. util::fail('保存失败');
  38. }
  39. }
  40. //获取我没有使用的电子标 ssh 20230817
  41. public function actionGetMyLabelList()
  42. {
  43. $mainId = $this->mainId;
  44. $list = LabelClass::getMyUnUseLabelList($mainId);
  45. util::success(['list' => $list]);
  46. }
  47. }