/**
* 获取指定类型的日期区间
* @param type :1 今天、2 昨天、3 本周、4 上周、5 本月、6 上月、7 本季度、8 上季度、9 本年、10 上年
* @return array
*/
function getTenTypeTime($type)
{
switch ($type) {
case 1:
$start = date("Y-m-d 00:00:00",time());
$end = date("Y-m-d 23:59:59",time());
break;
case 2:
$start = date("Y-m-d 00:00:00",strtotime("-1 day"));
$end = date("Y-m-d 23:59:59",strtotime("-1 day"));
break;
case 3:
$start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y")));
$end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));
break;
case 4:
$start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y")));
$end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y")));
break;
case 5:
$start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
$end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
break;
case 6:
$start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y")));
$end = date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y")));
break;
case 7:
$season = ceil((date('n'))/3);//当月是第几季度
$start = date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y')));
$end = date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y')));
break;
case 8:
$season = ceil((date('n'))/3)-1;//上季度是第几季度
$start = date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y')));
$end = date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y')));
break;
case 9:
$start = date('Y-m-d H:i:s',mktime(0,0,0,1,1,date('Y',time())));
$end = date('Y-m-d H:i:s',mktime(23,59,59,12,31,date('Y',time())));
break;
case 10:
$start = date('Y-m-d H:i:s',mktime(0,0,0,1,1,date('Y',strtotime("-1 year"))));
$end = date('Y-m-d H:i:s',mktime(23,59,59,12,31,date('Y',strtotime("-1 year"))));
break;
default:
$start = date("Y-m-d 00:00:00",time());
$end = date("Y-m-d 23:59:59",time());
break;
}
return ['start' => $start, 'end' => $end];
}