LabelController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 actionClearAll()
  10. {
  11. $sql = "delete from xhLabel";
  12. Yii::$app->db->createCommand($sql)->execute();
  13. util::complete();
  14. }
  15. //批量添加电子标 ssh 20230821
  16. public function actionBatchAddLabel()
  17. {
  18. $post = Yii::$app->request->post();
  19. $data = $post['data'] ?? '';
  20. $arr = json_decode($data, true);
  21. if (empty($arr)) {
  22. util::fail('没有电子标');
  23. }
  24. $ptItemId = $post['ptItemId'] ?? 0;
  25. if (empty($ptItemId)) {
  26. util::fail('没有花材信息');
  27. }
  28. $list = LabelClass::getAllByCondition(['mainId' => $this->mainId, 'use' => 0], null, '*');
  29. if (!empty($list)) {
  30. $has = array_column($list, 'epc');
  31. $common = array_intersect($arr, $has);
  32. if (!empty($common)) {
  33. $currentLabel = $common[0] ?? '';
  34. util::fail('标签已经添加过了:' . $currentLabel);
  35. }
  36. }
  37. $connection = Yii::$app->db;
  38. $transaction = $connection->beginTransaction();
  39. try {
  40. foreach ($arr as $epc) {
  41. LabelClass::add(['mainId' => $this->mainId, 'epc' => $epc, 'itemId' => $ptItemId]);
  42. }
  43. $transaction->commit();
  44. util::complete('操作成功');
  45. } catch (\Exception $e) {
  46. $transaction->rollBack();
  47. Yii::info("保存失败原因:" . $e->getMessage());
  48. util::fail('保存失败');
  49. }
  50. }
  51. //获取我没有使用的电子标 ssh 20230817
  52. public function actionGetMyLabelList()
  53. {
  54. $mainId = $this->mainId;
  55. $list = LabelClass::getMyUnUseLabelList($mainId);
  56. util::success(['list' => $list]);
  57. }
  58. }