"序号",
"price"=>"价格",
"title"=>"款式名",
"series"=>get_cate_title_no("arr_select","series"),
"season"=>get_cate_title_no("arr_select","season"),
"bc"=>get_cate_title_no("arr_select","bc"),
"category"=>get_cate_title_no("arr_select","category"),
"category1"=>get_cate_title_no("arr_select","category1"),
"designer"=>get_cate_title_no("arr_select","designer")
);
//---------priv
$priv=return_priv($_cid,$msg_login_user["priv"]);
//echo $priv[0]."-".$priv[1]."
";
$arr_report=array("top"=>"Top分析","ks_qs"=>"款式行为分析","client_qs"=>"客户行为分析","ms"=>"订货模式分析","client_active"=>"客户活跃度","ks_active"=>"款式活跃度","hd_active"=>"设备活跃度","detail"=>"客户行为明细");
$_a=$_a?$_a:"top";
$arr_con_time=array("day"=>"一天","half_day"=>"半天","hour"=>"小时");
$arr_zd=array("1"=>"订单量","2"=>"客户数");
switch($_a){
//ok
case "view_kh":
$json_data.="\"thiscase\":\"view_kh\",";
$json_data.="\"id\":\"".$id."\",";
$msg=get_db_msg("select * from ".$table_pre."kh where id='".$id."'");
//取得动作
$arr_action=array();
$q="select action from ".$table_pre."log_hd where iid='".$id."' group by action order by action";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$arr_action[$m["action"]]=get_main_value($arr_log_hd_action,$m["action"]);
}
//
$arrzd=$s_action?explode(",",$s_action):array();
$th_zd="";
foreach($arr_action as $k1 => $v1){
if(in_array($k1,$arrzd) || !$s_action){
$sign="y";
}else{
$sign="n";
}
$th_zd.="{\"no\":\"".$k1."\",\"title\":\"".$v1."\",\"sign\":\"".$sign."\"},";
}
$json_data.="\"th_zd\":[".substr($th_zd,0,-1)."],";
//查询店铺
$json_data.="\"s_username\":\"".$s_username."\",";
//表头
$thead_str="";
$thead_str.="{\"zd\":\"list\",\"title\":\"次序\"},";
$thead_str.="{\"zd\":\"kh\",\"title\":\"客户\"},";
$thead_str.="{\"zd\":\"client\",\"title\":\"客户端\"},";
$thead_str.="{\"zd\":\"ipaddress\",\"title\":\"IP地址\"},";
$thead_str.="{\"zd\":\"action1\",\"title\":\"动作\"},";
$thead_str.="{\"zd\":\"object1\",\"title\":\"对象\"},";
$thead_str.="{\"zd\":\"num\",\"title\":\"数量\"},";
$thead_str.="{\"zd\":\"lasttime\",\"title\":\"最后操作时间\"}";
$json_data.="\"thead_str\":[".$thead_str."],";
$pic=get_kh_picture($msg["no"],$msg["main_pic"],$msg["color"]);
$picarr=out_good_pic_set_arr($pic,200,200);
$json_data.="\"picsrc\":\"".$pic."\",";
$json_data.="\"picw\":\"".$picarr[0]."\",";
$json_data.="\"pich\":\"".$picarr[1]."\",";
//构建查询条件
$sql_con="";
if($s_username){
$tmp=get_db_msg("select id from ".$table_pre."client where username='".$s_username."'");
$sql_con.=" and uid='".$tmp["id"]."'";
}
if($s_action){
$tmp="";
for($i=0;$i";
$r=$db->query($q);
$i=0;
while($m=$db->fetch_array($r)){
$list=$i+1;
$m_client=get_db_msg("select * from ".$table_pre."client where id='".$m["uid"]."'");
$tmp=get_db_msg("select * from ".$table_pre."kh where id='".$m["iid"]."'");
$dx=$tmp["no"];
$tbody_str.="{";
$tbody_str.="\"list\":\"".$list."\",";
$tbody_str.="\"kh\":\"".$m_client["title"]."(".$m_client["username"].")\",";
$tbody_str.="\"client\":\"".$m["hd_type"]."\",";
$tbody_str.="\"ipaddress\":\"".$m["ip"]."\",";
$tbody_str.="\"action1\":\"".get_main_value($arr_log_hd_action,$m["action"])."\",";
$tbody_str.="\"object1\":\"".$dx."\",";
$tbody_str.="\"num\":\"".$m["num"]."\",";
$tbody_str.="\"lasttime\":\"".deel_add_date($m["add_date"])."\"";
$tbody_str.="},";
$i++;
}
$json_data.="\"tbody_str\":[".substr($tbody_str,0,-1)."],";
break;
//ok
case "view_client":
$json_data.="\"id\":\"".$id."\",";
$msg=get_db_msg("select * from ".$table_pre."client where id='".$id."'");
//取得动作
$arr_action=array();
$q="select action from ".$table_pre."log_hd where uid='".$id."' group by action order by action";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$arr_action[$m["action"]]=get_main_value($arr_log_hd_action,$m["action"]);
}
//
$arrzd=$s_action?explode(",",$s_action):array();
$th_zd="";
foreach($arr_action as $k1 => $v1){
if(in_array($k1,$arrzd) || !$s_action){
$sign="y";
}else{
$sign="n";
}
$th_zd.="{\"no\":\"".$k1."\",\"title\":\"".$v1."\",\"sign\":\"".$sign."\"},";
}
$json_data.="\"th_zd\":[".substr($th_zd,0,-1)."],";
//查询款号
$json_data.="\"thiscase\":\"view_client\",";
$json_data.="\"s_kh\":\"".$s_kh."\",";
//表头
$thead_str="";
$thead_str.="{\"zd\":\"list\",\"title\":\"次序\"},";
$thead_str.="{\"zd\":\"action1\",\"title\":\"动作\"},";
$thead_str.="{\"zd\":\"object1\",\"title\":\"对象\"},";
$thead_str.="{\"zd\":\"num\",\"title\":\"数量\"},";
$thead_str.="{\"zd\":\"lasttime\",\"title\":\"最后操作时间\"}";
$json_data.="\"thead_str\":[".$thead_str."],";
//构建查询条件
$sql_con="";
if($s_kh){
$tmp=get_db_msg("select id from ".$table_pre."kh where no='".$s_kh."'");
$sql_con.=" and iid='".$tmp["id"]."'";
}
if($s_action){
$tmp="";
for($i=0;$iquery($q);
$i=0;
while($m=$db->fetch_array($r)){
$list=$i+1;
$tmp=get_db_msg("select no from ".$table_pre."kh where id='".$m["iid"]."'");
$dx=$tmp["no"];
$tbody_str.="{";
$tbody_str.="\"list\":\"".$list."\",";
$tbody_str.="\"action1\":\"".get_main_value($arr_log_hd_action,$m["action"])."\",";
$tbody_str.="\"object1\":\"".$dx."\",";
$tbody_str.="\"num\":\"".$m["num"]."\",";
$tbody_str.="\"lasttime\":\"".deel_add_date($m["add_date"])."\"";
$tbody_str.="},";
$i++;
}
$json_data.="\"tbody_str\":[".substr($tbody_str,0,-1)."],";
break;
//ok
case "view_hd":
$json_data.="\"thiscase\":\"view_hd\",";
//表头
$thead_str="";
$thead_str.="{\"zd\":\"list\",\"title\":\"次序\"},";
$thead_str.="{\"zd\":\"kh\",\"title\":\"客户\"},";
$thead_str.="{\"zd\":\"client\",\"title\":\"客户端\"},";
$thead_str.="{\"zd\":\"action1\",\"title\":\"动作\"},";
$thead_str.="{\"zd\":\"object1\",\"title\":\"对象\"},";
$thead_str.="{\"zd\":\"num\",\"title\":\"数量\"},";
$thead_str.="{\"zd\":\"lasttime\",\"title\":\"最后操作时间\"}";
$json_data.="\"thead_str\":[".$thead_str."],";
$q="select * from ".$table_pre."log_hd where ip='".$ip."' order by add_date";
$r=$db->query($q);
$i=0;
while($m=$db->fetch_array($r)){
$list=$i+1;
$m_client=get_db_msg("select * from ".$table_pre."client where id='".$m["uid"]."'");
$m_=get_db_msg("select * from ".$table_pre."client where id='".$m["uid"]."'");
$tmp=get_db_msg("select * from ".$table_pre."kh where id='".$m["iid"]."'");
$dx=$tmp["no"];
$tbody_str.="{";
$tbody_str.="\"list\":\"".$list."\",";
$tbody_str.="\"kh\":\"".$m_client["title"]."(".$m_client["username"].")\",";
$tbody_str.="\"client\":\"".$m["hd_type"]."\",";
$tbody_str.="\"action1\":\"".get_main_value($arr_log_hd_action,$m["action"])."\",";
$tbody_str.="\"object1\":\"".$dx."\",";
$tbody_str.="\"num\":\"".$m["num"]."\",";
$tbody_str.="\"lasttime\":\"".deel_add_date($m["add_date"])."\"";
$tbody_str.="},";
$i++;
}
$json_data.="\"tbody_str\":[".substr($tbody_str,0,-1)."],";
break;
//ok
case "ks_qs":
$s_con_time=$s_con_time?$s_con_time:"day";
//$s_day=$s_day?$s_day:$default_day;
$json_data.="\"s_no\":\"".$s_no."\",";
//
$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);
//-----------------------tab
$str_tab="";
$i=0;
foreach($arr_report as $k => $v){
$str_tab.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},";
}
$str_tab=deel_end($str_tab);
$json_data.="\"tab\":[".$str_tab."],";
//-----------------------/tab
$json_data.="\"s_cate\":\"".$_a."\",";
//时间条件选项
$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."\",";
//组合条件
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;
//ok
case "client_qs":
//-----------------------tab
$str_tab="";
$i=0;
foreach($arr_report as $k => $v){
$str_tab.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},";
}
$str_tab=deel_end($str_tab);
$json_data.="\"tab\":[".$str_tab."],";
//-----------------------/tab
$json_data.="\"s_cate\":\"".$_a."\",";
$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){
$str_tab.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},";
}
$str_tab=deel_end($str_tab);
$json_data.="\"tab\":[".$str_tab."],";
//-----------------------/tab
$json_data.="\"s_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;
//ok
case "delete":
$id=(is_array($id))?$id:array($id);
$num=count($id);
for($i=0;$i<$num;$i++){
$tmp=get_db_msg("select * from ".$table_pre."log_hd where id='".$id[$i]."'");
$db->query("delete from ".$table_pre."log_hd where id='".$id[$i]."'");
$lid.=$tmp["uid"]."|".$id[$i].", ";
}
$lid=substr($lid,0,-2);
set_log("删除客户行为",$lid);
$json_data.="\"code\":1,";
break;
//ok
case "ks_active":
//-----------------------tab
$str_tab="";
$i=0;
foreach($arr_report as $k => $v){
$str_tab.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},";
}
$str_tab=deel_end($str_tab);
$json_data.="\"tab\":[".$str_tab."],";
//-----------------------/tab
$json_data.="\"s_cate\":\"ks_active\",";
//
$s_order_by=$s_order_by?$s_order_by:"num";
//排序
$arr_order_by=array("num"=>"活跃度","add_date"=>"最后操作时间");
$tmp_order_by="";
foreach($arr_order_by as $k=>$v){
$tmp_order_by.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},";
}
$json_data.="\"select_order_by\":[".deel_end($tmp_order_by)."],";
$json_data.="\"s_order_by\":\"".$s_order_by."\",";
//
$json_data.="\"s_xh\":\"".$s_xh."\",";
$json_data.="\"s_no\":\"".$s_no."\",";
//
$arrzd=$s_zd?explode(",",$s_zd):array("xh","bc","category");
$th_zd="";
$zd_ct=0;
foreach($arr_zd_kh as $k1 => $v1){
if(in_array($k1,$arrzd)){
$sign="y";
$zd_ct++;
}else{
$sign="n";
}
$th_zd.="{\"no\":\"".$k1."\",\"title\":\"".$v1."\",\"sign\":\"".$sign."\"},";
}
$json_data.="\"th_zd\":[".substr($th_zd,0,-1)."],";
//-----------------------/search
$thead_str="";
$thead_str.="{\"zd\":\"list\",\"title\":\"次序\"},";
$thead_str.="{\"zd\":\"no\",\"title\":\"款号\"},";
$colnum=0;
foreach($arr_zd_kh as $k1 => $v1){
if(in_array($k1,$arrzd)){
$thead_str.="{\"zd\":\"".$k1."\",\"title\":\"".get_main_value($arr_zd_kh,$k1)."\"},";
$colnum++;
}
}
$thead_str.="{\"zd\":\"hyd\",\"title\":\"活跃度\"},";
$thead_str.="{\"zd\":\"lasttime\",\"title\":\"最后操作时间\"}";
$json_data.="\"thead_str\":[".$thead_str."],";
$json_code="\"codeerr\":1,";
$sql_con="";
if($s_xh){
$tmp=get_db_msg("select id from ".$table_pre."kh where xh='".$s_xh."'");
if($tmp["id"]>0){
$sql_con.=" and a.iid='".$tmp["id"]."'";
}else{
$json_code="\"codeerr\":0,\"msgerr\":\"序号有误\",";
}
}
if($s_no){
$sql_con.=" and b.no like '%".$s_no."%'";
}
$json_data.=$json_code;
//
$query="select a.iid 'iid',count(a.iid) 'num',max(a.add_date) 'add_date',b.no 'no',b.xh 'xh' from ".$table_pre."log_hd a, ".$table_pre."kh b where a.iid=b.id and a.action<>'51' and a.iid>0".$sql_con." group by a.iid order by ".$s_order_by." desc";
//echo $query."
";
$res=$db->query($query);
$count=0;
$total_num=0;
while($m=$db->fetch_array($res)){
$list=$count+1;
$m1=get_db_msg("select * from ".$table_pre."kh where id='".$m["iid"]."'");
$total_num+=$m["num"];
//图片获取规则
$pic=get_kh_picture($m1["no"],$m1["main_pic"],$m1["color"]);
$tbody_str.="{";
$tbody_str.="\"id\":\"".$m["iid"]."\",";
$tbody_str.="\"list\":\"".$list."\",";
$tbody_str.="\"no\":\"".$m1["no"]."\",";
$tbody_str.="\"khpic\":\"".$pic."\",";
foreach($arr_zd_kh as $k1 => $v1){
if(in_array($k1,$arrzd)){
if($k1=="title" || $k1=="price" || $k1=="xh"){
$tbody_str.="\"".$k1."\":\"".deel_td($m1[$k1])."\",";
}else{
$tbody_str.="\"".$k1."\":\"".deel_td(get_cate_title_no($k1,$m1[$k1]))."\",";
}
}
}
$tbody_str.="\"hyd\":\"".$m["num"]."\",";
$tbody_str.="\"lasttime\":\"".deel_add_date($m["add_date"])."\"";
$tbody_str.="},";
$count++;
}
$json_data.="\"tbody_str\":[".substr($tbody_str,0,-1)."],";
$json_data.="\"total_num\":\"".$total_num."\",";
$json_data.="\"hjcol\":\"".($colnum+2)."\",";
break;
//ok
case "client_active":
//-----------------------tab
$str_tab="";
$i=0;
foreach($arr_report as $k => $v){
$str_tab.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},";
}
$str_tab=deel_end($str_tab);
$json_data.="\"tab\":[".$str_tab."],";
//-----------------------/tab
$json_data.="\"s_cate\":\"client_active\",";
$s_order_by=$s_order_by?$s_order_by:"num";
//
$tmp_client_face="";
foreach($arr_client_face as $k=>$v){
$tmp_client_face.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},";
}
$json_data.="\"select_client_face\":[".deel_end($tmp_client_face)."],";
$json_data.="\"s_face\":\"".$s_face."\",";
//客户端
$arr_khd=array("ipad"=>"ipad","pad8"=>"pad8","mobile"=>"mobile");
$tmp_khd="";
foreach($arr_khd as $k=>$v){
$tmp_khd.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},";
}
$json_data.="\"select_khd\":[".deel_end($tmp_khd)."],";
$json_data.="\"s_khd\":\"".$s_khd."\",";
//排序
$arr_order_by=array("num"=>"活跃度","add_date"=>"最后操作时间");
$tmp_order_by="";
foreach($arr_order_by as $k=>$v){
$tmp_order_by.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},";
}
$json_data.="\"select_order_by\":[".deel_end($tmp_order_by)."],";
$json_data.="\"s_order_by\":\"".$s_order_by."\",";
//
$json_data.="\"s_username\":\"".$s_username."\",";
$json_data.="\"s_title\":\"".$s_title."\",";
//-----------------------/search
//表头
$thead_str="";
$thead_str.="{\"zd\":\"list\",\"title\":\"次序\"},";
$thead_str.="{\"zd\":\"kh\",\"title\":\"客户\"},";
$thead_str.="{\"zd\":\"juese\",\"title\":\"角色\"},";
$thead_str.="{\"zd\":\"client\",\"title\":\"客户端\"},";
$thead_str.="{\"zd\":\"hyd\",\"title\":\"活跃度\"},";
$thead_str.="{\"zd\":\"lasttime\",\"title\":\"最后操作时间\"},";
$json_data.="\"thead_str\":[".substr($thead_str,0,-1)."],";
$sql_con="";
if($s_username){
$sql_con.=" and b.username like '%".$s_username."%'";
}
if($s_title){
$sql_con.=" and b.title like '%".$s_title."%'";
}
if($s_khd){
$sql_con.=" and a.hd_type='".$s_khd."'";
}
if($s_face){
$sql_con.=" and b.face='".$s_face."'";
}
//
$tbody_str="";
$query="select a.uid 'uid',a.hd_type 'hd_type',count(a.uid) 'num',max(a.add_date) 'add_date',b.face 'face',b.username 'username',b.title 'title' from ".$table_pre."log_hd a, ".$table_pre."client b where a.uid=b.id".$sql_con." group by a.uid order by ".$s_order_by." desc";
//echo $query."
";
$res=$db->query($query);
$count=0;
$total_num=0;
while($m=$db->fetch_array($res)){
$list=$count+1;
$total_num+=$m["num"];
$tbody_str.="{";
$tbody_str.="\"id\":\"".$m["uid"]."\",";
$tbody_str.="\"list\":\"".$list."\",";
$tbody_str.="\"kh\":\"".$m["title"]."(".$m["username"].")\",";
$tbody_str.="\"juese\":\"".get_main_value($arr_client_face,$m["face"])."\",";
$tbody_str.="\"client\":\"".$m["hd_type"]."\",";
$tbody_str.="\"hyd\":\"".$m["num"]."\",";
$tbody_str.="\"lasttime\":\"".deel_add_date($m["add_date"])."\"";
$tbody_str.="},";
$count++;
}
$json_data.="\"tbody_str\":[".substr($tbody_str,0,-1)."],";
$json_data.="\"total_num\":\"".$total_num."\",";
break;
//ok
case "hd_active":
//-----------------------tab
$str_tab="";
$i=0;
foreach($arr_report as $k => $v){
$str_tab.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},";
}
$str_tab=deel_end($str_tab);
$json_data.="\"tab\":[".$str_tab."],";
//-----------------------/tab
$json_data.="\"s_cate\":\"hd_active\",";
$s_order_by=$s_order_by?$s_order_by:"num";
//排序
$arr_order_by=array("num"=>"活跃度","add_date"=>"最后操作时间");
$tmp_order_by="";
foreach($arr_order_by as $k=>$v){
$tmp_order_by.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},";
}
$json_data.="\"select_order_by\":[".deel_end($tmp_order_by)."],";
$json_data.="\"s_order_by\":\"".$s_order_by."\",";
$json_data.="\"s_ip\":\"".$s_ip."\",";
//-----------------------/search
//表头
$thead_str="";
$thead_str.="{\"zd\":\"list\",\"title\":\"次序\"},";
$thead_str.="{\"zd\":\"ipaddress\",\"title\":\"IP地址\"},";
$thead_str.="{\"zd\":\"lx\",\"title\":\"类型\"},";
$thead_str.="{\"zd\":\"hyd\",\"title\":\"活跃度\"},";
$thead_str.="{\"zd\":\"lasttime\",\"title\":\"最后操作时间\"},";
$json_data.="\"thead_str\":[".substr($thead_str,0,-1)."],";
//
$sql_con="";
if($s_ip){
$sql_con.=" where ip like '%".$s_ip."%'";
}
$query="select ip,hd_type,count(ip) 'num',max(add_date) 'add_date' from ".$table_pre."log_hd ".$sql_con." group by ip order by ".$s_order_by." desc";
//echo $query."
";
$res=$db->query($query);
$count=0;
$total_num=0;
while($m=$db->fetch_array($res)){
$list=$count+1;
$total_num+=$m["num"];
$tbody_str.="{";
$tbody_str.="\"list\":\"".$list."\",";
$tbody_str.="\"ipaddress\":\"".$m["ip"]."\",";
$tbody_str.="\"lx\":\"".$m["hd_type"]."\",";
$tbody_str.="\"hyd\":\"".$m["num"]."\",";
$tbody_str.="\"lasttime\":\"".deel_add_date($m["add_date"])."\"";
$tbody_str.="},";
$count++;
}
$json_data.="\"tbody_str\":[".substr($tbody_str,0,-1)."],";
$json_data.="\"total_num\":\"".$total_num."\",";
break;
//ok
case "detail":
//-----------------------tab
$str_tab="";
$i=0;
foreach($arr_report as $k => $v){
$str_tab.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},";
}
$str_tab=deel_end($str_tab);
$json_data.="\"tab\":[".$str_tab."],";
//-----------------------/tab
$json_data.="\"s_cate\":\"detail\",";
//
$page=$page>0?$page:1;
$limit=$limit>0?$limit:10;
$start=($page-1)*$limit;
$end=$limit;
//
$json_data.="\"s_username\":\"".$s_username."\",";
$json_data.="\"s_no\":\"".$s_no."\",";
$json_data.="\"s_ip\":\"".$s_ip."\",";
//
$tmp_client_face="";
foreach($arr_client_face as $k=>$v){
$tmp_client_face.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},";
}
$json_data.="\"select_client_face\":[".deel_end($tmp_client_face)."],";
$json_data.="\"s_face\":\"".$s_face."\",";
//客户端
$arr_khd=array("ipad"=>"ipad","pad8"=>"pad8","mobile"=>"mobile");
$tmp_khd="";
foreach($arr_khd as $k=>$v){
$tmp_khd.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},";
}
$json_data.="\"select_khd\":[".deel_end($tmp_khd)."],";
$json_data.="\"s_khd\":\"".$s_khd."\",";
//
$tmp_ms="";
$q="select ms from ".$table_pre."log_hd group by ms order by ms";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$tmp_ms.="{\"val\":\"".$m["ms"]."\",\"title\":\"".$m["ms"]."\"},";
}
$json_data.="\"select_ms\":[".deel_end($tmp_ms)."],";
$json_data.="\"s_ms\":\"".$s_ms."\",";
//
$tmp_action="";
foreach($arr_log_hd_action as $k=>$v){
$tmp_action.="{\"val\":\"".$k."\",\"title\":\"".$v."\"},";
}
$json_data.="\"select_action\":[".deel_end($tmp_action)."],";
$json_data.="\"s_action\":\"".$s_action."\",";
//
$sql_con="";
if($s_ip || $s_username || $s_no || $s_face || $s_khd || $s_ms || $s_action){
if($s_khd)
$sql_con.=" and a.hd_type='".$s_khd."'";
if($s_face)
$sql_con.=" and b.face='".$s_face."'";
if($s_ms)
$sql_con.=" and a.ms='".$s_ms."'";
if($s_action)
$sql_con.=" and a.action='".$s_action."'";
if($s_username)
$sql_con.=" and b.username='".$s_username."'";
if($s_no){
$tmp=get_db_msg("select id from ".$table_pre."kh where no like '%".$s_no."%' order by xh limit 0,1");
$sql_con.=" and a.iid='".$tmp["id"]."'";
}
if($s_ip)
$sql_con.=" and a.ip like '%".$s_ip."%'";
}
if($s_no && $s_username)
$sql_order="uid,iid,add_date";
else if($s_no)
$sql_order="uid,add_date";
else if($s_username)
$sql_order="iid,add_date";
else
$sql_order="add_date desc";
//取得总条数
$tmp=get_db_msg("select count(*) 'num' from ".$table_pre."log_hd a,".$table_pre."client b where a.uid=b.id ".$sql_con);
$total_num=$tmp["num"];
$json_data.="\"code\":0,\"msg\":\"\",\"count\":".$total_num.",\"data\":[";
//
$query="select a.id 'id',a.iid 'iid',a.action 'action',a.ms 'ms',a.num 'num',a.hd_type 'khd',a.ip 'ip',a.add_date 'add_date',b.face 'face',b.username 'username',b.title 'title' from ".$table_pre."log_hd a,".$table_pre."client b where a.uid=b.id ".$sql_con."order by ".$sql_order." limit ".$start.",".$end;
//echo $query."
";
$res=$db->query($query);
$count=1;
$str_tmp="";
while($msg=$db->fetch_array($res)){
$list=$count+$start;
$str_tmp.="{";
$str_tmp.="\"id\":\"".$msg["id"]."\",";
$str_tmp.="\"list\":\"".$list."\",";
$str_tmp.="\"juese\":\"".get_main_value($arr_client_face,$msg["face"])."\",";
$str_tmp.="\"kh\":\"".$msg["title"]."(".$msg["username"].")\",";
$str_tmp.="\"client\":\"".$msg["khd"]."\",";
$str_tmp.="\"ipaddress\":\"".$msg["ip"]."\",";
$str_tmp.="\"ms\":\"".$msg["ms"]."\",";
$str_tmp.="\"action1\":\"".get_main_value($arr_log_hd_action,$msg["action"])."\",";
if($msg["action"]=="21" || $msg["action"]=="22" || $msg["action"]=="23" || $msg["action"]=="24" || $msg["action"]=="61" || $msg["action"]=="62"){
$tmp=get_db_msg("select * from ".$table_pre."kh where id='".$msg["iid"]."'");
$str_tmp.="\"object1\":\"".$tmp["no"]."\",";
}else{
$str_tmp.="\"object1\":\" \",";
}
$str_tmp.="\"num\":\"".deel_0($msg["num"])."\",";
$str_tmp.="\"cztime\":\"".$msg["add_date"]."\"";
$str_tmp.="},";
$count++;
}
$json_data.=substr($str_tmp,0,-1)."],";
break;
//ok
case "top":
$s_con_time=$s_con_time?$s_con_time:"half_day";
$s_zd=$s_zd?$s_zd:array("1");
$json_data.="\"s_cate\":\"top\",";
$json_data.="\"s_con_time\":\"".$s_con_time."\",";
//-----------------------tab
$str_tab="";
$i=0;
foreach($arr_report as $k => $v){
$str_tab.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},";
}
$str_tab=deel_end($str_tab);
$json_data.="\"tab\":[".$str_tab."],";
//-----------------------/tab
//取得数据
if($s_con_time=="day"){
$sql_time="substring(add_date,1,11)";
}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)";
}
//取得时间段数据
$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();
$data_tb_l="";
while($m=$db->fetch_array($r)){
$arr_sjd[]=$m["_t"];
$data_tb_l.=deel_date_format($s_con_time,$m["_t"]).",";
}
if($data_tb_l)
$data_tb_l=substr($data_tb_l,0,-1);
//内容
$q="select sum(case when action in (21,23) then num when action in (22,24) then -num else 0 end) 'num_1',".$sql_time." '_d' from ".$table_pre."log_hd where action>20 and action<25 group by _d order by _d";
//echo $q."
";
$r=$db->query($q);
$total1=0;
$arr1=$arr_label=array();
$i=0;
while($m=$db->fetch_array($r)){
$arr_label[$i]=deel_date_format($s_con_time,$m["_d"]);
$arr1[$i]=$m["num_1"];
$total1+=$m["num_1"];
$i++;
}
$tb_data_x="";
$tb_data_y=",";
for($i=0;$i