php教程 PHP源码 实现简单的按天数,按星期按月份搜索的框框

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

May 22, 2016 pm 05:22 PM

1.ajax.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

<?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;

}

로그인 후 복사

2.datehelper.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

<?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;

    }

로그인 후 복사

3.statistics

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

<?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);

}

로그인 후 복사





본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)