"展厅名称","zsh"=>"展示号","title"=>"展示名称","pic"=>"图片地址","ord"=>"次序号","iid"=>"款号","color"=>"颜色代码"); $arr_column_rfid=array("kh"=>"款号","color"=>"颜色代码","color_title"=>"颜色名称","rfid"=>"RFID"); $global_num=$max_tb_num; $json_data="{"; if($priv[0]=="n"){ //没有操作权限 $json_data.="\"error\":\"没有操作权限\",\"code\":0,\"msg\":\"\",\"count\":0,\"data\":[],"; }else{ $json_data.="\"uid\":".$uid.","; switch($_a){ //删除 case "del" : $id=(is_array($id))?$id:array($id); $num=count($id); for($i=0;$i<$num;$i++){ $tmp=get_db_msg("select * from ".$table_pre."kh_tb where zsh='".$id[$i]."' and tid='".$s_tid."' limit 0,1"); // $q="delete from ".$table_pre."kh_tb where zsh='".$id[$i]."' and tid='".$s_tid."'"; //echo $q."
"; $db->query($q); $lid.=$zsh[$i].", "; } $lid=substr($lid,0,-2); set_log("删除同步",$lid); $json_data.="\"code\":1,"; break; case "add_pic": $json_data.="\"code\":0,"; $s_dir2=$s_dir2?$s_dir2:"dp/".$order_session."/big"; //取得图片 $olddir="../attachments/".$s_dir2; $d=dir($olddir); $arr_pic=array(); while($a=$d->read()){ if(is_file($olddir.'/'.$a) && ($a!='.') && ($a!='..')){ $ext=get_file_ext($a); if($ext=="jpg"){ $arr_pic[]=$a; } } } $d->close(); // $tr_num=4; $str_pic_url=""; for($i=0;$i$v){ $strtmp.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},"; } $strtmp=deel_end($strtmp); $select_dz.="{\"no\":\"s_dir2\",\"title\":\"目录\",\"value\":\"".$s_dir2."\",\"op\":[".$strtmp."]},"; $select_dz=deel_end($select_dz); $json_data.="\"select_dz\":[".$select_dz."],"; break; case "set_is_show": //---- if($_v=="y"){ $log_action="设置"; $db->query("update ".$table_pre."kh_tb set is_show='y' where tid='".$s_tid."' and zsh='".$zsh."'"); $db->query("update ".$table_pre."kh_tb set is_show='n' where tid='".$s_tid."' and zsh<>'".$zsh."' and is_show='y'"); }else{ $db->query("update ".$table_pre."kh_tb set is_show='n' where tid='".$s_tid."' and zsh='".$zsh."'"); $log_action="取消"; } if($s_tid>0){ $tmp=get_db_msg("select title from ".$table_pre."kh_tb_t where id='".$s_tid."'"); $log_tid=$tmp["title"]."|"; }else{ $log_tid=""; } set_log($log_action."同步",$log_tid.$zsh); $json_data.="\"code\":1,"; break; case "add": if($tid>0){ $msg_t=get_db_msg("select title from ".$table_pre."kh_tb_t where id='".$tid."'"); } if($zsh){ //image $msg=get_db_msg("select * from ".$table_pre."kh_tb where tid='".$tid."' and zsh='".$zsh."' limit 0,1"); $pic=$msg["pic"]; $old_zsh=$zsh; // $title=$msg["title"]; }else{ $pic=""; // $tmp=get_db_msg("select max(zsh) 'num' from ".$table_pre."kh_tb where tid='".$tid."'"); if($tmp[num]>0) $zsh=$tmp[num]+1; else $zsh=1; $old_zsh=$zsh; $title=$tmp["title"]; } $json_data.="\"zsh\":\"".$zsh."\","; $json_data.="\"title\":\"".$title."\","; $json_data.="\"pic\":\"".$pic."\","; $json_data.="\"tid\":\"".$tid."\","; $json_data.="\"old_zsh\":\"".$old_zsh."\","; $select_ks=""; for($i=1;$i<=$global_num;$i++){ $v2=""; if($zsh>0){ $tmp22=get_db_msg("select a.no 'kh',b.color 'color',b.id 'id' from ".$table_pre."kh a,".$table_pre."kh_tb b where a.id=b.iid and b.tid='".$tid."' and b.zsh='".$zsh."' and b.ord='".$i."'"); if($tmp22["id"]>0){ if($tmp22["color"]) $v2=$tmp22["kh"].",".$tmp22["color"]; else $v2=$tmp22["kh"]; } } $select_ks.="{\"k1\":\"".$i."\",\"k2\":\"ks_".$i."\",\"k3\":\"".$v2."\"},"; } if($select_ks) $select_ks=substr($select_ks,0,-1); $json_data.="\"select_ks\":[".$select_ks."],"; break; case "save_add": $sign="n"; if($old_zsh!=$zsh){ $tmp=get_db_msg("select count(*) 'num' from ".$table_pre."kh_tb where tid='".$tid."' and zsh='".$zsh."'"); if($tmp["num"]>0){ $json_data.="\"code\":0,\"msg\":\"该展示号已经存在!\","; $sign="y"; }else{ //删除数据 $db->query("delete from ".$table_pre."kh_tb where zsh='".$old_zsh."' and tid='".$tid."'"); } } if($sign!='y'){ //处理同步数据 for($i=1;$i<=$global_num;$i++){ $q=""; $v1="ks_".$i; $tmp=explode(",",$$v1); $kh=$tmp[0]; $color=$tmp[1]; $m_kh=get_db_msg("select id from ".$table_pre."kh where no='".$kh."' order by id limit 0,1"); $check=get_db_msg("select id from ".$table_pre."kh_tb where tid='".$tid."' and zsh='".$zsh."' and ord='".$i."'"); if($m_kh["id"]){ $arr_tmp=explode("|",$$v1); if($check["id"]>0){ $q="update ".$table_pre."kh_tb set zsh='".$zsh."',title='".$title."',pic='".$pic."',iid='".$m_kh["id"]."',color='".$color."' where id='".$check["id"]."'"; }else{ $q="insert into ".$table_pre."kh_tb (tid,zsh,title,pic,ord,iid,color) values ('".$tid."','".$zsh."','".$title."','".$pic."','".$i."','".$m_kh["id"]."','".$color."')"; } }else{ if($check["id"]>0) $q="delete from ".$table_pre."kh_tb where id='".$check["id"]."'"; } if($q){ $db->query($q); //echo $q."
"; } } if($old_zsh){ $log_action="修改"; }else{ $log_action="新增"; } if($tid>0){ $tmp=get_db_msg("select title from ".$table_pre."kh_tb_t where id='".$tid."'"); $log_tid=$tmp["title"]."|"; }else{ $log_tid=""; } set_log($log_action."同步",$log_tid.$zsh); $json_data.="\"code\":1,"; } break; case "check": $str=""; $tmp=""; $q="select iid,color,zsh from ".$table_pre."kh_tb"; $r=$db->query($q); $i=0; $content=""; while($m=$db->fetch_array($r)){ $tmp=get_db_msg("select color,no from ".$table_pre."kh where id='".$m["iid"]."'"); $arr_color=explode(",",$tmp["color"]); if(trim($m["color"])!=""){ if(!in_array($m["color"],$arr_color)){ $tmp.="{\"zsh\":\"".$m["zsh"]."\",\"v\":\"".$tmp["no"].",".$m["color"]."\"},"; $i++; } } } if($i>0){ $str.="{\"cate\":\"款色有误\",\"data\":[".deel_end($tmp)."]},"; } if(!$str){ $str.="{\"cate\":\"无误\",\"data\":[]},"; } $json_data.="\"error\":[".deel_end($str)."],"; break; case "group_list": $tmp=get_db_msg("select count(*) 'num' from ".$table_pre."kh_tb_t "); $total_num=$tmp["num"]; // $page=$page>0?$page:1; $limit=$limit>0?$limit:10; $start=($page-1)*$limit; $end=$limit; $json_data.="\"code\":0,\"msg\":\"\",\"count\":".$total_num.",\"data\":["; $query="select * from ".$table_pre."kh_tb_t order by id limit ".$start.",".$end; $res=$db->query($query); $count=1; while($msg=$db->fetch_array($res)){ $list=$count+$start; $str_tmp.="{"; $str_tmp.="\"xh\":\"".$list."\","; $str_tmp.="\"id\":\"".$msg["id"]."\","; $str_tmp.="\"title\":\"".$msg["title"]."\""; $str_tmp.="},"; $count++; } $json_data.=substr($str_tmp,0,-1)."],"; break; case "group_add": if($id){ $msg=get_db_msg("select * from ".$table_pre."kh_tb_t where id='".$id."'"); $title=$msg["title"]; }else{ $title=""; } $json_data.="\"title\":\"".$title."\","; break; case "group_save_add": //验证 $c=get_db_msg("select count(*) 'num' from ".$table_pre."kh_tb_t where title='".$title."' and id<>'".$id."'"); if($c["num"]>0){ $json_data.="\"code\":0,\"msg\":\"该记录已经存在,请重新输入一个!\""; }else{ if($id){ $query="update ".$table_pre."kh_tb_t set title='".$title."' where id='".$id."'"; $db->query($query); $log_action="修改"; }else{ $query="insert ".$table_pre."kh_tb_t (title) values ('".$title."')"; $db->query($query); $iid=$db->insert_id(); $log_action="新增"; } $lid=$id?$id:$iid; set_log($log_action."展厅",$title."|".$lid); $json_data.="\"code\":1,"; } break; case "group_del": $id=(is_array($id))?$id:array($id); $num=count($id); for($i=0;$i<$num;$i++){ $tmp=get_db_msg("select * from ".$table_pre."kh_tb_t where id='".$id[$i]."'"); $lid.=$tmp["title"]."|".$id[$i].", "; $db->query("delete from ".$table_pre."kh_tb_t where id='".$id[$i]."'"); $db->query("delete from ".$table_pre."kh_tb where tid='".$id[$i]."'"); } $lid=substr($lid,0,-2); set_log("删除展厅",$lid); $json_data.="\"code\":1,"; break; case "rfid_export_do": $ex_col=$arr_column_rfid; $num=count($ex_col); $i=0; foreach($ex_col as $k1 => $v1){ $data["col"][]='str'; $data["header"][0][]=get_main_value($arr_column_rfid,$k1); $i++; } // $query="select * from ".$table_pre."kh order by no"; $r=$db->query($query); $row=0; while($m=$db->fetch_array($r)){ $arr_color=explode(",",$m["color"]); for($i=0;$i $v){ $column.="{\"k\":\"".$k."\",\"t\":\"".$v."\"},"; } if($column) $column=substr($column,0,-1); $json_data.="\"col\":[".$column."],"; break; case "export_do": //取得字段选择的值 foreach($arr_column_kh_tb 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_kh_tb,$ex_col[$i]); } $query="select * from ".$table_pre."kh_tb order by tid,zsh,ord"; $r=$db->query($query); $row=0; while($m=$db->fetch_array($r)){ for($i=0;$i<$num;$i++){ $k=$ex_col[$i]; if($k=="iid"){ $tmp=get_db_msg("select no from ".$table_pre."kh where id='".$m[$k]."'"); $data["body"][$row][]=$tmp["no"]; }else if($k=="tid"){ $tmp=get_db_msg("select title from ".$table_pre."kh_tb_t where id='".$m[$k]."'"); $data["body"][$row][]=$tmp["title"]; }else{ $data["body"][$row][]=$m[$k]; } } $row++; } $file_name="kh_tb_".date("Y-m-d-H-i"); output_excel($file_name,$data); set_log("导出 同步信息"); exit; 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_kh_tb); $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_kh_tb 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_kh_tb;"); } $json_data.="\"code\":1,\"reload_type\":\"1\","; //-------------------------------------------导入数据 $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_kh_tb); $insert_column=""; for($i=0;$i"; $db->query($q); } //更新次序号 $q="select tid from ".$table_pre."kh_tb group by tid"; $r=$db->query($q); while($m=$db->fetch_array($r)){ $q1="select zsh from ".$table_pre."kh_tb where tid='".$m["tid"]."' group by zsh"; $r1=$db->query($q1); while($m1=$db->fetch_array($r1)){ $q2="select id from ".$table_pre."kh_tb where tid='".$m["tid"]."' and zsh='".$m1["zsh"]."' order by ord"; $r2=$db->query($q2); $i=1; while($m2=$db->fetch_array($r2)){ $q3="update ".$table_pre."kh_tb set ord='".$i."' where id='".$m2["id"]."'"; $db->query($q3); //echo $q3."
"; $i++; } } } del_tmp_file($tmp_file_name); $log_remark=$import_flag; set_log("导入 同步数据",$log_remark); break; default: //取得默认s_tid $m=get_db_msg("select * from ".$table_pre."kh_tb_t order by id"); $s_tid=$s_tid?$s_tid:$m["id"]; //判断tid是否存在 $check_m=get_db_msg("select * from ".$table_pre."kh_tb_t where id='".$s_tid."'"); $s_tid=($check_m["id"]>0)?$s_tid:$m["id"]; $json_data.="\"s_tid\":\"".$s_tid."\","; $json_data.="\"lang_zsh\":\"展示号\","; $json_data.="\"s_zsh\":\"".$s_zsh."\","; $str_tab=""; $q="select * from ".$table_pre."kh_tb_t order by id"; $r=$db->query($q); while($m=$db->fetch_array($r)){ $str_tab.="{\"id\":\"".$m["id"]."\",\"title\":\"".$m["title"]."\"},"; } $str_tab=deel_end($str_tab); $json_data.="\"tab\":[".$str_tab."],"; //-----------------------/tab $s_con_gq=$s_con_gq?$s_con_gq:"1"; $arr_gq=array("1"=>"不显示已展示","2"=>"显示所有"); $select_gq=""; if(is_array($arr_gq)){ foreach($arr_gq as $k=>$v){ $select_gq.="{\"op_k\":\"".$k."\",\"op_v\":\"".$v."\"},"; } } if($select_gq) $select_gq=substr($select_gq,0,-1); $json_data.="\"select_gq\":[".$select_gq."],"; $json_data.="\"searchgq\":\"".$s_con_gq."\","; // $page=$page>0?$page:1; $limit=$limit>0?$limit:10; $start=($page-1)*$limit; $end=$limit; //条件 $sql_con=" tid='".$s_tid."' and "; if($s_con_gq || $s_zsh){ if($s_zsh) $sql_con.="zsh='".$s_zsh."' and "; if($s_con_gq=="1"){ //不显示已展示 $tmp=get_db_msg("select zsh from ".$table_pre."kh_tb where tid='".$s_tid."' and is_show='y' group by zsh order by zsh desc limit 0,1"); if($tmp["zsh"]>0) $sql_con.=" zsh>='".$tmp["zsh"]."' and "; } } if($sql_con) $sql_con="where ".substr($sql_con,0,-4); //取得总条数 $tmp=get_db_msg("select count(distinct zsh) 'num' from ".$table_pre."kh_tb ".$sql_con); $total_num=$tmp["num"]; $json_data.="\"code\":0,\"msg\":\"\",\"count\":".$total_num.",\"data\":["; $count=1; $str_tmp=""; $sql="select * from ".$table_pre."kh_tb ".$sql_con." group by zsh order by zsh limit ".$start.",".$end; $res=$db->query($sql); while($msg=$db->fetch_array($res)){ $str_ks=""; $q1="select * from ".$table_pre."kh_tb where tid='".$s_tid."' and zsh='".$msg["zsh"]."' order by ord"; $r1=$db->query($q1); while($m1=$db->fetch_array($r1)){ $m2=get_db_msg("select * from ".$table_pre."kh where id='".$m1["iid"]."' limit 0,1"); if($m1["color"]){ $pic2=get_kh_color_picture($m2["no"],$m1["color"]); }else{ $pic2=get_kh_picture($m2["no"],$m2["main_pic"],$m2["color"]); } $str_ks.=$m2["no"].",".get_cate_title_no("color",$m1["color"]).",".$m1["color"].",".$pic2."|"; } if($str_ks) $str_ks=substr($str_ks,0,-1); if(trim($msg["pic"])){ $pic="../attachments/".$msg["pic"]; if(!is_file($pic)){ $pic="images/no_pic_80.gif"; } }else{ $pic="images/no_pic_80.gif"; } $arr_pic_set=out_good_pic_set_arr($pic,120,120); $list=$count+$start; $str_tmp.="{"; $str_tmp.="\"ct\":\"".$list."\","; $str_tmp.="\"is_show\":\"".$msg["is_show"]."\","; $str_tmp.="\"zsh\":\"".$msg["zsh"]."\","; $str_tmp.="\"title\":\"".$msg["title"]."\","; $str_tmp.="\"kh\":\"".$str_ks."\","; $str_tmp.="\"pic_src\":\"".$pic."\","; $str_tmp.="\"pic_w\":\"".$arr_pic_set[0]."\","; $str_tmp.="\"pic_h\":\"".$arr_pic_set[1]."\""; $str_tmp.="},"; $count++; } $json_data.=substr($str_tmp,0,-1)."],"; break; } } $json_data=substr($json_data,0,-1)."}"; echo $json_data; ?>