$month=$this->getMonth(11);
$rmonarr=[];
for($i=0;$i<count($month);$i++) {
$mon=substr($month[$i], 5);
if($mon == '01' || $mon == '03' || $mon =='05' || $mon == '07' || $mon =='08' || $mon=='10' ||$mon=='12'){
$end_time=strtotime($month[$i])+24*60*60*30-1;
}else{
$end_time= strtotime($month[$i])+24*60*60*29-1;
}
$ocount=User::where("creat_at","between time",[strtotime($month[$i]),$end_time])->count(); //可变
$rmonarr[$month[$i]]=$ocount;
}
return json(["code"=>0,"data"=>$rmonarr,'msg'=>'会员增长']);
//获取全部月份
private function getMonth($sign)
{
//得到系统的年月
$tmp_date=date("Ym");
//切割出年份
$tmp_year=substr($tmp_date,0,4);
//dump($tmp_year);
//切割出月份
$tmp_mon =substr($tmp_date,4,2);
// dump($tmp_mon);
// 得到当前月份的下几月
$tmp_nextmonth=mktime(0,0,0,$tmp_mon+$sign,1,$tmp_year);
// 得到当前月份的前几月
$datearr=[];
for($i=$sign;$i>=0;$i--)
{
$tmp_forwardmonth=mktime(0,0,0,$tmp_mon-$i,1,$tmp_year);
$datearr[]=$fm_next_month=date("Y-m",$tmp_forwardmonth);
}
//return $fm_next_month=date("Y-m",$tmp_forwardmonth);
return $datearr;
}