lvhao 12 часов назад
Родитель
Сommit
2a3d6c4eb8
1 измененных файлов с 133 добавлено и 201 удалено
  1. 133 201
      core/CoreApp/controllers/Bosstwo.php

+ 133 - 201
core/CoreApp/controllers/Bosstwo.php

@@ -1055,214 +1055,146 @@ class Bosstwo extends Start_Controller
 			if ($lacetype) {
 			if ($lacetype) {
 				$where  .= "fpdata like '%-" . $lacetype . "-%' and ";
 				$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();
-			$cs = 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]);
-					//$fg = explode('-',trim($fg[1].$fg[0],'-'));
-					if (isset($fg[1])) {
-						$fg = explode('-', trim($fg[1] . $fg[0], '-'));
-					} else {
-						$fg = [];
-					}
-					$pm = array();
-					//$pm = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',35=>'','dc'=>'','c'=>'',12=>'',25=>'',26=>'',14=>'',27=>'',10=>'',6=>'',9=>'',39=>'',999=>'',9999=>'');//品名顺序
-					foreach ($fg as $vv) {
-						if (isset($tc[$vv]['zh'])) {
-							$zh = explode('|', trim($tc[$vv]['zh'], '|'));
-							$pm[$tc[$vv]['classid']] = $zh[0];
-						}
-					}
+			$final_all = [];
+			// 生成 SQL
+			$this->db->from('fullorder')
+			->where($where . $time . " > '$timetk' and " . $time . " < '$timetj'")
+			->select('fpdata,number,whlabel,type')
+			->order_by('id desc');
+			$sql = $this->db->get_compiled_select();
+			$this->db->reset_query();
+
+			// 检查连接
+			$mysqli = $this->db->conn_id;
+			if (!$mysqli instanceof mysqli) {
+				die('数据库连接不是 mysqli 对象');
+			}
+
+			// 执行非缓冲查询
+			$result = $mysqli->query($sql, MYSQLI_USE_RESULT);
+			if (!$result) {
+				// 查询失败,输出详细错误
+				echo 'MySQL 查询失败:<br>';
+				// echo '错误信息:' . $mysqli->error . '<br>';
+				// echo '执行的 SQL:' . $sql;
+				exit;
+			}
 
 
-					$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'];
-								}
-							}
+			$list = [];
+			$column_list = [
+				't'=>'','zh'=>'','cate'=>'','sku'=>'','features'=>'','jm'=>'','total'=>0,'xc'=>0,'mc'=>0,'dzc'=>0,'qt'=>0,
+			];
+			$params = [
+				'category'=>$category,
+				'color'=>$color,
+				'lowe'=>$lowe,
+				'size'=>$size,
+				'grade'=>$grade,
+				'lacetype'=>$lacetype,
+				'density'=>$density,
+			];
+			while ($row = $result->fetch_assoc()) {
+
+				$tmp_info = $this->dataTransfer($row,$params,$classid,$typeclass);
+				foreach($tmp_info as $k=>$v){
+
+					if(isset($list[$v['title']])){
+						$ck_type = '';
+						if($v['type'] == 13){
+							$ck_type = 'xc';
+						}elseif($v['type'] == 5){
+							$ck_type = 'mc';
+						}elseif($v['type'] == 16){
+							$ck_type = 'dzc';
+						}else{
+							$ck_type = 'qt';
 						}
 						}
-					}
-					$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]:" 异常";
-							}
+						
+						$list[$v['title']]['total'] += $v['num'];
+						$list[$v['title']][$ck_type] += $v['num'];
+					}else{
+						$tmp_sp = [
+							't'=>$v['title'],'zh'=>'','cate'=>'','sku'=>'','features'=>$v['features'],'jm'=>'','total'=>$v['num'],'xc'=>0,'mc'=>0,'dzc'=>0,'qt'=>0,
+						];
+						$ck_type = '';
+						if($v['type'] == 13){
+							$ck_type = 'xc';
+						}elseif($v['type'] == 5){
+							$ck_type = 'mc';
+						}elseif($v['type'] == 16){
+							$ck_type = 'dzc';
+						}else{
+							$ck_type = 'qt';
 						}
 						}
+						$tmp_sp[$ck_type] = $v['num'];
+
+						$list[$v['title']] =$tmp_sp;
+						
 					}
 					}
+				}
+			}
+			// 释放结果集
+			$result->free();
 
 
-					//由于原来的按照品名分组可能会有异常 这里将品名转化为skuid为分组依据
-					// $wh = explode('-',$w[$k]);
-					// if(isset($wh[0])){
-					// 	if(isset($sp[$wh[0]]))
-					// 	{
-					// 		$sp[$wh[0]]['n'] += $title[2];
-					// 		if(isset($sp[$wh[0]]['warehouse'][$val['type']])){
-					// 		    $sp[$wh[0]]['warehouse'][$val['type']] += $title[2];
-					// 		}else{
-					// 		    $sp[$wh[0]]['warehouse'][$val['type']] = $title[2];
-					// 		}
-					// 		//美仓
-					// 		if($val['type'] == 5){
-					// 			$sp[$wh[0]]['mc'] +=  $title[2];
-					// 		}elseif($val['type'] == 13){//许昌仓
-					// 			$sp[$wh[0]]['xcc'] +=  $title[2];
-					// 		}elseif($val['type'] == 16){//定制仓
-					// 			$sp[$wh[0]]['dzc'] +=  $title[2];
-					// 		}else{
-					// 			$sp[$wh[0]]['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[$wh[0]] = array('t'=>$title[1],'z'=>$zh,'c'=>$tmp_c,'w'=>$whs,'j'=>$jm,'n'=>$title[2],"warehouse"=>[
-					// 		        $val['type'] =>$title[2],
-					// 		    ],"warehouse_show"=>"","xcc"=>0,"mc"=>0,"dzc"=>0,"qtc"=>0);
-					// 		//美仓
-					// 		if($val['type'] == 5){
-					// 			$sp[$wh[0]]['mc'] =  $title[2];
-					// 		}elseif($val['type'] == 13){//许昌仓
-					// 			$sp[$wh[0]]['xcc'] =  $title[2];
-					// 		}elseif($val['type'] == 16){//定制仓
-					// 			$sp[$wh[0]]['dzc'] =  $title[2];
-					// 		}else{
-					// 			$sp[$wh[0]]['qtc'] =  $title[2];
-					// 		}
-					// 	}
-					// }
-
-
-				}
-			}
-			foreach ($sp as $k => $v) {
-				// foreach($sp[$k]['warehouse'] as $kk =>$vv){
-				//     $warehouse_name = isset($warehouses[$kk])?$warehouses[$kk]:"异常仓库-".$kk;
-				//     $sp[$k]['warehouse_show'] .=$warehouse_name.":".$vv."<br />";
-				// }
-				unset($sp[$k]['warehouse']);
-				unset($sp[$k]['warehouse_show']);
+
+			echo "<pre>";
+			print_r($list);
+
+			
+		}
+	}
+
+	//数据处理
+	private function dataTransfer($row,$params){
+		$list =[];
+		$f = explode(';', trim($row['fpdata'], ';'));
+		foreach ($f as $k => $v) {
+			if ($params['category']) {
+				if (stripos($v, '-' . $params['category'] . '-') === false) {
+					continue;
+				}
 			}
 			}
-			$sp = array_values($sp);
-			$title = "商品统计" . date('Y-m-d H-i-s', time());
-			$titlename = "<table border=1>
-            <tr>
-            <td>名称</td>
-			<td>中文</td>
-			<td>类型</td>
-			<td>SKU</td>
-			<td>用友料号</td>
-            <td>数量</td>
-			<td>许昌仓发货量</td>
-			<td>美仓发货量</td>
-			<td>定制仓发货量</td>
-			<td>其他仓发货量</td>
-            </tr>
-            </table>";
-			$filename = $title . ".xls";
-			$tail = "\n";
-			$this->excel->get_fz2($sp, $titlename, $filename, $tail);
+			if ($params['color']) {
+				if (stripos($v, '-' . $params['color'] . '-') === false) {
+					continue;
+				}
+			}
+			if ($params['lowe']) {
+				if (stripos($v, '-' . $params['lowe'] . '-') === false) {
+					continue;
+				}
+			}
+			if ($params['size']) {
+				if (stripos($v, $params['size'] . ',') === false) {
+					continue;
+				}
+			}
+			if ($params['grade']) {
+				if (stripos($v, '-' . $params['grade'] . '-') === false) {
+					continue;
+				}
+			}
+			if ($params['lacetype']) {
+				if (stripos($v, '-' . $params['lacetype'] . '-') === false) {
+					continue;
+				}
+			}
+			if ($params['density']) {
+				if (stripos($v, '-' . $params['density'] . '-') === false) {
+					continue;
+				}
+			}
+			$tmp_arr = explode('|', $v);
+			$fe = $this->logic_u9tools->getGoodFeatureAlone($tmp_arr[0]);
+			$list[] = [
+				'title'=>$tmp_arr[1],
+				'features'=>$fe,
+				'type'=>$row['type'],
+				'num'=>$tmp_arr[2]
+			];
 		}
 		}
+		return $list;
+	
 	}
 	}