Przeglądaj źródła

添加扫描日志的excel下载

lvhao 16 godzin temu
rodzic
commit
72c00f5991

+ 53 - 3
core/CoreApp/controllers/Whlabelfz.php

@@ -47,6 +47,8 @@ class Whlabelfz extends Start_Controller
 			$this->_printing();
 		}elseif($arg == 'whlabelscan'){
 			$this->_whlabelscan();
+		}elseif($arg == 'whlabelscanlogexcel'){
+			$this->_whlabelscanlogexcel();
 		}
 	    else {
 			$this->_index();
@@ -924,9 +926,9 @@ class Whlabelfz extends Start_Controller
 		}
 	}
 
-	// private function _bqplprint(){
+	private function _bqplprint(){
 
-	// }
+	}
 
 	private function _whlabelscan(){
 		if($this->input->method() == 'post'){
@@ -939,9 +941,10 @@ class Whlabelfz extends Start_Controller
 			$timetj = $this->input->post('timetj',true);
 			$timetk = strtotime($timetk);
 			$timetj = strtotime($timetj);
+			$where = "";
 			if($timetk && $timetj)
             {
-                $where  = " addtime  > '$timetk' and addtime < '$timetj'";
+                $where  .= " addtime  > '$timetk' and addtime < '$timetj'";
             }
 			if($type){
 				$where  .= " and type = '$type'";
@@ -988,4 +991,51 @@ class Whlabelfz extends Start_Controller
 			$this->_Template('whlabelfz_whlabelscan', $this->data);
 		}
 	}
+
+	private function _whlabelscanlogexcel(){
+		$title = $this->input->post('title',true);
+		$sku = $this->input->post('sku',true);
+		$type = $this->input->post('type',true);
+		$timetk = $this->input->post('timetk',true);
+		$timetj = $this->input->post('timetj',true);
+		$timetk = strtotime($timetk);
+		$timetj = strtotime($timetj);
+		$where = "";
+		if($timetk && $timetj)
+		{
+			$where  .= " addtime  > '$timetk' and addtime < '$timetj'";
+		}
+		if($type){
+			$where  .= " and type = '$type'";
+		}
+		if($title){
+			$where  .= " and title like '%$title%'";
+		}
+		if($sku){
+			$where  .= " and sku like '%$sku%'";
+		}
+		$info_list = $this->whlabelscanlog->find_all($where,'sku,title,warehouse,type,num,addtime');
+		foreach ($info_list as $key=>$value) 
+		{
+			$info_list[$key]['warehouse'] = $this->_getWarehouseById($value['warehouse']);
+			$info_list[$key]['type'] = $value['type'] == 1 ? '扫描入库' : '扫描出库';
+			$info_list[$key]['addtime'] = date('Y-m-d H:i:s', $value['addtime']);
+		}
+		if(empty($info_list)){
+			echo json_encode(array('msg'=>'没有数据','success'=>false));exit;
+		}
+		$final_list = [];
+		foreach ($info_list as $key => $value) {
+			$final_list[] = [
+				"SKU"=>$value['sku'],
+				"商品名称"=>$value['title'],
+				"仓库"=>$value['warehouse'],
+				"类型"=>$value['type'],
+				"数量"=>$value['num'],
+				"扫描时间"=> $value['addtime']
+			];
+		}
+		$filename = "扫描日志_".date("Ymd")."_".rand(1000,9999).".xls";
+		echo json_encode(array('msg'=>'获取数据成功','success'=>true,'data'=>$final_list,'filename'=>$filename));exit;
+	}
 }

Plik diff jest za duży
+ 24 - 0
template/erp/js/excel/xlxswidth.js


+ 64 - 0
template/erp/whlabelfz_whlabelscan.html

@@ -12,6 +12,9 @@
                 <li><span>确 定</span></li>
             </ul>
             <input type="hidden" name="type" value="{$type}">
+            <div class="control">
+                <a href="javascript:void(0);" class="scanlogs">导出日志</a>
+            </div>
             <table class="datatitle data" border="0" style="border-collapse:collapse;">
                 <tr>
                     <td><label onClick="swapCheck()"><input name="checkbox" type="checkbox"
@@ -74,7 +77,68 @@
         }
 
     </script>
+    <script>
+        $(".scanlogs").on("click", function() {
+            layx.load('loadId','导入中,请稍后',{shadable:0.6});
+            let obj = {};
+            $("input").each(function() {
+                let name = $(this).attr("name");
+                let value = $(this).val();
+                if (name) {                // 避免没有 name 属性的 input
+                    obj[name] = value;
+                }
+            });
+            
+            $.post("/whlabelfz/whlabelscanlogexcel",obj, function(res) {
+                layx.destroy('loadId');
+                if(!res.success){
+                    layx.msg(res.msg,{dialogIcon:'warn', position:'cc'});
+                }else{
+                    download_scanlogs(res.data,res.filename)
+                }
+            },'json')
+        })
+        function download_scanlogs(data,filename){
+            let  sheet = XLSX.utils.json_to_sheet(data)
+
+    
+            sheet['!cols'] = [
+                    //订单号
+                    {
+                        wch:40,
+                    },
+                    //订单编码
+                    {
+                        wch:60,
+                    },
+                    //店铺名称
+                    {
+                        wch:10,
+                    },
+                    //状态
+                    {
+                        wch:10,
+                    },
+                    {
+                        wch:10,
+                    },
+                    //状态
+                    {
+                        wch:15,
+                    },
+                    
+                    
+            ];
 
+
+            let workbook = XLSX.utils.book_new();
+            
+            XLSX.utils.book_append_sheet(workbook, sheet, "Sheet1");
+            XLSX.writeFile(workbook, filename);
+        }
+    </script>
+   
+    <script type="text/javascript" src="{$theme}js/excel/xlxswidth.js"></script>
     <script type="text/javascript" src="{$theme}js/laydate.js"></script>
     <script type="text/javascript" src="{$theme}js/print.js?v=202505301539"></script>
     {Template footer}