"客户代码","brand"=>"品牌代码");
if(in_array("je",$arr_zb_type))
$arr_column_client_brand["zb"]="金额指标";
if(in_array("js",$arr_zb_type))
$arr_column_client_brand["zb_js"]="件数指标";
$json_data="{";
if($priv[0]=="n"){
//没有操作权限
$json_data.="\"error\":\"没有操作权限\",\"code\":0,\"msg\":\"\",\"count\":0,\"data\":[],";
}else{
$json_data.="\"uid\":".$uid.",";
switch($_a){
case "cancel_jd":
$msg=get_db_msg("select username,title from ".$table_pre."client where id='".$cid."'");
//取消交单
$db->query("update ".$table_pre."client_brand set is_jd='n',is_checked='n' where cid='".$cid."' and brand='".$brand."'");
$s_brand=$brand;
update_order_state($uid,$cid,"后台退回订单","");
set_log("后台退回订单",$msg["title"]."(".$msg["username"].")|".get_cate_title_no("brand",$brand)."");
$json_data.="\"code\":1,";
break;
case "export_pl_do":
$arr_column_client=array("username"=>"客户代码","title"=>"客户名称");
$arr_column_pp=array("no"=>"品牌代码","title"=>"品牌名称");
//头
foreach($arr_column_client as $k => $v){
$data["header"][0][]=$v;
}
foreach($arr_column_pp as $k => $v){
$data["header"][0][]=$v;
}
if(in_array("je",$arr_zb_type))
$data["header"][0][]="金额指标";
if(in_array("js",$arr_zb_type))
$data["header"][0][]="件数指标";
//内容
if($source=="1"){
$q="select * from ".$table_pre."client where face='3' or face='4' or face='9'";
$r=$db->query($q);
$row=0;
while($m=$db->fetch_array($r)){
$q1="select * from ".$table_pre."keyword where cate='brand' order by no";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
foreach($arr_column_client as $k => $v){
$data["body"][$row][]=$m[$k];
}
foreach($arr_column_pp as $k => $v){
$data["body"][$row][]=$m1[$k];
}
if(in_array("je",$arr_zb_type))
$data["body"][$row][]="";
if(in_array("js",$arr_zb_type))
$data["body"][$row][]="";
$row++;
}
}
}else{
$q="select * from ".$table_pre."client_brand order by brand,cid";
$r=$db->query($q);
$row=0;
while($m=$db->fetch_array($r)){
$m_client=get_db_msg("select * from ".$table_pre."client where id='".$m["cid"]."'");
foreach($arr_column_client as $k => $v){
$data["body"][$row][]=$m_client[$k];
}
$m_brand=get_db_msg("select * from ".$table_pre."keyword where cate='brand' and no='".$m["brand"]."'");
foreach($arr_column_pp as $k => $v){
$data["body"][$row][]=$m_brand[$k];
}
if(in_array("je",$arr_zb_type))
$data["body"][$row][]=$m["zb"];
if(in_array("js",$arr_zb_type))
$data["body"][$row][]=$m["zb_js"];
$row++;
}
}
$file_name="client_brand_pl_".date("Y-m-d-H-i");
output_excel($file_name,$data);
set_log("导出 多品牌客户批量模板");
break;
//删除
case "del" :
$id=(is_array($id))?$id:array($id);
$num=count($id);
for($i=0;$i<$num;$i++){
$q="delete from ".$table_pre."client_brand where id='".$id[$i]."'";
$db->query($q);
}
$lid=substr($lid,0,-2);
set_log("删除多品牌客户",$lid);
$json_data.="\"code\":1,";
break;
case "add" :
//--------------------------新增
if($id){
$msg=get_db_msg("select * from ".$table_pre."client_brand where id='".$id."'");
$m_client=get_db_msg("select * from ".$table_pre."client where id='".$msg["cid"]."'");
$username=$m_client["username"];
$brand=$msg["brand"];
}else{
$username="";
$brand="";
}
$tmp_brand="";
$q="select * from ".$table_pre."keyword where cate='brand' order by no";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$tmp_brand.="{\"no\":\"".$m["no"]."\",\"title\":\"".$m["title"]."\"},";
}
$tmp_brand=deel_end($tmp_brand);
$json_data.="\"select_brand\":{\"no\":\"s_brand\",\"title\":\"品牌\",\"value\":\"".$brand."\",\"op\":[".$tmp_brand."]},";
if(in_array("je",$arr_zb_type)){
$json_data.="\"s_zbje_sign\":\"y\",";
$json_data.="\"s_zbje\":\"".$msg["zb"]."\",";
}else{
$json_data.="\"s_zbje_sign\":\"n\",";
}
if(in_array("js",$arr_zb_type)){
$json_data.="\"s_zbjs\":\"".$msg["zb_js"]."\",";
$json_data.="\"s_zbjs_sign\":\"y\",";
}else{
$json_data.="\"s_zbjs_sign\":\"n\",";
}
$json_data.="\"s_client\":\"".$username."\",";
break;
case "save_add":
$username=trim($s_client);
$brand=trim($s_brand);
$zb=$s_zbje+1-1;
$zb_js=$s_zbjs;
$msg_client=get_db_msg("select * from ".$table_pre."client where username='".$username."'");
if(!$msg_client["id"]){
$json_data.="\"code\":0,\"msg\":\"客户代码有误!\",";
}else{
//验证
$c=get_db_msg("select count(*) 'num' from ".$table_pre."client_brand where cid='".$msg_client["id"]."' and brand='".$brand."' and id<>'".$id."'");
if($c["num"]>0){
$json_data.="\"code\":0,\"msg\":\"该记录已经存在,请检查!\",";
}else{
if($id){
$query="update ".$table_pre."client_brand set cid='".$msg_client["id"]."',brand='".$brand."',zb='".$zb."',zb_js='".$zb_js."' where id='".$id."'";
$db->query($query);
$log_action="修改";
}else{
$query="insert ".$table_pre."client_brand (cid,brand,zb,zb_js) values ('".$msg_client["id"]."','".$brand."','".$zb."','".$zb_js."')";
$db->query($query);
$iid=$db->insert_id();
$log_action="新增";
}
$lid=$id?$id:$iid;
set_log($log_action."多品牌客户",$brand."|".$msg_client["username"]."|".$zb."|".$zb_js);
$json_data.="\"code\":1,";
}
}
break;
//----------------------------------------------------------------------导入EXCEL
case "import":
//目录权限
$arr_path=array(
"cache"=>"admin/cache"
);
$json_data.="\"path_priv\":[";
$tmp="";
foreach($arr_path as $path_real => $path_title){
$tmp.="{\"title\":\"".$path_title."\",\"priv\":";
if(new_is_writeable($path_real)==1){
$tmp.="\"y\"";
}else{
$tmp.="\"n\"";
}
$tmp.="},";
}
$json_data.=substr($tmp,0,-1)."],";
break;
case "import_check":
$file1=$_FILES["up_file"];
$tmp_file_name=save_tmp_file($file1);
$tmp_content=get_tmp_content($tmp_file_name);
$arr_content=explode("\n",$tmp_content);
$arr_thead=get_table_thead($tmp_content);
$arr_column=check_table_thead($arr_thead,$arr_column_client_brand);
$msg="";
if(count($arr_column[0])==0){
$msg.="未检测到可导入字段,请返回检查EXCEL文件!";
del_tmp_file($tmp_file_name);
$json_data.="\"code\":0,\"msg\":\"".$msg."\",";
}else{
//
$column="";
foreach($arr_column_client_brand as $k => $v){
$column.=$v.",";
}
if($column)
$column=substr($column,0,-1);
$msg1=array();
$msg1[0]=array("可导入正确字段",$column);
//
$column="";
for($i=0;$i".$arr_thead[$i].",";
}
if($column)
$column=substr($column,0,-1);
//
$msg1[1]=array("检测到的有效字段",$column);
//
$total=count($arr_content)-1;
$msg1[2]=array("记录条数",$total);
$m1="";
for($i=0;$iquery("TRUNCATE TABLE web_client_brand;");
}
$json_data.="\"code\":1,\"reload_type\":\"1\",";
$insert_column="";
for($i=0;$i";
$db->query($q);
}
del_tmp_file($tmp_file_name);
$log_remark=$import_flag;
set_log("导入 多品牌数据",$log_remark);
}
break;
//----------------------------------------------------------------------导出数据
case "export":
$column="";
foreach($arr_column_client_brand as $k => $v){
$column.="{\"k\":\"".$k."\",\"t\":\"".$v."\"},";
}
if($column)
$column=substr($column,0,-1);
$json_data.="\"col\":[".$column."],";
break;
case "export_do":
//取得字段选择的值
foreach($arr_column_client_brand as $k => $v){
$var="col_".$k;
if($$var=="on"){
$ex_col[]=$k;
}
}
$num=count($ex_col);
if($num==0)
alert_and_back("请至少选择一个要导出的字段");
for($i=0;$i<$num;$i++){
$data["col"][]='str';
$data["header"][0][]=get_main_value($arr_column_client_brand,$ex_col[$i]);
}
$query="select * from ".$table_pre."client_brand ".$sql_con." order by cid,brand";
$r=$db->query($query);
$row=0;
while($m=$db->fetch_array($r)){
for($i=0;$i<$num;$i++){
$k=$ex_col[$i];
if($k=="cid"){
$tmp=get_db_msg("select username from ".$table_pre."client where id='".trim($m[$k])."'");
$data["body"][$row][]=$tmp["username"];
}else{
$data["body"][$row][]=$m[$k];
}
}
$row++;
}
$file_name="client_brand_".date("Y-m-d-H-i");
output_excel($file_name,$data);
set_log("导出 多品牌客户");
exit;
break;
//-------------主界面
default:
$tmp_brand="";
$q="select * from ".$table_pre."keyword where cate='brand' order by no";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$tmp_brand.="{\"no\":\"".$m["no"]."\",\"title\":\"".$m["title"]."\"},";
}
$tmp_brand=deel_end($tmp_brand);
$json_data.="\"select_brand\":{\"no\":\"s_brand\",\"title\":\"品牌\",\"value\":\"".$s_brand."\",\"op\":[".$tmp_brand."]},";
//
$page=$page>0?$page:1;
$limit=$limit>0?$limit:10;
$start=($page-1)*$limit;
$end=$limit;
//条件
$sql_con="";
if($s_client || $s_brand){
if($s_client)
$sql_con.=" and c.username='".$s_client."'";
if($s_brand)
$sql_con.=" and a.brand='".$s_brand."'";
}
//取得总条数
$tmp=get_db_msg("select count(*) 'num' from ".$table_pre."client_brand a,".$table_pre."client c where a.cid=c.id ".$sql_con);
$total_num=$tmp["num"];
$json_data.="\"code\":0,\"msg\":\"\",\"count\":".$total_num.",\"data\":[";
$count=1;
$str_tmp="";
$sql="select a.id 'id',a.cid 'cid',c.username 'username',c.title 'title',a.brand 'brand',a.zb 'zb',a.zb_js 'zb_js',a.is_jd 'is_jd',a.is_checked 'is_checked' from ".$table_pre."client_brand a,".$table_pre."client c where a.cid=c.id ".$sql_con." order by a.brand,c.username limit ".$start.",".$end;
$res=$db->query($sql);
while($msg=$db->fetch_array($res)){
$list=$count+$start;
$str_tmp.="{";
$str_tmp.="\"ct\":\"".$list."\",";
$str_tmp.="\"id\":\"".$msg["id"]."\",";
$str_tmp.="\"cid\":\"".$msg["cid"]."\",";
$str_tmp.="\"brand\":\"".$msg["brand"]."\",";
$str_tmp.="\"brand_title\":\"".get_cate_title_no("brand",$msg["brand"])."\",";
$str_tmp.="\"client\":\"".$msg["title"]."(".$msg["username"].")\",";
$str_tmp.="\"zbje\":\"".$msg["zb"]."\",";
if($msg["is_jd"]=="y" || $msg["is_checked"]=="y"){
$str_tmp.="\"is_back_order\":\"y\",";
$str_tmp.="\"cz\":\"退回订单\",";
}else{
$str_tmp.="\"is_back_order\":\"n\",";
$str_tmp.="\"cz\":\"\",";
}
$str_tmp.="\"zbjs\":\"".$msg["zb_js"]."\"";
$str_tmp.="},";
$count++;
}
$json_data.=substr($str_tmp,0,-1)."],";
break;
}
}
$json_data=substr($json_data,0,-1)."}";
echo $json_data;
?>