实现简单的按天数,按星期按月份搜索的框框
1.ajax.php
<?php $year = $_GET['y']; if(!isset($_GET['m'])){ $month=1; }else{ $month = $_GET['m']; } $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.'-'.$current_month.'-01'); //该月的第一周有几天 $firstweekday = (7 - date('N',$firstday) +1); //计算该月第一个周一的时间 $starttime = $firstday-3600*24*(7-$firstweekday); //该月的最后一天 $lastday = strtotime($current_year.'-'.$current_month.'-01'." +1 month -1 day"); //该月的最后一周有几天 $lastweekday = date('N',$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('key'=>date('Y-m-d',$i).'|'.date('Y-m-d',$i+3600*24*6), 'val'=>date('Y-m-d',$i).'~'.date('Y-m-d',$i+3600*24*6)); } return $week_arr; }
Copier après la connexion
2.datehelper.php
<?php //获得系统年份数组 /** * * @return string[] */ function getSystemYearArr(){ $year_arr = array('2010'=>'2010','2011'=>'2011','2012'=>'2012','2013'=>'2013','2014'=>'2014','2015'=>'2015','2016'=>'2016','2017'=>'2017','2018'=>'2018','2019'=>'2019','2020'=>'2020'); return $year_arr; } /** * 获得系统月份数组 * * @return array */ function getSystemMonthArr(){ $month_arr = array('1'=>'01','2'=>'02','3'=>'03','4'=>'04','5'=>'05','6'=>'06','7'=>'07','8'=>'08','9'=>'09','10'=>'10','11'=>'11','12'=>'12'); return $month_arr; } /** * 获得系统周数组 * * @return string[] */ function getSystemWeekArr(){ $week_arr = array('1'=>'周一','2'=>'周二','3'=>'周三','4'=>'周四','5'=>'周五','6'=>'周六','7'=>'周日'); 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.'-'.$current_month.'-01'); //该月的第一周有几天 $firstweekday = (7 - date('N',$firstday) +1); //计算该月第一个周一的时间 $starttime = $firstday-3600*24*(7-$firstweekday); //该月的最后一天 $lastday = strtotime($current_year.'-'.$current_month.'-01'." +1 month -1 day"); //该月的最后一周有几天 $lastweekday = date('N',$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('key'=>date('Y-m-d',$i).'|'.date('Y-m-d',$i+3600*24*6), 'val'=>date('Y-m-d',$i).'~'.date('Y-m-d',$i+3600*24*6)); } return $week_arr; } /** * 处理搜索时间 */ function dealwithSearchTime($search_arr=''){ //初始化时间 //天 if(!isset($search_arr['search_time'])){ $search_arr['search_time'] = date('Y-m-d', time()- 86400); } $search_arr['day']['search_time'] = strtotime($search_arr['search_time']);//搜索的时间 //周 if(!isset($search_arr['searchweek_year'])){ $search_arr['searchweek_year'] = date('Y', time()); } if(!isset($search_arr['searchweek_month'])){ $search_arr['searchweek_month'] = date('m', time()); } if(!isset($search_arr['searchweek_week'])){ $search_arr['searchweek_week'] = implode('|', getWeek_SdateAndEdate(time())); } $weekcurrent_year = $search_arr['searchweek_year']; $weekcurrent_month = $search_arr['searchweek_month']; $weekcurrent_week = $search_arr['searchweek_week']; $search_arr['week']['current_year'] = $weekcurrent_year; $search_arr['week']['current_month'] = $weekcurrent_month; $search_arr['week']['current_week'] = $weekcurrent_week; //月 if(!isset($search_arr['searchmonth_year'])){ $search_arr['searchmonth_year'] = date('Y', time()); } if(!isset($search_arr['searchmonth_month'])){ $search_arr['searchmonth_month'] = date('m', time()); } $monthcurrent_year = $search_arr['searchmonth_year']; $monthcurrent_month = $search_arr['searchmonth_month']; $search_arr['month']['current_year'] = $monthcurrent_year; $search_arr['month']['current_month'] = $monthcurrent_month; return $search_arr; } /** * 获取本周的开始时间和结束时间 * * @param int $current_time * @return string */ function getWeek_SdateAndEdate($current_time){ $current_time = strtotime(date('Y-m-d',$current_time)); $return_arr['sdate'] = date('Y-m-d', $current_time-86400*(date('N',$current_time) - 1)); $return_arr['edate'] = date('Y-m-d', $current_time+86400*(7- date('N',$current_time))); return $return_arr; } /** * 查询每月的周数组 */ function getweekofmonth(){ $year = $_GET['y']; $month = $_GET['m']; $week_arr = getMonthWeekArr($year, $month); echo json_encode($week_arr); die; }
Copier après la connexion
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['chart']['type'] = 'line'; //图表序列颜色数组 $stat_arr['colors']?'':$stat_arr['colors'] = array('#058DC7', '#ED561B', '#8bbc21', '#0d233a'); //去除版权信息 $stat_arr['credits']['enabled'] = false; //导出功能选项 $stat_arr['exporting']['enabled'] = false; //标题如果为字符串则使用默认样式 is_string($stat_arr['title'])?$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):''; //子标题如果为字符串则使用默认样式 is_string($stat_arr['subtitle'])?$stat_arr['subtitle'] = array('text'=>"<b>{$stat_arr['subtitle']}</b>",'x'=>-20):''; //Y轴如果为字符串则使用默认样式 if(is_string($stat_arr['yAxis'])){ $text = $stat_arr['yAxis']; unset($stat_arr['yAxis']); $stat_arr['yAxis']['title']['text'] = $text; } return json_encode($stat_arr); } /** * 获得Column2D统计图数据 * * @param array $stat_arr * @return string */ function getStatData_Column2D($stat_arr){ //图表区、图形区和通用图表配置选项 $stat_arr['chart']['type'] = 'column'; //去除版权信息 $stat_arr['credits']['enabled'] = false; //导出功能选项 $stat_arr['exporting']['enabled'] = false; //标题如果为字符串则使用默认样式 is_string($stat_arr['title'])?$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):''; //子标题如果为字符串则使用默认样式 is_string($stat_arr['subtitle'])?$stat_arr['subtitle'] = array('text'=>"<b>{$stat_arr['subtitle']}</b>",'x'=>-20):''; //Y轴如果为字符串则使用默认样式 if(is_string($stat_arr['yAxis'])){ $text = $stat_arr['yAxis']; unset($stat_arr['yAxis']); $stat_arr['yAxis']['title']['text'] = $text; } //柱形的颜色数组 $color = array('#7a96a4','#cba952','#667b16','#a26642','#349898','#c04f51','#5c315e','#445a2b','#adae50','#14638a','#b56367','#a399bb','#070dfa','#47ff07','#f809b7'); foreach ($stat_arr['series'] as $series_k=>$series_v){ foreach ($series_v['data'] as $data_k=>$data_v){ $data_v['color'] = $color[$data_k]; $series_v['data'][$data_k] = $data_v; } $stat_arr['series'][$series_k]['data'] = $series_v['data']; } //print_r($stat_arr); die; return json_encode($stat_arr); } /** * 获得Basicbar统计图数据 * * @param array $stat_arr * @return string */ function getStatData_Basicbar($stat_arr){ //图表区、图形区和通用图表配置选项 $stat_arr['chart']['type'] = 'bar'; //去除版权信息 $stat_arr['credits']['enabled'] = false; //导出功能选项 $stat_arr['exporting']['enabled'] = false; //显示datalabel $stat_arr['plotOptions']['bar']['dataLabels']['enabled'] = true; //标题如果为字符串则使用默认样式 is_string($stat_arr['title'])?$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):''; //子标题如果为字符串则使用默认样式 is_string($stat_arr['subtitle'])?$stat_arr['subtitle'] = array('text'=>"<b>{$stat_arr['subtitle']}</b>",'x'=>-20):''; //Y轴如果为字符串则使用默认样式 if(is_string($stat_arr['yAxis'])){ $text = $stat_arr['yAxis']; unset($stat_arr['yAxis']); $stat_arr['yAxis']['title']['text'] = $text; } //柱形的颜色数组 $color = array('#7a96a4','#cba952','#667b16','#a26642','#349898','#c04f51','#5c315e','#445a2b','#adae50','#14638a','#b56367','#a399bb','#070dfa','#47ff07','#f809b7'); foreach ($stat_arr['series'] as $series_k=>$series_v){ foreach ($series_v['data'] as $data_k=>$data_v){ if (!$data_v['color']){ $data_v['color'] = $color[$data_k%15]; } $series_v['data'][$data_k] = $data_v; } $stat_arr['series'][$series_k]['data'] = $series_v['data']; } //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).'%'; } else { $mtomrate = '-'; } return $mtomrate; } /** * 计算同比 * * @param array $updata * @param array $currentdata * @return string */ function getTb($updata, $currentdata){ if($updata != 0){ $ytoyrate = round(($currentdata - $updata)/$updata*100, 2).'%'; } else { $ytoyrate = '-'; } return $ytoyrate; } /** * 地图统计图 * * @param array $stat_arr * @return string */ function getStatData_Map($stat_arr){ //$color_arr = array('#f63a3a','#ff5858','#ff9191','#ffc3c3','#ffd5d5'); $color_arr = array('#fd0b07','#ff9191','#f7ba17','#fef406','#25aae2'); $stat_arrnew = array(); foreach ($stat_arr as $k=>$v){ $stat_arrnew[] = array('cha'=>$v['cha'],'name'=>$v['name'],'des'=>$v['des'],'color'=>$color_arr[$v['level']]); } return json_encode($stat_arrnew); } /** * 获得饼形图数据 * * @param array $data * @return string */ function getStatData_Pie($data){ $stat_arr['chart']['type'] = 'pie'; $stat_arr['credits']['enabled'] = false; $stat_arr['title']['text'] = $data['title']; $stat_arr['tooltip']['pointFormat'] = '{series.name}: <b>{point.y}</b>'; $stat_arr['plotOptions']['pie'] = array( 'allowPointSelect'=>true, 'cursor'=>'pointer', 'dataLabels'=>array( 'enabled'=>$data['label_show'], 'color'=>'#000000', 'connectorColor'=>'#000000', 'format'=>'<b>{point.name}</b>: {point.percentage:.1f} %' ) ); $stat_arr['series'][0]['name'] = $data['name']; $stat_arr['series'][0]['data'] = array(); foreach ($data['series'] as $k=>$v){ $stat_arr['series'][0]['data'][] = array($v['p_name'],$v['allnum']); } //exit(json_encode($stat_arr)); return json_encode($stat_arr); }
Copier après la connexion
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

Video Face Swap
Échangez les visages dans n'importe quelle vidéo sans effort grâce à notre outil d'échange de visage AI entièrement gratuit !

Article chaud
Assassin's Creed Shadows: Solution d'énigmes de coquille
3 Il y a quelques semaines
By DDD
Quoi de neuf dans Windows 11 KB5054979 et comment résoudre les problèmes de mise à jour
2 Il y a quelques semaines
By DDD
Assassin's Creed Shadows - Comment trouver le forgeron et déverrouiller les armes et la personnalisation des armes
1 Il y a quelques mois
By DDD
Où trouver la courte de la grue à atomide atomique
3 Il y a quelques semaines
By DDD
<🎜>: Dead Rails - Comment relever chaque défi
3 Il y a quelques semaines
By DDD

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)