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.=""; if(in_array("je",$arr_zb_type)) $content.=""; if(in_array("js",$arr_zb_type)) $content.=""; $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.=""; if(in_array("je",$arr_zb_type)) $content.=""; if(in_array("js",$arr_zb_type)) $content.=""; $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.=""; if(in_array("je",$arr_zb_type)) $content.=""; if(in_array("js",$arr_zb_type)) $content.=""; $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.=""; if(in_array("je",$arr_zb_type)) $content.=""; if(in_array("js",$arr_zb_type)) $content.=""; $content.=""; } } } $content.="
客户品牌指标金额(万)指标件数
代理:".$m["title"]."(".$m["username"].")".$m2["title"]."".$m1["zb"]."".$m1["zb_js"]."
区域:".$m["title"]."(".$m["username"].")".$m2["title"]."".$m1["zb"]."".$m1["zb_js"]."
客户指标金额(万)指标件数
代理:".$m["title"]."(".$m["username"].")".$m1["zb"]."".$m1["zb_js"]."
区域:".$m["title"]."(".$m["username"].")".$m1["zb"]."".$m1["zb_js"]."
"; } ?> 自动合计客户指标
自动合计客户指标