lvhao 9 часов назад
Родитель
Сommit
279e83afd1
2 измененных файлов с 203 добавлено и 1 удалено
  1. 102 0
      core/CoreApp/controllers/Whlabeltransport.php
  2. 101 1
      template/erp/whlabeltransport.html

+ 102 - 0
core/CoreApp/controllers/Whlabeltransport.php

@@ -139,6 +139,108 @@ class Whlabeltransport extends Start_Controller {
 	}
 	//添加
 	public function _add()
+	{
+		$post = $this->input->post(NULL, TRUE);
+		$data_str = $post['data'];
+		$list = json_decode($data_str,true);
+		if(empty($list)){
+			echo json_encode(['smg'=>"在途数据为空",'success'=>false]);
+		}
+		$i = 0;$j = 0;$ed = array();
+		$order_no = "ZT".date("ymdHis");
+		foreach ($list as $key=>$value)
+		{
+			if($key == 0){
+				if(!empty($value[5])){
+					if(strpos($value[5], "ZT") !== false){
+						$order_no = $value[5];
+					}
+				}
+				
+			}
+			$time = time();
+			if($value['0'] == "")
+			{
+				continue;
+			}
+			$warehouse = $this->warehouse->get_title($value['0']);
+			//$d = $this->whlabel->get_sku($value['1']);//针对各个仓库
+			if($value['2'] =='' || $value['2'] < 1)
+			{
+				continue;
+			}
+			$d = $this->whlabel->get_warehousesku(5,$value['1']);//针对各个仓库
+			if(!$d)//如果没有这个SKU
+			{
+				$ed[] = array($value['1'].'-库存中不存在此SKU');
+				$j++;
+				continue;
+			}
+			if(!isset($warehouse['id']))
+			{
+				$ed[] = array($value['1'].'-仓库名错误!');
+				$j++;
+				continue;
+			}
+			if($value['3'] == '')
+			{
+				$ed[] = array($value['1'].'-没有填写预达日期!');
+				$j++;
+				continue;
+			}
+			$post['sku'] = $value['1'];
+			$post['num'] = $value['2'];//数量
+			$post['stime'] = strtotime($value['3']);//预计到达日期
+			$post['text'] = $value['4'];//备注
+			$post['enter'] = $time;//添加时间
+			$post['shop'] = $d['shop'];
+			$post['warehouse'] = $warehouse['id'];
+			$post['purchase'] = $d['purchase'];
+			$post['title'] = $d['title'];
+			$post['number'] = $d['number'];
+			$post['features'] = $d['features'];
+			$post['retreatwarehouse'] = $d['retreatwarehouse'];
+			$post['order_no'] = $order_no;
+			$post['u9_tb'] = 0;
+			$this->whlabeltransport->insert($post);
+		}
+		$num = $this->whlabeltransport->find_all("order_no = '".$order_no."'");
+		if(!empty($num)  ){
+			$num2 = $this->zzquque_u9->find_all("order_no = '".$order_no."'");
+			if(empty($num2)){
+				$this->zzquque_u9->insert( [
+					'platform'=>'',
+					'warehouse'=>0,
+					'type'=>1,   //成品库到在途库
+					'order_no'=>$order_no,
+					'status'=>0,
+					'create_time'=>time(),
+					'update_time'=>time(),
+				]);
+				
+			}
+		}
+		if($j > 0)
+		{
+			$tt = date('Ymd',time());
+			$title = '导入错误信息-'.$tt;
+			$filename = $title.".xlsx";
+			$eds =[];
+			foreach($ed as $k=>$v){
+				$eds[]= [
+					"错误信息"=>$v[0]
+				];
+			}
+			echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','data'=>['filename'=>$filename,'error'=>$eds],'success'=>true));exit;
+		}
+		else
+		{
+			echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
+		}
+		
+	}
+
+	public function _addbak()
 	{
 		$dir = '/data/excel/'.date('Ymd',time()).'/';
 		$config['upload_path'] = '.'.$dir ;

+ 101 - 1
template/erp/whlabeltransport.html

@@ -25,7 +25,7 @@
 <div class="control">
 <a href="javascript:void(0);" class="datalistwc">批量完成</a>
 <a href="javascript:void(0);" class="whlabeltransportmb">导出模板</a>
-<a href="javascript:void(0);" class="whlabeldr">导入在途数据</a>
+<a href="javascript:void(0);" class="whlabeldr_erp">导入在途数据</a>
 <a href="javascript:void(0);" class="whlabeltransportexcel">导出在途数据</a>
 <a href="javascript:void(0);" class="whlabeltransportexcelzh">导出在途中及库存数据</a>
 <a href="javascript:void(0);" class="check">删 除</a>
@@ -154,6 +154,106 @@ $(".datatext").on('click',"td .ztwc",function() {
  
 });
 </script>
+<script>
+    $(".whlabeldr_erp").on('click',function(){
+        var me = $(this);
+        $("#upload-file").click();
+        $("#upload-file").unbind("change");
+        $("#upload-file").bind("change",function(){
+            whlabeldr_two(me);
+            layx.load('loadId','导入中,请稍后',{shadable:0.6});
+        });
+    })
+
+    let excel_data = [];
+    function whlabeldr_two(dr){
+        var file = document.getElementById("upload-file").files[0];
+        if (!file) return;
+
+        // 显示加载提示
+        //layx.load('loadId', '解析 Excel 中,请稍后', { shadable: 0.6 });
+
+        // 使用 FileReader 读取文件
+        var reader = new FileReader();
+        reader.onload = function(e) {
+            var data = e.target.result;
+            try {
+                // 使用 SheetJS 解析 Excel 为 JSON
+                var workbook = XLSX.read(data, { type: 'array' });
+                var sheetName = workbook.SheetNames[0]; // 取第一个工作表
+                var worksheet = workbook.Sheets[sheetName];
+                var jsonData = XLSX.utils.sheet_to_json(worksheet, { header:1,defval: "" });
+                jsonData.shift(); // 去掉第一行表头
+                // console.log(jsonData)
+                excel_data = jsonData;
+                // 构建要上传的数据(可以包含文件名、sheet名等)
+                // var uploadData = {
+                //     fileName: file.name,
+                //     sheetName: sheetName,
+                //     data: jsonData   // 解析后的 JSON 数组
+                // };
+                // 通过 AJAX 上传 JSON 数据
+                document.getElementById("upload-file").files[0] = '';
+                if(excel_data.length>100){
+                    layx.destroy('loadId');
+                    errorc({ success: false, msg: "一次最多只能上传100条数据" });
+                    return;
+                }
+                save_transfer_data();
+            } catch (err) {
+                layx.destroy('loadId');
+                console.error("解析 Excel 失败:", err);
+                errorc({ success: false, msg: "解析 Excel 文件失败" });
+            }
+        };
+        reader.onerror = function() {
+            layx.destroy('loadId');
+            errorc({ success: false, msg: "文件读取失败" });
+        };
+        reader.readAsArrayBuffer(file); // 以 ArrayBuffer 读取
+    }
+    function save_transfer_data(){
+        $.post("/whlabeltransport/add/", { data: JSON.stringify(excel_data) }, function(res) {
+            layx.destroy('loadId');
+            console.log(res)
+            if(res.code == 1){
+                errora({ success: true, msg: res.msg }); 
+            }else{
+
+                layx.confirm('错误提示',res.msg,null,{
+                    buttons:[
+                        {
+                            label:'确定',
+                            callback:function(id, button, event){
+                                download_excel(res.data.error,res.data.filename);
+                                layx.destroy(id);
+                            }
+                        }
+                    ],dialogIcon:'warn',shadable:0.6
+                });
+
+
+
+            }
+        },'json');
+    }
+
+    function download_excel(data,filename){
+        let  sheet = XLSX.utils.json_to_sheet(data)
+        sheet['!cols'] = [
+            //订单号
+            {
+                wch:60,
+            },
+        ];
+        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>
 <div style="display:none;">
 <input id="upload-file" name="files" accept="image/xls,image/xlsx" type="file">