$v){ foreach($v as $key => $val){ $pushData = array('show_x' => $k + 1, 'show_y' =>$key + 1, 'result' => $val['toning_result']); $showRoadLocation[] = $pushData; } } /**************************** 计算 showRoad end ***************************/ /**************************** 计算 bigRoad start ***************************/ //列 $yKey = 0; //行 $xKey = 0; $bigRoad = array(); foreach($ns AS $key => $value){ $bigRoad[$yKey][$xKey] = array('result' => $value['toning_result']); if(isset($ns[$key+1]) && $ns[$key+1]['toning_result'] != $bigRoad[$yKey][$xKey]['result']){ $yKey++; $xKey = 0; }else{ $xKey++; } } //重新计算坐标 $bigRoadLocation = array(); $occupy = array(); foreach($bigRoad AS $key => $value){ $swerve = false; $swerveY = $key; foreach($value AS $k => $v){ $show_y = $key; $show_x = $k; if($show_x > 5 && $swerve === false){ $swerveY = $swerveY + 1; $show_y = $swerveY; $show_x = 5; $occupy[] = $show_y . '-' . $show_x; }elseif(in_array($show_y.'-'.$show_x,$occupy)){ if($swerve === false){ $swerve = $show_x - 1; } $swerveY = $swerveY + 1; $show_y = $swerveY; $show_x = $swerve; $occupy[] = $show_y . '-' . $show_x; }elseif($swerve !== false){ $swerveY = $swerveY + 1; $show_y = $swerveY; $show_x = $swerve; $occupy[] = $show_y . '-' . $show_x; } $pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']); $bigRoadLocation[] = $pushArray; } } /**************************** 计算 bigRoad end ***************************/ /**************************** 计算 bigRoadBS start ***************************/ //列 $yKey = 0; //行 $xKey = 0; $last = array(); $bigRoadBS = array(); foreach($ns AS $key => $value) { if ($value['toning_result'] < 2) { $value['result'] = 2; } elseif ($value['toning_result'] > 2) { $value['result'] = 1; } else { $value['result'] = 3; } $ns[$key] = $value; } foreach($ns AS $key => $value){ if($key == 0 && $value['result'] == 3){ $bigRoadBS[$yKey][$xKey] = array('result' => 3, 'tie_num' => 1); $last = array('yKey' => $yKey, 'xKey' => $xKey); }elseif($yKey == 0 && $xKey == 0 && !empty($last) && $value['result'] != 3){ $bigRoadBS[$last['yKey']][$last['xKey']]['result'] = $value['result']; if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoadBS[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3){ $yKey++; $xKey = 0; }elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoadBS[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3){ $xKey++; } $last = array('yKey' => $yKey, 'xKey' => $xKey); }elseif($key > 0 && $value['result'] == 3){ $bigRoadBS[$last['yKey']][$last['xKey']]['tie_num'] = $bigRoadBS[$last['yKey']][$last['xKey']]['tie_num'] + 1; if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoadBS[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3 && $bigRoadBS[$last['yKey']][$last['xKey']]['result'] != 3){ $yKey++; $xKey = 0; }elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoadBS[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3 && $bigRoadBS[$last['yKey']][$last['xKey']]['result'] != 3){ $xKey++; } $last = array('yKey' => $last['yKey'], 'xKey' => $last['xKey']); }else{ $bigRoadBS[$yKey][$xKey] = array('result' => $value['result'], 'tie_num' => 0); if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoadBS[$yKey][$xKey]['result'] && $ns[$key+1]['result'] != 3){ $yKey++; $xKey = 0; }elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoadBS[$yKey][$xKey]['result'] && $ns[$key+1]['result'] != 3){ $xKey++; } $last = array('yKey' => $yKey, 'xKey' => $xKey); } } //重新计算坐标 $bigRoadBSLocation = array(); $occupy = array(); foreach($bigRoadBS AS $key => $value){ $swerve = false; $swerveY = $key; foreach($value AS $k => $v){ $show_y = $key; $show_x = $k; if($show_x > 5 && $swerve === false){ $swerveY = $swerveY + 1; $show_y = $swerveY; $show_x = 5; $occupy[] = $show_y . '-' . $show_x; }elseif(in_array($show_y.'-'.$show_x,$occupy)){ if($swerve === false){ $swerve = $show_x - 1; } $swerveY = $swerveY + 1; $show_y = $swerveY; $show_x = $swerve; $occupy[] = $show_y . '-' . $show_x; }elseif($swerve !== false){ $swerveY = $swerveY + 1; $show_y = $swerveY; $show_x = $swerve; $occupy[] = $show_y . '-' . $show_x; } $pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result'], 'tie_num' => $v['tie_num']); $bigRoadBSLocation[] = $pushArray; } } /**************************** 计算 bigRoadBS end ***************************/ /**************************** 计算 bigRoadSP start ***************************/ //列 $yKey = 0; //行 $xKey = 0; $bigRoadSP = array(); foreach($ns AS $key => $value) { if ($value['toning_result'] == 1 || $value['toning_result'] == 3) { $value['result'] = 2; } else { $value['result'] = 1; } $ns[$key] = $value; } foreach($ns AS $key => $value){ $bigRoadSP[$yKey][$xKey] = array('result' => $value['result']); if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoadSP[$yKey][$xKey]['result']){ $yKey++; $xKey = 0; }else{ $xKey++; } } //重新计算坐标 $bigRoadSPLocation = array(); $occupy = array(); foreach($bigRoadSP AS $key => $value){ $swerve = false; $swerveY = $key; foreach($value AS $k => $v){ $show_y = $key; $show_x = $k; if($show_x > 5 && $swerve === false){ $swerveY = $swerveY + 1; $show_y = $swerveY; $show_x = 5; $occupy[] = $show_y . '-' . $show_x; }elseif(in_array($show_y.'-'.$show_x,$occupy)){ if($swerve === false){ $swerve = $show_x - 1; } $swerveY = $swerveY + 1; $show_y = $swerveY; $show_x = $swerve; $occupy[] = $show_y . '-' . $show_x; }elseif($swerve !== false){ $swerveY = $swerveY + 1; $show_y = $swerveY; $show_x = $swerve; $occupy[] = $show_y . '-' . $show_x; } $pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']); $bigRoadSPLocation[] = $pushArray; } } /**************************** 计算 bigRoadSP end ***************************/ $data = array(); $data['showRoad'] = $showRoadLocation; $data['bigRoad'] = $bigRoadLocation; $data['bigRoadBS'] = $bigRoadBSLocation; $data['bigRoadSP'] = $bigRoadSPLocation; return (['status'=>true, 'msg'=>'数据存在', 'waybill'=>$data]); } }