"店铺等级","bc"=>"波段代码","color"=>"颜色代码","num"=>"数量");
switch($_a){
case "check":
$q="select kh from ".$table_pre."gz where cate='bds' group by kh";
$r=$db->query($q);
$i=0;
$content="以下数据有误:
";
$tmp="";
while($m=$db->fetch_array($r)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."kh where bc='".$m["bc"]."' and concat(',',color,',') like '%,".$m["color"].",%'");
if($check["num"]==0){
$content.=$i.".".$m["kh"]."
";
$tmp.="{\"bc\":\"".$m["bc"]."-".$m["color"]."\",\"v\":\"".$m["bc"]."-".$m["color"]."\"},";
$i++;
}
}
if($i>0){
$str.="{\"cate\":\"款号有误\",\"data\":[".deel_end($tmp)."]},";
}
//include template("blank");
$json_data.="\"error\":[".deel_end($str)."],";
break;
case "add" :
//--------------------------新增
$http_pre=$http_pre?$http_pre:$_SERVER['HTTP_REFERER'];
if($id){
$msg=get_db_msg("select * from ".$table_pre."gz where id='".$id."' limit 0,1");
$json_data.="\"kh\":\"".$msg["kh"]."\",";
$dj=$msg["dj"];
$json_data.="\"dj\":\"".$msg["dj"]."\",";
$json_data.="\"bc\":\"".$msg["bc"]."\",";
$bc=$msg["bc"];
$json_data.="\"color\":\"".$msg["color"]."\",";
$color=$msg["color"];
$json_data.="\"num\":\"".$msg["num"]."\",";
//
}else{
$json_data.="\"kh\":\"\",";
$json_data.="\"dj\":\"\",";
$json_data.="\"bc\":\"\",";
$json_data.="\"color\":\"\",";
$json_data.="\"num\":\"\",";
$dj="";
$bc="";
$color="";
}
$select_dz="";
//取得选项
$tmp="";
$r1=$db->query("select dj from ".$table_pre."client where dj<>'' group by dj order by dj");
while($m1=$db->fetch_array($r1)){
$tmp.="{\"no\":\"".$m1["dj"]."\",\"title\":\"".$m1["dj"]."\"},";
}
$tmp=deel_end($tmp);
$var="s_dj";
$select_dz.="{\"no\":\"dj\",\"title\":\"店铺等级\",\"value\":\"".$dj."\",\"op\":[".$tmp."]},";
$select_dz=deel_end($select_dz);
$json_data.="\"select_dz\":[".$select_dz."],";
$select_dz1="";
//取得选项
$tmp="";
$r1=$db->query("select * from ".$table_pre."keyword where cate='bc' order by no");
$json_data.="\"q\":\"select * from ".$table_pre."keyword where cate='bc' order by no\",";
while($m1=$db->fetch_array($r1)){
$tmp.="{\"no\":\"".$m1["no"]."\",\"title\":\"".$m1["title"]."\"},";
}
$tmp=deel_end($tmp);
$var="s_bc";
$select_dz1.="{\"no\":\"bc\",\"title\":\"波段\",\"value\":\"".$bc."\",\"op\":[".$tmp."]},";
$select_dz1=deel_end($select_dz1);
$json_data.="\"select_dz1\":[".$select_dz1."],";
$select_dz2="";
//取得选项
$tmp="";
$r1=$db->query("select * from ".$table_pre."keyword where cate='color' order by no");
while($m1=$db->fetch_array($r1)){
$tmp.="{\"no\":\"".$m1["no"]."\",\"title\":\"".$m1["title"]."\"},";
}
$tmp=deel_end($tmp);
$var="s_color";
$select_dz2.="{\"no\":\"color\",\"title\":\"颜色\",\"value\":\"".$color."\",\"op\":[".$tmp."]},";
$select_dz2=deel_end($select_dz2);
$json_data.="\"select_dz2\":[".$select_dz2."],";
break;
case "save_add":
//检查重复
if(!$bc)
$msg_error="请选择波段!";
if(!$color)
$msg_error="请选择颜色!";
$check=get_db_msg("select id from ".$table_pre."gz where bc='".$bc."' and color='".$color."' and cate='".$s_cate."' and dj='".$dj."' and id<>'".$id."'");
if($check["id"]>0)
$msg_error="该数据已存在,请检查!";
if($msg_error){
$json_data.="\"code\":0,\"msg\":\"".$msg_error."\",";
}else{
if($id){
$log_action="修改";
$msg=get_db_msg("select * from ".$table_pre."gz where id='".$id."'");
$query="update ".$table_pre."gz set dj='".$dj."',bc='".$bc."',color='".$color."',num='".$num."' where id='".$id."'";
}else{
$log_action="新增";
$query="insert into ".$table_pre."gz (cate,dj,bc,color,num) values ('bds','".$dj."','".$bc."','".$color."','".$num."')";
}
$log_remark=$dj."|".$bc."|".$color."|".$num;
$db->query($query);
set_log($log_action.get_cate_title_no("dhgz","bds"),$log_remark);
$json_data.="\"code\":1,";
}
break;
case "del" :
$num=count($id);
if($num==0)
alert_and_back("请至少选择一条记录!");
for($i=0;$i<$num;$i++){
$tmp=get_db_msg("select * from ".$table_pre."gz where id='".$id[$i]."' limit 0,1");
//
$q="delete from ".$table_pre."gz where id='".$id[$i]."'";
//echo $q."
";
$db->query($q);
$lid.=$tmp["dj"]."|".$tmp["kh"]."|".$tmp["num"].", ";
}
$lid=substr($lid,0,-2);
set_log("删除".get_cate_title_no("dhgz","bds"),$lid);
//url_redirect();
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"];
//echo $file1["name"]."--";
$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_this);
$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_this 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("delete from ".$table_pre."gz where cate='bds';");
}
//
$insert_column="";
for($i=0;$i";
$db->query($q);
}
//
del_tmp_file($tmp_file_name);
$log_remark=$import_flag;
set_log("导入必定色规则数据",$log_remark);
}
break;
//----------------------------------------------------------------------/导入EXCEL
default :
$page=$page>0?$page:1;
$limit=$limit>0?$limit:10;
$start=($page-1)*$limit;
$end=$limit;
$sql_con="cate='bds' and ";
if($s_bc || $s_color || $s_dj){
if($s_bc)
$sql_con.="bc='".$s_bc."' and ";
if($s_color)
$sql_con.="color='".$s_color."' and ";
if($s_dj)
$sql_con.="dj='".$s_dj."' and ";
}
if($sql_con)
$sql_con="where ".substr($sql_con,0,-4);
$query="select count(*) 'total' from ".$table_pre."gz ".$sql_con;
//$json_data.="\"q1\":\"".$query."\",";
$res=$db->query($query);
$msg=$db->fetch_array($res);
$total=$msg["total"];
//page class
$op="";
$q1="select dj from ".$table_pre."client where dj<>'' group by dj order by dj";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$op.="";
}
$select_dz="";
//取得选项
$tmp="";
$r1=$db->query("select dj from ".$table_pre."client where dj<>'' group by dj order by dj");
while($m1=$db->fetch_array($r1)){
$tmp.="{\"no\":\"".$m1["dj"]."\",\"title\":\"".$m1["dj"]."\"},";
}
$tmp=deel_end($tmp);
$var="s_dj";
$select_dz.="{\"no\":\"dj\",\"title\":\"店铺等级\",\"value\":\"".$$var."\",\"op\":[".$tmp."]},";
$tmp="";
$r1=$db->query("select * from ".$table_pre."keyword where cate='bc' order by no");
while($m1=$db->fetch_array($r1)){
$tmp.="{\"no\":\"".$m1["no"]."\",\"title\":\"".$m1["title"]."\"},";
}
$tmp=deel_end($tmp);
$var="s_bc";
$select_dz.="{\"no\":\"bc\",\"title\":\"波段\",\"value\":\"".$$var."\",\"op\":[".$tmp."]},";
$tmp="";
$r1=$db->query("select * from ".$table_pre."keyword where cate='color' order by no");
while($m1=$db->fetch_array($r1)){
$tmp.="{\"no\":\"".$m1["no"]."\",\"title\":\"".$m1["title"]."\"},";
}
$tmp=deel_end($tmp);
$var="s_color";
$select_dz.="{\"no\":\"color\",\"title\":\"颜色\",\"value\":\"".$$var."\",\"op\":[".$tmp."]},";
$select_dz=deel_end($select_dz);
$json_data.="\"select_dz\":[".$select_dz."],";
$query="select * from ".$table_pre."gz ".$sql_con." order by id limit ".$start.",".$end;
//echo $query."
";
//$json_data.="\"q2\":\"".$query."\",";
$res=$db->query($query);
$count=0;
$xh_ms=get_set("xh_ms");
$json_data.="\"code\":0,\"msg\":\"\",\"count\":".$total.",\"data\":[";
$str_tmp="";
while($msg=$db->fetch_array($res)){
$list=$start+$count+1;
$msg_kh=get_db_msg("select * from ".$table_pre."kh where no='".$msg["kh"]."'");
$str_tmp.="{";
$str_tmp.="\"id\":\"".$msg["id"]."\",";
if($msg["dj"]){
$str_tmp.="\"dj\":\"".$msg["dj"]."\",";
}else{
$str_tmp.="\"dj\":\"所有店铺\",";
}
$str_tmp.="\"kh\":\"".$msg["kh"]."\",";
$str_tmp.="\"color\":\"".$msg["color"]."\",";
//$tmpkh=get_db_msg("select * from ".$table_pre."kh where no='".$msg["kh"]."'");
$ks=get_cate_title_no("bc",$msg["bc"]).",".$msg["color"]."-".get_cate_title_no("color",$msg["color"]);
$str_tmp.="\"ks\":\"".$ks."\",";
$str_tmp.="\"bc\":\"".$msg["bc"]."\",";
$str_tmp.="\"num\":\"".$msg["num"]."\"";
$str_tmp.="},";
$count++;
}
$json_data.=substr($str_tmp,0,-1)."],";
break;
}
//}
$json_data=substr($json_data,0,-1)."}";
echo $json_data;
?>