connect($dbhost,$dbuser,$dbpw,$dbname,"p");
$is_brand=get_set("is_brand");
$zb_type=get_set("zb_type");
$arr_zb_type=explode(",",$zb_type);
$arr_hj_type=array("qy"=>"合计区域","dl"=>"合计代理");
$sub=$_POST["sub"];
$hj_type=$_POST["hj_type"]?$_POST["hj_type"]:array("1","2");
$content="
";
if($sub=="y"){
if($is_brand=="y"){
$content.="| 客户 | 品牌 | ";
if(in_array("je",$arr_zb_type))
$content.="指标金额(万) | ";
if(in_array("js",$arr_zb_type))
$content.="指标件数 | ";
$content.=" ";
if(in_array("dl",$hj_type)){
//合计代理指标
$q="select * from ".$table_pre."client where face='3'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$q2="select * from ".$table_pre."keyword where cate='brand'";
$r2=$db->query($q2);
while($m2=$db->fetch_array($r2)){
$m1=get_db_msg("select sum(b.zb) 'zb',sum(b.zb_js) 'zb_js' from ".$table_pre."client_brand b,".$table_pre."client c where b.cid=c.id and b.brand='".$m2["no"]."' and c.path='".$m["path"]."-".$m["id"]."'");
$tmp1=get_db_msg("select id from ".$table_pre."client_brand where cid='".$m["id"]."' and brand='".$m2["no"]."'");
if($tmp1["id"]>0){
$q1="update ".$table_pre."client_brand set zb='".$m1["zb"]."',zb_js='".$m1["zb_js"]."' where id='".$tmp1["id"]."'";
}else{
$q1="insert into ".$table_pre."client_brand (cid,brand,zb,zb_js) values ('".$m["id"]."','".$m2["no"]."','".$m1["zb"]."','".$m1["zb_js"]."')";
}
$db->query($q1);
$content.="| 代理:".$m["title"]."(".$m["username"].") | ".$m2["title"]." | ";
if(in_array("je",$arr_zb_type))
$content.="".$m1["zb"]." | ";
if(in_array("js",$arr_zb_type))
$content.="".$m1["zb_js"]." | ";
$content.=" ";
}
}
}
if(in_array("qy",$hj_type)){
//合计区域指标
$q="select * from ".$table_pre."client where face='9'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$q2="select * from ".$table_pre."keyword where cate='brand'";
$r2=$db->query($q2);
while($m2=$db->fetch_array($r2)){
$m1=get_db_msg("select sum(b.zb) 'zb',sum(b.zb_js) 'zb_js' from ".$table_pre."client_brand b,".$table_pre."client c where b.cid=c.id and b.brand='".$m2["no"]."' and c.path='".$m["path"]."-".$m["id"]."'");
$tmp1=get_db_msg("select id from ".$table_pre."client_brand where cid='".$m["id"]."' and brand='".$m2["no"]."'");
if($tmp1["id"]>0){
$q1="update ".$table_pre."client_brand set zb='".$m1["zb"]."',zb_js='".$m1["zb_js"]."' where id='".$tmp1["id"]."'";
}else{
$q1="insert into ".$table_pre."client_brand (cid,brand,zb,zb_js) values ('".$m["id"]."','".$m2["no"]."','".$m1["zb"]."','".$m1["zb_js"]."')";
}
$db->query($q1);
$content.="| 区域:".$m["title"]."(".$m["username"].") | ".$m2["title"]." | ";
if(in_array("je",$arr_zb_type))
$content.="".$m1["zb"]." | ";
if(in_array("js",$arr_zb_type))
$content.="".$m1["zb_js"]." | ";
$content.=" ";
}
}
}
}else{
$content.="| 客户 | ";
if(in_array("je",$arr_zb_type))
$content.="指标金额(万) | ";
if(in_array("js",$arr_zb_type))
$content.="指标件数 | ";
$content.=" ";
if(in_array("dl",$hj_type)){
//合计代理指标
$q="select * from ".$table_pre."client where face='3'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$m1=get_db_msg("select sum(zb) 'zb',sum(zb_js) 'zb_js' from ".$table_pre."client where path='".$m["path"]."-".$m["id"]."'");
$q1="update ".$table_pre."client set zb='".$m1["zb"]."',zb_js='".$m1["zb_js"]."' where id='".$m["id"]."'";
$db->query($q1);
$content.="| 代理:".$m["title"]."(".$m["username"].") | ";
if(in_array("je",$arr_zb_type))
$content.="".$m1["zb"]." | ";
if(in_array("js",$arr_zb_type))
$content.="".$m1["zb_js"]." | ";
$content.=" ";
}
}
if(in_array("qy",$hj_type)){
//合计区域指标
$q="select * from ".$table_pre."client where face='9'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$m1=get_db_msg("select sum(zb) 'zb',sum(zb_js) 'zb_js' from ".$table_pre."client where path='".$m["path"]."-".$m["id"]."'");
$q1="update ".$table_pre."client set zb='".$m1["zb"]."',zb_js='".$m1["zb_js"]."' where id='".$m["id"]."'";
$db->query($q1);
$content.="| 区域:".$m["title"]."(".$m["username"].") | ";
if(in_array("je",$arr_zb_type))
$content.="".$m1["zb"]." | ";
if(in_array("js",$arr_zb_type))
$content.="".$m1["zb_js"]." | ";
$content.=" ";
}
}
}
$content.=" |
";
}
?>