jquery tabs 切换控制 hicharts 数据

HTML 

<div style="text-align: center" id="call">
    <button class="layui-btn"   value="0">本周</button>
    <button class="layui-btn"   value="1">当月</button>
    <button class="layui-btn"   value="2">上月</button>
    <button class="layui-btn"   value="3">上上月</button>
</div>
 <div id="container_call_distribution" style="min-width:400px;height:400px"></div>

js


$(document).on('click','#call>button',function(){
    var dat = {
        mobilePhone: "<?php echo   $data['mobilePhone'] ;?>",
        time: this.value
    };
    console.log(dat);
    $.post('/index/user/callDistribution',dat,function(res){
        var start_times  = res.start_times;
        var sum_total  = res.sum_total;
        call(start_times,sum_total)
    });

});
$(document).ready(function() {
    var dat = {
        mobilePhone: "<?php echo   $data['mobilePhone'] ;?>",
        time: 4
    };
    console.log(dat);
    $.post('/index/user/callDistribution',dat,function(res){
        var start_times  = res.start_times;
        var sum_total  = res.sum_total;
        call(start_times,sum_total)
    });
});
//24小时通话分布
function call(start_times,sum_total){
    $(function () {
        $('#container_call_distribution').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: '24小时通话分布'
            },
//            subtitle: {
//                text: ''
//            },
            xAxis: {
                categories: start_times,
                crosshair: true
            },
            yAxis: {
                min: 0,
                title: {
                    text: '次数'
                }
            },

            plotOptions: {
                column: {
                    borderWidth: 0
                }
            },
            series: [{
                name:'通话分布',
                data: sum_total
            }]
        });
    });
}




php 


public function callDistribution($mobilePhone='',$time='')
{
    //本周
    $where2 = '';
     if($time==0){
         $week = date('Y-m-d',strtotime('this week Monday',time()));
         $where2['start_time'] = ['>',$week];
    //当月
     }elseif($time==1){
         $lastmonth = date('Y-m-01');
         $where2['start_time'] = ['>',$lastmonth];
     //上月
     }elseif($time==2){
         $lastmonth = date('Y-m-01');
         $beforemonth = date('Y-m-d',strtotime($lastmonth.' -1 month'));
         $where2['start_time'] = array('BETWEEN',array($beforemonth,$lastmonth));
     }elseif($time==3){
         $month = date('Y-m-01');
         $lastmonth = date('Y-m-d',strtotime($month.' -1 month'));
         $beforemonth = date('Y-m-d',strtotime($lastmonth.' -2 month'));
         $where2['start_time'] = array('BETWEEN',array($beforemonth,$lastmonth));
     }elseif($time==4){
         $day = date('Y-m-d',strtotime('-1 day'));
         $where2['start_time'] = ['>',$day];
     }else{
         $week = date('Y-m-d',strtotime('this week Monday',time()));

         $where2['start_time'] = ['>',$week];
     }


    $container_call_distribution = model('CreditMobileCalls')->field("sum(cell_phone=$mobilePhone) sum_total, left(right(start_time,8),2) start_times")
        ->where('cell_phone',$mobilePhone)
        ->where($where2)
        ->group('start_times')
        ->select()->toArray();
    $data['start_times'] = string_conversion(array_column($container_call_distribution,'start_times'));
    $data['sum_total'] = string_conversion(array_column($container_call_distribution,'sum_total'));
    return  $data;
}



start_time  字段 是varchar(255)不能用thinkphp 的 whereTime

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值