控制器内容

    1. /**
    2. * 订单分析,数据统计
    3. * author:咔咔
    4. * time:2018.7.4
    5. * @access public
    6. */
    7. public function goodsanalysis(){
    8. //获得展示类型
    9. if($_GET['time_type']){
    10. $time_type = $_GET['time_type'];
    11. }else{
    12. $time_type = 'day';
    13. }
    14. //获得月份
    15. if($_GET['month']){
    16. $month = $_GET['month'];
    17. }else{
    18. $month = date("m",time());
    19. }
    20. // 获取到当前的年份 2018
    21. $years_time =date("Y",time()) ;
    22. // 视图传过来的月份,跟当前年份拼接 string(7) "2018-07"
    23. $oldtime = $years_time."-".$month;
    24. /*
    25. array(3) {
    26. //当月第一天的时间戳
    27. [0] => int(1530374400)
    28. //当月最后一天的时间戳
    29. [1] => int(1532966400)
    30. //当月的天数
    31. [2] => int(30)
    32. }
    33. */
    34. $time_interval = $this->getMonth($oldtime);
    35. $data = array();
    36. if($time_type=='day'){
    37. // 循环每月的天数
    38. for ($x=0; $x<=$time_interval['2']; $x++) {
    39. // 从第一天到最后一天的时间戳
    40. $time = $time_interval['0']+(86400*$x);
    41. // 将第一天到最后一天的时间戳格式化 在视图底部输出日期
    42. $data['time'][$x]=date("m/d",$time);
    43. // 统计订单的查询条件
    44. $where['is_pay'] = 1;
    45. // $where['refund'] = 1;
    46. $where['ctime'] = array(array('EGT',$time),array('ELT',($time+86400)),'AND');
    47. // 订单的所有数量
    48. $data['sales_sum'][$x]=M('goodsorder')->where($where)->count();
    49. // 订单的总价
    50. $data['saleroom'][$x]=M('goodsorder')->where($where)->sum('price');
    51. // 当没有订单的时候总价为0
    52. if($data['saleroom'][$x]==NULL){
    53. $data['saleroom'][$x]=0;
    54. }
    55. }
    56. }else{
    57. for ($x=1; $x<=12; $x++) {
    58. $time = $years_time."-".$x;
    59. $time_interval = $this->getMonth($time);
    60. $data['time'][$x]=$x."月";
    61. $where['is_pay'] = 1;
    62. // $where['refund'] = 1;
    63. $where['ctime'] = array(array('EGT',$time_interval[0]),array('ELT',$time_interval[1]),'AND');
    64. $data['sales_sum'][$x]=M('goodsorder')->where($where)->count();
    65. $data['saleroom'][$x]=M('goodsorder')->where($where)->sum('price');
    66. if($data['saleroom'][$x]==NULL){
    67. $data['saleroom'][$x]=0;
    68. }
    69. }
    70. }
    71. //将time 拼接字符串
    72. // 将当月的所有天数转换为字符串
    73. $time_str ="";
    74. foreach($data['time'] as $k=>$v){
    75. $time_str=$time_str."_".$v ;
    76. }
    77. // 截取第一个-
    78. $time_str = substr($time_str,1);
    79. //将销量拼接字符串
    80. $sales_sum_str ="";
    81. foreach($data['sales_sum'] as $k=>$v){
    82. $sales_sum_str=$sales_sum_str."_".$v ;
    83. }
    84. $sales_sum_str = substr($sales_sum_str,1);
    85. //将销售额拼接数组
    86. $saleroom_str ="";
    87. foreach($data['saleroom'] as $k=>$v){
    88. $saleroom_str=$saleroom_str."_".$v ;
    89. }
    90. $saleroom_str = substr($saleroom_str,1);
    91. $data['max_count'] =max($data['sales_sum']);
    92. $data['max_salessum'] =max($data['saleroom']);
    93. $data['saleroom'] = $saleroom_str;
    94. $data['time'] =$time_str;
    95. $data['sales_sum'] = $sales_sum_str;
    96. $this->assign('data',$data);
    97. $this->display();
    98. }
    99. /**
    100. * 时间
    101. * author:咔咔
    102. * time:2018.7.4
    103. * param string $data 当前的年份跟月份
    104. */
    105. //获取月初和月末的时间戳
    106. function getMonth($date){
    107. // 获取到当月的第一天时间戳
    108. $firstday = date("Y-m-01",strtotime($date));
    109. // string(10) "2018-07-31" 获取到当月的最后天
    110. $lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day"));
    111. // 将第一天转为时间戳
    112. $firstday = strtotime($date);
    113. // 最后一天转为时间戳
    114. $lastday = strtotime($lastday);
    115. // 获取当月天数
    116. $day_sum = (($lastday - $firstday)/86400);
    117. return array($firstday,$lastday,$day_sum);
    118. }

    修改过得html内容

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>Document</title>
    6. </head>
    7. <body>
    8. <style type="text/css">
    9. .pagination{
    10. padding: 10px 0;
    11. }
    12. .pagination *{
    13. margin-right:3px;
    14. padding: 5px 10px;
    15. }
    16. .pagination a{
    17. border:1px solid #337ab7;
    18. border-radius: 3px;
    19. }
    20. .sousuo {
    21. width: 263px;
    22. }
    23. .nr {
    24. font-size: 10px;
    25. color: #3F3F3F;
    26. }
    27. .tabledown{
    28. width:10%;
    29. margin-bottom:25px;
    30. display:inline-block;
    31. }
    32. .tabletype{
    33. display:inline-block;
    34. margin-right:5px;
    35. }
    36. .tabletypeleft{
    37. margin-left:20px;
    38. }
    39. </style>
    40. <div class="mod">
    41. <!-- 数据分析select -->
    42. <div class="tabletype">报表类型</div>
    43. <div class="tabledown">
    44. <select name="" class="form-control" id="styleselect">
    45. <option value="day" select>日报表</option>
    46. <option value="years">月报表</option>
    47. </select>
    48. </div>
    49. <div class="tabletype tabletypeleft">时间</div>
    50. <div class="tabledown" id="month_div">
    51. <select name="" class="form-control" id="month">
    52. <for start="1" end="13" name="i">
    53. <option value="{$i}">{$i}月</option>
    54. </for>
    55. </select>
    56. </div>
    57. <div class="tabledown" style="display:none" id="years_div">
    58. <select name="" class="form-control" id="years_sum">
    59. <option value="2018" select >2018年</option>
    60. </select>
    61. </div>
    62. <!-- Bootstrap 的搜索按钮 -->
    63. <button class="btn btn-primary" id="sales_report"><i class="icon-search"></i></button>
    64. <!-- !!数据分析select -->
    65. <br class="table-responsive">
    66. <input type="hidden" name="field_name" id="max_count" value={$data['max_count']}>
    67. <input type="hidden" name="field_name" id="max_salessum" value={$data['max_salessum']}>
    68. <input type="hidden" name="field_name" id="saleroom" value={$data['saleroom']}>
    69. <input type="hidden" name="field_name" id="time" value={$data['time']}>
    70. <input type="hidden" name="field_name" id="sales_sum" value={$data['sales_sum']}>
    71. <div id="container" style="height: 500px"></div>
    72. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js"></script>
    73. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-gl/echarts-gl.min.js"></script>
    74. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-stat/ecStat.min.js"></script>
    75. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/dataTool.min.js"></script>
    76. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/china.js"></script>
    77. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/world.js"></script>
    78. <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ZUONbpqGBsYGXNIYHicvbAbM"></script>
    79. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/bmap.min.js"></script>
    80. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/simplex.js"></script>
    81. <script type="text/javascript">
    82. var dom = document.getElementById("container");
    83. var myChart = echarts.init(dom);
    84. var app = {};
    85. //定义参数
    86. var max_count=parseInt(document.getElementById("max_count").value)+parseInt(20);
    87. var max_salessum=parseInt(document.getElementById("max_salessum").value)+parseInt(50);
    88. var saleroom=document.getElementById("saleroom").value;
    89. var time=document.getElementById("time").value;
    90. var sales_sum=document.getElementById("sales_sum").value;
    91. option = null;
    92. var data_time = time.split("_");
    93. var data_sales_sum = sales_sum.split("_");
    94. var data_saleroom = saleroom.split("_");
    95. app.title = '折柱混合';
    96. option = {
    97. tooltip: {
    98. trigger: 'axis',
    99. axisPointer: {
    100. type: 'cross',
    101. crossStyle: {
    102. color: '#999'
    103. }
    104. }
    105. },
    106. toolbox: {
    107. feature: {
    108. dataView: {show: true, readOnly: false},
    109. magicType: {show: true, type: ['line', 'bar']},
    110. restore: {show: true},
    111. saveAsImage: {show: true}
    112. }
    113. },
    114. legend: {
    115. data:[,'销售数量','销售总额']
    116. },
    117. xAxis: [
    118. {
    119. type: 'category',
    120. data: data_time,
    121. axisPointer: {
    122. type: 'shadow'
    123. }
    124. }
    125. ],
    126. yAxis: [
    127. {
    128. type: 'value',
    129. name: '数量',
    130. min: 0,
    131. max: max_count,
    132. interval: Math.ceil(max_count/5),
    133. axisLabel: {
    134. formatter: '{value} 件'
    135. }
    136. },
    137. {
    138. type: 'value',
    139. name: '总额',
    140. min: 0,
    141. max: max_salessum,
    142. interval: Math.ceil(max_salessum/5),
    143. axisLabel: {
    144. formatter: '{value} 元'
    145. }
    146. }
    147. ],
    148. series: [
    149. {
    150. name:'销售数量',
    151. type:'bar',
    152. data:data_sales_sum
    153. },
    154. {
    155. name:'销售总额',
    156. type:'line',
    157. yAxisIndex: 1,
    158. data:data_saleroom
    159. }
    160. ]
    161. };
    162. ;
    163. if (option && typeof option === "object") {
    164. myChart.setOption(option, true);
    165. }
    166. $("#styleselect").change(function(){
    167. var opt=$("#styleselect").val();
    168. if(opt=="day"){
    169. $("#years_div").attr("style","display:none;");
    170. $("#month_div").attr("style","display:inline-block;");
    171. }else{
    172. $("#years_div").attr("style","display:inline-block;");
    173. $("#month_div").attr("style","display:none;");
    174. }
    175. });
    176. $("#sales_report").click(function(){
    177. var time_type = $("#styleselect").val();
    178. if(time_type =="day"){
    179. var month = $("#month").val();
    180. }
    181. window.location.href="index.php?s=/addon/WeiuidStore/web/analysis/time_type/"+time_type+"/month/"+month;
    182. })
    183. </script>
    184. </div>
    185. </div>
    186. </div>
    187. </body>
    188. </html>

    本身自带的html文件

    1. <extend name="./App/Common/View/default/Base/common.html" />
    2. <block name="main_content">
    3. <include file="./App/Common/View/default/Public/crumb.html" />
    4. <style type="text/css">
    5. .pagination{
    6. padding: 10px 0;
    7. }
    8. .pagination *{
    9. margin-right:3px;
    10. padding: 5px 10px;
    11. }
    12. .pagination a{
    13. border:1px solid #337ab7;
    14. border-radius: 3px;
    15. }
    16. .sousuo {
    17. width: 263px;
    18. }
    19. .nr {
    20. font-size: 10px;
    21. color: #3F3F3F;
    22. }
    23. .tabledown{
    24. width:10%;
    25. margin-bottom:25px;
    26. display:inline-block;
    27. }
    28. .tabletype{
    29. display:inline-block;
    30. margin-right:5px;
    31. }
    32. .tabletypeleft{
    33. margin-left:20px;
    34. }
    35. </style>
    36. <div class="mod">
    37. <div class="mod-head">
    38. <h3>
    39. <include file="./App/Common/View/default/Public/nav.html" />
    40. </h3>
    41. </div>
    42. <div class="mod-body tab-content">
    43. <if condition="$tip">
    44. <div class="alert alert-info tip" role="alert">{$tip}</div>
    45. </if>
    46. <include file="./App/Common/View/default/Public/search.html" />
    47. <div class="tab-pane active" id="list">
    48. <if condition="$subnav">
    49. <ul class="nav nav-tabs">
    50. <volist name="subnav" id="vo">
    51. <li role="presentation" class="{$vo.class}"><a href="{$vo.url}">{$vo.title}</a></li>
    52. </volist>
    53. </ul>
    54. <br>
    55. </if>
    56. <br>
    57. <!-- 数据分析select -->
    58. <div class="tabletype">报表类型</div>
    59. <div class="tabledown">
    60. <select name="" class="form-control" id="styleselect">
    61. <option value="day" select>日报表</option>
    62. <option value="years">月报表</option>
    63. </select>
    64. </div>
    65. <div class="tabletype tabletypeleft">时间</div>
    66. <div class="tabledown" id="month_div">
    67. <select name="" class="form-control" id="month">
    68. <for start="1" end="13" name="i">
    69. <option value="{$i}">{$i}月</option>
    70. </for>
    71. </select>
    72. </div>
    73. <div class="tabledown" style="display:none" id="years_div">
    74. <select name="" class="form-control" id="years_sum">
    75. <option value="2018" select >2018年</option>
    76. </select>
    77. </div>
    78. <button class="btn btn-primary" id="sales_report"><i class="icon-search"></i></button>
    79. <!-- !!数据分析select -->
    80. <br class="table-responsive">
    81. <input type="hidden" name="field_name" id="max_count" value={$data['max_count']}>
    82. <input type="hidden" name="field_name" id="max_salessum" value={$data['max_salessum']}>
    83. <input type="hidden" name="field_name" id="saleroom" value={$data['saleroom']}>
    84. <input type="hidden" name="field_name" id="time" value={$data['time']}>
    85. <input type="hidden" name="field_name" id="sales_sum" value={$data['sales_sum']}>
    86. <div id="container" style="height: 500px"></div>
    87. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js"></script>
    88. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-gl/echarts-gl.min.js"></script>
    89. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-stat/ecStat.min.js"></script>
    90. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/dataTool.min.js"></script>
    91. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/china.js"></script>
    92. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/world.js"></script>
    93. <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ZUONbpqGBsYGXNIYHicvbAbM"></script>
    94. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/bmap.min.js"></script>
    95. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/simplex.js"></script>
    96. <script type="text/javascript">
    97. var dom = document.getElementById("container");
    98. var myChart = echarts.init(dom);
    99. var app = {};
    100. //定义参数
    101. var max_count=parseInt(document.getElementById("max_count").value)+parseInt(20);
    102. var max_salessum=parseInt(document.getElementById("max_salessum").value)+parseInt(50);
    103. var saleroom=document.getElementById("saleroom").value;
    104. var time=document.getElementById("time").value;
    105. var sales_sum=document.getElementById("sales_sum").value;
    106. option = null;
    107. var data_time = time.split("_");
    108. var data_sales_sum = sales_sum.split("_");
    109. var data_saleroom = saleroom.split("_");
    110. app.title = '折柱混合';
    111. option = {
    112. tooltip: {
    113. trigger: 'axis',
    114. axisPointer: {
    115. type: 'cross',
    116. crossStyle: {
    117. color: '#999'
    118. }
    119. }
    120. },
    121. toolbox: {
    122. feature: {
    123. dataView: {show: true, readOnly: false},
    124. magicType: {show: true, type: ['line', 'bar']},
    125. restore: {show: true},
    126. saveAsImage: {show: true}
    127. }
    128. },
    129. legend: {
    130. data:[,'销售数量','销售总额']
    131. },
    132. xAxis: [
    133. {
    134. type: 'category',
    135. data: data_time,
    136. axisPointer: {
    137. type: 'shadow'
    138. }
    139. }
    140. ],
    141. yAxis: [
    142. {
    143. type: 'value',
    144. name: '数量',
    145. min: 0,
    146. max: max_count,
    147. interval: Math.ceil(max_count/5),
    148. axisLabel: {
    149. formatter: '{value} 件'
    150. }
    151. },
    152. {
    153. type: 'value',
    154. name: '总额',
    155. min: 0,
    156. max: max_salessum,
    157. interval: Math.ceil(max_salessum/5),
    158. axisLabel: {
    159. formatter: '{value} 元'
    160. }
    161. }
    162. ],
    163. series: [
    164. {
    165. name:'销售数量',
    166. type:'bar',
    167. data:data_sales_sum
    168. },
    169. {
    170. name:'销售总额',
    171. type:'line',
    172. yAxisIndex: 1,
    173. data:data_saleroom
    174. }
    175. ]
    176. };
    177. ;
    178. if (option && typeof option === "object") {
    179. myChart.setOption(option, true);
    180. }
    181. $("#styleselect").change(function(){
    182. var opt=$("#styleselect").val();
    183. if(opt=="day"){
    184. $("#years_div").attr("style","display:none;");
    185. $("#month_div").attr("style","display:inline-block;");
    186. }else{
    187. $("#years_div").attr("style","display:inline-block;");
    188. $("#month_div").attr("style","display:none;");
    189. }
    190. });
    191. $("#sales_report").click(function(){
    192. var time_type = $("#styleselect").val();
    193. if(time_type =="day"){
    194. var month = $("#month").val();
    195. }
    196. window.location.href="index.php?s=/addon/WeiuidStore/web/analysis/time_type/"+time_type+"/month/"+month;
    197. })
    198. </script>
    199. </div>
    200. </div>
    201. </div>
    202. </block>