WsoCheckCtrl.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. require_once 'trdLibrary/PHPExcel/PHPExcel.php';
  3. require_once 'library/mdb.php';
  4. require_once 'library/common.php';
  5. class WsoCheckCtrl{
  6. public function __construct(){
  7. $this->db = new MdbLib();
  8. $this->common = new CommonLib();
  9. }
  10. //show
  11. public function getOrders(){
  12. if(!isset($_GET['now']) || !isset($_GET['startDate']) || !isset($_GET['endDate'])){
  13. return false;
  14. }else{
  15. $now = $this->common->my_filter_input($_GET['now']);
  16. $startDate = $_GET['startDate'] . ' 00:00:00';
  17. $endDate = $_GET['endDate'].' 23:59:59';
  18. $pnsn = isset($_GET['pnsn'])?$this->common->my_filter_input($_GET['pnsn']):50;
  19. }
  20. $offset = ($now-1)*$pnsn;
  21. $sql = 'SELECT `id`,`order_barcode`,`goods_no`,`goods_info`,`out_time`,`transport`';
  22. $sql .= ' FROM `app_wsocheck` ';
  23. $sql .= " WHERE `out_time` BETWEEN '{$startDate}' AND '{$endDate}'";
  24. $sql .= " ORDER BY `out_time` DESC LIMIT {$offset},$pnsn;";
  25. $query = $this->db->querySql($sql);
  26. $line = "";
  27. while($item = $this->db->queryRs($query)) {
  28. $line .= '<div class="list_block">';
  29. $line .= "<span class=\"order_id\">{$item['id']}</span>";
  30. $line .= "<span class=\"order_barcode\" title=\"{$item['order_barcode']}\">{$item['order_barcode']}</span>";
  31. $line .= "<span class=\"goods_no\">{$item['goods_no']}</span>";
  32. $line .= "<span class=\"goods_info\" title=\"{$item['goods_info']}\">{$item['goods_info']}</span>";
  33. $line .= "<span class=\"transport\">{$item['transport']}</span>";
  34. $line .= "<span class=\"out_time\">{$item['out_time']}</span>";
  35. $line .= '<span class="options">';
  36. $line .= "<input type=\"button\" class=\"delete_order\" data-id=\"{$item['id']}\" value=\"删除\">";
  37. $line .= '</span></div>';
  38. }
  39. return $line;
  40. }
  41. public function searchOrders(){
  42. $sql = 'SELECT `id`,`order_barcode`,`goods_no`,`goods_info`,`out_time`,`transport` FROM `app_wsocheck`';
  43. if(isset($_GET['code'])){
  44. $code = $this->common->my_filter_input($_GET['code']);
  45. $sql .= " WHERE `order_barcode`='{$code}' OR `goods_no`='{$code}';";
  46. }
  47. $query = $this->db->querySql($sql);
  48. $line = "";
  49. while($item = $this->db->queryRs($query)) {
  50. $line .= '<div class="list_block">';
  51. $line .= "<span class=\"order_id\">{$item['id']}</span>";
  52. $line .= "<span class=\"order_barcode\" title=\"{$item['order_barcode']}\">{$item['order_barcode']}</span>";
  53. $line .= "<span class=\"goods_no\">{$item['goods_no']}</span>";
  54. $line .= "<span class=\"goods_info\" title=\"{$item['goods_info']}\">{$item['goods_info']}</span>";
  55. $line .= "<span class=\"transport\">{$item['transport']}</span>";
  56. $line .= "<span class=\"out_time\">{$item['out_time']}</span>";
  57. $line .= '<span class="options">';
  58. $line .= "<input type=\"button\" class=\"delete_order\" data-id=\"{$item['id']}\" value=\"删除\">";
  59. $line .= '</span></div>';
  60. }
  61. if(!empty($line)){
  62. return $line;
  63. }else{
  64. return -1;
  65. }
  66. }
  67. public function getStatistics(){
  68. if(!isset($_GET['startDate']) || !isset($_GET['endDate'])){
  69. return false;
  70. } else {
  71. $startDate = $_GET['startDate'] . ' 00:00:00';
  72. $endDate = $_GET['endDate'].' 23:59:59';
  73. }
  74. $sql_total = "SELECT COUNT(`id`) AS `total_num` FROM `app_wsocheck` ";
  75. $sql_total .= "WHERE `out_time` BETWEEN '{$startDate}' AND '{$endDate}';";
  76. $query_total = $this->db->querySql($sql_total);
  77. $rs_total = $this->db->queryRs($query_total);
  78. $rs = array();
  79. $rs['total'] = $rs_total['total_num'];
  80. return json_encode($rs);
  81. }
  82. public function exportExcel(){
  83. set_time_limit(120);
  84. if(!isset($_GET['startDate']) || !isset($_GET['endDate'])){
  85. return false;
  86. }else{
  87. $startDate = $_GET['startDate'] . ' 00:00:00';
  88. $endDate = $_GET['endDate'].' 23:59:59';
  89. }
  90. // $sql = 'SELECT `id`,`order_barcode`,`goods_no`,`goods_info`,`out_time`,`transport` FROM `app_wsocheck`';
  91. $sql = 'SELECT `id`,`order_barcode`,`goods_info` FROM `app_wsocheck`';
  92. $sql .= " WHERE `out_time` BETWEEN '{$startDate}' AND '{$endDate}' ";
  93. $query = $this->db->querySql($sql);
  94. $PHPExcel = new \PHPExcel();
  95. $PHPExcel->setActiveSheetIndex(0)
  96. ->setCellValue('A1', '序号')
  97. ->setCellValue('B1', '条码编号')
  98. ->setCellValue('C1', '货物明细');
  99. // ->setCellValue('D1', '订单编号')
  100. // ->setCellValue('E1', '物流方式')
  101. // ->setCellValue('F1', '出库日期');
  102. $k = 2;
  103. while($item = $this->db->queryRs($query)) {
  104. $PHPExcel->setActiveSheetIndex(0)
  105. ->setCellValue('A'.$k, $k-1)
  106. ->setCellValue('B'.$k, $item['order_barcode'])
  107. ->setCellValue('C'.$k, $item['goods_info']);
  108. // ->setCellValue('D'.$k, $item['goods_no'])
  109. // ->setCellValue('E'.$k, $item['transport'])
  110. // ->setCellValue('F'.$k, $item['out_time']);
  111. $k++;
  112. }
  113. // set wdith
  114. $PHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
  115. $PHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  116. $PHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(70);
  117. // $PHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(40);
  118. // $PHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
  119. // $PHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
  120. // set align
  121. $PHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setWrapText(TRUE);
  122. $filename = 'wsocheck.'.date('His',time()).'.xls';
  123. $PHPExcel->getActiveSheet()->setTitle('wsocheck');
  124. $PHPExcel->setActiveSheetIndex(0);
  125. header("Content-Type: application/ms-excel; charset=utf-8");
  126. header("Content-Disposition: attachment; filename={$filename}");
  127. header("Expires: 0");
  128. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  129. header("Cache-Control: private",false);
  130. $PHPWriter = new PHPExcel_Writer_Excel5($PHPExcel, 'Excel5');
  131. $PHPWriter->save('php://output');
  132. }
  133. public function pagination(){
  134. if(!isset($_GET['startDate']) || !isset($_GET['endDate']) || !isset($_GET['wh'])){
  135. return false;
  136. }else{
  137. $startDate = $_GET['startDate'] . ' 00:00:00';
  138. $endDate = $_GET['endDate'].' 23:59:59';
  139. $wh = $this->common->my_filter_input($_GET['wh']);
  140. $pnsn = isset($_GET['pnsn'])?$this->common->my_filter_input($_GET['pnsn']):50;
  141. }
  142. $sql = "SELECT `id` FROM `app_wsocheck`";
  143. $sql .= " WHERE `out_time` BETWEEN '{$startDate}' AND '{$endDate}';";
  144. $query = $this->db->querySql($sql);
  145. $total = $this->db->queryNum($query);
  146. if($total == 0){
  147. $num = '0';
  148. }else{
  149. $num = ceil($total/$pnsn);
  150. $wh_max = ceil($num/10);
  151. }
  152. $direction = substr($wh, 0, 1);
  153. $wh = substr($wh, 1);
  154. if($direction == 'h'){
  155. $whh = ($wh==0)?'0':$wh-1;
  156. $wht = ($wh==0)?'1':$wh;
  157. }elseif($direction == 't'){
  158. $whh = ($wh==$wh_max)?($wh-1):$wh;
  159. $wht = ($wh==$wh_max)?$wh:($wh+1);
  160. }else{
  161. $whh = '0';
  162. $wht = '1';
  163. }
  164. $pagination = '<span class="total_page" data-ttpg="'.$num.'">共&nbsp;'.$num.'&nbsp;页</span>';
  165. if($num > 1){
  166. $pagination .= ($num>10)?"<span class=\"gtlt head\" data-wh=\"h{$whh}\">&lt;&lt;</span>":'';
  167. $clazz = '';
  168. for($i=1+$whh*10; $i<=10+$whh*10; $i++){
  169. if($i > $num){
  170. break;
  171. }else{
  172. if($i != 1+$whh*10){
  173. $clazz = 'page';
  174. }else{
  175. $clazz = 'page pn';
  176. }
  177. $start = substr($startDate, 0, 10);
  178. $end = substr($endDate, 0, 10);
  179. $param = "&now={$i}&startDate={$start}&endDate={$end}&pnsn=50";
  180. $pagination .= "<span class=\"{$clazz}\" onclick=\"getOFP('{$param}')\">".$i."</span>";
  181. }
  182. }
  183. $pagination .= ($num>10)?"<span class=\"gtlt tail\" data-wh=\"t{$wht}\">&gt;&gt;</span>":'';
  184. }
  185. $pagination .= "<span>展示 <select class=\"pnsn\">";
  186. $pns = array('50', '100', '250', '500');
  187. for($i=0; $i<4; $i++){
  188. if($pnsn == $pns[$i]){
  189. $s = 'selected="selected"';
  190. }else{
  191. $s = '';
  192. }
  193. $pagination .= "<option value=\"{$pns[$i]}\" {$s}>{$pns[$i]}条</option>";
  194. }
  195. $pagination .= "</select> 记录</span>";
  196. return $pagination;
  197. }
  198. public function deleteOrder(){
  199. if(isset($_GET['id']) && !empty($_GET['id'])){
  200. $id = $this->common->my_filter_input($_GET['id']);
  201. }else{
  202. return false;
  203. }
  204. $sql = "DELETE FROM `app_wsocheck` WHERE `id`='{$id}';";
  205. if($this->db->querySql($sql)){
  206. return 1;
  207. }else{
  208. return -1;
  209. }
  210. }
  211. public function addNewOrder(){
  212. if(!isset($_POST['barcode']) || empty($_POST['barcode'])){
  213. return false;
  214. }else{
  215. $barcode = $_POST['barcode'];
  216. }
  217. $sql = "SELECT `goods_no`,`goods_info`,`transport` FROM `app_wigsout` WHERE `order_barcode`='{$barcode}';";
  218. $query = $this->db->querySql($sql);
  219. $rs = $this->db->queryRs($query);
  220. if(empty($rs)){
  221. return -1;
  222. }
  223. $sql = "INSERT INTO `app_wsocheck`(`order_barcode`,`goods_no`,`goods_info`,`transport`) VALUES ('{$barcode}','{$rs['goods_no']}','{$rs['goods_info']}','{$rs['transport']}');";
  224. if(!($this->db->querySql($sql))){
  225. return -2;
  226. }else{
  227. return 1;
  228. }
  229. }
  230. public function __destruct(){
  231. //TODO
  232. }
  233. }