近期处理多个Highcharts图标时,碰到重复操作,所以编写了一个流程控制器
HTML选择页面
第一部分:<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/8
* Time: 14:40
*/
include('common/common.php');
// 获取初次加载必要信息
if(empty($_SESSION['firstYear']) || empty($_SESSION['firstMonth']) || empty($_SESSION['maxDay'])) {
echo "<script>window.location.href='index.php'</script>";
}
if(!empty($_GET['Pass'])) {
$firstYear = $_SESSION['firstYear'];
$firstMonth = $_SESSION['firstMonth'];
$maxDay = $_SESSION['maxDay'];
// 开始日期
$startDate = $firstYear."-".$firstMonth."-01";
// 结束日期
$endData = $firstYear."-".$firstMonth."-".$maxDay;
// 查询该段日期内共有多少种织带
/*
* 统计织带类别
*/
$sel_ribbon_sql = "SELECT ID,ribbontype FROM ribbon";
$res = getRes($sel_ribbon_sql);
$ribbontype_List = array();
$numbers_List = array();
$new_ribbontype_List = array();
$new_numbers_List = array();
for($i=0;$i<count($res);$i++) {
$ribbontype_List[$i] = $res[$i]['ribbontype'];
$sel_sql = "SELECT SUM(numbers) as num FROM orders WHERE category = ".$res[$i]['ID']." and state = 10 AND delivery >= '".$startDate."' AND delivery <= '".$endData."'";
$sel_orders_num_List = getRes($sel_sql);
$numbers_List[$i] = $sel_orders_num_List[0]['num'];
}
$index = 0;
for($j=0;$j<count($ribbontype_List);$j++) {
if($numbers_List[$j] != 0) { // 如果某种织带数量不为0
$new_ribbontype_List[$index] = $ribbontype_List[$j]; // 将不为0的织带数量给index下标
$new_numbers_List[$index] = $numbers_List[$j]; // 名字给index下标
$index++;
}
}
$k=0;
while($k<count($new_ribbontype_List)) {
// 将数组转换成higscharts可读格式
if($res[$k]['ID']==1) {
$arr1[] = array(
"name" => $new_ribbontype_List[$k],
"y" => intval($new_numbers_List[$k]),
"sliced" => true,
"selected" => true
);
} else {
$arr[] = array(
$new_ribbontype_List[$k],intval($new_numbers_List[$k])
);
}
$k++;
}
//合并数组
$arrs = array_merge($arr1,$arr);
$data = json_encode($arrs);
$_SESSION['data_num'] = $data;
if ($_GET['Pass'] == 1) {
echo "<script>window.location.href='chart_line_num.php'</script>";
} else if($_GET['Pass'] == 2) {
echo "<script>window.location.href='chart_columnar_num.php'</script>";
} else if($_GET['Pass'] == 3) {
echo "<script>window.location.href='chart_pie_num.php'</script>";
}
} else {
echo "<script>window.location.href='index.php'</script>";
}
第一部分进入分流(例举其一):
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/4
* Time: 9:50
*/
include('common/common.php');
if(empty($_SESSION['data_num']) || "null" == $_SESSION['data_num']) {
echo "<script>window.location.href='log_num.php?Pass=3;'</script>";
} else {
$data = $_SESSION['data_num'];;
}
include('tpl/chart_pie_num.html');