30 05 2015
 //统计最近7天的优惠券

$days = strtotime ( "-6 day" );
//var_dump($days);exit;
$sql="SELECT count(id) as id , date_format(FROM_UNIXTIME( `gettime`),'%y-%m-%d') sdate FROM tp_shopcoupon_record where token='$token' and gettime > '$days' group by sdate"; //时间戳格式化date类型
$shopcoupon_bet=$shopcou_record_model->query($sql);//一星期内每天的领取数量\
$shopcoupon_date='';
$shopcoupon_cntid='';
$shopcou_array=array();
$date=date ( 'y-m-d', strtotime ( "-6 day" ));
$bet=array();
foreach($shopcoupon_bet as $v){
while(strtotime($date)<time()){ //while循环

if(in_array($date, $v)){ 在数组中就执行

if(in_array($v['id'], $shopcou_array[$date])){
$bet[$date]=$shopcou_array[$date];    第二次循环就赋值第一次有的值
}else{
$bet[$date]=array('cnt'=>$v['id']);   赋值本次值
}

}else{

if($shopcou_array[$date]){  否则第一次有

$bet[$date]=$shopcou_array[$date];  赋值第一次的
}else{
$bet[$date]=array('cnt'=>0);   没有就赋值第本次的

}

}
//var_dump( $shopcou_array);

$date=date('y-m-d', strtotime('+1 day',strtotime($date)));
//var_dump($date);
}
$shopcou_array=$bet;  把第本次的赋给他
$date=date ( 'y-m-d', strtotime ( "-6 day" ));


}
for($i=6;$i>=0;$i--){
$shopcoupon_cntid.=$shopcou_array[date ( 'y-m-d', strtotime ( -$i." day" ))]['cnt'].",";  组合成字符串
}

发表评论