BarcodeCtrl.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. /*
  3. * Barcode Class
  4. * by lijg 20181030
  5. */
  6. require_once 'trdLibrary/PHPExcel/PHPExcel.php';
  7. require_once 'library/mdb.php';
  8. require_once 'library/common.php';
  9. class BarcodeCtrl{
  10. public function __construct(){
  11. $this->db = new MdbLib();
  12. $this->common = new CommonLib();
  13. }
  14. //show
  15. public function showProduct(){
  16. $now = isset($_GET['now'])?$this->common->my_filter_input($_GET['now']):'1';
  17. $type = isset($_GET['type'])?$this->common->my_filter_input($_GET['type']):'1';
  18. $offset = ($now-1)*15;
  19. if($type == 1){
  20. $sql = "SELECT `bc_id`,`bc_product`,`bc_code`,`bc_tag`,`bc_tag2`,`bc_amount`,`bc_print_status`,`create_time` FROM `barcode_amazon` ORDER BY `bc_id` DESC LIMIT {$offset},15";
  21. }elseif($type == 2){
  22. $sql = "SELECT `bc_id`,`bc_product`,`bc_sku`,`bc_tag`,`bc_amount`,`bc_print_status`,`create_time` FROM `barcode_oversea` ORDER BY `bc_id` DESC LIMIT {$offset},15";
  23. }elseif($type == 3){
  24. $sql = "SELECT `bc_id`,`bc_product`,`bc_code`,`bc_tag`,`bc_tag2`,`bc_amount`,`bc_print_status`,`create_time` FROM `barcode_alie` ORDER BY `bc_id` DESC LIMIT {$offset},15";
  25. }elseif($type == 4){
  26. $sql = "SELECT `bc_id`,`bc_product`,`bc_code`,`bc_tag`,`bc_tag2`,`bc_amount`,`bc_print_status`,`create_time` FROM `barcode_gzc` ORDER BY `bc_id` DESC LIMIT {$offset},15";
  27. }
  28. $query = $this->db->querySql($sql);
  29. $line = "";
  30. while($item = $this->db->queryRs($query)) {
  31. if($item['bc_print_status']){
  32. $print_status = "已打印";
  33. $class = 'ok';
  34. }else{
  35. $print_status = "未打印";
  36. $class = 'no';
  37. }
  38. $line .= '<div class="list_block">';
  39. $line .= "<span class=\"id\">{$item['bc_id']}</span>";
  40. $line .= "<span class=\"product\">{$item['bc_product']}</span>";
  41. if($type == 1 || $type == 3 || $type == 4){
  42. $line .= "<span class=\"code\">{$item['bc_code']}</span>";
  43. }elseif($type == 2){
  44. $line .= "<span class=\"code\">{$item['bc_sku']}</span>";
  45. }
  46. $line .= "<span class=\"tag\">{$item['bc_tag']}</span>";
  47. if($type == 1 || $type == 3 || $type == 4){
  48. $line .= "<span class=\"tag2\">{$item['bc_tag2']}</span>";
  49. }
  50. $line .= "<span class=\"amount la\">{$item['bc_amount']}</span>";
  51. $line .= "<span class=\"create_time\">{$item['create_time']}</span>";
  52. $line .= "<span class=\"print_status {$class}\">{$print_status}</span>";
  53. $line .= '<span class="options"><input type="button" value="Print" class="print_bc" onclick="myAjax(\'barcode_updatePrintStatus\',\''.$item['bc_id'].'_'.$type.'\');" /></span>';
  54. $line .= '</div>';
  55. }
  56. return $line;
  57. }
  58. //search
  59. public function searchProduct(){
  60. if(!isset($_POST['code'])){
  61. return -1;
  62. }else{
  63. $code = $this->common->my_filter_input($_POST['code']);
  64. }
  65. $type = isset($_POST['type'])?$this->common->my_filter_input($_POST['type']):'1';
  66. $sql = "SELECT `bc_id`,`bc_product`,`bc_code`,`bc_tag`,`bc_tag2`,`bc_amount`,`bc_print_status`,`create_time` FROM `barcode_amazon` WHERE `bc_code`='{$code}' ORDER BY `create_time` DESC";
  67. $query = $this->db->querySql($sql);
  68. $line = "";
  69. while($item = $this->db->queryRs($query)) {
  70. if($item['bc_print_status']){
  71. $print_status = "已打印";
  72. $class = 'ok';
  73. }else{
  74. $print_status = "未打印";
  75. $class = 'no';
  76. }
  77. $line .= '<div class="list_block">';
  78. $line .= "<span class=\"id\">{$item['bc_id']}</span>";
  79. $line .= "<span class=\"product\">{$item['bc_product']}</span>";
  80. $line .= "<span class=\"code\">{$item['bc_code']}</span>";
  81. $line .= "<span class=\"tag\">{$item['bc_tag']}</span>";
  82. $line .= "<span class=\"tag2\">{$item['bc_tag2']}</span>";
  83. $line .= "<span class=\"amount la\">{$item['bc_amount']}</span>";
  84. $line .= "<span class=\"create_time\">{$item['create_time']}</span>";
  85. $line .= "<span class=\"print_status {$class}\">{$print_status}</span>";
  86. $line .= '<span class="options"><input type="button" value="Print" class="print_bc" onclick="myAjax(\'barcode_updatePrintStatus\',\''.$item['bc_id'].'_'.$type.'\');" /></span>';
  87. $line .= '</div>';
  88. }
  89. return $line;
  90. }
  91. //upload
  92. public function uploadExcel(){
  93. if(isset($_POST['type']) && !empty($_POST['type'])){
  94. $type = $this->common->my_filter_input($_POST['type']);
  95. if($type == 1){
  96. $parentFolder = 'AMAZON';
  97. }elseif($type == 2){
  98. $parentFolder = 'OVERSEA';
  99. }elseif($type == 3){
  100. $parentFolder = 'ALIE';
  101. }elseif($type == 4){
  102. $parentFolder = 'GZC';
  103. }
  104. }else{
  105. return false;
  106. }
  107. // if(($_FILES['excel']['type'] == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') && ($_FILES['excel']['size'] < 5000000)){
  108. if($_FILES['excel']['size'] < 5000000){
  109. if($_FILES['excel']['error'] > 0){
  110. echo "error on upload file";
  111. return -2;
  112. }else{
  113. $tmp = pathinfo($_FILES['excel']['name']);
  114. $newName = date('YmdHis').'.'.$tmp['extension'];
  115. $newPath = "../public/upload/BARCODE/{$parentFolder}/{$newName}";
  116. if(!move_uploaded_file($_FILES['excel']['tmp_name'], $newPath)){
  117. return -3;
  118. }else{
  119. if($this->readExcel($newPath, $type) !== 1){
  120. return -4;
  121. }else{
  122. return 1;
  123. }
  124. }
  125. }
  126. } else {
  127. return -1;
  128. }
  129. }
  130. //read excel
  131. public function readExcel($file, $type){
  132. $PHPExcel = new \PHPExcel();
  133. $PHPReader = new \PHPExcel_Reader_Excel2007();
  134. if(!$PHPReader->canRead($file)){
  135. return -1;
  136. }
  137. $PHPExcel = $PHPReader->load($file);
  138. $currentSheet = $PHPExcel->getsheet(0);
  139. //$allColumn = $currentSheet->getHighestColumn();
  140. $allRow = $currentSheet->getHighestRow();
  141. if($type == 1 || $type == 3 || $type == 4){
  142. //$lastColumn = 'E';
  143. $startRow = 3;
  144. $startColumn = 'A';
  145. $endColumn = 'E';
  146. }elseif($type == 2){
  147. //$lastColumn = 'I';
  148. $startRow = 2;
  149. $startColumn = 'D';
  150. $endColumn = 'G';
  151. }
  152. //if($allColumn != $lastColumn){
  153. // return -2;
  154. //}
  155. $insertValues = '';
  156. for($currentRow = $startRow; $currentRow <= $allRow; $currentRow++){
  157. $cellStr = "";
  158. for($currentColumn = $startColumn; $currentColumn <= $endColumn; $currentColumn++){
  159. $cellValue = $currentSheet->getCellByColumnAndRow(ord($currentColumn)-65, $currentRow)->getValue();
  160. $cellValue = $this->common->my_filter_input($cellValue);
  161. if(empty($cellValue)){
  162. if($currentColumn == 'C' || $currentColumn == 'D'){
  163. $cellStr .= '" ",';
  164. }else{
  165. break;
  166. }
  167. }else{
  168. $cellStr .= '"' . $cellValue . '",';
  169. }
  170. }
  171. $cellStr = trim($cellStr, ',');
  172. if(!empty($cellStr)){
  173. $insertValues .= "({$cellStr}),";
  174. }
  175. }
  176. $insertValues = trim($insertValues, ',');
  177. if($type == 1){
  178. $sql = "INSERT INTO `barcode_amazon`(`bc_product`,`bc_code`,`bc_tag`,`bc_tag2`,`bc_amount`) VALUES {$insertValues};";
  179. }elseif($type == 2){
  180. $sql = "INSERT INTO `barcode_oversea`(`bc_product`,`bc_sku`,`bc_tag`,`bc_amount`) VALUES {$insertValues};";
  181. }elseif($type == 3){
  182. $sql = "INSERT INTO `barcode_alie`(`bc_product`,`bc_code`,`bc_tag`,`bc_tag2`,`bc_amount`) VALUES {$insertValues};";
  183. }elseif($type == 4){
  184. $sql = "INSERT INTO `barcode_gzc`(`bc_product`,`bc_code`,`bc_tag`,`bc_tag2`,`bc_amount`) VALUES {$insertValues};";
  185. }
  186. if($this->db->querySql($sql)){
  187. return 1;
  188. }else{
  189. return -3;
  190. }
  191. }
  192. //ups
  193. public function updatePrintStatus(){
  194. if(isset($_GET['bid']) && !empty($_GET['bid']) && isset($_GET['type']) && !empty($_GET['type'])){
  195. $bid = $this->common->my_filter_input($_GET['bid']);
  196. $type = $this->common->my_filter_input($_GET['type']);
  197. } else {
  198. return false;
  199. }
  200. if($type == 1){
  201. $db = 'barcode_amazon';
  202. }elseif($type == 2){
  203. $db = 'barcode_oversea';
  204. }elseif($type == 3){
  205. $db = 'barcode_alie';
  206. }elseif($type == 4){
  207. $db = 'barcode_gzc';
  208. }
  209. $sql = "UPDATE `{$db}` SET `bc_print_status`=`bc_print_status`+1 WHERE `bc_id`='{$bid}';";
  210. $this->db->querySql($sql);
  211. return 1;
  212. }
  213. //pagination
  214. public function pagination(){
  215. if(isset($_GET['type']) && !empty($_GET['type']) && isset($_GET['wh'])){
  216. $type = $this->common->my_filter_input($_GET['type']);
  217. $wh = $this->common->my_filter_input($_GET['wh']);
  218. } else {
  219. return false;
  220. }
  221. if($type == 1){
  222. $db = 'barcode_amazon';
  223. }elseif($type == 2){
  224. $db = 'barcode_oversea';
  225. }elseif($type == 3){
  226. $db = 'barcode_alie';
  227. }elseif($type == 4){
  228. $db = 'barcode_gzc';
  229. }
  230. $sql = "SELECT `bc_id` FROM `{$db}`";
  231. $query = $this->db->querySql($sql);
  232. $total = $this->db->queryNum($query);
  233. if($total == 0){
  234. $num = '0';
  235. }else{
  236. $num = ceil($total/15);
  237. $wh_max = ceil($num/10);
  238. }
  239. $direction = substr($wh, 0, 1);
  240. $wh = substr($wh, 1);
  241. if($direction == 'h'){
  242. $whh = ($wh==0)?'0':$wh-1;
  243. $wht = ($wh==0)?'1':$wh;
  244. }elseif($direction == 't'){
  245. $whh = ($wh==$wh_max)?($wh-1):$wh;
  246. $wht = ($wh==$wh_max)?$wh:($wh+1);
  247. }else{
  248. $whh = '0';
  249. $wht = '1';
  250. }
  251. $pagination = '<span class="total_page" data-ttpg="'.$num.'">共&nbsp;'.$num.'&nbsp;页</span>';
  252. if($num > 1){
  253. $pagination .= ($num>10)?"<span class=\"gtlt head\" data-wh=\"h{$whh}\">&lt;&lt;</span>":'';
  254. $clazz = '';
  255. for($i=1+$whh*10; $i<=10+$whh*10; $i++){
  256. if($i > $num){
  257. break;
  258. }else{
  259. if($i != 1+$whh*10){
  260. $clazz = 'page';
  261. }else{
  262. $clazz = 'page pn';
  263. }
  264. $param = $i . '_' . $type;
  265. $pagination .= "<span class=\"{$clazz}\" onclick=\"myAjax('barcode_showProduct','{$param}')\">".$i."</span>";
  266. }
  267. }
  268. $pagination .= ($num>10)?"<span class=\"gtlt tail\" data-wh=\"t{$wht}\">&gt;&gt;</span>":'';
  269. }
  270. return $pagination;
  271. }
  272. public function __destruct(){
  273. //TODO
  274. }
  275. }