$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();
laravel 模型 unionAll 分页 数据按天进行分组
最新推荐文章于 2024-08-07 16:15:14 发布