This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
wsh5485 7e47ce238b chore: 添加多个图片和资源文件
添加了管理后台所需的图片资源、Excel文件、安装程序以及设计相关的图片文件
2025-06-15 13:04:37 +08:00

626 lines
20 KiB
PHP

<?php
//-------------------------------
header("Content-type: text/html; charset=utf-8");
if(THIS_IN!="edt_admin")
exit("错误的访问!");
//-------------------------------execute action
$db=_mysql_connect();
$msg_login_user=get_db_msg("select * from ".$table_pre."user where id='".$uid."'");
//权限判断
$priv=return_priv($_m,$msg_login_user["priv"]);
$order_session=get_set("order_session");
$s_dir=$order_session?$order_session."/":"";
//
$arr_column_kh_tb=array("tid"=>"展厅名称","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."<br>";
$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<ceil(count($arr_pic)/$tr_num);$i++){
$ct=1;
$str_pic_url.="{";
for($k=0;$k<$tr_num;$k++){
if($arr_pic[$i*$tr_num+$k]){
$str_pic_url.="\"pic_".$ct."\":\"".$olddir."/".$arr_pic[$i*$tr_num+$k]."\",\"upic_".$ct."\":\"".$s_dir2."/".$arr_pic[$i*$tr_num+$k]."\",";
}else{
$str_pic_url.="\"pic_".$ct."\":\"\",\"upic_".$ct."\":\"\",";
}
$ct++;
}
$str_pic_url=substr($str_pic_url,0,-1)."},";
}
if($str_pic_url)
$str_pic_url=substr($str_pic_url,0,-1);
$json_data.="\"data\":[".$str_pic_url."],";
$arr_dir["dp/".$order_session."/big"]="搭配图";
$arr_dir["cl/".$order_session."/big"]="陈列图";
$select_dz="";
$strtmp="";
foreach($arr_dir as $k=>$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."<br>";
}
}
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<count($arr_color);$i++){
$data["body"][$row][]=$m["no"];
$data["body"][$row][]=$arr_color[$i];
$data["body"][$row][]=get_cate_title_no("color",$arr_color[$i]);
$m1=get_db_msg("select rfid from ".$table_pre."kh_rfid where kh='".$m["no"]."' and color='".$arr_color[$i]."'");
$data["body"][$row][]=$m1["rfid"];
$row++;
}
}
$file_name="RFID_".date("Y-m-d-H-i");
output_excel($file_name,$data);
set_log("导出 款号RFID");
exit;
break;
//----------------------------------------------------------------------导出数据
case "export":
$column="";
foreach($arr_column_kh_tb 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_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<count($arr_thead);$i++){
if(in_array(get_main_key($arr_column_kh_tb,$arr_thead[$i]),$arr_column[1])){
$style=" style='font-weight:bold;color:#0000ff'";
}else{
$style=" style='color:#cccccc'";
}
$column.="<span".$style.">".$arr_thead[$i]."</span>,";
}
if($column)
$column=substr($column,0,-1);
//
$msg1[1]=array("检测到的有效字段",$column);
//
$total=count($arr_content)-1;
$msg1[2]=array("记录条数",$total);
$m1="";
for($i=0;$i<count($msg1);$i++){
$m1.="{\"col1\":\"".$msg1[$i][0]."\",\"col2\":\"".$msg1[$i][1]."\"},";
}
if($m1)
$m1=substr($m1,0,-1);
$json_data.="\"code\":1,\"tmp_file_name\":\"".$tmp_file_name."\",\"msg\":[".$m1."],";
$json_data.="\"input\":[{\"type\":\"radio\",\"title\":\"导入方式\",\"name\":\"import_type\",\"op\":\"清空导入|新增导入\",\"value\":\"清空导入\"}],";
}
break;
case "import_do":
$import_type=($import_type=="清空导入")?"y":"n";
if($import_type=="y"){
$db->query("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<count($arr_column[1]);$i++){
$ititle=$arr_column[1][$i];
$insert_column.=$arr_column[1][$i].",";
}
$insert_column=substr($insert_column,0,-1);
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
$insert_value="";
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="iid"){
$tmp=get_db_msg("select id from ".$table_pre."kh where no='".trim($tmp_arr[$ind])."'");
$insert_value.="'".$tmp["id"]."',";
}else if($ititle=="tid"){
$tmp=get_db_msg("select id from ".$table_pre."kh_tb_t where title='".trim($tmp_arr[$ind])."'");
$insert_value.="'".$tmp["id"]."',";
}else{
$insert_value.="'".mysql_escape_string(trim($tmp_arr[$ind]))."',";
}
}
$insert_value=substr($insert_value,0,-1);
$q="insert into web_kh_tb (".$insert_column.") values (".$insert_value.")";
//echo $q."<br>";
$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."<br>";
$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;
?>