Bladeren bron

提交测试数据

lvhao 1 week geleden
bovenliggende
commit
b4007d17c7
2 gewijzigde bestanden met toevoegingen van 310 en 0 verwijderingen
  1. 235 0
      core/CoreApp/controllers/Boss.php
  2. 75 0
      template/erp/boss_qtcs.html

+ 235 - 0
core/CoreApp/controllers/Boss.php

@@ -1319,6 +1319,235 @@ class Boss extends Start_Controller
 
 
 	private function _spexceljs()
+	{
+		
+		$tc = array();
+		$typeclass = $this->typeclass->find_all();
+		foreach ($typeclass as $v) {
+			$tc[$v['id']] = $v;
+		}
+		if (isset($_SESSION['api'])) {
+			$user = $this->user->get_api($_SESSION['api']);
+			$usp = $user;
+			$fgshop = "";
+			$sid = "";
+			$excelshop = "";
+			$usersp = explode('|', trim($user['shop'], '|'));
+			foreach ($usersp as $value) {
+				$fgshop .= " shop = " . $value . " or";
+				$sid .= " id = " . $value . " or";
+			}
+			$userexcel = explode('|', trim($user['excelshop'], '|'));
+			foreach ($userexcel as $value) {
+				$excelshop .= " shop =  " . $value . " or";
+			}
+			if ($excelshop != "") {
+				$excelshop = "(" . rtrim($excelshop, 'or') . ")";
+			}
+		}else{
+			exit(json_encode(array('code' => 0, 'msg' => '登录信息异常')));
+		}
+		$tcall = $this->typeclass->find_all();
+		$typeclass = array();
+		foreach ($tcall as $v) {
+			$tcjm[$v['id']] = array($v['jm'], $v['classid']);
+			$typeclass[$v['id']] = array('zh' => $v['zh'], 'classid' => $v['classid'], 'bm' => $v['bm'], 'title' => $v['title'], 'jm' => $v['jm']);
+		}
+		$classid = $this->classid->sku();
+		if (isset($_GET['category'])) {
+			$timetk = $this->input->get('timetk', true);
+			$timetj = $this->input->get('timetj', true);
+			$color = $this->input->get('color', true);
+			$lowe = $this->input->get('lowe', true);
+			$size = $this->input->get('size', true);
+			$grade = $this->input->get('grade', true);
+			$lacetype = $this->input->get('lacetype', true);
+			$category = $this->input->get('category', true);
+			$shop = $this->input->get('shop', true);
+			$density = $this->input->get('density', true);
+			$warehouse = $this->input->get('warehouse', true);
+			$time = $this->input->get('time', true);
+			$timetk = strtotime($timetk);
+			$timetj = strtotime($timetj);
+			$where = "";
+			if ($warehouse) {
+				$where .= " type = " . $warehouse . " and  ";
+			}
+			if ($category) {
+				$where  .= "fpdata like '%-" . $category . "-%' and ";
+			}
+			if ($color) {
+				$where  .= "fpdata like '%-" . $color . "-%' and ";
+			}
+			if ($size) {
+				$where  .= "fpdata like '%-" . $size . "-%' and ";
+			}
+			if ($grade) {
+				$where  .= "fpdata like '%-" . $grade . "-%' and ";
+			}
+			if ($shop) {
+				$where  .= "shop = '$shop' and ";
+			} else {
+				$where  .= $excelshop . " and ";
+			}
+			if ($lowe) {
+				$where  .= "fpdata like '%-" . $lowe . "-%' and ";
+			}
+			if ($density) {
+				$where  .= "fpdata like '%-" . $density . "-%' and ";
+			}
+			if ($lacetype) {
+				$where  .= "fpdata like '%-" . $lacetype . "-%' and ";
+			}
+			$dataa = $this->fullorder->find_all($where . $time . " > '$timetk' and " . $time . " < '$timetj'", 'fpdata,number,whlabel,type', 'id desc');
+			$datab = $this->fullordersmt->find_all($where . $time . " > '$timetk' and " . $time . " < '$timetj' and shop != '9'", 'fpdata,number,whlabel,type', 'id desc');
+			$datac = $this->fullordertt->find_all($where . $time . " > '$timetk' and " . $time . " < '$timetj'", 'fpdata,number,whlabel,type', 'id desc');
+			$data = array_merge($dataa, $datab, $datac);
+			$sp = array();
+			$warehouses = $this->warehouse->find_all('1=1', 'id,title');
+			$warehouses = array_column($warehouses, 'title', 'id');
+			foreach ($data as $val) {
+				$f = explode(';', trim($val['fpdata'], ';'));
+				$w = explode('|', trim($val['whlabel'], '|'));
+				foreach ($f as $k => $v) {
+					if ($category) {
+						if (stripos($v, '-' . $category . '-') === false) {
+							continue;
+						}
+					}
+					if ($color) {
+						if (stripos($v, '-' . $color . '-') === false) {
+							continue;
+						}
+					}
+					if ($lowe) {
+						if (stripos($v, '-' . $lowe . '-') === false) {
+							continue;
+						}
+					}
+					if ($size) {
+						if (stripos($v, $size . ',') === false) {
+							continue;
+						}
+					}
+					if ($grade) {
+						if (stripos($v, '-' . $grade . '-') === false) {
+							continue;
+						}
+					}
+					if ($lacetype) {
+						if (stripos($v, '-' . $lacetype . '-') === false) {
+							continue;
+						}
+					}
+					if ($density) {
+						if (stripos($v, '-' . $density . '-') === false) {
+							continue;
+						}
+					}
+					$title = explode('|', $v);
+					$fg = str_replace(array('-163-', '-164-', '-165-', '-166-', '-0-', '-126-', '-127-', '-128-', '-197-', '-195-'), '-', $title[0]);
+					$fg = explode(',', $fg);
+					$tmp_c = $this->getCate($title[0]);
+					if (isset($fg[1])) {
+						$fg = explode('-', trim($fg[1] . $fg[0], '-'));
+					} else {
+						$fg = [];
+					}
+					$pm = array();
+
+					foreach ($fg as $vv) {
+						if (isset($tc[$vv]['zh'])) {
+							$zh = explode('|', trim($tc[$vv]['zh'], '|'));
+							$pm[$tc[$vv]['classid']] = $zh[0];
+						}
+					}
+					$features = str_replace(array('-163-', '-164-', '-165-', '-166-'), '-', $v);
+					$tsk = explode('|', trim($features, '|'));
+					if (stripos($tsk[0], ',') !== false) {
+						$ftt = explode(',', $tsk[0]);
+						$features = explode('-', trim($ftt[1], '-'));
+						$features[] = $ftt[0];
+					} else {
+						$features = explode('-', trim($tsk[0], '-'));
+					}
+					$jm = $classid;
+					$jm = $classid;
+					foreach ($features as $vv) {
+						if ($vv != 0) {
+							if (!isset($typeclass[$vv])) {
+								continue;
+							}
+							if (isset($jm[$typeclass[$vv]['classid']])) {
+								if ($typeclass[$vv]['jm']) {
+									$jm[$typeclass[$vv]['classid']] = $typeclass[$vv]['jm'];
+								}
+							}
+						}
+					}
+					$jm = array_filter($jm); //去除空值
+					$jm = implode("-", $jm);
+					$zh = implode(" ", $pm);
+					$zh = str_replace('自然色 ', '', rtrim($zh, ' '));
+					$zh = str_replace(array('        ', '       ', '      ', '     ', '    ', '   ', '  '), ' ', $zh);
+					if (isset($title[1])) {
+						if (isset($sp[$title[1]])) {
+							$sp[$title[1]]['n'] += $title[2];
+							if (isset($sp[$title[1]]['warehouse'][$val['type']])) {
+								$sp[$title[1]]['warehouse'][$val['type']] += $title[2];
+							} else {
+								$sp[$title[1]]['warehouse'][$val['type']] = $title[2];
+							}
+							//美仓
+							if ($val['type'] == 5) {
+								$sp[$title[1]]['mc'] +=  $title[2];
+							} elseif ($val['type'] == 13) { //许昌仓
+								$sp[$title[1]]['xcc'] +=  $title[2];
+							} elseif ($val['type'] == 16) { //定制仓
+								$sp[$title[1]]['dzc'] +=  $title[2];
+							} else {
+								$sp[$title[1]]['qtc'] +=  $title[2];
+							}
+						} else {
+							$wh = explode('-', $w[$k]);
+							$wsku = $this->whlabel->find_all("number = '" . $wh[0] . "' and sku != 'Preset'");
+							$whs = (isset($wsku[0]['sku'])) ? $wsku[0]['sku'] : '';
+							$sp[$title[1]] = array('t' => $title[1], 'z' => $zh, 'c' => $tmp_c, 'w' => $whs, 'j' => $jm, 'n' => isset($title[2]) ? $title[2] : "异常 ", "warehouse" => [
+								$val['type'] => isset($title[2])? $title[2]:" 异常",
+							], "warehouse_show" => "", "xcc" => 0, "mc" => 0, "dzc" => 0, "qtc" => 0);
+							//美仓
+							if ($val['type'] == 5) {
+								$sp[$title[1]]['mc'] =  isset($title[2])? $title[2]:" 异常";
+							} elseif ($val['type'] == 13) { //许昌仓
+								$sp[$title[1]]['xcc'] = isset($title[2])? $title[2]:" 异常";
+							} elseif ($val['type'] == 16) { //定制仓
+								$sp[$title[1]]['dzc'] =  isset($title[2])? $title[2]:" 异常";
+							} else {
+								$sp[$title[1]]['qtc'] =  isset($title[2])? $title[2]:" 异常";
+							}
+						}
+					}
+				}
+			}
+			foreach ($sp as $k => $v) {
+				unset($sp[$k]['warehouse']);
+				unset($sp[$k]['warehouse_show']);
+			}
+			$sp = array_values($sp);
+			$title = "商品统计" . date('Y-m-d H-i-s', time());
+			echo json_encode(array('code' => 1,'msg'=>"获取成功", 'data' => $sp,'filename'=>$title));
+			die;
+		}else{
+			exit(json_encode(array('code' => 0, 'msg' => '参数异常')));
+		}
+
+
+	}
+
+
+
+
+	private function _spexceljsbak()
 	{
 		$tcjm = $tmp_typeclass =  $tc = [];
 		$typeclass = $this->typeclass->find_all();
@@ -1539,6 +1768,12 @@ class Boss extends Start_Controller
 		die;
 	}
 
+
+
+
+
+
+
 	public function getCate($str)
 	{
 		//就是为了匹配类型的导出的一个定义数组

+ 75 - 0
template/erp/boss_qtcs.html

@@ -222,7 +222,82 @@ var f = {}; var i = 0;
 });
  </script>
  <script>
+
     function bossspexcel(id_name){
+        var f = "";
+        $("."+id_name+" input:text").each(function() {
+            var str2 = escape($(this).val());
+            str2 = $(this).val().replace(/\</g,"&lt;");
+            str2 = str2.replace(/\>/g,"&gt;");
+            str2 = str2.replace(/\+/g,"%2B");
+            str2 = str2.replace(/&/g,"%26");
+        f = f + $(this).attr("name") + "=" + str2 + "&";
+        });
+        $("."+id_name+" .select").each(function() {
+            f = f + $(this).attr("name") + "=" + $(this).children("option:selected").val() + "&";
+        });
+        let url = "/boss/spexceljs?"+f;
+        $.get(url,function(res){
+            if(res.code==0){
+                layx.destroy('loadId');
+                layx.confirm('提示',res.msg,null,{
+                    buttons:[
+                        {
+                            label:'确定',
+                            callback:function(id, button, event){
+                            
+                                layx.destroy(id);
+                            }
+                        }
+                    ],dialogIcon:'error',shadable:0.6
+                });
+            }else{
+                const fileName = res.filename+'.xlsx' ;
+                // 将数据转换为工作表
+
+                let  list = [];
+                let  data = res.data;
+                for(let item in data){
+                    list.push({
+                        "名称":data[item].t,
+                        "中文":data[item].z,
+                        "类型":data[item].c,
+                        "SKU":data[item].w,
+                        "用友料号":data[item].j,
+                        "数量":data[item].n*1,
+                        "许昌仓发货量":data[item].xcc*1,
+                        "美仓发货量":data[item].mc*1,
+                        "定制仓发货量":data[item].dzc*1,
+                        "其他仓发货量":data[item].qtc*1,
+                    })
+                }
+                const worksheet = XLSX.utils.json_to_sheet(list);
+                // 创建工作簿
+                const workbook = XLSX.utils.book_new();
+            
+                worksheet['!cols'] = 
+                [
+                    { wch: 80 }, 
+                    { wch: 80 },  
+                    { wch: 20 },  
+                    { wch: 20 },  
+                    { wch: 20 },  
+                    { wch: 10 },  
+                    { wch: 10 },
+                    { wch: 10 },
+                    { wch: 10 },
+                    { wch: 10 },
+                ];
+                // 将工作表添加到工作簿
+                XLSX.utils.book_append_sheet(workbook, worksheet, res.filename);
+                
+                // 导出文件
+                XLSX.writeFile(workbook, fileName);
+                layx.destroy('loadId');
+            }
+        },'json')
+    }
+    function bossspexcelbak(id_name){
         let obj = {}
         let shop = $("select[name='shop']").val();
         if(shop){