Просмотр исходного кода

提交数据whlabel的type 优化方案

lvhao 1 день назад
Родитель
Сommit
b60b27293e
2 измененных файлов с 871 добавлено и 0 удалено
  1. 391 0
      core/CoreApp/controllers/Whlabel.php
  2. 480 0
      template/erp/whlabel_typev1.html

+ 391 - 0
core/CoreApp/controllers/Whlabel.php

@@ -58,6 +58,9 @@ class Whlabel extends Start_Controller
 		} else if ($arg == 'type') //进销存浏览
 		{
 			$this->_type();
+		}else if ($arg == 'typev1') //进销存浏览
+		{
+			$this->_typev1();
 		} else if ($arg == 'typedy') //进销存浏览店员页面
 		{
 			$this->_typedy($arg_array);
@@ -1563,6 +1566,394 @@ class Whlabel extends Start_Controller
 		$this->_Template('whlabel_type', $this->data);
 	}
 
+	/**
+	 * _type 优化版 v1
+	 * 优化点:
+	 *   1. 循环内 N+1 查询改为批量预取(方案 A),SQL 从 2+2P 降到固定 4 条
+	 *   2. 总数统计改为只 COUNT 不传输明细字段(方案 C)
+	 *   3. 批量 qbdata 查询去掉 features like 条件,走组合键 IN 精确匹配
+	 *   4. 批量 transport 查询加 ORDER BY stime 保证顺序与原来一致
+	 */
+	public function _typev1()
+	{
+		$vip = 0;
+		if (isset($_SESSION['api'])) {
+			$user = $this->user->get_api($_SESSION['api']);
+			$fgshop = "";
+			$sid = "";
+			$usersp = explode('|', trim($user['shop'], '|'));
+			foreach ($usersp as $value) {
+				$fgshop .= " shop = " . $value . " or";
+				$sid .= " id = " . $value . " or";
+			}
+			if ($user['vip'] == 1) {
+				$vip = 1;
+			}
+		} else {
+			header('Location: /');
+			exit;
+		}
+		$prc = array();
+		$purchase = $this->purchase->find_all();
+		foreach ($purchase as $k => $v) {
+			$prc[$v['id']] = $v['title'];
+		}
+		$company = array();
+		$ct = $this->company->find_all();
+		foreach ($ct as $k => $v) {
+			$company[$v['id']] = $v['title'];
+		}
+		$sp = array();
+		$s = $this->shop->find_all('1=1', 'id,shopname');
+		foreach ($s as $v) {
+			$sp[$v['id']] = $v['shopname'];
+		}
+		$wh = array();
+		$w = $this->warehouse->find_all('1=1', 'id,title');
+		foreach ($w as $v) {
+			$wh[$v['id']] = $v['title'];
+		}
+		$post = $this->input->post(NULL, TRUE);
+		if (isset($post['page'])) {
+			$page = $this->input->post('page', true);
+			$perpage = $this->input->post('perpage', true);
+			$category = $this->input->post('category', true);
+			$size = $this->input->post('size', true);
+			$grade = $this->input->post('grade', true);
+			$color = $this->input->post('color', true);
+			$lowe = $this->input->post('lowe', true);
+			$sku = $this->input->post('sku');
+			$title = $this->input->post('title');
+			$warehouse = $this->input->post('warehouse', true);
+			$usa = $this->input->post('usa', true);
+			$purchase = $this->input->post('purchase', true);
+			$lacetype = $this->input->post('lacetype', true);
+			$haircap = $this->input->post('haircap', true);
+			$density = $this->input->post('density', true);
+			$details = $this->input->post('details', true);
+			$state = $this->input->post('state', true);
+			$shop = $this->input->post('shop', true);
+			$lacecolor = $this->input->post('lacecolor', true);
+			$hairnumber = $this->input->post('hairnumber', true);
+			$type = $this->input->post('type', true);
+			$ktime = $this->input->post('ktime', true);
+			$jtime = $this->input->post('jtime', true);
+			$ktime = strtotime($ktime);
+			$jtime = strtotime($jtime);
+			$cpbz = $this->input->post('cpbz', true);
+			$sm = $this->input->post('sm', true);
+			$where = "1=1";
+			// $where_no_features 用于批量预取,去掉 features like 条件,靠组合键精确匹配
+			$where_no_features = "1=1";
+
+			if ($usa) {
+				if (!$warehouse) {
+					$where  .= " and (warehouse = '5' or warehouse = '8')";
+					$where_no_features .= " and (warehouse = '5' or warehouse = '8')";
+				}
+			}
+			if ($warehouse) {
+				$where  .= " and warehouse = '$warehouse'";
+				$where_no_features .= " and warehouse = '$warehouse'";
+			}
+			if ($details) {
+				$where  .= " and details = '$details'";
+				$where_no_features .= " and details = '$details'";
+			}
+			if ($purchase) {
+				$where  .= " and purchase = '$purchase'";
+				$where_no_features .= " and purchase = '$purchase'";
+			}
+			if ($state) {
+				$where  .= " and state = '$state'";
+				$where_no_features .= " and state = '$state'";
+			}
+			if ($shop) {
+				$where  .= " and shop like '%$shop%'";
+				$where_no_features .= " and shop like '%$shop%'";
+			}
+			if ($type) {
+				$where  .= " and type = '$type'";
+				$where_no_features .= " and type = '$type'";
+			}
+			if ($cpbz) {
+				$where .= " and cpbz like '%$cpbz%' ";
+				$where_no_features .= " and cpbz like '%$cpbz%' ";
+			}
+			if ($sm) {
+				$where .= " and sm like '%$sm%' ";
+				$where_no_features .= " and sm like '%$sm%' ";
+			}
+
+			// features like 条件只加入 $where(列表分组用),不加入 $where_no_features
+			if ($lacecolor) {
+				$where  .= " and features like '%-$lacecolor-%'";
+			}
+			if ($lacetype) {
+				$where  .= " and features like '%-$lacetype-%'";
+			}
+			if ($category) {
+				$where  .= " and features like '%-$category-%'";
+			}
+			if ($size) {
+				$where  .= " and features like '%-$size-%'";
+			}
+			if ($grade) {
+				$where  .= " and features like '%-$grade-%'";
+			}
+			if ($color) {
+				$where  .= " and features like '%-$color-%'";
+			}
+			if ($lowe) {
+				$where  .= " and features like '%-$lowe-%'";
+			}
+			if ($haircap) {
+				$where  .= " and features like '%-$haircap-%'";
+			}
+			if ($density) {
+				$where  .= " and features like '%-$density-%'";
+			}
+			if (!empty($hairnumber)) {
+				$where  .= " and  features like '%-128-%' ";
+				if ($hairnumber < 0) {
+					$class_list = $this->typeclass->find_all('classid = 43');
+					foreach ($class_list as $v) {
+						$where .= " and  features not like '%-" . $v['id'] . "-%'";
+					}
+				} else {
+					$where  .= " and features like '%-$hairnumber-%'";
+				}
+			}
+
+			//数据排序
+			$order_str = "id desc";
+			if (empty($page)) {
+				$start = 0;
+				$perpage = 1;
+			} else {
+				$start = ($page - 1) * $perpage;
+			}
+			$fjnr = '';
+			if ($sku) {
+				$sku = trim($sku, ' ');
+				$sku = trim($sku, '	');
+				$fjnr  .= " and sku like '%$sku%'";
+			}
+			if ($title) {
+				$title = trim($title, ' ');
+				$title = trim($title, '	');
+				$fjnr  .= " and title like '%$title%'";
+			}
+			$wt = array();
+			$whlabel_type = $this->whlabel_type->find_all();
+			foreach ($whlabel_type as $v) {
+				$wt[$v['id']] = $v['title'];
+			}
+
+			// 列表分组(与原来完全一致)
+			$info_list = $this->whlabel->find_pc($where . $fjnr, 'sku,purchase,features,warehouse', 'id,warehouse,purchase,sku,title,details,shop,cpbz,label,type,features,number,sm', $order_str, $start, $perpage);
+
+			//取得信息列表
+			$info_list = $this->logic_whlabel->dataTran($info_list, ['pm']);
+
+			// ========== 优化方案 A:批量预取 whlabel 组数据和 transport 数据 ==========
+			$keys = array();
+			foreach ($info_list as $v) {
+				$keys[] = "('" . addslashes($v['sku']) . "','" . addslashes($v['purchase'])
+					. "','" . addslashes($v['features']) . "','" . addslashes($v['warehouse']) . "')";
+			}
+
+			// 组合键函数,用于 PHP 端按分组索引
+			$comboKey = function ($r) {
+				return $r['sku'] . '|' . $r['purchase'] . '|' . $r['features'] . '|' . $r['warehouse'];
+			};
+
+			// 批量拉取 whlabel 组数据(使用 $where_no_features,不带 features like,靠 IN 元组精确匹配)
+			$all_qb = array();
+			if (!empty($keys)) {
+				$keyInSql = implode(',', $keys);
+				$qbAll = $this->whlabel->find_all(
+					$where_no_features . " and (sku,purchase,features,warehouse) IN (" . $keyInSql . ")"
+				);
+				foreach ($qbAll as $r) {
+					$all_qb[$comboKey($r)][] = $r;
+				}
+			}
+
+		// 批量拉取 transport 在途数据(3 列元组: sku,warehouse,features,与 IN 左侧列顺序一致)
+		$all_zt = array();
+		if (!empty($info_list)) {
+			$ztKeys = array();
+			foreach ($info_list as $v) {
+				$ztKeys[] = "('" . addslashes($v['sku']) . "','"
+					. addslashes($v['warehouse']) . "','"
+					. addslashes($v['features']) . "')";
+			}
+			$ztInSql = implode(',', $ztKeys);
+			$ztAll = $this->whlabeltransport->find_all(
+				"cz = '0' and (sku,warehouse,features) IN (" . $ztInSql . ")",
+				'*',
+				'stime'
+			);
+			foreach ($ztAll as $r) {
+				$ck = $r['sku'] . '|' . $r['warehouse'] . '|' . $r['features'];
+				$all_zt[$ck][] = $r;
+			}
+		}
+
+			$rows = array();
+			$list = array();
+			foreach ($info_list as $key => $value) {
+				if (isset($wt[$value['type']])) {
+					$info_list[$key]['type'] = $wt[$value['type']];
+				} else {
+					$info_list[$key]['type'] = '未设置';
+				}
+				$info_list[$key]['purchase'] = (isset($prc[$value['purchase']])) ? $prc[$value['purchase']] : '未知';
+
+				// transport 在途数据:从预取数组中取
+				$ztCk = $value['sku'] . '|' . $value['warehouse'] . '|' . $value['features'];
+				$zt = isset($all_zt[$ztCk]) ? $all_zt[$ztCk] : array();
+				$ztdata = '';
+				if (count($zt) > 0) {
+					foreach ($zt as $vv) {
+						$ztdata .= '<p>' . $vv['num'] . ' - ' . date('Y-m-d', $vv['stime']) . '</p>';
+					}
+				}
+
+				// whlabel 组数据:从预取数组中取
+				$qbCk = $comboKey($value);
+				$qbdata = isset($all_qb[$qbCk]) ? $all_qb[$qbCk] : array();
+
+				$cdata = array_filter($qbdata, function ($item) {
+					return $item['state'] < 1;
+				});
+				$c = array_sum(array_column($cdata, 'jnum'));
+
+				$gdata = array_filter($qbdata, function ($item) use ($ktime, $jtime) {
+					return $item['state'] < 100 && $item['enter'] > $ktime && $item['enter'] < $jtime;
+				});
+				$g = array_sum(array_column($gdata, 'jnum'));
+
+				$xdata = array_filter($qbdata, function ($item) use ($ktime, $jtime) {
+					return $item['state'] == 1 && $item['outk'] > $ktime && $item['outk'] < $jtime;
+				});
+				$x = array_sum(array_column($xdata, 'jnum'));
+
+				$tdata = array_filter($qbdata, function ($item) use ($ktime, $jtime) {
+					return $item['retreat'] > 0 && $item['outk'] > $ktime && $item['outk'] < $jtime;
+				});
+				$t = array_sum(array_column($tdata, 'jnum'));
+
+				$zdata = array_filter($qbdata, function ($item) {
+					return $item['zd'] != "" && $item['state'] < 1;
+				});
+				$z = array_sum(array_column($zdata, 'jnum'));
+
+				$detailsArr = array();
+				$cpid = array();
+				$od = array();
+				$odid = '';
+				$companytitle = '';
+				$shop_list = [];
+
+				foreach ($qbdata as $v) {
+					if ($v['zd'] != "" && $v['state'] < 1) {
+						if (!isset($od[$v['zd']])) {
+							$od[$v['zd']] = 1;
+						} else {
+							$od[$v['zd']] = $od[$v['zd']] + 1;
+						}
+					}
+					if ($v['state'] == 0) {
+						$detailsArr[$v['details']] = $v['details'];
+					}
+					if ($v['state'] < 1) {
+						if ($v['cpid'] != 0) {
+							$cpid[$v['cpid']] = $v['cpid'];
+						}
+					}
+					if ($v['state'] == 0) {
+						if ($v['companytitle'] != '' && stripos($companytitle, $company[$v['companytitle']]) === false) {
+							$companytitle .= '<p>' . $company[$v['companytitle']] . '</p>';
+						}
+						if ($v['shop'] != '') {
+							$shopArr = explode(',', trim($v['shop'], ','));
+							foreach ($shopArr as $vv) {
+								if (!in_array($vv, $shop_list)) {
+									$shop_list[] = $vv;
+								}
+							}
+						}
+					}
+				}
+				foreach ($od as $k => $vv) {
+					$odid .= $k . '数量' . $vv;
+				}
+				$info_list[$key]['cpbz'] = $value['cpbz'];
+				$info_list[$key]['label'] = $value['sm'];
+				$number = $value['number'];
+				$z = $z . '(' . $odid . ')';
+				$info_list[$key]['warehouse'] = isset($wh[$value['warehouse']]) ? $wh[$value['warehouse']] : '无';
+				$info_list[$key]['features'] = $c;
+				$info_list[$key]['number'] = $ztdata;
+				$info_list[$key]['sm'] = $g;
+				$info_list[$key]['x'] = $x;
+				$info_list[$key]['t'] = $t;
+				$info_list[$key]['z'] = $z;
+				$info_list[$key]['shop'] = '';
+				$info_list[$key]['details'] = ($cpid) ? implode(" ", $detailsArr) . '<p>' . implode(" ", $cpid) . '</p>' : implode(" ", $detailsArr);
+
+				$shop_list = array_unique($shop_list);
+				$shop_str = '';
+				foreach ($shop_list as $v) {
+					if (isset($sp[$v])) {
+						$shop_str .= '<p>' . $sp[$v] . '</p>';
+					}
+				}
+				$info_list[$key]['shop'] = $shop_str . $companytitle;
+			}
+
+			$final_all_list = [];
+			foreach ($info_list as $k => $v) {
+				$final_all_list[] = [
+					'id' => $v['id'],
+					"warehouse" => $v["warehouse"],
+					"purchase" => $v["purchase"],
+					"sku" => $v["sku"],
+					"title" => $v["title"] . "<br/>" . $v["pm"],
+					"details" => $v["details"],
+					"shop" => $v["shop"],
+					"cpbz" => $v["cpbz"],
+					'label' => $v['label'],
+					"type" => $v["type"],
+					"features" => $v["features"],
+					"number" => $v["number"],
+					"sm" => $v["sm"],
+					"x" => $v["x"],
+					"t" => $v["t"],
+					"z" => $v["z"]
+				];
+			}
+
+			// ========== 优化方案 C:总数统计只 COUNT,不传明细字段 ==========
+			// 原实现: count(find_pc(..., 'id,warehouse,sku,title,features,number')),传输了大量明细字段
+			// 优化为: SELECT COUNT(*) FROM (SELECT 1 FROM whlabel WHERE ... GROUP BY ...) t,只传一个数字
+		$countSql = "SELECT COUNT(*) AS cnt FROM (SELECT 1 FROM crowd_whlabel WHERE " . $where . $fjnr . " GROUP BY sku,purchase,features,warehouse) t";
+		$countResult = $this->whlabel->query($countSql)->result_array();
+			$total = isset($countResult[0]['cnt']) ? (int)$countResult[0]['cnt'] : 0;
+			$pagenum = ceil($total / $perpage);
+			$over = $total - ($start + $perpage);
+			$rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($final_all_list));
+			echo json_encode($rows);
+			exit;
+		}
+		$wlshop = $this->shop->find_all('1=1 and ' . rtrim($sid, 'or'));
+		$this->data['shop'] = $wlshop;
+		$this->data['vip'] = $vip;
+		$this->_Template('whlabel_typev1', $this->data);
+	}
+
 	//美仓进销存浏览
 	public function _usatype()
 	{

+ 480 - 0
template/erp/whlabel_typev1.html

@@ -0,0 +1,480 @@
+{Template header}
+<style>
+    .diysearch{
+        padding: 5px;
+    }
+    .diysearch select{
+        width: 110px;
+        height: 28px;
+        color: #333;
+        border: 1px #ccc solid;
+        font-size: 13px;
+        margin-right: 20px;
+        border-radius: 5px;
+    }
+    .diysearch input{
+        width: 100px;
+        height: 26px;
+        color: #000;
+        border: 1px #ccc solid;
+        font-size: 13px;
+        margin-right: 20px;
+        text-align: center;
+        color: #333;
+        border-radius: 5px;
+    }
+    .diysearch .qd_show{
+        width: 70px;
+        height: 30px;
+        line-height: 30px;
+        background: #2ca8a1;
+        text-align: center;
+        color: #fff;
+        border-radius: 5px;
+        display: inline-block;
+        margin-left: 20px;
+        cursor: pointer;
+        border: 0px solid #2ca8a1;
+    }
+    
+</style>
+<link href="{$theme}js/select2/select2.min.css?v={time()}" rel="stylesheet" />
+<script src="{$theme}js/select2/select2.full.min.js?v={time()}"></script>
+
+<body>
+<div class="warp">
+<div class="fixed">
+<div  style="width:100%;display: flex;flex-direction: row;flex-wrap: wrap;">
+    <div class="diysearch">
+        类目   :<select name="category" class="select">
+            <option value="">请选择</option>{loop typeclass(16) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>{/loop}</select>
+    </div>
+    <div class="diysearch">
+        等级  :<select name="grade" class="select">
+            <option value="">请选择</option>{loop typeclass(13) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>{/loop}</select>
+    </div>
+    <div class="diysearch" >
+        颜色  :<select name="color" class="select select_two"  style="width: 150px !important;">
+            <option value="">请选择</option>{loop typeclassyc(8) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>{/loop}</select>
+    </div>
+    <div  class="diysearch" >
+        曲度  :<select name="lowe" class="select select_two"  style="width: 150px !important;" >
+            <option value="">请选择</option>{loop typeclassyc(15) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>{/loop}</select>
+    </div>
+    <div  class="diysearch">
+        头套种类  :<select name="lacetype" class="select select_two"  style="width: 220px !important;">
+            <option value="">请选择</option><option value="146">13*4 Lace Front wigs</option>
+            {loop typeclassyc(18) as $val}
+            {if $val['id']!=146}
+            <option value="{$val['id']}">{$val['title']}</option>
+            {/if}
+            {/loop}
+            </select>
+    </div>
+    <div  class="diysearch">
+        蕾丝颜色  :<select name="lacecolor" class="select">
+            <option value="">请选择</option>{loop typeclassyc(9) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>{/loop}</select>
+    </div>
+    <div  class="diysearch">
+        长度  :<select name="size" class="select">
+            <option value="">请选择</option>{loop typeclass(14) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>{/loop}</select>
+    </div>
+    <div  class="diysearch">
+        密度  :<select name="density" class="select">
+            <option value="">请选择</option>{loop typeclassyc(10) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>{/loop}</select>
+    </div>
+    <div  class="diysearch">
+        头套大小  :<select name="haircap" class="select">
+            <option value="">请选择</option>{loop typeclassyc(6) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>{/loop}</select>
+    </div>
+    <div  class="diysearch">
+        人发头套编号  :<select name="hairnumber" class="select select_two"  style="width: 150px !important;">
+            <option value="">请选择</option>
+            <option value="-1">无编号</option>
+            {loop typeclassyc(43) as $val}
+            
+            <option value="{$val['id']}">{$val['title']}</option>
+            {/loop}
+            </select>
+    </div>
+   
+    <div  class="diysearch">
+        仓库  :<select name="warehouse" class="select">
+            <option value="">请选择</option>{loop warehouse(10) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>{/loop}</select>
+    </div>
+    <div  class="diysearch">
+        仓库位置  :<input value="" name="details" type="text" >
+    </div>
+    <div  class="diysearch">
+        店铺  :<select name="shop" class="select">
+            <option value="">请选择</option>{loop $shop as $val}
+            <option value=",{$val['id']},">{$val['shopname']}</option>{/loop}</select>
+    </div>
+    <div  class="diysearch">
+        供应商  :<select name="purchase" class="select">
+            <option value="">全部</option>
+            {loop purchase(100) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>
+            {/loop}
+            </select>
+    </div>
+    <div  class="diysearch">
+        类型  :<select name="type" class="select">
+            <option value="">全部</option>
+            {loop whlabel_type(100) as $val}
+            <option value="{$val['id']}">{$val['title']}</option>
+            {/loop}
+            </select>
+    </div>
+    <div  class="diysearch">
+        SKU  :<input value="" name="sku" type="text" style="width:270px">
+    </div>
+    <div  class="diysearch">
+        商品名称  :<input value="" name="title" type="text" style="width:400px">
+    </div>
+    <div  class="diysearch">
+        产品备注  :<input value="" name="cpbz" type="text" >
+    </div>
+    <div  class="diysearch">
+        库位负责人  :<input value="" name="sm" type="text" >
+    </div>
+   
+    <div  class="diysearch">
+        状态  :<select name="state" class="select">
+            <option value="">请选择</option>
+            <option value="1">正常出库</option>
+            <option value="10">美店零售</option>
+            </select>
+    </div>
+    <div style="width:auto;;display: flex;flex-direction: row;flex-wrap: wrap;">
+        <div  class="diysearch">
+            入库类型  :<select name="rktype" class="select">
+                <option value="">请选择</option>
+                <option value="1">采购入库</option>
+                <option value="2">盘盈调整</option>
+                <option value="3">其他调整入库</option>
+                <option value="4">其他调整入库</option>
+                <option value="5">退库入库</option>
+                <option value="6">退货可用入库</option>
+                <option value="7">形态转换入库</option>
+                <option value="9">许昌仓备货入库</option>
+                </select>
+        </div>
+        <div  class="diysearch">
+            出库类型  :<select name="cktype" class="select">
+                <option value="">请选择</option>
+                <option value="1">销售出库</option>
+                <option value="2">美国销售调货出库</option>
+                <option value="3">盘亏调整</option>
+                <option value="4">其他调整出库</option>
+                <option value="5">形态转换出库</option>
+                </select>
+        </div>
+       
+    </div>
+    
+    <div  class="diysearch">
+        统计时间:<input id="timetk"  value="{date('Y-m-d',time()-29*24*3600)} 0:00" name="ktime" type="text" onClick="laydate({istime: true,format:'YYYY-MM-DD hh:mm'})">
+        至&nbsp;&nbsp;&nbsp;&nbsp; <input id="timetj" value="{date('Y-m-d',time()+24*3600)} 0:00" name="jtime" type="text" onClick="laydate({istime: true,format:'YYYY-MM-DD hh:mm'})">
+    </div>
+    <div  class="diysearch">
+        <button onclick="searchspan(1)" class="qd_show">确 定</button>
+    </div>
+    
+
+</div>
+<div class="control">
+<select name="dccz" class="dcmb">
+<option value="">选择导出内容</option>
+<option data-url="excelr" value="1">导出入库数据</option>
+<option data-url="excelct" value="2">导出退库数据</option>
+<option data-url="excelct" value="1">导出出库数据</option>
+<option data-url="excelct" value="5">导出零售数据</option>
+<option data-url="excelct" value="4">导出出库+零售数据</option>
+<option data-url="excelcr" value="4">导出出库+入库合数据</option>
+</select>
+<a href="javascript:void(0);" data-url="exceljxc" data-id="1" class="whlabelexcel">导出进销存</a>
+<a href="javascript:void(0);" data-url="excelct" data-id="3" class="whlabelexcel">导出条件检索</a>
+<a href="javascript:void(0);" class="summary">出库汇总</a>
+
+<a href="javascript:void(0);" data-url="presetout" data-id="3" class="whlabelexcel">导出库存模板</a>
+<a href="javascript:void(0);" class="whlabeldr_two">导入库存</a>
+{if $vip > 0} {/if}
+<a href="javascript:void(0);" class="whlabelxq">导出数据详情</a>
+<a href="javascript:void(0);" class="whlabelexcelzh">导出库存数据及在途中</a>
+<!--<a href="javascript:void(0);" class="window" data-h="/whlabel/abnormal/" data-t="异常占单" style="background-color:#fc5454;color:#fff">查看异常占单</a>-->
+{if $vip > 0}
+<a href="/whlabel/error/" style="background-color:#fc5454;color:#fff">0库存SKU</a>
+{/if}
+<a href="javascript:void(0);" class="plszbhtype">批量设置备货类型</a>
+<a href="javascript:void(0);" class="dccrtype">导出出入库分类数据</a>
+</div>
+<table class="datatitle data" border="0" style="border-collapse:collapse;">
+<tr>
+<td><label onClick="swapCheck()"><input name="checkbox" type="checkbox" class="regular-checkbox"></label></td>
+<td>仓库</td>
+<td>供应商</td>
+<td>SKU</td>
+<td>商品名称</td>
+<td>位置</td>
+<td>品牌 / 公司</td>
+<td>备注</td>
+<td>库位负责人</td>
+<td>类型</td>
+<td>库存</td>
+<td>在途</td>
+<td>购进</td>
+<td>销售</td>
+<td>退货</td>
+<td>占单数量</td>
+</tr>
+</table>
+</div>
+<table class="datatext data" border="0" style="border-collapse:collapse;">
+</table>
+<div class="bomf"></div>
+</div>
+<div class="systemwindow">
+<div>
+<p><select name="whlabeltype" class="select" style="width:200px;margin-left:15px;">{loop whlabel_type(99) as $val}<option value="{$val['id']}" data-content="{$val['content']}">{$val['title']}</option>{/loop}</select></p>
+<p>{loop whlabel_type(1) as $val}{$val['content']}{/loop}</p>
+<p><font class="button">确 定</font><font class="esc">取 消</font></p>
+</div>
+</div>
+<script>
+let ppkc = false
+let kcpd = false
+var dataurl = "/whlabel/typev1";var fdataurl = "/whlabel/";var excel = "/whlabel/";
+$(function () { $("#ktime").calendar();$("#jtime").calendar();});
+var customon = 1;
+var editurl = "/whlabel/kj/";
+var editdj = 3;
+var editt = "扣减库存 - 操作";
+function custom(){
+$(".data tr").each(function() {
+$(this).find('td:eq(1)').css("width","3%");
+$(this).find('td:eq(2)').css("width","3%");
+$(this).find('td:eq(3)').css("width","12%");
+$(this).find('td:eq(4)').css("width","22%");
+$(this).find('td:eq(5)').css("width","4%");
+$(this).find('td:eq(6)').css("width","5%");
+$(this).find('td:eq(7)').css("width","4%");
+$(this).find('td:eq(8)').css("width","4%");
+$(this).find('td:eq(8)').css("width","4%");
+$(this).find('td:eq(9)').css("width","3%");
+$(this).find('td:eq(10)').css("width","4%");
+$(this).find('td:eq(11)').css("width","8%");
+$(this).find('td:eq(12)').css("width","3%");
+$(this).find('td:eq(13)').css("width","3%");
+$(this).find('td:eq(14)').css("width","3%");
+$(this).find('td:eq(15)').css("width","12%");
+});}
+$("select[name=dccz]").change(function(){
+	if($(this).find("option:selected").val() == "")
+	{
+		 $(".ts p").html("请选择导出模板");
+                $(".ts").fadeIn();
+                setTimeout('$(".ts").fadeOut()', 800);
+				return false;
+	}
+    var f = "";
+    $(".select").each(function() {
+        f = f + $(this).attr("name") + "=" + $(this).children("option:selected").val() + "&";
+    });
+    $("input:text").each(function() {
+        f = f + $(this).attr("name") + "=" + encodeURIComponent($(this).val()) + "&";
+    });
+	$("input:hidden").each(function() {
+        f = f + $(this).attr("name") + "=" + $(this).val() + "&";
+    });
+	window.location.href = "/whlabel/"+$("select[name=dccz]").find("option:selected").data("url")+"?excel="+$("select[name=dccz]").find("option:selected").val()+"&"+f;
+	$("select[name=dccz] option:eq(0)").prop('selected','selected'); 
+});
+$(".whlabelxq").click(function() {
+window.location.href = "/whlabel/uck?excel=1";
+});
+$(".whlabelexcelzh").click(function() {
+window.location.href = "/whlabel/whlabelexcelzh?excel=1";
+});
+$(".plszbhtype").click(function() {
+            $(".systemwindow").show();
+});
+$(".systemwindow .esc").click(function() {
+	$(".systemwindow").hide();
+	});
+$(".systemwindow .button").click(function() {
+var n = $(".systemwindow select").find("option:selected").val();
+var a = "";
+    $(".datatext input[name='check']:checked").each(function() {
+        a = a + $(this).val()+",";
+    });
+$(".systemwindow").hide();
+	layx.load('loadId','操作中,请稍后',{shadable:0.6});
+     $.ajax({
+        url: "/whlabel/gbhtype",
+        data: "s="+a+"&n="+n,
+        type: "POST",
+        dataType: "json",
+        success: function(a) {
+			layx.destroy('loadId');
+            if (a && a.success) {
+			layx.alert('正确',a.msg,function(id,button){
+			$.each(a.d,function(f,b){ $("#"+b).find("td:eq(8)").text(a.t)});
+},{dialogIcon:'success'});
+            }
+			else
+			{
+				 layx.alert('错误',a.msg,function(id,button){
+},{dialogIcon:'error'});
+			}
+        }
+    });
+	});
+
+
+$("select[name=whlabeltype]").change(function(){
+	$(".systemwindow p:eq(1)").html($(this).children("option:selected").data("content"));
+});
+
+$(".dccrtype").click(function() {
+    var f = "";
+	var a = "";
+    $(".datatext input[name='check']:checked").each(function() {
+        a = a + $(this).val()+",";
+    });
+	f = f + "sid=" + a + "&";
+    $(".select").each(function() {
+        f = f + $(this).attr("name") + "=" + $(this).children("option:selected").val() + "&";
+    });
+    $("input:text").each(function() {
+		
+		var str = $(this).val().replace(/\#/g,"%23");
+        f = f + $(this).attr("name") + "=" + str + "&";
+    });
+	$("input:hidden").each(function() {
+        f = f + $(this).attr("name") + "=" + $(this).val() + "&";
+    });
+	window.location.href = excel+"dccrtype?"+f;
+});
+</script>
+<script>
+    $(document).ready(function(){
+        $('.select_two').select2({
+                placeholder: "请选择",
+                allowClear: true,
+                //tags: true // 允许输入新值
+            });
+       searchspan(1);
+    })
+    
+</script>
+
+
+<script>
+
+$(".whlabeldr_two").click(function() {
+    var dr = $(this);
+    $("#upload-file").click();
+    $("#upload-file").unbind("change");
+    $("#upload-file").bind("change",function(){
+    whlabeldr_two(dr);
+        layx.load('loadId','导入中,请稍后',{shadable:0.6});
+    });
+});
+
+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(); // 去掉第一行表头
+           
+            // 构建要上传的数据(可以包含文件名、sheet名等)
+            // var uploadData = {
+            //     fileName: file.name,
+            //     sheetName: sheetName,
+            //     data: jsonData   // 解析后的 JSON 数组
+            // };
+            // 通过 AJAX 上传 JSON 数据
+            document.getElementById("upload-file").files[0] = '';
+            $.ajax({
+                url: excel + "presetedittwo/",  // 注意:后端接口可能需要改为接收 JSON
+                type: "POST",
+                contentType: "application/json", // 发送 JSON 格式
+                data:JSON.stringify({
+                    list:jsonData
+                }),
+                dataType: "json",
+                success: function(a) {
+                    layx.destroy('loadId');
+                    if (a && a.success) {
+                        if (a.error == 1){
+                            errora(a);
+                        } 
+                        else {
+                           layx.alert('提示', a.msg, function(id, button) {
+                                console.log(a.ed)
+                                downloadexcel(a.ed,a.error)
+			                }, { dialogIcon: 'error' });
+                        }
+                    } else {
+                        errorc(a);
+                    }
+                },
+                error: function(xhr, status, error) {
+                    layx.destroy('loadId');
+                    console.error("上传失败:", error);
+                    errorc({ success: false, message: "上传失败" });
+                }
+            });
+        } catch (err) {
+            layx.destroy('loadId');
+            console.error("解析 Excel 失败:", err);
+            errorc({ success: false, message: "解析 Excel 文件失败" });
+        }
+    };
+    reader.onerror = function() {
+        layx.destroy('loadId');
+        errorc({ success: false, message: "文件读取失败" });
+    };
+    reader.readAsArrayBuffer(file); // 以 ArrayBuffer 读取
+}
+function downloadexcel(data,filename){
+    let  sheet = XLSX.utils.json_to_sheet(data)
+
+
+
+    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/xlxs.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">
+</div>
+{Template footer}