"订单量","2"=>"客户数"); $arr_con_time=array("day"=>"一天","half_day"=>"半天","hour"=>"小时"); $json_data.="\"uid\":\"".$uid."\","; switch($cate){ case "ms": $json_data.="\"cate\":\"ms\","; $s_con_time=$s_con_time?$s_con_time:"day"; // $s_zd=""; foreach($arr_zd as $k => $v){ $var="zd_".$k; if($$var=="on") $s_zd.=$k.","; } $s_zd=deel_end($s_zd); $s_zd=$s_zd?$s_zd:"1"; $arr_s_zd=explode(",",$s_zd); //时间条件选项 $tmp=""; foreach($arr_con_time as $k => $v){ $tmp.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},"; } $json_data.="\"con_time\":[".deel_end($tmp)."],"; $json_data.="\"s_con_time\":\"".$s_con_time."\","; //按照天的选项 $q="select substring(add_date,1,11) '_d' from ".$table_pre."log_hd where action>20 and action<25 group by _d order by _d"; $r=$db->query($q); $tmp=""; while($m=$db->fetch_array($r)){ $tmp.="{\"val\":\"".$m["_d"]."\",\"title\":\"".deel_date_format("day",$m["_d"])."\"},"; } $json_data.="\"con_day\":[".deel_end($tmp)."],"; $json_data.="\"s_day\":\"".$s_day."\","; //数据选项 $tmp=""; foreach($arr_zd as $k => $v){ $tmp.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},"; } $json_data.="\"con_zd\":[".deel_end($tmp)."],"; $json_data.="\"s_zd\":\"".$s_zd."\","; //取得数据 $arr_data=array(); if($s_con_time=="day"){ $sql_time="substring(add_date,1,11)"; $con_hour=" where action>20 and action<25"; }else if($s_con_time=="half_day"){ $sql_time="concat(substring(add_date,1,11),' ',case when substring(add_date,12,2)<13 then '1' when substring(add_date,12,2)<19 then '2' else '3' end)"; $con_hour=" where action>20 and action<25"; }else{ $sql_time="concat(substring(add_date,1,11),'',substring(add_date,12,2))"; $con_hour=" where action>20 and action<25 and substring(add_date,1,11)='".$s_day."'"; } //取得时间段数据 $q="select ".$sql_time." as '_t' from ".$table_pre."log_hd".$con_hour." group by _t order by _t"; $r=$db->query($q); $arr_sjd=array(); $tb_data_x=""; while($m=$db->fetch_array($r)){ $arr_sjd[]=$m["_t"]; $tb_data_x.=deel_date_format($s_con_time,$m["_t"]).","; } $tb_data_x=deel_end($tb_data_x); //内容 $q="select ms from ".$table_pre."log_hd where ms<>'' group by ms order by ms"; $r=$db->query($q); $i=0; $total_num=0; $arr_data_js=$arr_data_khs=array(); while($m=$db->fetch_array($r)){ $data_tb_v1=$data_tb_v2=""; for($i1=0;$i11) $tr.=",\"colspan\":".count($arr_s_zd).",\"align\":\"center\""; $tr.="},"; } $thead.="{\"row\":0,\"tr\":[".deel_end($tr)."]},"; //第二行 $tr=""; for($i=0;$i $str_data_js){ $arr_pc[$iid]=get_pc(explode(",",$str_data_js)); $i++; } arsort($arr_pc); //内容 $i=0; $data=""; foreach($arr_pc as $iid => $pc){ // $content1=""; $arr_tmp_js=explode(",",$arr_data_js[$iid]); $arr_tmp_khs=explode(",",$arr_data_khs[$iid]); for($i1=0;$i120 and action<25 and ".$sql_time."<='".$arr_sjd[$i1]."'"); $content1.=",\"num_".$i1."_".$j1."\":\"".add_0($m1["num_2"])."\""; $data_tb_v2.=add_0($m1["num_2"]).","; } } } //合计 $data.="{\"ms\":\"合计\"".$content1."},"; //输出表格数据 $json_data.="\"code\":0,\"msg\":\"\",\"count\":".$i.",\"data\":[".deel_end($data)."],"; //输出图表数据 $data_tb_v1=deel_end($data_tb_v1); $data_tb_v2=deel_end($data_tb_v2); $tb_data_y=""; if($data_tb_v1) $tb_data_y.=$data_tb_v1."|"; if($data_tb_v2) $tb_data_y.=$data_tb_v2."|"; $tb_data_y=deel_end($tb_data_y); $json_data.="\"chart_title\":\"订单模式趋势图\","; $json_data.="\"chart_type\":\"line\","; $json_data.="\"chart_data_x\":\"".$tb_data_x."\","; $json_data.="\"chart_data_y\":\"".$tb_data_y."\","; break; case "client": $json_data.="\"cate\":\"client\","; $s_con_time=$s_con_time?$s_con_time:"day"; // $s_zd=""; foreach($arr_zd as $k => $v){ $var="zd_".$k; if($$var=="on") $s_zd.=$k.","; } $s_zd=deel_end($s_zd); $s_zd=$s_zd?$s_zd:"1"; $arr_s_zd=explode(",",$s_zd); $json_data.="\"s_zd\":\"".$s_zd."\","; //时间条件选项 $tmp=""; foreach($arr_con_time as $k => $v){ $tmp.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},"; } $json_data.="\"con_time\":[".deel_end($tmp)."],"; $json_data.="\"s_con_time\":\"".$s_con_time."\","; //按照天的选项 $q="select substring(add_date,1,11) '_d' from ".$table_pre."log_hd where action>20 and action<25 group by _d order by _d"; $r=$db->query($q); $tmp=""; while($m=$db->fetch_array($r)){ $tmp.="{\"val\":\"".$m["_d"]."\",\"title\":\"".deel_date_format("day",$m["_d"])."\"},"; } $json_data.="\"con_day\":[".deel_end($tmp)."],"; $json_data.="\"s_day\":\"".$s_day."\","; $json_data.="\"s_username\":\"".$s_username."\","; //组合条件 if($s_con_time=="day"){ $sql_time="substring(add_date,1,11)"; $con_hour=" where action>20 and action<25"; }else if($s_con_time=="half_day"){ $sql_time="concat(substring(add_date,1,11),' ',case when substring(add_date,12,2)<13 then '1' when substring(add_date,12,2)<19 then '2' else '3' end)"; $con_hour=" where action>20 and action<25"; }else{ $sql_time="concat(substring(add_date,1,11),'',substring(add_date,12,2))"; $con_hour=" where action>20 and action<25 and substring(add_date,1,11)='".$s_day."'"; } //取得时间段数据 $q="select ".$sql_time." as '_t' from ".$table_pre."log_hd".$con_hour." group by _t order by _t"; $r=$db->query($q); $arr_sjd=array(); $tb_data_x=""; while($m=$db->fetch_array($r)){ $arr_sjd[]=$m["_t"]; $tb_data_x.=deel_date_format($s_con_time,$m["_t"]).","; } $tb_data_x=deel_end($tb_data_x); $con1=""; if($s_username){ $m1=get_db_msg("select id,face,path from ".$table_pre."client where username='".$s_username."'"); if($m1["id"]>0){ if($m1["face"]=="4") $con1.=" and c.id='".$m1["id"]."'"; else $con1.=" and c.path='".$m1["path"]."-".$m1["id"]."'"; }else{ $con1.=" and c.id='0'"; } } //取得数据 $q="select b.uid 'uid',sum(case when b.action in (21,23) then b.num when b.action in (22,24) then -b.num else 0 end) 'num_1' from ".$table_pre."log_hd b,".$table_pre."client c where c.face='4' and b.uid=c.id ".$con1." and b.action>20 and b.action<25 group by b.uid order by num_1 desc"; //echo $q."
"; $r=$db->query($q); $i=0; $total_num=0; $arr_data_js=array(); while($m=$db->fetch_array($r)){ // $data_tb_v1=""; for($i1=0;$i11) $tr.=",\"colspan\":".count($arr_s_zd).",\"align\":\"center\""; $tr.="},"; } $thead.="{\"row\":0,\"tr\":[".deel_end($tr)."]},"; //第二行 $tr=""; for($i=0;$i $str_data_js){ $arr_pc[$iid]=get_pc(explode(",",$str_data_js)); $i++; } arsort($arr_pc); //内容 $i=0; $hj_total_num=0; $data=""; foreach($arr_pc as $uid => $pc){ $m_client=get_db_msg("select username,title from ".$table_pre."client where id='".$uid."'"); $tmp=get_db_msg("select sum(num) 'num' from ".$table_pre."order where ka<>'y' and uid='".$uid."' and _key='".$_key."'"); $tmp_total_num=$tmp["num"]; $hj_total_num+=$tmp_total_num; // $content1=""; $arr_tmp_js=explode(",",$arr_data_js[$iid]); for($i1=0;$i1 $v){ $var="zd_".$k; if($$var=="on") $s_zd.=$k.","; } $s_zd=deel_end($s_zd); $s_zd=$s_zd?$s_zd:"1"; $arr_s_zd=explode(",",$s_zd); //时间条件选项 $tmp=""; foreach($arr_con_time as $k => $v){ $tmp.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},"; } $json_data.="\"con_time\":[".deel_end($tmp)."],"; $json_data.="\"s_con_time\":\"".$s_con_time."\","; //按照天的选项 $q="select substring(add_date,1,11) '_d' from ".$table_pre."log_hd where action>20 and action<25 group by _d order by _d"; $r=$db->query($q); $tmp=""; while($m=$db->fetch_array($r)){ $tmp.="{\"val\":\"".$m["_d"]."\",\"title\":\"".deel_date_format("day",$m["_d"])."\"},"; } $json_data.="\"con_day\":[".deel_end($tmp)."],"; $json_data.="\"s_day\":\"".$s_day."\","; //数据选项 $tmp=""; foreach($arr_zd as $k => $v){ $tmp.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},"; } $json_data.="\"con_zd\":[".deel_end($tmp)."],"; $json_data.="\"s_zd\":\"".$s_zd."\","; $json_data.="\"s_no\":\"".$s_no."\","; //组合条件 if($s_con_time=="day"){ $sql_time="substring(add_date,1,11)"; $con_hour=" where action>20 and action<25"; }else if($s_con_time=="half_day"){ $sql_time="concat(substring(add_date,1,11),' ',case when substring(add_date,12,2)<13 then '1' when substring(add_date,12,2)<19 then '2' else '3' end)"; $con_hour=" where action>20 and action<25"; }else{ $sql_time="concat(substring(add_date,1,11),'',substring(add_date,12,2))"; $con_hour=" where action>20 and action<25 and substring(add_date,1,11)='".$s_day."'"; } //取得时间段数据 $q="select ".$sql_time." as '_t' from ".$table_pre."log_hd".$con_hour." group by _t order by _t"; $r=$db->query($q); $arr_sjd=array(); $tb_data_x=""; while($m=$db->fetch_array($r)){ $arr_sjd[]=$m["_t"]; $tb_data_x.=deel_date_format($s_con_time,$m["_t"]).","; } $tb_data_x=deel_end($tb_data_x); //取得数据 $q="select b.iid 'iid',sum(case when b.action in (21,23) then b.num when b.action in (22,24) then -b.num else 0 end) 'num_1',count(distinct b.uid) 'num_2' from ".$table_pre."log_hd b where b.action>20 and b.action<25 group by b.iid order by num_1 desc"; $r=$db->query($q); $i=0; $total_num=0; $arr_data_js=$arr_data_khs=array(); while($m=$db->fetch_array($r)){ // $data_tb_v1=$data_tb_v2=""; for($i1=0;$i11) $tr.=",\"colspan\":".count($arr_s_zd).",\"align\":\"center\""; $tr.="},"; } $thead.="{\"row\":0,\"tr\":[".deel_end($tr)."]},"; //第二行 $tr=""; for($i=0;$i $str_data_js){ $arr_pc[$iid]=get_pc(explode(",",$str_data_js)); $i++; } arsort($arr_pc); //内容 $i=0; $hj_total_num=0; $data=""; foreach($arr_pc as $iid => $pc){ $m_kh=get_db_msg("select no,id,main_pic,color,xh from ".$table_pre."kh where id='".$iid."'"); if(!$s_no || ($s_no && (strpos(" ".$m_kh["no"],$s_no)!=false))){ $tmp=get_db_msg("select sum(num) 'num' from ".$table_pre."order where ka<>'y' and iid='".$iid."' and _key='".$_key."'"); $tmp_total_num=$tmp["num"]; $hj_total_num+=$tmp_total_num; // $content1=""; $arr_tmp_js=explode(",",$arr_data_js[$iid]); $arr_tmp_khs=explode(",",$arr_data_khs[$iid]); for($i1=0;$i120 and action<25 and ".$sql_time."<='".$arr_sjd[$i1]."'"); $content1.=",\"num_".$i1."_".$j1."\":\"".add_0($m1["num_2"])."\""; $data_tb_v2.=add_0($m1["num_2"]).","; } } } //合计 $data.="{\"xh\":\"合计\",\"id\":\"0\",\"kh\":\"\",\"total_num\":\"".$hj_total_num."\"".$content1."},"; //输出表格数据 $json_data.="\"code\":0,\"msg\":\"\",\"count\":".$i.",\"data\":[".deel_end($data)."],"; //输出图表数据 $data_tb_v1=deel_end($data_tb_v1); $data_tb_v2=deel_end($data_tb_v2); $tb_data_y=""; if($data_tb_v1) $tb_data_y.=$data_tb_v1."|"; if($data_tb_v2) $tb_data_y.=$data_tb_v2."|"; $tb_data_y=deel_end($tb_data_y); $json_data.="\"chart_title\":\"订单趋势图\","; $json_data.="\"chart_type\":\"line\","; $json_data.="\"chart_data_x\":\"".$tb_data_x."\","; $json_data.="\"chart_data_y\":\"".$tb_data_y."\","; break; } $json_data=substr($json_data,0,-1)."}"; echo $json_data; ?>