PHP输出整月数据

该博客内容涉及SQL查询技术,用于从数据库中提取特定时间段内代理收入的日统计信息。通过聚合和组合操作,计算总收入并进行日期填充,以展示每月的收入分布。此外,还进行了收入的预测,为业务分析提供了数据支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

$date=date('Y-m-d 23:59:59');
$res=DB::table('explor_agent_income_log')
                 ->select(DB::raw('SUM(money) as count'),
                     DB::raw("FROM_UNIXTIME(create_time,'%m.%d') as time"))
                     ->where('agent_pid',$agent_pid)
                     ->where('is_agent',1)
                     ->where('settlement',1)
                     ->whereBetween('create_time',[$firstDay,$lastDay])
                     ->orderBy('create_time','asc')
                     ->groupBy('time')->get()->toArray();
            $allDay=date("t",strtotime($date));
          $count = array_column($res,'count');
            $estimate_income=array_sum($count);
            $time = array_column($res,'time');
            $combine = array_combine($time,$count);
            for($i=1;$i<=$allDay;$i++){
                if($i<10){
                    $day = date('m.'.'0'.$i);
                }else{
                    $day = date('m.'.$i);
                }
                $count=$combine[$day]??0;
                $thirty_total[] = [
                    $day=>$count,
                ];
            }
            $result['income']=$thirty_total;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值