"展示号","title"=>"名称","pic"=>"图片名称","remark"=>"橱窗介绍","ord"=>"次序号","kh"=>"款号","color"=>"颜色代码","size"=>"尺码"); $global_num=$max_cc_num; $json_data="{"; if($priv[0]=="n"){ //没有操作权限 $json_data.="\"error\":\"没有操作权限\",\"code\":0,\"msg\":\"\",\"count\":0,\"data\":[],"; }else{ $json_data.="\"uid\":".$uid.","; switch($_a){ case "add": if($zsh){ $msg=get_db_msg("select * from ".$table_pre."kh_cc where zsh='".$zsh."' limit 0,1"); $pic_mini=get_kh_cc_mini($msg["pic"]); $pic_big=get_kh_cc_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_cc"); 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.="\"cch\":\"".$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.="\"ccremark\":\"".htmlspecialchars($msg["remark"])."\","; $json_data.="\"old_zsh\":\"".$old_zsh."\","; $json_data.="\"old_pic\":\"".$msg["pic"]."\","; $select_ks=""; for($i=1;$i<=$global_num;$i++){ $v2=""; $v5=""; if($zsh>0){ $tmp22=get_db_msg("select * from ".$table_pre."kh_cc where zsh='".$zsh."' and ord='".$i."'"); if($tmp22["id"]>0){ $v2=$tmp22["kh"]; $v5=$tmp22["size"]; if($tmp22["color"]) $v2.="|".get_cate_title_no("color",$tmp22["color"])."|".$tmp22["color"]; } } $select_ks.="{\"k1\":\"".$i."\",\"k2\":\"ks_".$i."\",\"k3\":\"".$v2."\",\"k4\":\"size_".$i."\",\"k5\":\"".$v5."\"},"; } if($select_ks) $select_ks=substr($select_ks,0,-1); $json_data.="\"select_ks\":[".$select_ks."],"; break; case "save_add": //处理数据 for($i=1;$i<=$global_num;$i++){ $q=""; $v1="ks_".$i; $v2="size_".$i; $check=get_db_msg("select id from ".$table_pre."kh_cc where zsh='".$old_zsh."' and ord='".$i."'"); if($$v1){ $arr_tmp=explode("|",$$v1); if($check["id"]>0){ $q="update ".$table_pre."kh_cc set zsh='".$zsh."',title='".$cch."',pic='".$pic."',remark='".$ccremark."',kh='".$arr_tmp[0]."',color='".$arr_tmp[2]."',size='".$$v2."' where id='".$check["id"]."'"; }else{ $q="insert into ".$table_pre."kh_cc (zsh,title,pic,remark,ord,kh,color,size) values ('".$zsh."','".$cch."','".$pic."','".$ccremark."','".$i."','".$arr_tmp[0]."','".$arr_tmp[2]."','".$$v2."')"; } }else{ if($check["id"]>0) $q="delete from ".$table_pre."kh_cc where id='".$check["id"]."'"; } if($q){ $db->query($q); } } if($old_pic!=$pic){ //修改图片名字 if(is_file("../attachments/cc/".$s_dir."big/".$old_pic.".jpg")){ copy("../attachments/cc/".$s_dir."big/".$old_pic.".jpg","../attachments/cc/".$s_dir."big/".$pic.".jpg"); del_file("../attachments/cc/".$s_dir."big/".$old_pic.".jpg"); } if(is_file("../attachments/cc/".$s_dir."mini/".$old_pic.".jpg")){ copy("../attachments/cc/".$s_dir."mini/".$old_pic.".jpg","../attachments/cc/".$s_dir."mini/".$pic.".jpg"); del_file("../attachments/cc/".$s_dir."mini/".$old_pic.".jpg"); } } $json_data.="\"code\":1,"; break; case "add_pic": $msg=get_db_msg("select * from ".$table_pre."kh_cc where zsh='".$zsh."' limit 0,1"); $pic=get_kh_cc_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_cc where zsh='".$zsh."' limit 0,1"); if($up_image["name"]){ $path1="../attachments/cc/".$s_dir."big"; $path2="../attachments/cc/".$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,400); } $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_cc where zsh='".$id[$i]."' limit 0,1"); // del_file("../attachments/cc/".$s_dir."big/".$tmp["pic"].".jpg"); del_file("../attachments/cc/".$s_dir."mini/".$tmp["pic"].".jpg"); $q="delete from web_kh_cc 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_cc 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; case "check": //检查款号 $str=""; $tmp=""; $q="select kh from ".$table_pre."kh_cc 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_cc"; $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)."]},"; } //检查尺码 $tmp=""; $q="select * from ".$table_pre."kh_cc order by kh,color"; $r=$db->query($q); $i=0; while($m=$db->fetch_array($r)){ $check3=get_db_msg("select * from ".$table_pre."kh where no='".$m["kh"]."'"); if($check3["id"]>0){ //检查尺码 $check_size=explode(",",$check3["size"]); $arr_size=explode(",",trim($m["size"])); for($j=0;$j0){ $str.="{\"cate\":\"尺码有误\",\"data\":[".deel_end($tmp)."]},"; } //--------------------检查图片 $q="select * from ".$table_pre."kh_cc group by zsh"; $r=$db->query($q); $i=0; $tmp=""; while($m=$db->fetch_array($r)){ $pic=get_kh_cc_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; //----------------------------------------------------------------------导入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_cc); $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_cc 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_cc;"); } $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_cc); $insert_column=""; for($i=0;$i"; $db->query($q); } //更新次序号 $q="select * from ".$table_pre."kh_cc group by zsh order by zsh"; $r=$db->query($q); while($m=$db->fetch_array($r)){ $q1="select * from ".$table_pre."kh_cc where zsh='".$m["zsh"]."' order by ord"; $r1=$db->query($q1); $i=1; while($m1=$db->fetch_array($r1)){ $q2="update ".$table_pre."kh_cc 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_cc 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_cc 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_cc,$ex_col[$i]); } $query="select * from ".$table_pre."kh_cc ".$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]; $data["body"][$row][]=$m[$k]; } $row++; } $file_name="kh_cc_".date("Y-m-d-H-i"); output_excel($file_name,$data); set_log("导出 橱窗信息"); exit; break; //-------------主界面 default: $json_data.="\"lang_zsh\":\"展示号\","; $json_data.="\"lang_kh\":\"款号\","; $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($sql_con) $sql_con="where ".substr($sql_con,0,-4); //取得总条数 $tmp=get_db_msg("select count(distinct zsh) 'num' from ".$table_pre."kh_cc ".$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_cc ".$sql_con." group by zsh order by zsh limit ".$start.",".$end; $res=$db->query($sql); while($msg=$db->fetch_array($res)){ $list=$count+$start; $str_ks=""; $q1="select * from ".$table_pre."kh_cc 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"]); $thissize=str_replace(",","&",$m1["size"]); $thissize=str_replace("|","&",$thissize); $str_ks.=$m1["kh"].",".get_cate_title_no("color",$m1["color"]).",".$m1["color"].",".$thissize.",".$pic2."|"; } if($str_ks) $str_ks=substr($str_ks,0,-1); $pic=get_kh_cc_mini($msg["pic"]);; $arr_pic_set=out_good_pic_set_arr($pic,120,120); $str_tmp.="{"; $str_tmp.="\"ct\":\"".$list."\","; $str_tmp.="\"zsh\":\"".$msg["zsh"]."\","; $str_tmp.="\"cch\":\"".$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.="\"ccjs\":\"".htmlspecialchars($msg["remark"])."\""; $str_tmp.="},"; $count++; } $json_data.=substr($str_tmp,0,-1)."],"; break; } } $json_data=substr($json_data,0,-1)."}"; echo $json_data; ?>