BarcodeGenerator.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. // Copyright (C) 2002-2015 Nicola Asuni - Tecnick.com LTD
  8. //
  9. // This file was part of TCPDF software library.
  10. //
  11. // TCPDF is free software: you can redistribute it and/or modify it
  12. // under the terms of the GNU Lesser General Public License as
  13. // published by the Free Software Foundation, either version 3 of the
  14. // License, or (at your option) any later version.
  15. //
  16. // TCPDF is distributed in the hope that it will be useful, but
  17. // WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. // See the GNU Lesser General Public License for more details.
  20. //
  21. // You should have received a copy of the License
  22. // along with TCPDF. If not, see
  23. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  24. //
  25. // See LICENSE.TXT file for more information.
  26. namespace app\librarys\Picqer\Barcode;
  27. use app\librarys\Picqer\Barcode\Exceptions\UnknownTypeException;
  28. use app\librarys\Picqer\Barcode\Types\TypeCodabar;
  29. use app\librarys\Picqer\Barcode\Types\TypeCode11;
  30. use app\librarys\Picqer\Barcode\Types\TypeCode128;
  31. use app\librarys\Picqer\Barcode\Types\TypeCode128A;
  32. use app\librarys\Picqer\Barcode\Types\TypeCode128B;
  33. use app\librarys\Picqer\Barcode\Types\TypeCode128C;
  34. use app\librarys\Picqer\Barcode\Types\TypeCode32;
  35. use app\librarys\Picqer\Barcode\Types\TypeCode39;
  36. use app\librarys\Picqer\Barcode\Types\TypeCode39Checksum;
  37. use app\librarys\Picqer\Barcode\Types\TypeCode39Extended;
  38. use app\librarys\Picqer\Barcode\Types\TypeCode39ExtendedChecksum;
  39. use app\librarys\Picqer\Barcode\Types\TypeCode93;
  40. use app\librarys\Picqer\Barcode\Types\TypeEan13;
  41. use app\librarys\Picqer\Barcode\Types\TypeEan8;
  42. use app\librarys\Picqer\Barcode\Types\TypeIntelligentMailBarcode;
  43. use app\librarys\Picqer\Barcode\Types\TypeInterleaved25;
  44. use app\librarys\Picqer\Barcode\Types\TypeInterleaved25Checksum;
  45. use app\librarys\Picqer\Barcode\Types\TypeKix;
  46. use app\librarys\Picqer\Barcode\Types\TypeMsi;
  47. use app\librarys\Picqer\Barcode\Types\TypeMsiChecksum;
  48. use app\librarys\Picqer\Barcode\Types\TypePharmacode;
  49. use app\librarys\Picqer\Barcode\Types\TypePharmacodeTwoCode;
  50. use app\librarys\Picqer\Barcode\Types\TypePlanet;
  51. use app\librarys\Picqer\Barcode\Types\TypePostnet;
  52. use app\librarys\Picqer\Barcode\Types\TypeRms4cc;
  53. use app\librarys\Picqer\Barcode\Types\TypeStandard2of5;
  54. use app\librarys\Picqer\Barcode\Types\TypeStandard2of5Checksum;
  55. use app\librarys\Picqer\Barcode\Types\TypeUpcA;
  56. use app\librarys\Picqer\Barcode\Types\TypeUpcE;
  57. use app\librarys\Picqer\Barcode\Types\TypeUpcExtension2;
  58. use app\librarys\Picqer\Barcode\Types\TypeUpcExtension5;
  59. abstract class BarcodeGenerator
  60. {
  61. const TYPE_CODE_32 = 'C32';
  62. const TYPE_CODE_39 = 'C39';
  63. const TYPE_CODE_39_CHECKSUM = 'C39+';
  64. const TYPE_CODE_39E = 'C39E'; // CODE 39 EXTENDED
  65. const TYPE_CODE_39E_CHECKSUM = 'C39E+'; // CODE 39 EXTENDED + CHECKSUM
  66. const TYPE_CODE_93 = 'C93';
  67. const TYPE_STANDARD_2_5 = 'S25';
  68. const TYPE_STANDARD_2_5_CHECKSUM = 'S25+';
  69. const TYPE_INTERLEAVED_2_5 = 'I25';
  70. const TYPE_INTERLEAVED_2_5_CHECKSUM = 'I25+';
  71. const TYPE_CODE_128 = 'C128';
  72. const TYPE_CODE_128_A = 'C128A';
  73. const TYPE_CODE_128_B = 'C128B';
  74. const TYPE_CODE_128_C = 'C128C';
  75. const TYPE_EAN_2 = 'EAN2'; // 2-Digits UPC-Based Extention
  76. const TYPE_EAN_5 = 'EAN5'; // 5-Digits UPC-Based Extention
  77. const TYPE_EAN_8 = 'EAN8';
  78. const TYPE_EAN_13 = 'EAN13';
  79. const TYPE_UPC_A = 'UPCA';
  80. const TYPE_UPC_E = 'UPCE';
  81. const TYPE_MSI = 'MSI'; // MSI (Variation of Plessey code)
  82. const TYPE_MSI_CHECKSUM = 'MSI+'; // MSI + CHECKSUM (modulo 11)
  83. const TYPE_POSTNET = 'POSTNET';
  84. const TYPE_PLANET = 'PLANET';
  85. const TYPE_RMS4CC = 'RMS4CC'; // RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
  86. const TYPE_KIX = 'KIX'; // KIX (Klant index - Customer index)
  87. const TYPE_IMB = 'IMB'; // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
  88. const TYPE_CODABAR = 'CODABAR';
  89. const TYPE_CODE_11 = 'CODE11';
  90. const TYPE_PHARMA_CODE = 'PHARMA';
  91. const TYPE_PHARMA_CODE_TWO_TRACKS = 'PHARMA2T';
  92. protected function getBarcodeData(string $code, string $type): Barcode
  93. {
  94. $barcodeDataBuilder = $this->createDataBuilderForType($type);
  95. return $barcodeDataBuilder->getBarcodeData($code);
  96. }
  97. protected function createDataBuilderForType(string $type)
  98. {
  99. switch (strtoupper($type)) {
  100. case self::TYPE_CODE_32:
  101. return new TypeCode32();
  102. case self::TYPE_CODE_39:
  103. return new TypeCode39();
  104. case self::TYPE_CODE_39_CHECKSUM:
  105. return new TypeCode39Checksum();
  106. case self::TYPE_CODE_39E:
  107. return new TypeCode39Extended();
  108. case self::TYPE_CODE_39E_CHECKSUM:
  109. return new TypeCode39ExtendedChecksum();
  110. case self::TYPE_CODE_93:
  111. return new TypeCode93();
  112. case self::TYPE_STANDARD_2_5:
  113. return new TypeStandard2of5();
  114. case self::TYPE_STANDARD_2_5_CHECKSUM:
  115. return new TypeStandard2of5Checksum();
  116. case self::TYPE_INTERLEAVED_2_5:
  117. return new TypeInterleaved25();
  118. case self::TYPE_INTERLEAVED_2_5_CHECKSUM:
  119. return new TypeInterleaved25Checksum();
  120. case self::TYPE_CODE_128:
  121. return new TypeCode128();
  122. case self::TYPE_CODE_128_A:
  123. return new TypeCode128A();
  124. case self::TYPE_CODE_128_B:
  125. return new TypeCode128B();
  126. case self::TYPE_CODE_128_C:
  127. return new TypeCode128C();
  128. case self::TYPE_EAN_2:
  129. return new TypeUpcExtension2();
  130. case self::TYPE_EAN_5:
  131. return new TypeUpcExtension5();
  132. case self::TYPE_EAN_8:
  133. return new TypeEan8();
  134. case self::TYPE_EAN_13:
  135. return new TypeEan13();
  136. case self::TYPE_UPC_A:
  137. return new TypeUpcA();
  138. case self::TYPE_UPC_E:
  139. return new TypeUpcE();
  140. case self::TYPE_MSI:
  141. return new TypeMsi();
  142. case self::TYPE_MSI_CHECKSUM:
  143. return new TypeMsiChecksum();
  144. case self::TYPE_POSTNET:
  145. return new TypePostnet();
  146. case self::TYPE_PLANET:
  147. return new TypePlanet();
  148. case self::TYPE_RMS4CC:
  149. return new TypeRms4cc();
  150. case self::TYPE_KIX:
  151. return new TypeKix();
  152. case self::TYPE_IMB:
  153. return new TypeIntelligentMailBarcode();
  154. case self::TYPE_CODABAR:
  155. return new TypeCodabar();
  156. case self::TYPE_CODE_11:
  157. return new TypeCode11();
  158. case self::TYPE_PHARMA_CODE:
  159. return new TypePharmacode();
  160. case self::TYPE_PHARMA_CODE_TWO_TRACKS:
  161. return new TypePharmacodeTwoCode();
  162. }
  163. throw new UnknownTypeException();
  164. }
  165. }