0){ for($i=1;$i<=$num_dp_zd;$i++){ $arr_column_kh_dp["zd".$i]=$sys_dp_zd[$i-1]; } } $arr_column_kh_dp["pic"]="图片名称"; $arr_column_kh_dp["kh"]="款号"; $arr_column_kh_dp["color"]="颜色代码"; $arr_column_kh_dp["ord"]="次序号"; $arr_column_kh_dp["remark"]="搭配介绍"; $arr_column_kh_dp["gz"]="搭配规则"; $json_data="{"; if($priv[0]=="n"){ //没有操作权限 $json_data.="\"error\":\"没有操作权限\",\"code\":0,\"msg\":\"\",\"count\":0,\"data\":[],"; }else{ $json_data.="\"uid\":".$uid.","; switch($_a){ case "mod_upath_do": $arr_zsh=$zsh; if($s_dp=="_all_"){ $upath=""; }else{ $m1=get_db_msg("select path,id from ".$table_pre."client where username='".$s_dp."'"); $upath=$m1["path"]."-".$m1["id"]; } $q="update ".$table_pre."kh_dp set upath='".$upath."' where zsh='".$arr_zsh."'"; $db->query($q); $lid.=$arr_zsh.", "; $lid=substr($lid,0,-2); set_log("修改搭配权限",$lid); $json_data.="\"code\":1,"; break; case "check": //检查款号 $str=""; $tmp=""; $q="select kh from ".$table_pre."kh_dp group by kh"; $r=$db->query($q); $i=0; while($m=$db->fetch_array($r)){ $check=get_db_msg("select id from ".$table_pre."kh where no='".$m["kh"]."'"); if(!$check["id"]){ $tmp.="{\"kh\":\"".$m["kh"]."\",\"v\":\"".$m["kh"]."\"},"; $i++; } } if($i>0){ $str.="{\"cate\":\"款号有误\",\"data\":[".deel_end($tmp)."]},"; } //检查颜色 $tmp=""; $q="select * from ".$table_pre."kh_dp"; $r=$db->query($q); $i=0; while($m=$db->fetch_array($r)){ $check2=get_db_msg("select * from ".$table_pre."kh where no='".$m["kh"]."'"); $arr_color=explode(",",$check2["color"]); if(!in_array($m["color"],$arr_color,true)){ $tmp.="{\"kh\":\"".$m["kh"]."\",\"v\":\"".$m["kh"].",".$m["color"]."\"},"; $i++; } } if($i>0){ $str.="{\"cate\":\"款色有误\",\"data\":[".deel_end($tmp)."]},"; } //--------------------检查图片 $q="select * from ".$table_pre."kh_dp group by zsh"; $r=$db->query($q); $i=0; $tmp=""; while($m=$db->fetch_array($r)){ $pic=get_kh_dp_mini($m["pic"]); if($pic=="images/no_pic_80.gif"){ $tmp.="{\"zsh\":\"".$m["zsh"]."\",\"v\":\"".$m["zsh"]."(".$m["title"].")\"},"; $i++; } } if($i>0){ $str.="{\"cate\":\"缺图片\",\"data\":[".deel_end($tmp)."]},"; } if(!$str){ $str.="{\"cate\":\"无误\",\"data\":[]},"; } $json_data.="\"error\":[".deel_end($str)."],"; break; case "add": if($zsh){ $msg=get_db_msg("select * from ".$table_pre."kh_dp where zsh='".$zsh."' limit 0,1"); $pic_mini=get_kh_dp_mini($msg["pic"]); $pic_big=get_kh_dp_big($msg["pic"]); $title=$msg["title"]; $pic=$msg["pic"]; $old_zsh=$zsh; }else{ $pic_big=$pic_mini="images/no_pic_80.gif"; //kph $tmp=get_db_msg("select max(zsh) 'num' from ".$table_pre."kh_dp"); if($tmp[num]>0) $zsh=$tmp[num]+1; else $zsh=1; $title="第".$zsh."组"; $pic=""; $old_zsh=""; } $arr_pic_set=out_good_pic_set_arr($pic_mini,120,120); $json_data.="\"zsh\":\"".$zsh."\","; $json_data.="\"dph\":\"".$title."\","; $json_data.="\"pic\":\"".$pic."\","; $json_data.="\"picurl\":\"".$pic_mini."\","; $json_data.="\"pic_w\":\"".$arr_pic_set[0]."\","; $json_data.="\"pic_h\":\"".$arr_pic_set[1]."\","; $json_data.="\"dpremark\":\"".addslashes($msg["remark"])."\","; $json_data.="\"old_zsh\":\"".$old_zsh."\","; $json_data.="\"old_pic\":\"".$msg["pic"]."\","; $select_dz=""; if($num_dp_zd>0){ for($i=1;$i<=$num_dp_zd;$i++){ $arr_column_kh_dp["zd".$i]=$sys_dp_zd[$i-1]; $select_dz.="{\"zd\":\"zd".$i."\",\"zdtitle\":\"".$sys_dp_zd[$i-1]."\",\"zdval\":\"".$msg["zd".$i]."\"},"; } } if($select_dz) $select_dz=substr($select_dz,0,-1); $json_data.="\"select_dz\":[".$select_dz."],"; $select_dpgz=""; if(is_array($arr_kh_dp_gz)){ foreach($arr_kh_dp_gz as $k=>$v){ $select_dpgz.="{\"op_k\":\"".$k."\",\"op_v\":\"".$v."\"},"; } } if($select_dpgz) $select_dpgz=substr($select_dpgz,0,-1); $json_data.="\"select_dpgz\":[".$select_dpgz."],"; $json_data.="\"dhgz\":[".$msg["gz"]."],"; $select_ks=""; for($i=1;$i<=$global_num;$i++){ $v2=""; if($zsh>0){ $tmp22=get_db_msg("select * from ".$table_pre."kh_dp where zsh='".$zsh."' and ord='".$i."'"); if($tmp22["id"]>0){ $v2=$tmp22["kh"]; if($tmp22["color"]) $v2.="|".get_cate_title_no("color",$tmp22["color"])."|".$tmp22["color"]; } } $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 "add_pic": $msg=get_db_msg("select * from ".$table_pre."kh_dp where zsh='".$zsh."' limit 0,1"); $pic=get_kh_dp_big($msg["pic"]); $arr_pic_set=out_good_pic_set_arr($pic,300,300); $json_data.="\"pic\":\"".$pic."\",\"pic_w\":\"".$arr_pic_set[0]."\",\"pic_h\":\"".$arr_pic_set[1]."\","; $json_data.="\"this_title\":\"".$msg["title"]."\","; break; case "save_add_pic": $up_image=$_FILES["up_file"];; $msg=get_db_msg("select * from ".$table_pre."kh_dp where zsh='".$zsh."' limit 0,1"); if($up_image["name"]){ $path1="../attachments/dp/".$s_dir."big"; $path2="../attachments/dp/".$s_dir."mini"; $new_file_name=$msg["pic"].".jpg"; make_mini_picture($up_image["tmp_name"],$path1."/".$new_file_name,800); //缩略图 make_mini_picture($path1."/".$new_file_name,$path2."/".$new_file_name,250); } $json_data.="\"code\":1,"; break; case "save_add": //处理搭配数据 for($i=1;$i<=$global_num;$i++){ $q=""; $v1="ks_".$i; $check=get_db_msg("select id from ".$table_pre."kh_dp where zsh='".$old_zsh."' and ord='".$i."'"); if($$v1){ $arr_tmp=explode("|",$$v1); if($check["id"]>0){ $q="update ".$table_pre."kh_dp set zsh='".$zsh."',title='".$dph."',zd1='".$zd1."',zd2='".$zd2."',zd3='".$zd3."',zd4='".$zd4."',zd5='".$zd5."',pic='".$pic."',remark='".$dpremark."',kh='".$arr_tmp[0]."',color='".$arr_tmp[2]."',gz='".$dpgz."' where id='".$check["id"]."'"; }else{ $q="insert into ".$table_pre."kh_dp (zsh,title,zd1,zd2,zd3,zd4,zd5,pic,remark,ord,kh,color,gz) values ('".$zsh."','".$dph."','".$zd1."','".$zd2."','".$zd3."','".$zd4."','".$zd5."','".$pic."','".$dpremark."','".$i."','".$arr_tmp[0]."','".$arr_tmp[2]."','".$dpgz."')"; } }else{ if($check["id"]>0) $q="delete from ".$table_pre."kh_dp where id='".$check["id"]."'"; } if($q){ $db->query($q); } } if($old_pic!=$pic){ //修改图片名字 if(is_file("../attachments/dp/".$s_dir."big/".$old_pic.".jpg")){ copy("../attachments/dp/".$s_dir."big/".$old_pic.".jpg","../attachments/dp/".$s_dir."big/".$pic.".jpg"); del_file("../attachments/dp/".$s_dir."big/".$old_pic.".jpg"); } if(is_file("../attachments/dp/".$s_dir."mini/".$old_pic.".jpg")){ copy("../attachments/dp/".$s_dir."mini/".$old_pic.".jpg","../attachments/dp/".$s_dir."mini/".$pic.".jpg"); del_file("../attachments/dp/".$s_dir."mini/".$old_pic.".jpg"); } } $json_data.="\"code\":1,"; break; //删除 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_dp where zsh='".$id[$i]."' limit 0,1"); // del_file("../attachments/dp/".$s_dir."big/".$tmp["pic"].".jpg"); del_file("../attachments/dp/".$s_dir."mini/".$tmp["pic"].".jpg"); $q="delete from web_kh_dp where zsh='".$id[$i]."'"; $db->query($q); $lid.=$id[$i].", "; } $lid=substr($lid,0,-2); set_log("删除搭配",$lid); $json_data.="\"code\":1,"; break; case "zsh_pl": $arr=explode("\n",$text); $msg=""; for($i=0;$i0 && $zsh>0){ $q="update ".$table_pre."kh_dp set zsh='".$zsh."' where ".$zd."='".$v1."'"; $db->query($q); $msg.="{\"t1\":\"".$v1."|".$zsh."\",\"t2\":\"y\"},"; }else{ //有误 $msg.="{\"t1\":\"".$v1."|".$zsh."\",\"t2\":\"n\"},"; } } $json_data.="\"code\":1,\"data\":[".substr($msg,0,-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_kh_dp); $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_dp 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_dp;"); } $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_dp); $insert_column=""; for($i=0;$i"; $db->query($q); } //更新次序号 $q="select * from ".$table_pre."kh_dp group by zsh"; $r=$db->query($q); while($m=$db->fetch_array($r)){ $q1="select * from ".$table_pre."kh_dp where zsh='".$m["zsh"]."' order by ord"; $r1=$db->query($q1); $i=1; while($m1=$db->fetch_array($r1)){ $q2="update ".$table_pre."kh_dp set ord='".$i."' where id='".$m1["id"]."'"; $db->query($q2); //echo $q2."
"; $i++; } } del_tmp_file($tmp_file_name); $log_remark=$import_flag; set_log("导入 搭配数据",$log_remark); break; //----------------------------------------------------------------------导出数据 case "export": $column=""; foreach($arr_column_kh_dp 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_kh_dp 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_dp,$ex_col[$i]); } if($s_client){ if($s_client=="_all_"){ $sql_con.="(upath='') and "; }else{ $tmp=get_db_msg("select * from ".$table_pre."client where username='".$s_client."'"); if($tmp["id"]>0){ $s_jxs=$tmp["path"]."-".$tmp["id"]; $sql_con.="(upath='".$s_jxs."' or upath like '".$s_jxs."-%') and "; } } } if($sql_con) $sql_con="where ".substr($sql_con,0,-4); $query="select * from ".$table_pre."kh_dp ".$sql_con." order by 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=="username" || $k=="usertitle"){ $m1=get_db_msg("select username,title 'usertitle' from ".$table_pre."client where id='".get_parent_id($m["upath"])."'"); $data["body"][$row][]=$m1[$k]; }else{ $data["body"][$row][]=$m[$k]; } } $row++; } $file_name="kh_dp_".date("Y-m-d-H-i"); output_excel($file_name,$data); set_log("导出 搭配信息"); exit; break; //-------------主界面 default: $json_data.="\"lang_zsh\":\"展示号\","; $json_data.="\"lang_kh\":\"款号\","; $ctt=1; $select_dz=""; for($i=0;$iquery("select ".$zd." from ".$table_pre."kh_dp group by ".$zd." order by ".$zd); while($msg1=$db->fetch_array($res1)){ $strtmp.="{\"no\":\"".$msg1[$zd]."\",\"title\":\"".$msg1[$zd]."\"},"; } $strtmp=deel_end($strtmp); $var="s_".$zd; $select_dz.="{\"no\":\"".$zd."\",\"title\":\"".$sys_dp_zd[$i]."\",\"value\":\"".$$var."\",\"op\":[".$strtmp."]},"; $ctt++; } $select_dz=deel_end($select_dz); $json_data.="\"select_dz\":[".$select_dz."],"; // $page=$page>0?$page:1; $limit=$limit>0?$limit:10; $start=($page-1)*$limit; $end=$limit; //条件 $sql_con=""; if($s_kh || $s_zsh){ if($s_zsh) $sql_con.="zsh='".$s_zsh."' and "; if($s_kh) $sql_con.="kh like '%".$s_kh."%' and "; } if($s_client){ if($s_client=="_all_"){ $sql_con.="(upath='') and "; }else{ $tmp=get_db_msg("select * from ".$table_pre."client where username='".$s_client."'"); if($tmp["id"]>0){ $s_jxs=$tmp["path"]."-".$tmp["id"]; $sql_con.="(upath='".$s_jxs."') and "; } } } $ctt=1; for($i=0;$iquery($sql); while($msg=$db->fetch_array($res)){ $list=$count+$start; $str_ks=""; $q1="select * from ".$table_pre."kh_dp where 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 no='".$m1["kh"]."' limit 0,1"); $pic2=($m1["color"])?get_kh_color_picture($m1["kh"],$m1["color"]):get_kh_picture($m1["no"],$m2["main_pic"],$m2["color"]); $str_ks.=$m1["kh"].",".get_cate_title_no("color",$m1["color"]).",".$m1["color"].",".$pic2."|"; } if($str_ks) $str_ks=substr($str_ks,0,-1); if($msg["upath"]==""){ $str_user="全国"; }else{ $str_user=get_path_title($msg["upath"],"-",$table_pre."client","title"); } $ctt2=1; $strzd=""; for($i=0;$i