Heim > php教程 > PHP源码 > Hauptteil

实现简单的按天数,按星期按月份搜索的框框

PHP中文网
Freigeben: 2016-05-22 17:22:20
Original
1166 Leute haben es durchsucht

1.ajax.php

<?php
 
        $year = $_GET[&#39;y&#39;];
        if(!isset($_GET[&#39;m&#39;])){
             $month=1;
        }else{
                 $month = $_GET[&#39;m&#39;];
        }
        $week_arr = getMonthWeekArr($year, $month);
        echo json_encode($week_arr);
        die;
         
         
         
    /**
 * 获得系统某月的周数组,第一周不足的需要补足
 * 
 * @param int $current_year
 * @param int $current_month
 * @return string[][]
 */
function getMonthWeekArr($current_year, $current_month){
     
    //该月第一天
    $firstday = strtotime($current_year.&#39;-&#39;.$current_month.&#39;-01&#39;);
    //该月的第一周有几天
    $firstweekday = (7 - date(&#39;N&#39;,$firstday) +1);
    //计算该月第一个周一的时间
    $starttime = $firstday-3600*24*(7-$firstweekday);
    //该月的最后一天
    $lastday = strtotime($current_year.&#39;-&#39;.$current_month.&#39;-01&#39;." +1 month -1 day");
    //该月的最后一周有几天
    $lastweekday = date(&#39;N&#39;,$lastday);
    //该月的最后一个周末的时间
    $endtime = $lastday-3600*24*($lastweekday%7);
    $step = 3600*24*7;//步长值
    $week_arr = array();
    for ($i=$starttime; $i<$endtime; $i= $i+3600*24*7){
        $week_arr[] = array(&#39;key&#39;=>date(&#39;Y-m-d&#39;,$i).&#39;|&#39;.date(&#39;Y-m-d&#39;,$i+3600*24*6), &#39;val&#39;=>date(&#39;Y-m-d&#39;,$i).&#39;~&#39;.date(&#39;Y-m-d&#39;,$i+3600*24*6));
    }
    return $week_arr;
}
Nach dem Login kopieren

2.datehelper.php

<?php
 
 //获得系统年份数组
/**
 * 
 * @return string[]
 */
function getSystemYearArr(){
    $year_arr = array(&#39;2010&#39;=>&#39;2010&#39;,&#39;2011&#39;=>&#39;2011&#39;,&#39;2012&#39;=>&#39;2012&#39;,&#39;2013&#39;=>&#39;2013&#39;,&#39;2014&#39;=>&#39;2014&#39;,&#39;2015&#39;=>&#39;2015&#39;,&#39;2016&#39;=>&#39;2016&#39;,&#39;2017&#39;=>&#39;2017&#39;,&#39;2018&#39;=>&#39;2018&#39;,&#39;2019&#39;=>&#39;2019&#39;,&#39;2020&#39;=>&#39;2020&#39;);
    return $year_arr;
}
 
/**
 * 获得系统月份数组
 * 
 * @return array
 */
function getSystemMonthArr(){
     
    $month_arr = array(&#39;1&#39;=>&#39;01&#39;,&#39;2&#39;=>&#39;02&#39;,&#39;3&#39;=>&#39;03&#39;,&#39;4&#39;=>&#39;04&#39;,&#39;5&#39;=>&#39;05&#39;,&#39;6&#39;=>&#39;06&#39;,&#39;7&#39;=>&#39;07&#39;,&#39;8&#39;=>&#39;08&#39;,&#39;9&#39;=>&#39;09&#39;,&#39;10&#39;=>&#39;10&#39;,&#39;11&#39;=>&#39;11&#39;,&#39;12&#39;=>&#39;12&#39;);
    return $month_arr;
}
 
/**
 * 获得系统周数组
 * 
 * @return string[]
 */
function getSystemWeekArr(){
    $week_arr = array(&#39;1&#39;=>&#39;周一&#39;,&#39;2&#39;=>&#39;周二&#39;,&#39;3&#39;=>&#39;周三&#39;,&#39;4&#39;=>&#39;周四&#39;,&#39;5&#39;=>&#39;周五&#39;,&#39;6&#39;=>&#39;周六&#39;,&#39;7&#39;=>&#39;周日&#39;);
    return $week_arr;
}
 
/**
 * 获取某月的最后一天
 * 
 * @param int $year
 * @param int $month
 * @return number
 */
function getMonthLastDay($year, $month){
     
    $t = mktime(0, 0, 0, $month + 1, 1, $year);
    $t = $t - 60 * 60 * 24;
    return $t;
}
 
/**
 * 获得系统某月的周数组,第一周不足的需要补足
 * 
 * @param int $current_year
 * @param int $current_month
 * @return string[][]
 */
function getMonthWeekArr($current_year, $current_month){
     
    //该月第一天
    $firstday = strtotime($current_year.&#39;-&#39;.$current_month.&#39;-01&#39;);
    //该月的第一周有几天
    $firstweekday = (7 - date(&#39;N&#39;,$firstday) +1);
    //计算该月第一个周一的时间
    $starttime = $firstday-3600*24*(7-$firstweekday);
    //该月的最后一天
    $lastday = strtotime($current_year.&#39;-&#39;.$current_month.&#39;-01&#39;." +1 month -1 day");
    //该月的最后一周有几天
    $lastweekday = date(&#39;N&#39;,$lastday);
    //该月的最后一个周末的时间
    $endtime = $lastday-3600*24*($lastweekday%7);
    $step = 3600*24*7;//步长值
    $week_arr = array();
    for ($i=$starttime; $i<$endtime; $i= $i+3600*24*7){
        $week_arr[] = array(&#39;key&#39;=>date(&#39;Y-m-d&#39;,$i).&#39;|&#39;.date(&#39;Y-m-d&#39;,$i+3600*24*6), &#39;val&#39;=>date(&#39;Y-m-d&#39;,$i).&#39;~&#39;.date(&#39;Y-m-d&#39;,$i+3600*24*6));
    }
    return $week_arr;
}
 
 
 
 /**
     * 处理搜索时间
     */
  function dealwithSearchTime($search_arr=&#39;&#39;){
        //初始化时间
        //天
        if(!isset($search_arr[&#39;search_time&#39;])){
            $search_arr[&#39;search_time&#39;] = date(&#39;Y-m-d&#39;, time()- 86400);
        }
 
        $search_arr[&#39;day&#39;][&#39;search_time&#39;] = strtotime($search_arr[&#39;search_time&#39;]);//搜索的时间
        //周
        if(!isset($search_arr[&#39;searchweek_year&#39;])){
            $search_arr[&#39;searchweek_year&#39;] = date(&#39;Y&#39;, time());
        }
        if(!isset($search_arr[&#39;searchweek_month&#39;])){
            $search_arr[&#39;searchweek_month&#39;] = date(&#39;m&#39;, time());
        }
        if(!isset($search_arr[&#39;searchweek_week&#39;])){
            $search_arr[&#39;searchweek_week&#39;] =  implode(&#39;|&#39;, getWeek_SdateAndEdate(time()));
        }
 
 
        $weekcurrent_year = $search_arr[&#39;searchweek_year&#39;];
        $weekcurrent_month = $search_arr[&#39;searchweek_month&#39;];
        $weekcurrent_week = $search_arr[&#39;searchweek_week&#39;];
        $search_arr[&#39;week&#39;][&#39;current_year&#39;] = $weekcurrent_year;
        $search_arr[&#39;week&#39;][&#39;current_month&#39;] = $weekcurrent_month;
        $search_arr[&#39;week&#39;][&#39;current_week&#39;] = $weekcurrent_week;
 
        //月
        if(!isset($search_arr[&#39;searchmonth_year&#39;])){
            $search_arr[&#39;searchmonth_year&#39;] = date(&#39;Y&#39;, time());
        }
        if(!isset($search_arr[&#39;searchmonth_month&#39;])){
            $search_arr[&#39;searchmonth_month&#39;] = date(&#39;m&#39;, time());
        }
        $monthcurrent_year = $search_arr[&#39;searchmonth_year&#39;];
        $monthcurrent_month = $search_arr[&#39;searchmonth_month&#39;];
        $search_arr[&#39;month&#39;][&#39;current_year&#39;] = $monthcurrent_year;
        $search_arr[&#39;month&#39;][&#39;current_month&#39;] = $monthcurrent_month;
        return $search_arr;
    }
 
    /**
     * 获取本周的开始时间和结束时间
     * 
     * @param int $current_time
     * @return string
     */
    function getWeek_SdateAndEdate($current_time){
         
        $current_time = strtotime(date(&#39;Y-m-d&#39;,$current_time));
        $return_arr[&#39;sdate&#39;] = date(&#39;Y-m-d&#39;, $current_time-86400*(date(&#39;N&#39;,$current_time) - 1));
        $return_arr[&#39;edate&#39;] = date(&#39;Y-m-d&#39;, $current_time+86400*(7- date(&#39;N&#39;,$current_time)));
         
        return $return_arr;
    }
   /**
     * 查询每月的周数组
     */
 function getweekofmonth(){
        $year = $_GET[&#39;y&#39;];
        $month = $_GET[&#39;m&#39;];
        $week_arr = getMonthWeekArr($year, $month);
        echo json_encode($week_arr);
        die;
    }
Nach dem Login kopieren

3.statistics

<?php
/**
 * 统计
 *
 * @abstract
 *
 * @copyright 格里西,2016
 *
 * @author liujun
 *
 * @version  Id:statics v1.0 2016/2/5
 */
 
/**
 * 获得折线图统计图数据
 * 
 * param $statarr 图表需要的设置项
 * @return string
 */
function getStatData_LineLabels($stat_arr){
     
    //图表区、图形区和通用图表配置选项
    $stat_arr[&#39;chart&#39;][&#39;type&#39;] = &#39;line&#39;;
    //图表序列颜色数组
    $stat_arr[&#39;colors&#39;]?&#39;&#39;:$stat_arr[&#39;colors&#39;] = array(&#39;#058DC7&#39;, &#39;#ED561B&#39;, &#39;#8bbc21&#39;, &#39;#0d233a&#39;);
    //去除版权信息
    $stat_arr[&#39;credits&#39;][&#39;enabled&#39;] = false;
    //导出功能选项
    $stat_arr[&#39;exporting&#39;][&#39;enabled&#39;] = false;
    //标题如果为字符串则使用默认样式
    is_string($stat_arr[&#39;title&#39;])?$stat_arr[&#39;title&#39;] = array(&#39;text&#39;=>"<b>{$stat_arr[&#39;title&#39;]}</b>",&#39;x&#39;=>-20):&#39;&#39;;
    //子标题如果为字符串则使用默认样式
    is_string($stat_arr[&#39;subtitle&#39;])?$stat_arr[&#39;subtitle&#39;] = array(&#39;text&#39;=>"<b>{$stat_arr[&#39;subtitle&#39;]}</b>",&#39;x&#39;=>-20):&#39;&#39;;
    //Y轴如果为字符串则使用默认样式
    if(is_string($stat_arr[&#39;yAxis&#39;])){
        $text = $stat_arr[&#39;yAxis&#39;];
        unset($stat_arr[&#39;yAxis&#39;]);
        $stat_arr[&#39;yAxis&#39;][&#39;title&#39;][&#39;text&#39;] = $text;
    }
    return json_encode($stat_arr);
}
 
/**
 * 获得Column2D统计图数据
 * 
 * @param array $stat_arr
 * @return string
 */
function getStatData_Column2D($stat_arr){
     
    //图表区、图形区和通用图表配置选项
    $stat_arr[&#39;chart&#39;][&#39;type&#39;] = &#39;column&#39;;
    //去除版权信息
    $stat_arr[&#39;credits&#39;][&#39;enabled&#39;] = false;
    //导出功能选项
    $stat_arr[&#39;exporting&#39;][&#39;enabled&#39;] = false;
    //标题如果为字符串则使用默认样式
    is_string($stat_arr[&#39;title&#39;])?$stat_arr[&#39;title&#39;] = array(&#39;text&#39;=>"<b>{$stat_arr[&#39;title&#39;]}</b>",&#39;x&#39;=>-20):&#39;&#39;;
    //子标题如果为字符串则使用默认样式
    is_string($stat_arr[&#39;subtitle&#39;])?$stat_arr[&#39;subtitle&#39;] = array(&#39;text&#39;=>"<b>{$stat_arr[&#39;subtitle&#39;]}</b>",&#39;x&#39;=>-20):&#39;&#39;;
    //Y轴如果为字符串则使用默认样式
    if(is_string($stat_arr[&#39;yAxis&#39;])){
        $text = $stat_arr[&#39;yAxis&#39;];
        unset($stat_arr[&#39;yAxis&#39;]);
        $stat_arr[&#39;yAxis&#39;][&#39;title&#39;][&#39;text&#39;] = $text;
    }
    //柱形的颜色数组
    $color = array(&#39;#7a96a4&#39;,&#39;#cba952&#39;,&#39;#667b16&#39;,&#39;#a26642&#39;,&#39;#349898&#39;,&#39;#c04f51&#39;,&#39;#5c315e&#39;,&#39;#445a2b&#39;,&#39;#adae50&#39;,&#39;#14638a&#39;,&#39;#b56367&#39;,&#39;#a399bb&#39;,&#39;#070dfa&#39;,&#39;#47ff07&#39;,&#39;#f809b7&#39;);
     
    foreach ($stat_arr[&#39;series&#39;] as $series_k=>$series_v){
        foreach ($series_v[&#39;data&#39;] as $data_k=>$data_v){
            $data_v[&#39;color&#39;] = $color[$data_k];
            $series_v[&#39;data&#39;][$data_k] = $data_v;
        }
        $stat_arr[&#39;series&#39;][$series_k][&#39;data&#39;] = $series_v[&#39;data&#39;];
    }
    //print_r($stat_arr); die;
    return json_encode($stat_arr);
}
 
/**
 * 获得Basicbar统计图数据
 * 
 * @param array $stat_arr
 * @return string
 */
function getStatData_Basicbar($stat_arr){
     
    //图表区、图形区和通用图表配置选项
    $stat_arr[&#39;chart&#39;][&#39;type&#39;] = &#39;bar&#39;;
    //去除版权信息
    $stat_arr[&#39;credits&#39;][&#39;enabled&#39;] = false;
    //导出功能选项
    $stat_arr[&#39;exporting&#39;][&#39;enabled&#39;] = false;
    //显示datalabel
    $stat_arr[&#39;plotOptions&#39;][&#39;bar&#39;][&#39;dataLabels&#39;][&#39;enabled&#39;] = true;
    //标题如果为字符串则使用默认样式
    is_string($stat_arr[&#39;title&#39;])?$stat_arr[&#39;title&#39;] = array(&#39;text&#39;=>"<b>{$stat_arr[&#39;title&#39;]}</b>",&#39;x&#39;=>-20):&#39;&#39;;
    //子标题如果为字符串则使用默认样式
    is_string($stat_arr[&#39;subtitle&#39;])?$stat_arr[&#39;subtitle&#39;] = array(&#39;text&#39;=>"<b>{$stat_arr[&#39;subtitle&#39;]}</b>",&#39;x&#39;=>-20):&#39;&#39;;
    //Y轴如果为字符串则使用默认样式
    if(is_string($stat_arr[&#39;yAxis&#39;])){
        $text = $stat_arr[&#39;yAxis&#39;];
        unset($stat_arr[&#39;yAxis&#39;]);
        $stat_arr[&#39;yAxis&#39;][&#39;title&#39;][&#39;text&#39;] = $text;
    }
    //柱形的颜色数组
    $color = array(&#39;#7a96a4&#39;,&#39;#cba952&#39;,&#39;#667b16&#39;,&#39;#a26642&#39;,&#39;#349898&#39;,&#39;#c04f51&#39;,&#39;#5c315e&#39;,&#39;#445a2b&#39;,&#39;#adae50&#39;,&#39;#14638a&#39;,&#39;#b56367&#39;,&#39;#a399bb&#39;,&#39;#070dfa&#39;,&#39;#47ff07&#39;,&#39;#f809b7&#39;);
     
    foreach ($stat_arr[&#39;series&#39;] as $series_k=>$series_v){
        foreach ($series_v[&#39;data&#39;] as $data_k=>$data_v){
            if (!$data_v[&#39;color&#39;]){
                $data_v[&#39;color&#39;] = $color[$data_k%15];
            }
            $series_v[&#39;data&#39;][$data_k] = $data_v;
        }
        $stat_arr[&#39;series&#39;][$series_k][&#39;data&#39;] = $series_v[&#39;data&#39;];
    }
    //print_r($stat_arr); die;
    return json_encode($stat_arr);
}
 
/**
 * 计算环比
 * 
 * @param array $updata
 * @param array $currentdata
 * @return string
 */
function getHb($updata, $currentdata){
     
    if($updata != 0){
        $mtomrate = round(($currentdata - $updata)/$updata*100, 2).&#39;%&#39;;
    } else {
        $mtomrate = &#39;-&#39;;
    }
    return $mtomrate; 
}
 
/**
 * 计算同比
 * 
 * @param array $updata
 * @param array $currentdata
 * @return string
 */
function getTb($updata, $currentdata){
     
    if($updata != 0){
        $ytoyrate = round(($currentdata - $updata)/$updata*100, 2).&#39;%&#39;;
    } else {
        $ytoyrate = &#39;-&#39;;
    }
    return $ytoyrate; 
}
 
/**
 * 地图统计图
 * 
 * @param array $stat_arr
 * @return string
 */
function getStatData_Map($stat_arr){
     
    //$color_arr = array(&#39;#f63a3a&#39;,&#39;#ff5858&#39;,&#39;#ff9191&#39;,&#39;#ffc3c3&#39;,&#39;#ffd5d5&#39;);
    $color_arr = array(&#39;#fd0b07&#39;,&#39;#ff9191&#39;,&#39;#f7ba17&#39;,&#39;#fef406&#39;,&#39;#25aae2&#39;);
    $stat_arrnew = array();
    foreach ($stat_arr as $k=>$v){
        $stat_arrnew[] = array(&#39;cha&#39;=>$v[&#39;cha&#39;],&#39;name&#39;=>$v[&#39;name&#39;],&#39;des&#39;=>$v[&#39;des&#39;],&#39;color&#39;=>$color_arr[$v[&#39;level&#39;]]);
    }
    return json_encode($stat_arrnew);
}
 
/**
 * 获得饼形图数据
 * 
 * @param array $data
 * @return string
 */
function getStatData_Pie($data){
     
    $stat_arr[&#39;chart&#39;][&#39;type&#39;] = &#39;pie&#39;;
    $stat_arr[&#39;credits&#39;][&#39;enabled&#39;] = false;
    $stat_arr[&#39;title&#39;][&#39;text&#39;] = $data[&#39;title&#39;];
    $stat_arr[&#39;tooltip&#39;][&#39;pointFormat&#39;] = &#39;{series.name}: <b>{point.y}</b>&#39;;
    $stat_arr[&#39;plotOptions&#39;][&#39;pie&#39;] = array(
        &#39;allowPointSelect&#39;=>true,
        &#39;cursor&#39;=>&#39;pointer&#39;,
        &#39;dataLabels&#39;=>array(
            &#39;enabled&#39;=>$data[&#39;label_show&#39;],
            &#39;color&#39;=>&#39;#000000&#39;,
            &#39;connectorColor&#39;=>&#39;#000000&#39;,
            &#39;format&#39;=>&#39;<b>{point.name}</b>: {point.percentage:.1f} %&#39;
        )
    );
    $stat_arr[&#39;series&#39;][0][&#39;name&#39;] = $data[&#39;name&#39;];
    $stat_arr[&#39;series&#39;][0][&#39;data&#39;] = array();
    foreach ($data[&#39;series&#39;] as $k=>$v){
        $stat_arr[&#39;series&#39;][0][&#39;data&#39;][] = array($v[&#39;p_name&#39;],$v[&#39;allnum&#39;]);
    }
    //exit(json_encode($stat_arr));
    return json_encode($stat_arr);
}
Nach dem Login kopieren





Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!