laravel 模型 unionAll 分页 数据按天进行分组

            $sday = explode('-',date('Y-m-1'))[2];
            $eday = explode('-',date('Y-m-t'))[2];
            $month = date('n');
            $year = date('Y');
            // dd($month.'===='.$year);
            $where = [];
            $where[] = ['customer','=',$input['customer']];
            // dd($where);
            if(isset($input['start_time']) && $input['start_time'] != ''){
                $sday = date('j',strtotime($input['start_time']));
                $month = date('n',strtotime($input['start_time']));
                $year = date('Y',strtotime($input['start_time']));
            }
            
            if(isset($input['end_time']) && $input['end_time'] != ''){
                $eday = date('j',strtotime($input['end_time']));
                $month = date('n',strtotime($input['end_time']));
                $year = date('Y',strtotime($input['end_time']));
            }
            DB::enableQueryLog();
            $query1 = Sell::wheres($where)
                ->whereRaw("year(from_unixtime(time))={$year} and     
                            month(from_unixtime(time))={$month} and 
                            day(from_unixtime(time))>={$sday} and 
                            day(from_unixtime(time))<={$eday}")
                ->selectRaw('group_concat(distinct id) as 
                             combined_data,group_concat(type) as types,group_concat(time) 
                             as times,date(from_unixtime(time)) as day,count(time) 
                             count')
                ->groupByRaw('day');
                // ->orderByRaw('day desc');
                // ->get()
                // ->toArray();
                
            $query2 = Sre::wheres($where)
                ->whereRaw("year(from_unixtime(time))={$year} and 
                            month(from_unixtime(time))={$month} and 
                            day(from_unixtime(time))>={$sday} and 
                            day(from_unixtime(time))<={$eday}")
                ->selectRaw('group_concat(distinct id) as 
                             combined_data,group_concat(type) as types,group_concat(time) 
                             as times,date(from_unixtime(time)) as day,count(time) 
                             count')
                ->groupByRaw('day');
                // ->orderByRaw('day desc');
                // ->get()
                // ->toArray();
            $unionAllQuery = $query1->unionAll($query2)->orderByRaw('day desc');
            // dd($unionAllQuery->toSql());
            // $mm = $unionAllQuery->paginate($input['size']);
            
            $data = $unionAllQuery->paginate($input['size']);
            // dd($data);
            // dd(DB::getQueryLog());
            $total = $data->total();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值