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

2212 lines
79 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"]);
$json_data="{";
if($priv[0]=="n"){
//没有操作权限
$json_data.="\"error\":\"没有操作权限\",\"code\":0,\"msg\":\"\",\"count\":0,\"data\":[],";
}else{
$json_data.="\"uid\":".$uid.",";
$att_dir=dir_cutb(THIS_FILE_ROOT,1);
//
$image_root=$att_dir."/attachments/design/big";
$image_root_mini=$att_dir."/attachments/design/mini";
//make_dir($image_root);
//make_dir($image_root_mini);
$image_view_path="../attachments/design/mini";
$image_view_path_big="../attachments/design/big";
$image_file_type="jpg|jpeg";
//
$arr_kh_size=arr_select("size","title","title");
$zk_type=get_set("zk_type");
$is_multi_price=get_set("is_multi_price");
//取得选项
$arr_select_no=$arr_select_no1=array();
$arr_select_title=$arr_select_title1=array();
$q="select no,title from ".$table_pre."keyword where cate='arr_select' and flag_ka='y' and no<>'jgd' and no<>'sx' order by ord";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
if($m["no"]!="zd1" && $m["no"]!="zd2" && $m["no"]!="zd3"){
$arr_select_no1[]=$m["no"];
$arr_select_title1[]=$m["title"];
if($m["no"]!="designer"){
$arr_select_no2[]=$m["no"];
$arr_select_title2[]=$m["title"];
}
}
$arr_select_no[]=$m["no"];
$arr_select_title[]=$m["title"];
}
//
//---------------
$arr_column_kh["pic"]="图片";
$arr_column_kh["xh"]=d_translate("xh");
$arr_column_kh["no"]="款号";
$arr_column_kh["color_code"]="颜色代码";
$arr_column_kh["color"]="颜色名称";
if(is_array($sys_color_zd)){
if(count($sys_color_zd)>0){
foreach($sys_color_zd as $k1 => $v1){
$arr_column_kh["kh_color_".$k1]=$v1;
}
}
}
if($is_gg=="y"){
$arr_column_kh["gg"]=d_translate("gg");
foreach($sys_gg_zd as $k1 => $v1){
$arr_column_kh["kh_gg_".$k1]=$v1;
}
}else if($is_gg=="b"){
//版型
$arr_column_kh["gg"]=d_translate("gg");
}
$arr_column_kh["size_bx"]="款型";
$arr_column_kh["title"]="款式名";
if($is_multi_price=="y"){
foreach($sys_multi_price as $k1 => $v1){
$arr_column_kh[$k1]=$v1;
}
}else{
$arr_column_kh["price"]="吊牌价";
}
//$arr_column_kh["bd"]="最高订量";
//$arr_column_kh["dhbs"]=d_translate("dhbs");
$arr_column_kh["remark"]="备注";
$arr_column_kh["is_sp"]=d_translate("spk");
$arr_column_kh["ka"]="删除标记";
$arr_column_kh["in_ph"]="参与排行";
$arr_column_kh["size_group"]="尺码组";
$arr_column_kh["size"]="尺码";
$arr_column_kh["dpk"]="搭配款";
$arr_column_kh["dp_pic"]="搭配图";
$arr_column_kh["pm_dj"]="配码等级";
$arr_column_kh["unit_title"]="单位";
//
for($i=0;$i<count($arr_select_no);$i++){
$arr_column_kh[$arr_select_no[$i]]=$arr_select_title[$i];
}
//文胸
if($bx_sizegroup_title){
$tmp=get_db_msg("select id from ".$table_pre."keyword where cate='size' and title='".$bx_sizegroup_title."' limit 0,1");
$bx_sizegroup_id=$tmp["id"];
}else{
$bx_sizegroup_id=0;
}
//童装
if($child_sizegroup_title){
$tmp=get_db_msg("select id from ".$table_pre."keyword where cate='size' and title='".$child_sizegroup_title."' limit 0,1");
$child_sizegroup_id=$tmp["id"];
}else{
$child_sizegroup_id=0;
}
switch($_a){
case "pick_color" :
//--------------------------选取颜色
//取得所有颜色
$q0="select no,title from ".$table_pre."keyword where cate='color' order by no";
$r0=$db->query($q0);
$str_color="";
while($m0=$db->fetch_array($r0)){
$str_color.="{\"no\":\"".$m0["no"]."\",\"title\":\"".$m0["title"]."\"},";
}
$str_color=deel_end($str_color);
$json_data.="\"color\":[".$str_color."],";
break;
case "add" :
//--------------------------新增
$add_date=date("Y-m-d H:i:s");
if($id){
$msg=get_db_msg("select * from ".$table_pre."kh where id='".$id."'");
$add_date=date("Y-m-d H:i:s",$msg["add_date"]);
$ka=$msg["ka"];
$xh=$msg["xh"];
$no=$msg["no"];
$title=$msg["title"];
$main_pic=$msg["main_pic"];
$color=$msg["color"];
$pm_dj=$msg["pm_dj"];
$unit_title=$msg["unit_title"];
//颜色
if($color){
$arr_color=explode(",",$color);
$num_color=count($arr_color);
}else{
$num_color=0;
$arr_color=array();
}
$color_title="";
for($i=0;$i<count($arr_color);$i++){
$tmp=get_cate_title_no("color",$arr_color[$i]);
$color_title.=$tmp.",";
}
$color_title=deel_end($color_title);
//图片
$pic="";
for($i=0;$i<$num_color;$i++){
$pic1=get_kh_color_picture($msg["no"],$arr_color[$i]);
$arr_pic_set=out_good_pic_set_arr($pic1,150,150);
$pic.="{\"color\":\"".$arr_color[$i]."\",\"color_title\":\"".get_cate_title_no("color",$arr_color[$i])."\",\"pic\":\"".$pic1."\",\"w\":\"".$arr_pic_set[0]."\",\"h\":\"".$arr_pic_set[1]."\"},";
}
$pic=deel_end($pic);
//规格
$gg_zd="";
foreach($sys_gg_zd as $k1 => $v1){
$gg_zd.="{\"zd\":\"".$k1."\",\"title\":\"".$v1."\"},";
}
$gg_zd=deel_end($gg_zd);
//规格取值
$gg_zd_value="";
$q1="select * from ".$table_pre."kh_gg where iid='".$id."' order by color,ord";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$m_gg=get_db_msg("select title from ".$table_pre."kh_gg_title where id='".$m1["gg"]."'");
$tmp="{\"zd\":\"title\",\"value\":\"".$m_gg["title"]."\"},";
foreach($sys_gg_zd as $k1 => $v1){
$tmp.="{\"zd\":\"".$k1."\",\"value\":\"".$m1[$k1]."\"},";
}
$gg_zd_value.="{\"color\":\"".$m1["color"]."\",\"zd\":[".deel_end($tmp)."]},";
}
$gg_zd_value=deel_end($gg_zd_value);
//到色属性
$color_zd="";
foreach($sys_color_zd as $k1 => $v1){
$color_zd.="{\"zd\":\"".$k1."\",\"title\":\"".$v1."\"},";
}
$color_zd=deel_end($color_zd);
//到色属性取值
$color_zd_value="";
for($i=0;$i<count($arr_color);$i++){
$m1=get_db_msg("select * from ".$table_pre."kh_color where iid='".$id."' and color='".$arr_color[$i]."'");
$tmp="";
foreach($sys_color_zd as $k1 => $v1){
$tmp.="{\"zd\":\"".$k1."\",\"value\":\"".$m1[$k1]."\"},";
}
$color_zd_value.="{\"color\":\"".$arr_color[$i]."\",\"zd\":[".deel_end($tmp)."]},";
}
$color_zd_value=deel_end($color_zd_value);
//尺码组
$size_group_id=$msg["size_group"];
$tmp=get_db_msg("select id,title from ".$table_pre."keyword where id='".$size_group_id."'");
$size_group_title=$tmp["title"];
//尺码
$arr_size=explode(",",$msg["size"]);
//备注
$remark=htmlspecialchars($msg["remark"]);
$dpk=$msg["dpk"];
$price=$msg["price"];
$in_ph=$msg["in_ph"];
$is_sp=$msg["is_sp"];
}else{
//ord
$tmp=get_db_msg("select max(xh) 'num' from ".$table_pre."kh");
if($tmp[num]>0)
$xh=$tmp[num]+1;
else
$xh=1;
$no=$title=$main_pic=$color=$color_title=$pic=$remark=$dpk=$pm_dj=$unit_title="";
//尺码组
$tmp=get_db_msg("select id,title from ".$table_pre."keyword where cate='size' order by ord limit 0,1");
$size_group_id=$tmp["id"];
$size_group_title=$tmp["title"];
$ka="n";
$in_ph="y";
$is_sp="n";
$arr_color=$arr_size=array();
$price="";
}
//取得所有尺码
$q0="select id,title from ".$table_pre."keyword where cate='size' order by ord";
$r0=$db->query($q0);
$str_size_all="";
while($m0=$db->fetch_array($r0)){
$str_size_all.="{\"id\":\"".$m0["id"]."\",\"title\":\"".$m0["title"]."\",\"size_bx\":[";
if($m0["id"]==$bx_sizegroup_id){
//---文胸
$tmp="";
for($k1=0;$k1<count($arr_bx);$k1++){
//
$tmp.="{\"bx\":\"".$arr_bx[$k1]."\",\"size\":\"";
$tmp1="";
$r1=$db->query("select no,title from ".$table_pre."size where iid='".$m0["id"]."' order by no");
while($m1=$db->fetch_array($r1)){
$tmp1.=$m1["no"]."|".$m1["title"].",";
}
$tmp1=deel_end($tmp1);
$tmp.=$tmp1."\"},";
}
$tmp=deel_end($tmp);
$str_size_all.=$tmp;
}else if($m0["id"]==$child_sizegroup_id){
//---童装
$tmp="";
foreach($arr_child_bx as $bx1 => $arr_size_title1){
//取得所有尺码
$tmp.="{\"bx\":\"".$bx1."\",\"size\":\"";
$tmp1="";
for($j=0;$j<count($arr_size_title1);$j++){
$m1=get_db_msg("select no from ".$table_pre."size where iid='".$m0["id"]."' and title='".$arr_size_title1[$j]."'");
$tmp1.=$m1["no"]."|".$arr_size_title1[$j].",";
}
$tmp1=deel_end($tmp1);
$tmp.=$tmp1."\",\"price\":\"0\"},";
}
$tmp=deel_end($tmp);
$str_size_all.=$tmp;
}else{
//标准
$tmp="{\"bx\":\"\",\"size\":\"";
$r1=$db->query("select no,title from ".$table_pre."size where iid='".$m0["id"]."' order by no");
$tmp1="";
while($m1=$db->fetch_array($r1)){
$tmp1.=$m1["no"]."|".$m1["title"].",";
}
$tmp1=deel_end($tmp1);
$tmp.=$tmp1."\"}";
$str_size_all.=$tmp;
}
$str_size_all.="]},";
}
$str_size_all=deel_end($str_size_all);
//取得已选尺码
$size="";
if($size_group_id==$bx_sizegroup_id){
//---文胸
$tmp="";
for($k1=0;$k1<count($arr_bx);$k1++){
//
$m1=get_db_msg("select size from ".$table_pre."size_bx where no='".$no."' and bx='".$arr_bx[$k1]."'");
$tmp.="{\"bx\":\"".$arr_bx[$k1]."\",\"size\":\"".$m1["size"]."\"},";
}
$tmp=deel_end($tmp);
$size.=$tmp;
}else if($size_group_id==$child_sizegroup_id){
//---童装
$tmp="";
foreach($arr_child_bx as $bx1 => $arr_size_title1){
//取得所有尺码
$m1=get_db_msg("select size,price from ".$table_pre."size_bx where no='".$no."' and bx='".$bx1."'");
$tmp.="{\"bx\":\"".$bx1."\",\"size\":\"".$m1["size"]."\",\"price\":\"".$m1["price"]."\"},";
}
$tmp=deel_end($tmp);
$size.=$tmp;
}else{
//标准
$size="{\"bx\":\"\",\"size\":\"".$msg["size"]."\"}";
}
//echo $size."--<br>";
//取得定制选项
$select_dz="";
for($i=0;$i<count($arr_select_no);$i++){
if($arr_select_no[$i]!="zd1" && $arr_select_no[$i]!="zd2" && $arr_select_no[$i]!="zd3"){
//取得选项
$tmp="";
$r1=$db->query("select no,title from ".$table_pre."keyword where cate='".$arr_select_no[$i]."' order by no");
while($m1=$db->fetch_array($r1)){
$tmp.="{\"no\":\"".$m1["no"]."\",\"title\":\"".$m1["title"]."\"},";
}
$tmp=deel_end($tmp);
$select_dz.="{\"no\":\"".$arr_select_no[$i]."\",\"title\":\"".$arr_select_title[$i]."\",\"value\":\"".$msg[$arr_select_no[$i]]."\",\"op\":[".$tmp."]},";
}
}
$select_dz=deel_end($select_dz);
//取得自定义字段
$select_zdy="";
$q="select no,title from ".$table_pre."keyword where (no='zd1' or no='zd2' or no='zd3') and flag_ka='y' order by ord";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$select_zdy.="{\"no\":\"".$m["no"]."\",\"title\":\"".$m["title"]."\",\"value\":\"".$msg[$m["no"]]."\"},";
}
$select_zdy=deel_end($select_zdy);
//取得多吊牌价
$str_ddp="";
if($is_multi_price=="y"){
foreach($sys_multi_price as $k1 => $v1){
if($id){
$str_ddp.="{\"k\":\"".$k1."\",\"v\":\"".$v1."\",\"value\":\"".$msg[$k1]."\"},";
}else{
$str_ddp.="{\"k\":\"".$k1."\",\"v\":\"".$v1."\",\"value\":\"\"},";
}
}
$str_ddp=deel_end($str_ddp);
$json_data.="\"is_multi_price\":\"".$is_multi_price."\",";
$json_data.="\"arr_multi_price\":[".$str_ddp."],";
}
//取得规格
$content_color="";
$json_data.="\"is_gg\":\"".$is_gg."\",";
$json_data.="\"gg_zd\":[".$gg_zd."],";
$json_data.="\"gg_zd_value\":[".$gg_zd_value."],";
$json_data.="\"color_zd\":[".$color_zd."],";
$json_data.="\"color_zd_value\":[".$color_zd_value."],";
$json_data.="\"ka\":\"".$ka."\",";
$json_data.="\"xh\":\"".$xh."\",";
$json_data.="\"no\":\"".$no."\",";
$json_data.="\"title\":\"".$title."\",";
$json_data.="\"color\":\"".$color."\",";
$json_data.="\"color_title\":\"".$color_title."\",";
$json_data.="\"pm_dj\":\"".$pm_dj."\",";
$json_data.="\"unit_title\":\"".$unit_title."\",";
$json_data.="\"pic\":[".$pic."],";
$json_data.="\"main_pic\":\"".$main_pic."\",";
$json_data.="\"size_all\":[".$str_size_all."],";
$json_data.="\"size_group_id\":\"".$size_group_id."\",";
$json_data.="\"size_group_title\":\"".$size_group_title."\",";
$json_data.="\"size\":[".$size."],";
$json_data.="\"price\":\"".$price."\",";
$json_data.="\"select_dz\":[".$select_dz."],";
$json_data.="\"select_zdy\":[".$select_zdy."],";
$json_data.="\"remark\":\"".htmlspecialchars($remark)."\",";
$json_data.="\"in_ph\":\"".$in_ph."\",";
$json_data.="\"is_sp\":\"".$is_sp."\",";
$json_data.="\"dpk\":\"".$dpk."\",";
$json_data.="\"add_date\":\"".$add_date."\",";
$json_data.="\"lang_xh\":\"".d_translate("xh")."\",";
$json_data.="\"lang_gg\":\"".d_translate("gg")."\",";
$json_data.="\"child_sizegroup_title\":\"".$child_sizegroup_title."\",";
$json_data.="\"bx_sizegroup_title\":\"".$bx_sizegroup_title."\",";
break;
case "copy" :
//--------------------------复制
if($id>0){
$msg=get_db_msg("select * from ".$table_pre."kh where id='".$id."'");
$add_date=time();
//xh
$tmp=get_db_msg("select max(xh) 'num' from ".$table_pre."kh");
if($tmp[num]>0)
$xh=$tmp[num]+1;
else
$xh=1;
//复制一条
$no=$msg["no"]."_copy";
$sql_dz1=$sql_dz2="";
for($i=0;$i<count($arr_select_no);$i++){
$sql_dz1.=$arr_select_no[$i].",";
$sql_dz2.="'".$msg[$arr_select_no[$i]]."',";
}
$query="insert ".$table_pre."kh (uid,is_sp,ka,in_ph,xh,no,title,main_pic,color,size,size_group,".$sql_dz1."price,price1,price2,price3,price4,price5,price_zk,bd,jgd,remark,add_date,pm_dj) values ('".$uid."','".$msg["is_sp"]."','".$msg["ka"]."','".$msg["in_ph"]."','".$xh."','".$no."','".$msg["title"]."','".$msg["main_pic"]."','".$msg["color"]."','".$msg["size"]."','".$msg["size_group"]."',".$sql_dz2."'".$msg["price"]."','".$msg["price1"]."','".$msg["price2"]."','".$msg["price3"]."','".$msg["price4"]."','".$msg["price5"]."','".$msg["price_zk"]."','".$msg["bd"]."','".$msg["jgd"]."','".$msg["remark"]."','".$add_date."','".$msg["pm_dj"]."')";
$db->query($query);
$lid=$db->insert_id();
$no_old=$msg["no"];
//取得新复制的记录
$msg=get_db_msg("select * from ".$table_pre."kh where id='".$lid."'");
//复制杯型
$r1=$db->query("select * from ".$table_pre."size_bx where no='".$no_old."'");
while($m1=$db->fetch_array($r1)){
$db->query("insert into ".$table_pre."size_bx (no,bx,size) values ('".$msg["no"]."','".$m1["bx"]."','".$m1["size"]."')");
}
//复制到款色表
$arr_color=explode(",",$msg["color"]);
for($i=0;$i<count($arr_color);$i++){
$q1="insert ".$table_pre."kh_color (iid,color) values ('".$lid."','".$arr_color[$i]."')";
$db->query($q1);
}
//
$json_data.="\"code\":1,\"id\":\"".$lid."\",";
}else{
$json_data.="\"code\":0,\"msg\":\"选择的记录不存在\",";
}
break;
case "save_add" :
$add_date=day_to_time($add_date);
$json_data.="\"unit_title\":\"".$unit_title."\",";
//根据尺码组名称取得尺码组id
$tmp=get_db_msg("select id from ".$table_pre."keyword where cate='size' and title='".$size_group_title."'");
$size_group=$tmp["id"];
$a=$size_group_id;
$b=$size_group;
//
$v_size="";
if($size_group==$bx_sizegroup_id){
//文胸
$size_bx1=array();
for($i=0;$i<count($arr_bx);$i++){
$bx1=$arr_bx[$i];
$r1=$db->query("select no,title from ".$table_pre."size where iid='".$size_group."' order by no");
$tmp_size="";
while($m1=$db->fetch_array($r1)){
$v2="size_".$size_group."_".$i."_".$m1["no"];
if($$v2=="on")
$tmp_size.=$m1["no"].",";
}
$tmp_size=deel_end($tmp_size);
//echo $size_group."-".$i."-".$tmp_size."<br>";
//
if($tmp_size){
$c=get_db_msg("select id from ".$table_pre."size_bx where no='".$no."' and bx='".$bx1."'");
if($c["id"]>0){
$q1="update ".$table_pre."size_bx set size='".$tmp_size."' where id='".$c["id"]."'";
}else{
$q1="insert into ".$table_pre."size_bx (no,bx,size) values ('".$no."','".$bx1."','".$tmp_size."')";
}
$db->query($q1);
$size_bx1[]=$bx1;
//echo $arr_bx[$i-1].":".$$v1."<br>";
}
}
//删除未勾选的杯型数据
$q1="select * from ".$table_pre."size_bx where no='".$no."'";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
//
if(!in_array($m1["bx"],$size_bx1)){
$db->query("delete from ".$table_pre."size_bx where id='".$m1["id"]."'");
}
}
$v_size="";
}else if($size_group==$child_sizegroup_id){
//童装
$size_bx1=array();
$i=0;
foreach($arr_child_bx as $bx1 => $arr_bx_size_title1){
$v3="price_".$size_group."_".$i;
$tmp_size="";
for($j=0;$j<count($arr_bx_size_title1);$j++){
$tmp=get_db_msg("select no from ".$table_pre."size where iid='".$size_group."' and title='".$arr_bx_size_title1[$j]."'");
$v2="size_".$size_group."_".$i."_".$tmp["no"];
if($$v2=="on")
$tmp_size.=$tmp["no"].",";
}
$tmp_size=deel_end($tmp_size);
//echo $size_group."-".$i."-".$tmp_size."<br>";
//
if($tmp_size){
$c=get_db_msg("select id from ".$table_pre."size_bx where no='".$no."' and bx='".$bx1."'");
if($c["id"]>0){
$q1="update ".$table_pre."size_bx set size='".$tmp_size."',price='".$$v3."' where id='".$c["id"]."'";
}else{
$q1="insert into ".$table_pre."size_bx (no,bx,size,price) values ('".$no."','".$bx1."','".$tmp_size."','".$$v3."')";
}
//echo $q1."<br>";
$db->query($q1);
$size_bx1[]=$bx1;
}
$i++;
}
//删除未勾选的杯型数据
$q1="select * from ".$table_pre."size_bx where no='".$no."'";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
//
if(!in_array($m1["bx"],$size_bx1)){
$db->query("delete from ".$table_pre."size_bx where id='".$m1["id"]."'");
}
}
$v_size="";
}else{
$v_size="";
$q1="select no,title from ".$table_pre."size where iid='".$size_group."' order by no";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$var="size_".$size_group."_0_".$m1["no"];
if($$var=="on")
$v_size.=$m1["no"].",";
}
$v_size=deel_end($v_size);
}
$jgd=get_jgd($price);
$is_sp=($is_sp=="on")?"y":"n";
$in_ph=($in_ph=="on")?"y":"n";
//取得颜色
$color1="";
$arr1=explode(",",$color);
for($i=0;$i<count($arr1);$i++){
$tmp=explode("-",$arr1[$i]);
$color1.=$tmp[0].",";
}
$color=deel_end($color1);
//--------------------------------------------------验证
if($is_gg!="n"){
//-------------------------------保存规格
for($i=0,$ord=0;$i<$gg_num;$i++){
$var_gg_color="gg_color_".$i;
$var_gg_title="gg_title_".$i;
if(trim($$var_gg_title) && $$var_gg_color){
$ord++;
}
}
//删除多余规格
$m1=get_db_msg("select count(*) 'num' from ".$table_pre."kh_gg g,".$table_pre."order o where g.iid='".$lid."' and g.ord>=".$ord." and o.iid='".$lid."' and o.bx=g.gg and o.color=g.color and o._key='".$_key."'");
$wrong_gg="";
if($m1["num"]>0){
//已经有订单的规格不能删除
$msg_error="已经有订单的规格不能删除!";
}
}
//验证颜色,尺码
if($id>0){
$msg=get_db_msg("select * from ".$table_pre."kh where id='".$id."'");
if($size_group==$bx_sizegroup_id){
//文胸
}else if($size_group==$child_sizegroup_id){
//童装
}else{
//是否修改了尺码
//echo $v_size."-".$msg["size"];
if($v_size!=$msg["size"]){
//取得差异的尺码
$arr1=explode(",",$v_size);
$arr2=explode(",",$msg["size"]);
$arr_size_jia=$arr_size_jian=$arr_size_cy=array();
for($i=0;$i<count($arr1);$i++){
if($arr1[$i]>0){
if(!in_array($arr1[$i],$arr2)){
$arr_size_cy[]=$arr1[$i];
$arr_size_jia[]=$arr1[$i];
}
}
}
for($i=0;$i<count($arr2);$i++){
if($arr2[$i]>0){
if(!in_array($arr2[$i],$arr1)){
$arr_size_cy[]=$arr2[$i];
$arr_size_jian[]=$arr2[$i];
}
}
}
sort($arr_size_cy);
//检测尺码有订单,不允许修改
$flag=0;
for($i=0;$i<count($arr_size_cy);$i++){
if($arr_size_cy[$i]>0){
$check=get_db_msg("select num_".$arr_size_cy[$i]." 'num' from ".$table_pre."order where iid='".$id."' and _key='".$_key."'");
if($check["num"]>0){
//取得尺码名称
$tmp=get_db_msg("select title from ".$table_pre."size where iid='".$msg["size_group"]."' and no='".$arr_size_cy[$i]."'");
$msg_error="尺码(".$tmp["title"].")存在订单,请先删除该订单再操作!";
$flag++;
}
}
}
//没有订单,修改size_pm表
if(!$flag){
$q="select id,gz,num from ".$table_pre."size_pm where khid='".$id."'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$arr_pm1=explode(":",$m["gz"]);
$arr_old_size=explode(",",$msg["size"]);
$arr_old_pm=array();
for($i=0;$i<count($arr_old_size);$i++){
$arr_old_pm[$arr_old_size[$i]]=$arr_pm1[$i];
}
$new_pm=deel_pm_by_size($arr_old_pm,$arr_old_size,$arr1);
$new_num=count_pm_num($new_pm);
$q1="update ".$table_pre."size_pm set gz='".$new_pm."',num='".$new_num."' where id='".$m["id"]."'";
//echo $q1."<br>";
$db->query($q1);
}
}
}
}
//是否修改了颜色
if($color!=$msg["color"]){
//
$check_arr_color=explode(",",$color);
$tmp=explode(",",$msg["color"]);
for($i=0;$i<count($tmp);$i++){
if(!in_array($tmp[$i],$check_arr_color)){
$tmp1=get_db_msg("select count(*) 'num' from ".$table_pre."order where iid='".$id."' and color='".$tmp[$i]."' and _key='".$_key."'");
if($tmp1["num"]>0)
$wrong_color.=$tmp[$i].",";
}
}
}
if($wrong_color){
$msg_error="颜色(".substr($wrong_color,0,-1).")已经有订单,不能删除!";
$alter_color="";
}else{
$alter_color="color='".$color."',";
}
if($size_group_id!=$size_group){
$tmp1=get_db_msg("select count(*) 'num' from ".$table_pre."order where iid='".$id."' and _key='".$_key."'");
if($tmp1["num"]>0){
$msg_error="该款已经有订单,不能修改尺码组!";
}
}
}
//验证款号重复
$c=get_db_msg("select count(*) 'num' from ".$table_pre."kh where id<>'".$id."' and no='".$no."'");
if($c["num"]>0)
$msg_error="该款号已经存在,请检查!";
//
if($msg_error){
$json_data.="\"code\":0,\"msg\":\"".$msg_error."\",";
}else{
//--------------------------------------------------保存
$wrong_color="";
$color=deel_color($color);
if($id){
$msg=get_db_msg("select * from ".$table_pre."kh where id='".$id."'");
$log_action="修改";
//是否修改了款号
if($no!=$msg["no"]){
//修改图片名字
modify_file_name("../attachments/design/big/".$msg["no"].".jpg","../attachments/design/big/".$no.".jpg");
modify_file_name("../attachments/design/mini/".$msg["no"].".jpg","../attachments/design/mini/".$no.".jpg");
$arr_color=explode(",",$msg["color"]);
for($i1=0;$i1<count($arr_color);$i1++){
modify_file_name("../attachments/design/big/".$msg["no"]."_".$arr_color[$i1].".jpg","../attachments/design/big/".$no."_".$arr_color[$i1].".jpg");
modify_file_name("../attachments/design/mini/".$msg["no"]."_".$arr_color[$i1].".jpg","../attachments/design/mini/".$no."_".$arr_color[$i1].".jpg");
}
//修改搭配数据
$tmp="update ".$table_pre."kh_dp set kh='".$no."' where kh='".$msg["no"]."'";
$db->query($tmp);
//修改陈列数据
$tmp="update ".$table_pre."kh_cl set kh='".$no."' where kh='".$msg["no"]."'";
$db->query($tmp);
//修改橱窗数据
$tmp="update ".$table_pre."kh_cc set kh='".$no."' where kh='".$msg["no"]."'";
$db->query($tmp);
//修改杯型数据
$tmp="update ".$table_pre."size_bx set no='".$no."' where no='".$msg["no"]."'";
$db->query($tmp);
//修改规则表
$tmp="update ".$table_pre."gz set kh='".$no."' where kh='".$msg["no"]."'";
$db->query($tmp);
}
//取得定制选项
$sql_dz="";
for($i=0;$i<count($arr_select_no);$i++){
$v1=$arr_select_no[$i];
$sql_dz.=$v1."='".$$v1."',";
}
$query="update ".$table_pre."kh set is_sp='".$is_sp."',uid='".$uid."',dp_pic='".$dp_pic."',xh='".$xh."',in_ph='".$in_ph."',no='".$no."',title='".$title."',".$alter_color."size='".$v_size."',size_group='".$size_group."',price='".$price."',price1='".$price1."',price2='".$price2."',price3='".$price3."',price4='".$price4."',price5='".$price5."',price_zk='".$price_zk."',bd='".$bd."',dpk='".trim($dpk)."',jgd='".$jgd."',remark='".$remark."',".$sql_dz."add_date='".$add_date."',pm_dj='".$pm_dj."',unit_title='".$unit_title."' where id='".$id."'";
$db->query($query);
//设置修改订单表
$sql_dz="";
for($i=0;$i<count($arr_select_no1);$i++){
$v1=$arr_select_no1[$i];
$sql_dz.=$v1."='".$$v1."',";
}
$db->query("update ".$table_pre."order set is_sp='".$is_sp."',no='".$no."',".$sql_dz."jgd='".$jgd."' where iid='".$id."' and _key='".$_key."'");
if($is_multi_price=="y"){
if(($price1 && $msg["price1"]!=$price1) || ($price2 && $msg["price2"]!=$price2) || ($price3 && $msg["price3"]!=$price3) || ($price4 && $msg["price4"]!=$price4) || ($price5 && $msg["price5"]!=$price5)){
//缓存折扣表
$q1="select * from ".$table_pre."zk where iid='".$id."'";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$db->query("update ".$table_pre."zk set price=zk*".get_price_dp($m1["cid"],$id)." where iid='".$id."'");
}
//缓存订单表
$q1="select * from ".$table_pre."order where iid='".$id."' and _key='".$_key."'";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
cache_order($m1["uid"],$m1["iid"],$m1["color"],$m1["bx"]);
}
//缓存客户表
set_order_total_all();
}
}else{
//修改价格缓存订单
if($msg["price"]!=$price){
//缓存折扣表
$db->query("update ".$table_pre."zk set price=zk*".deel_num($price)." where iid='".$id."'");
//缓存订单表
$q1="select * from ".$table_pre."order where iid='".$id."' and _key='".$_key."'";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
cache_order($m1["uid"],$m1["iid"],$m1["color"],$m1["bx"]);
}
//缓存客户表
set_order_total_all();
}
}
$lid=$id;
}else{
//取得定制选项
$sql_dz1=$sql_dz2="";
for($i=0;$i<count($arr_select_no);$i++){
$v1=$arr_select_no[$i];
$sql_dz1.=$v1.",";
$sql_dz2.="'".$$v1."',";
}
$log_action="新增";
$query="insert ".$table_pre."kh (uid,is_sp,ka,in_ph,".$sql_dz1."dp_pic,xh,no,title,color,size,size_group,price,price1,price2,price3,price4,price5,price_zk,bd,jgd,remark,dpk,add_date,pm_dj,unit_title) values ('".$uid."','".$is_sp."','n','".$in_ph."',".$sql_dz2."'".$dp_pic."','".$xh."','".$no."','".$title."','".$color."','".$v_size."','".$size_group."','".$price."','".$price1."','".$price2."','".$price3."','".$price4."','".$price5."','".$price_zk."','".$bd."','".$jgd."','".$remark."','".$dpk."','".$add_date."','".$pm_dj."','".$unit_title."')";
$db->query($query);
$lid=$db->insert_id();
}
if($is_gg!="n"){
//-------------------------------保存规格
for($i=0,$ord=0;$i<$gg_num;$i++){
$var_gg_color="gg_color_".$i;
$var_gg_title="gg_title_".$i;
$var_gg_price="gg_price_".$i;
$var_gg_zd1="gg_zd1_".$i;
$var_gg_zd2="gg_zd2_".$i;
$var_gg_zd3="gg_zd3_".$i;
$var_gg_zd4="gg_zd4_".$i;
$var_gg_zd5="gg_zd5_".$i;
if(trim($$var_gg_title) && $$var_gg_color){
insert_gg(trim($$var_gg_title));
$ck=get_db_msg("select * from ".$table_pre."kh_gg where iid='".$lid."' and ord=".$ord);
$new_gg=get_gg_id(trim($$var_gg_title));
$new_price=$$var_gg_price;
$new_color=$$var_gg_color;
if($ck["id"]>0){
$q1="update ".$table_pre."kh_gg set color='".$new_color."',gg='".$new_gg."',price='".$new_price."',zd1='".$$var_gg_zd1."',zd2='".$$var_gg_zd2."',zd3='".$$var_gg_zd3."',zd4='".$$var_gg_zd4."',zd5='".$$var_gg_zd5."' where id='".$ck["id"]."'";
$db->query($q1);
if($new_color!=$ck["color"] || $new_gg!=$ck["gg"]){
//-----------修改了颜色或者规格
$sql_up1="";
if($new_color!=$ck["color"])
$sql_up1.="color='".$new_color."',";
if($new_gg!=$ck["gg"])
$sql_up1.="bx='".$new_gg."',";
$sql_up1=substr($sql_up1,0,-1);
//处理订单
$db->query("update ".$table_pre."order set ".$sql_up1." where iid='".$lid."' and color='".$ck["color"]."' and bx='".$ck["gg"]."' and _key='".$_key."'");
}
if($new_price && $new_price!=$ck["price"]){
//-----------修改了价格
//缓存折扣表
$q1="select * from ".$table_pre."zk where iid='".$lid."'";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$db->query("update ".$table_pre."zk set price=zk*".(get_price_dp($m1["cid"],$m1["iid"]))." where iid='".$lid."'");
}
//缓存订单表
$q1="select uid,iid,color,bx from ".$table_pre."order where iid='".$lid."' and color='".$new_color."' and bx='".$new_gg."' and _key='".$_key."'";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
cache_order($m1["uid"],$m1["iid"],$m1["color"],$m1["bx"]);
//echo $m1["iid"].",".$m1["color"].",".$m1["bx"]."<br>";
}
//缓存客户表
set_order_total_all();
}
}else{
$q1="insert ".$table_pre."kh_gg (iid,color,ord,gg,price,zd1,zd2,zd3,zd4,zd5) values ('".$lid."','".$new_color."','".$ord."','".$new_gg."','".$new_price."','".$$var_gg_zd1."','".$$var_gg_zd2."','".$$var_gg_zd3."','".$$var_gg_zd4."','".$$var_gg_zd5."')";
$db->query($q1);
//更新已订数据
$db->query("update ".$table_pre."order set bx='".$new_gg."' where iid='".$lid."' and color='".$new_color."' and bx='' and _key='".$_key."'");
}
$ord++;
}
}
//删除多余规格
$m1=get_db_msg("select count(*) 'num' from ".$table_pre."kh_gg g,".$table_pre."order o where g.iid='".$lid."' and g.ord>=".$ord." and o.iid='".$lid."' and o.bx=g.gg and o.color=g.color and o._key='".$_key."'");
$wrong_gg="";
if($m1["num"]>0){
//已经有订单的规格不能删除
$wrong_gg="已经有订单的规格不能删除!";
}else{
$db->query("delete from ".$table_pre."kh_gg where iid='".$lid."' and ord>=".$ord);
}
}
//-------------------------------保存款色表
$arr_color=explode(",",$color);
for($i=0;$i<count($arr_color);$i++){
$var_color_zd1="color_zd_".$arr_color[$i]."_zd1";
$var_color_zd2="color_zd_".$arr_color[$i]."_zd2";
$var_color_zd3="color_zd_".$arr_color[$i]."_zd3";
$var_color_zd4="color_zd_".$arr_color[$i]."_zd4";
$var_color_zd5="color_zd_".$arr_color[$i]."_zd5";
$ck=get_db_msg("select * from ".$table_pre."kh_color where iid='".$lid."' and color='".$arr_color[$i]."'");
if($ck["id"]>0){
$q1="update ".$table_pre."kh_color set zd1='".$$var_color_zd1."',zd2='".$$var_color_zd2."',zd3='".$$var_color_zd3."',zd4='".$$var_color_zd4."',zd5='".$$var_color_zd5."' where id='".$ck["id"]."'";
$db->query($q1);
}else{
$q1="insert ".$table_pre."kh_color (iid,color,zd1,zd2,zd3,zd4,zd5) values ('".$lid."','".$arr_color[$i]."','".$$var_color_zd1."','".$$var_color_zd2."','".$$var_color_zd3."','".$$var_color_zd4."','".$$var_color_zd5."')";
$db->query($q1);
}
//echo $q1."<br>";
}
//删除多余颜色
$q1="select * from ".$table_pre."kh_color where iid='".$lid."'";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
if(!in_array($m1["color"],$arr_color,true)){
$db->query("delete from ".$table_pre."kh_color where id='".$m1["id"]."'");
}
}
//echo $query."<br>";
set_log($log_action."款号",$no."|".$lid);
$json_data.="\"code\":1,";
}
break;
case "set_main_pic" :
$query="update ".$table_pre."kh set main_pic='".$c."' where id='".$id."'";
$db->query($query);
//echo $query."<br>";
set_log("设置主图",$c."|".$id);
$json_data.="\"code\":1,";
break;
case "add_pic":
$msg=get_db_msg("select * from ".$table_pre."kh where id='".$id."'");
$pic=get_kh_color_picture_big($msg["no"],$c);
$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.="\"no\":\"".$msg["no"]."\",\"color\":\"".$c."\",\"color_title\":\"".get_cate_title_no("color",$c)."\",";
break;
case "save_add_pic":
$up_image=$_FILES["up_file"];;
$msg=get_db_msg("select no,color from ".$table_pre."kh where id='".$id."'");
if($del_pic=="y"){
del_file("../attachments/design/big/".$msg["no"]."_".$c.".jpg");
del_file("../attachments/design/mini/".$msg["no"]."_".$c.".jpg");
$check=explode(",",$msg["color"]);
if($check[0]==$c){
del_file("../attachments/design/mini/".$msg["no"].".jpg");
del_file("../attachments/design/big/".$msg["no"].".jpg");
}
}else{
if($up_image["name"]){
//$path1=$image_root;
$path1="../attachments/design/big";
$path2="../attachments/design/mini";
$new_file_name=$msg["no"]."_".$c.".jpg";
make_mini_picture($up_image["tmp_name"],$path1."/".$new_file_name,800);
//缩略图
make_mini_picture($path1."/".$new_file_name,$path2."/".$new_file_name);
}
}
$json_data.="\"code\":1,";
break;
case "set_spk" :
$id=(is_array($id))?$id:array($id);
$num=count($id);
for($i=0;$i<$num;$i++){
$tmp=get_db_msg("select is_sp,no from ".$table_pre."kh where id='".$id[$i]."'");
$is_sp=($tmp["is_sp"]=="y")?"n":"y";
//
$db->query("update ".$table_pre."kh set is_sp='".$is_sp."' where id='".$id[$i]."'");
$db->query("update ".$table_pre."order set is_sp='".$is_sp."' where iid='".$id[$i]."' and _key='".$_key."'");
$lid.=$tmp["no"].", ";
}
$lid=substr($lid,0,-2);
set_log("设置饰品款",$lid);
$json_data.="\"code\":1,";
break;
case "del" :
$id=(is_array($id))?$id:array($id);
$num=count($id);
//验证
$msg_error="";
for($i=0;$i<$num;$i++){
$tmp=get_db_msg("select no from ".$table_pre."kh where id='".$id[$i]."'");
$check=get_db_msg("select count(*) 'num' from ".$table_pre."order where iid='".$id[$i]."' and _key='".$_key."'");
if($check["num"]>0){
$msg_error="对不起,".$tmp["no"]."已经有订单,请先删除订单数据";
}
}
if($msg_error){
$json_data.="\"code\":0,\"msg\":\"".$msg_error."\",";
}else{
//删除
for($i=0;$i<$num;$i++){
$tmp=get_db_msg("select no from ".$table_pre."kh where id='".$id[$i]."'");
//删除款号表
$db->query("delete from ".$table_pre."kh where id='".$id[$i]."'");
//删除款色表
$db->query("delete from ".$table_pre."kh_color where iid='".$id[$i]."'");
$lid.=$tmp["no"].",";
}
$json_data.="\"code\":1,";
$lid=substr($lid,0,-1);
set_log("删除款号",$lid);
}
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_kh);
$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 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,$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\":\"清空导入\"},{\"type\":\"radio\",\"title\":\"选项导入方式\",\"name\":\"import_select\",\"op\":\"清空导入|新增导入\",\"value\":\"新增导入\"}],";
}
break;
case "import_do":
//$tmp_file_name="20191030153523774511";
$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);
$import_type=($import_type=="清空导入")?"y":"n";
$import_select=($import_select=="清空导入")?"y":"n";
$error_msg="";
//检查尺码
$error_size="";
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
//取得尺码组id,款号,颜色
$size_group_id=$kh=$color="";
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="size_group"){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='size' and title='".trim($tmp_arr[$ind])."'");
$size_group_id=$tmp["id"];
}
if($ititle=="no"){
$kh=trim($tmp_arr[$ind]);
}
if($ititle=="color_code"){
$color=trim($tmp_arr[$ind]);
}
}
//取得尺码
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="size"){
$tmp1=explode(",",trim($tmp_arr[$ind]));
for($k1=0;$k1<count($tmp1);$k1++){
$tmp=get_db_msg("select id,no from ".$table_pre."size where iid='".$size_group_id."' and title='".$tmp1[$k1]."'");
if($tmp["id"]>0){
//尺码正常
}else{
//尺码有问题
$error_size.=$kh.",".$color.",".$tmp1[$k1]."<br>";
}
}
}
}
}
if($error_size){
$error_msg="尺码有有问题,请检查!<br>".$error_size;
}
//检查颜色代码重复
$repeat_str="";
$r1=$db->query("select no,title from ".$table_pre."keyword where cate='color' group by no having count(no)>1 order by no");
while($m1=$db->fetch_array($r1)){
$repeat_str.=$m1["no"]."-".$m1["title"].",";
}
if($repeat_str){
$repeat_str=substr($repeat_str,0,-1);
$error_msg="颜色代码有重复,请检查(".$repeat_str.")!";
}
//检查订单
if($import_type=="y" || $import_select=="y"){
$check_dd=get_db_msg("select count(*) 'num' from ".$table_pre."order");
if($check_dd["num"]>0)
$error_msg="对不起,已经有订单,不允许清空导入操作!";
}
if($error_msg){
$json_data.="\"code\":0,\"msg\":\"".$error_msg."\",";
del_tmp_file($tmp_file_name);
}else{
$json_data.="\"code\":1,\"reload_type\":\"1\",";
//-------------------------------------------导入数据
//----导入选项
$check_keyword_zd=array();
for($i=0;$i<count($arr_select_no1);$i++){
$check_keyword_zd[]=$arr_select_no1[$i];
}
$ind_color_code=$ind_color=0;
for($k=0;$k<count($arr_column[1]);$k++){
if($arr_column[1][$k]=="color")
$ind_color=$arr_column[0][$k];
if($arr_column[1][$k]=="color_code")
$ind_color_code=$arr_column[0][$k];
}
$check_dd=get_db_msg("select count(*) 'num' from ".$table_pre."order");
$error_msg="";
if($import_type=="y"){
//清空款号相关数据
$db->query("TRUNCATE TABLE ".$table_pre."kh;");
$db->query("TRUNCATE TABLE ".$table_pre."ph;");
$db->query("TRUNCATE TABLE ".$table_pre."size_bx");
$db->query("TRUNCATE TABLE ".$table_pre."kh_gg_title");
$db->query("TRUNCATE TABLE ".$table_pre."kh_gg");
$db->query("TRUNCATE TABLE ".$table_pre."kh_color");
}
if($import_select=="y"){
//清空选项数据
$db->query("delete from ".$table_pre."keyword where cate<>'zd_color' and cate<>'arr_select' and cate<>'size' and cate<>'jgd' and cate<>'dhgz'");
}
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
$insert_value="";
$tmp_color_code=explode(",",$tmp_arr[$ind_color_code]);
$tmp_color_title=explode(",",$tmp_arr[$ind_color]);
for($j=0;$j<count($tmp_color_code);$j++){
//echo $tmp_arr[0]."|".$tmp_arr[1]."|".$tmp_color_code[$j]."|".$tmp_color_title[$j]."<br>";
update_keyword_color($tmp_color_code[$j],$tmp_color_title[$j]);
}
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if(in_array($arr_column[1][$k],$check_keyword_zd))
update_keyword($arr_column[1][$k],$tmp_arr[$ind]);
}
}
//
$insert_column="";
for($i=0;$i<count($arr_column[1]);$i++){
if($arr_column[1][$i]!="color_code" && $arr_column[1][$i]!="size_bx" && $arr_column[1][$i]!="gg" && !preg_match("/kh_gg_/",$arr_column[1][$i]) && !preg_match("/kh_color_/",$arr_column[1][$i]))
$insert_column.=$arr_column[1][$i].",";
}
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
$insert_value="";
//取得尺码组id,款号,颜色
$size_group_id=$kh=$color="";
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="size_group"){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='size' and title='".trim($tmp_arr[$ind])."'");
$size_group_id=$tmp["id"];
}
if($ititle=="no"){
$kh=trim($tmp_arr[$ind]);
}
if($ititle=="color_code"){
$color=trim($tmp_arr[$ind]);
}
}
//取得尺码
$size="";
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="size"){
$tmp1=explode(",",trim($tmp_arr[$ind]));
for($k1=0;$k1<count($tmp1);$k1++){
$tmp=get_db_msg("select * from ".$table_pre."size where iid='".$size_group_id."' and title='".$tmp1[$k1]."'");
$size.=$tmp["no"].",";
}
if($size)
$size=substr($size,0,-1);
}
}
//检查是否存在款号
$check=get_db_msg("select id,color,size from ".$table_pre."kh where no='".$kh."'");
if($check["id"]>0){
//存在款号
$arr_old_color=explode(",",$check["color"]);
if(!in_array($color,$arr_old_color)){
if(trim($check["color"]))
$color=$check["color"].",".$color;
else
$color=$color;
$q="update ".$table_pre."kh set color='".$color."',size='".size_hb($check["size"],$size)."' where id='".$check["id"]."'";
}else{
$q="update ".$table_pre."kh set size='".size_hb($check["size"],$size)."' where id='".$check["id"]."'";
}
}else{
//不存在款号
for($k=0;$k<count($arr_column[0]);$k++){
if($arr_column[1][$k]!="color_code" && $arr_column[1][$k]!="gg" && !preg_match("/kh_gg_/",$arr_column[1][$k]) && !preg_match("/kh_color_/",$arr_column[1][$k])){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if(in_array($ititle,$arr_select_no1)){
$tmp=get_db_msg("select no from ".$table_pre."keyword where cate='".$ititle."' and title='".trim($tmp_arr[$ind])."'");
$insert_value.="'".mysql_escape_string(trim($tmp["no"]))."',";
}else if($ititle=="size_group"){
$insert_value.="'".mysql_escape_string($size_group_id)."',";
}else if($ititle=="color"){
$insert_value.="'".trim($color)."',";
}else if($ititle=="size"){
$v1="";
$tmp1=explode(",",trim($tmp_arr[$ind]));
for($k1=0;$k1<count($tmp1);$k1++){
$tmp=get_db_msg("select * from ".$table_pre."size where iid='".$size_group_id."' and title='".$tmp1[$k1]."'");
$v1.=$tmp["no"].",";
}
if($v1)
$v1=substr($v1,0,-1);
$insert_value.="'".mysql_escape_string($v1)."',";
}else if($ititle=="size_bx"){
//不导入杯型
}else{
$insert_value.="'".mysql_escape_string(trim($tmp_arr[$ind]))."',";
}
}
}
$q="insert into ".$table_pre."kh (uid,".$insert_column."add_date) values ('".$uid."',".$insert_value."'".time()."')";
}
//echo $i.".".$q."<br>";
if($q)
$db->query($q);
}
//
del_tmp_file($tmp_file_name);
//去掉重复色号,处理价格带
$q="select * from ".$table_pre."kh";
$r=$db->query($q);
$i=1;
while($m=$db->fetch_array($r)){
//处理价格带
$q1="update ".$table_pre."kh set jgd='".get_jgd($m["price"])."' where id='".$m["id"]."'";
$db->query($q1);
//去掉重复色
$arr_color=explode(",",trim($m["color"]));
$arr_color1=array_unique($arr_color);
if($arr_color1!=$arr_color){
$q1="update ".$table_pre."kh set color='".arr_to_str($arr_color1)."' where id='".$m["id"]."'";
$db->query($q1);
}
$i++;
}
//自动编排圆牌号
$tmp=get_db_msg("select max(xh) 'max_xh' from ".$table_pre."kh");
$max_xh=$tmp["max_xh"]>0?$tmp["max_xh"]:0;
$q="select id,xh from ".$table_pre."kh where xh=0 order by no";
$r=$db->query($q);
$i=1;
while($m=$db->fetch_array($r)){
$this_xh=$max_xh+$i;
$db->query("update ".$table_pre."kh set xh='".$this_xh."' where id='".$m["id"]."'");
$i++;
}
//导入杯型
if($bx_sizegroup_id>0 || $child_sizegroup_id>0){
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
//取得尺码组id
$size_group_id="";
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="size_group"){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='size' and title='".trim($tmp_arr[$ind])."'");
$size_group_id=$tmp["id"];
//echo $size_group_id."-";
}
}
//取得款号,款型,价格,尺码
$bx=$kh=$price=$size="";
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="no"){
$kh=trim($tmp_arr[$ind]);
}
if($ititle=="size_bx"){
if($size_group_id==$child_sizegroup_id){
$bx=deel_bx_zt($tmp_arr[$ind]);
}else if($size_group_id==$bx_sizegroup_id){
$bx=deel_bx($tmp_arr[$ind]);
}else{
$bx=$tmp_arr[$ind];
}
}
if($ititle=="price"){
$price=trim($tmp_arr[$ind]);
}
if($ititle=="size"){
$tmp1=explode(",",trim($tmp_arr[$ind]));
for($k1=0;$k1<count($tmp1);$k1++){
$tmp=get_db_msg("select no from ".$table_pre."size where iid='".$size_group_id."' and title='".$tmp1[$k1]."'");
$size.=$tmp["no"].",";
}
if($size)
$size=substr($size,0,-1);
}
}
//echo $kh."-".$size_group_id."-".$bx."-".$size."-".$price."<Br>";
if($size_group_id==$bx_sizegroup_id){
$c=get_db_msg("select id,size from ".$table_pre."size_bx where no='".$kh."' and bx='".$bx."'");
if($c["id"]>0){
$q1="update ".$table_pre."size_bx set size='".size_hb($c["size"],$size)."' where id='".$c["id"]."'";
}else{
$q1="insert into ".$table_pre."size_bx (no,bx,size) values ('".$kh."','".$bx."','".$size."')";
}
//echo $q1."<br>";
$db->query($q1);
}else if($size_group_id==$child_sizegroup_id){
$c=get_db_msg("select id,size from ".$table_pre."size_bx where no='".$kh."' and bx='".$bx."'");
if($c["id"]>0){
$q1="update ".$table_pre."size_bx set size='".size_hb($c["size"],$size)."',price='".$price."' where id='".$c["id"]."'";
}else{
$q1="insert into ".$table_pre."size_bx (no,bx,size,price) values ('".$kh."','".$bx."','".$size."','".$price."')";
}
//echo $q1."<br>";
$db->query($q1);
}
}
}
//导入规格
if($is_gg!="n"){
//导入规格名称
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
//取得款号,规格
$gg="";
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="gg"){
$gg=trim($tmp_arr[$ind]);
insert_gg($gg);
}
}
}
//导入规格数据
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
//取得款号,规格
$kh=$color=$gg="";
if($is_gg=="y"){
foreach($sys_gg_zd as $k1 => $v1){
$tmp="kh_gg_".$k1;
$$tmp="";
}
}
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="gg"){
$gg=trim($tmp_arr[$ind]);
}
if($ititle=="no"){
$kh=trim($tmp_arr[$ind]);
}
if($ititle=="color_code"){
$color=trim($tmp_arr[$ind]);
}
if(preg_match("/kh_gg_/",$ititle)){
$$ititle=trim($tmp_arr[$ind]);
}
}
//
if($gg){
$m_kh=get_db_msg("select id from ".$table_pre."kh where no='".$kh."'");
$m_gg=get_db_msg("select id from ".$table_pre."kh_gg_title where title='".$gg."'");
$c=get_db_msg("select id from ".$table_pre."kh_gg where iid='".$m_kh["id"]."' and color='".$color."' and gg='".$gg."'");
if($c["id"]>0){
//记录重复,不处理
}else{
$sql_insert1=$sql_insert2="";
if($is_gg=="y"){
foreach($sys_gg_zd as $k1 => $v1){
$tmp="kh_gg_".$k1;
$sql_insert1.=",".$k1;
$sql_insert2.=",'".$$tmp."'";
}
}
$q1="insert into ".$table_pre."kh_gg (iid,color,ord,gg".$sql_insert1.") values ('".$m_kh["id"]."','".$color."','".$i."','".$m_gg["id"]."'".$sql_insert2.")";
}
//echo $q1."<br>";
$db->query($q1);
}
}
//更新ord
$q="select iid from ".$table_pre."kh_gg group by iid order by iid,color";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$q1="select id from ".$table_pre."kh_gg where iid='".$m["iid"]."' order by color,ord";
$r1=$db->query($q1);
$i1=0;
while($m1=$db->fetch_array($r1)){
$q2="update ".$table_pre."kh_gg set ord='".$i1."' where id='".$m1["id"]."'";
$db->query($q2);
$i1++;
}
}
}
//导入款号颜色表
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
//取得款号,颜色,以及自定义字段
$kh=$color="";
foreach($sys_color_zd as $k1 => $v1){
$tmp="kh_color_".$k1;
$$tmp="";
}
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="no"){
$kh=trim($tmp_arr[$ind]);
}
if($ititle=="color_code"){
$color=trim($tmp_arr[$ind]);
}
if(preg_match("/kh_color_/",$ititle)){
$$ititle=trim($tmp_arr[$ind]);
}
}
//
if($kh && $color){
$m_kh=get_db_msg("select id from ".$table_pre."kh where no='".$kh."'");
$c=get_db_msg("select id from ".$table_pre."kh_color where iid='".$m_kh["id"]."' and color='".$color."'");
if($c["id"]>0){
//记录重复,不处理
}else{
$sql_insert1=$sql_insert2="";
foreach($sys_color_zd as $k1 => $v1){
$tmp="kh_color_".$k1;
$sql_insert1.=",".$k1;
$sql_insert2.=",'".$$tmp."'";
}
$q1="insert into ".$table_pre."kh_color (iid,color".$sql_insert1.") values ('".$m_kh["id"]."','".$color."'".$sql_insert2.")";
$db->query($q1);
}
//echo $q1."<br>";
}
}
$log_remark=$import_flag;
set_log("导入 款号数据",$log_remark);
}
break;
//----------------------------------------------------------------------/导入EXCEL
//----------------------------------------------------------------------导出数据
case "export":
$column="";
foreach($arr_column_kh as $k => $v){
if($k=="size_bx"){
if($bx_sizegroup_id>0 || $child_sizegroup_id>0)
$column.="{\"k\":\"".$k."\",\"t\":\"".$v."\"},";
}else{
$column.="{\"k\":\"".$k."\",\"t\":\"".$v."\"},";
}
}
if($column)
$column=substr($column,0,-1);
$json_data.="\"col\":[".$column."],";
$json_data.="\"color_select\":[{\"k\":\"2\",\"t\":\"纵向\"},{\"k\":\"1\",\"t\":\"横向逗号隔开\"}],";
break;
case "export_do":
//取得字段选择的值
foreach($arr_column_kh as $k => $v){
$var="col_".$k;
if($$var=="on"){
$ex_col[]=$k;
}
}
$num=count($ex_col);
if($num==0)
alert_and_back("请至少选择一个要导出的字段");
$show_bx=$show_gg="n";
$data=array();
//设置表头数据类型
for($i=0;$i<$num;$i++){
if($ex_col[$i]=="pic"){
$data["col"][]="img";
}else{
$data["col"][]="str";
}
}
//设置表头
for($i=0;$i<$num;$i++){
if($ex_col[$i]=="pic"){
$data["header"][0][]="图片|img";
}else if($ex_col[$i]=="color_code"){
$data["header"][0][]="颜色代码|str";
}else if($ex_col[$i]=="size_bx"){
$show_bx="y";
$data["header"][0][]=get_main_value($arr_column_kh,$ex_col[$i]);
}else if($ex_col[$i]=="gg"){
$show_gg="y";
$data["header"][0][]=get_main_value($arr_column_kh,$ex_col[$i]);
}else{
$data["header"][0][]=get_main_value($arr_column_kh,$ex_col[$i]);
}
}
//取得数据
$query="select * from ".$table_pre."kh order by no";
$r=$db->query($query);
$row=0;
while($m=$db->fetch_array($r)){
//取得杯型
$arr1=array();
if(($m["size_group"]==$bx_sizegroup_id || $m["size_group"]==$child_sizegroup_id) && $show_bx=="y"){
$r1=$db->query("select * from ".$table_pre."size_bx where no='".$m["no"]."' order by bx");
$i1=0;
while($m1=$db->fetch_array($r1)){
$arr1[$i1][]=$m1["bx"];
$arr1[$i1][]=$m1["size"];
$i1++;
}
}
if(count($arr1)==0){
$arr1[0][]="";
$arr1[0][]=$m["size"];
}
if($color_select=="1"){
//---------------------------------------------------颜色横向逗号方式
//取得规格
$i1=0;
$str_gg="";
if($is_gg!="n" && $show_gg=="y"){
$r1=$db->query("select * from ".$table_pre."kh_gg where iid='".$m["id"]."' order by ord");
while($m1=$db->fetch_array($r1)){
$str_gg.=get_cate_title_no("color",$m1["color"])."-".get_gg_title($m1["gg"]).",";
$i1++;
}
}
if($i1>0)
$str_gg=substr($str_gg,0,-1);
//
for($j1=0;$j1<count($arr1);$j1++){
for($i=0;$i<$num;$i++){
$k=$ex_col[$i];
if(in_array($k,$arr_select_no1)){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='".$k."' and no='".$m[$k]."'");
$data["body"][$row][]=$tmp["title"];
}else if($k=="size_bx"){
$data["body"][$row][]=$arr1[$j1][0];
}else if($k=="pic"){
$pic=get_kh_picture($m["no"],$m["main_pic"],$m["color"]);
$pic=str_replace("images/no_pic_80.gif","",$pic);
$data["body"][$row][]=$pic;
}else if($k=="gg"){
$data["body"][$row][]=$str_gg;
}else if(preg_match("/kh_gg_/",$k)){
$tmp1=str_replace("kh_gg_","",$k);
$data["body"][$row][]="";
}else if(preg_match("/kh_color_/",$k)){
$data["body"][$row][]="";
}else if($k=="size_group"){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='size' and id='".$m[$k]."'");
$data["body"][$row][]=$tmp["title"];
}else if($k=="size"){
$v1="";
$tmp1=explode(",",$arr1[$j1][1]);
for($k=0;$k<count($tmp1);$k++){
$tmp=get_db_msg("select * from ".$table_pre."size where iid='".$m["size_group"]."' and no='".$tmp1[$k]."'");
$v1.=$tmp["title"].",";
}
if($v1)
$v1=substr($v1,0,-1);
$data["body"][$row][]=$v1;
}else if($k=="color" || $k=="color_ka"){
$v1="";
$tmp1=explode(",",$m[$k]);
for($k1=0;$k1<count($tmp1);$k1++){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='color' and no='".$tmp1[$k1]."'");
$v1.=$tmp["title"].",";
}
if($v1)
$v1=substr($v1,0,-1);
$data["body"][$row][]=$v1;
}else if($k=="color_code"){
$data["body"][$row][]=$m["color"];
}else if($k=="ka"){
if($m[$k]=="y")
$ka="";
else
$ka="";
$data["body"][$row][]=$ka;
}else{
$data["body"][$row][]=$m[$k];
}
}
$row++;
}
}else{
//---------------------------------------------------颜色纵向方式
$arr_color=explode(",",$m["color"]);
$arr_color_ka=explode(",",$m["color_ka"]);
for($j=0;$j<count($arr_color);$j++){
//取得规格
$arr_gg_data=array();
$i1=0;
if($is_gg!="n" && $show_gg=="y"){
$r1=$db->query("select * from ".$table_pre."kh_gg where iid='".$m["id"]."' and color='".$arr_color[$j]."' order by ord");
while($m1=$db->fetch_array($r1)){
$arr_gg_data[$i1]["gg"]=get_gg_title($m1["gg"]);
if($is_gg=="y"){
foreach($sys_gg_zd as $k1 => $v1){
$tmp="kh_gg_".$k1;
//$arr_gg_data[$i1][$k1]=$m1[$k1];
$arr_gg_data[$i1][$tmp]=$m1[$k1];
}
}
$i1++;
}
}else{
if(is_array($sys_color_zd) && count($sys_color_zd)>0){
$arr_color_data=array();
$i2=0;
$r1=$db->query("select * from ".$table_pre."kh_color where iid='".$m["id"]."' and color='".$arr_color[$j]."' order by color");
while($m1=$db->fetch_array($r1)){
foreach($sys_color_zd as $k1 => $v1){
$tmp="kh_color_".$k1;
$arr_color_data[$i2][$tmp]=$m1[$k1];
//$arr_color_data[$i2][$k1]=$m1[$k1];
}
$i2++;
}
}
}
if($i1==0)
$arr_gg_data[0]=array();
for($j1=0;$j1<count($arr1);$j1++){//杯型
for($g1=0;$g1<count($arr_gg_data);$g1++){//规格
for($i=0;$i<$num;$i++){
$k=$ex_col[$i];
$k1="".$ex_col[$i];
if(in_array($k,$arr_select_no1)){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='".$k."' and no='".$m[$k]."'");
$data["body"][$row][]=$tmp["title"];
}else if($k=="pic"){
$pic=get_kh_color_picture($m["no"],$arr_color[$j]);
$pic=str_replace("images/no_pic_80.gif","",$pic);
$data["body"][$row][]=$pic;
}else if($k=="size_group"){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='size' and id='".$m[$k]."'");
$data["body"][$row][]=$tmp["title"];
}else if($k=="size_bx"){
$data["body"][$row][]=$arr1[$j1][0];
}else if($k=="gg"){
$data["body"][$row][]=$arr_gg_data[$g1]["gg"];
}else if(preg_match("/kh_gg_/",$k)){
//$tmp1=str_replace("kh_gg_","",$k);
//$data["body"][$row][]=$arr_gg_data[$g1][$tmp1];
$data["body"][$row][]=$arr_gg_data[$g1][$k];
}else if(preg_match("/kh_color_/",$k)){
//$tmp1=str_replace("kh_color_","",$k);
//var_dump($tmp1);
//exit;
//$data["body"][$row][]=$arr_color_data[$g1][$tmp1];
$data["body"][$row][]=$arr_color_data[$g1][$k];
}else if($k=="size"){
$v1="";
$tmp1=explode(",",$arr1[$j1][1]);
for($k1=0;$k1<count($tmp1);$k1++){
//检查不予下单尺码
$check=get_db_msg("select size from ".$table_pre."size_not where kh='".$m["no"]."' and color='".$arr_color[$j]."' and bx='".$arr1[$j1][0]."'");
$tmp_size=explode(",",$check["size"]);
if(!in_array($tmp1[$k1],$tmp_size)){
$tmp=get_db_msg("select * from ".$table_pre."size where iid='".$m["size_group"]."' and no='".$tmp1[$k1]."'");
$v1.=$tmp["title"].",";
}
}
if($v1)
$v1=substr($v1,0,-1);
$data["body"][$row][]=$v1;
}else if($k=="color"){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='color' and no='".$arr_color[$j]."'");
$data["body"][$row][]=$tmp["title"];
}else if($k=="color_code"){
$data["body"][$row][]=$arr_color[$j];
}else if($k=="price"){
if($m["size_group"]==$child_sizegroup_id){
//童装
$c=get_db_msg("select price from ".$table_pre."size_bx where no='".$m["no"]."' and bx='".$arr1[$j1][0]."'");
$data["body"][$row][]=$c["price"];
}else{
$data["body"][$row][]=$m["price"];
}
}else if($k=="ka"){
if($m["ka"]=="y" || in_array($arr_color[$j],$arr_color_ka))
$ka="";
else
$ka="";
$data["body"][$row][]=$ka;
}else if($k=="color_ka"){
$v1="";
if(is_array($arr_color_ka)){
if(in_array($arr_color[$j],$arr_color_ka)){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='color' and no='".$arr_color[$j]."'");
$v1=$tmp["title"];
}
}else{
$v1="";
}
$data["body"][$row][]=$v1;
}else{
$data["body"][$row][]=$m[$k];
}
}
$row++;
}
}
}
}
}
$file_name="kh_".date("Y-m-d-H-i");
//print_r($data);
//exit;
output_excel($file_name,$data);
set_log("导出 款号信息");
exit;
break;
//----------------------------------------------------------------------/导出数据
case "check":
$str="";
//--------------------款号重复
$q="select * from ".$table_pre."kh group by no having count(no)>1";
$r=$db->query($q);
$i=0;
$tmp="";
while($m=$db->fetch_array($r)){
$tmp.="{\"kh\":\"".$m["no"]."\",\"v\":\"".$m["no"]."\"},";
$i++;
}
if($i>0){
$str.="{\"cate\":\"款号重复\",\"data\":[".deel_end($tmp)."]},";
}
//--------------------圆牌号重复
$q="select * from ".$table_pre."kh group by xh having count(xh)>1";
$r=$db->query($q);
$i=0;
$tmp="";
while($m=$db->fetch_array($r)){
$tmp.="{\"v\":\"".$m["xh"]."\",\"xh\":\"".$m["xh"]."\"},";
$i++;
}
if($i>0){
$str.="{\"cate\":\"".d_translate("xh")."重复\",\"data\":[".deel_end($tmp)."]},";
}
//--------------------检查颜色
$q="select * from ".$table_pre."kh";
$r=$db->query($q);
$tmp1=$tmp2=$tmp3="";
$i1=$i2=$i3=0;
while($m=$db->fetch_array($r)){
//缺颜色
if(trim($m["color"])==""){
$tmp1.="{\"v\":\"".$m["id"]."-".$m["no"]."\",\"kh\":\"".$m["no"]."\"},";
$i1++;
}
//颜色不正确
if(trim($m["color"])!=""){
$arr1=explode(",",trim($m["color"]));
$wrong_color="";
for($j=0;$j<count($arr1);$j++){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='color' and no='".$arr1[$j]."'");
if(!$tmp["id"])
$wrong_color.=$arr1[$j].",";
}
if($wrong_color){
$wrong_color=substr($wrong_color,0,-1);
$tmp2.="{\"v\":\"".$m["id"]."-".$m["no"]."-".$wrong_color."\",\"kh\":\"".$m["no"]."\"},";
$i2++;
}
}
//重复色
if(trim($m["color"])!=""){
$arr_color=explode(",",trim($m["color"]));
$arr_color1=array_unique($arr_color);
if($arr_color!=$arr_color1){
$tmp3.="{\"v\":\"".$m["id"]."-".$m["no"]."\",\"kh\":\"".$m["no"]."\"},";
$i3++;
}
}
}
if($i1>0){
$str.="{\"cate\":\"缺颜色\",\"data\":[".deel_end($tmp1)."]},";
}
if($i2>0){
$str.="{\"cate\":\"颜色不正确\",\"data\":[".deel_end($tmp2)."]},";
}
if($i3>0){
$str.="{\"cate\":\"颜色重复\",\"data\":[".deel_end($tmp3)."]},";
}
//--------------------检查折扣
/*
$zk_type=get_set("zk_type");
if($zk_type!=""){
$q="select * from ".$table_pre."kh";
$r=$db->query($q);
$i=0;
$tmp="";
while($m=$db->fetch_array($r)){
$m1=get_db_msg("select count(*) 'num' from ".$table_pre."zk where iid='".$m["id"]."'");
if($m1["num"]<=0){
$tmp.="{\"v\":\"".$m["no"]."\",\"kh\":\"".$m["no"]."\"},";
$i++;
}
}
if($i>0){
$str.="{\"cate\":\"未设置折扣\",\"data\":[".deel_end($tmp)."]},";
}
}
*/
//--------------------检查价格
$q="select * from ".$table_pre."kh";
$r=$db->query($q);
$i=0;
$tmp="";
while($m=$db->fetch_array($r)){
if($m["price"]<=0){
$tmp.="{\"v\":\"".$m["no"]."\",\"kh\":\"".$m["no"]."\"},";
$i++;
}
}
if($i>0){
$str.="{\"cate\":\"缺价格\",\"data\":[".deel_end($tmp)."]},";
}
//--------------------检查图片
$q="select * from ".$table_pre."kh";
$r=$db->query($q);
$i=0;
$tmp="";
while($m=$db->fetch_array($r)){
$pic=get_kh_picture($m["no"],$m["main_pic"],$m["color"]);
if($pic=="images/no_pic_80.gif"){
$tmp.="{\"v\":\"".$m["no"]."(".$m["color"].")\",\"kh\":\"".$m["no"]."\"},";
$i++;
}
}
if($i>0){
$str.="{\"cate\":\"缺图片的款\",\"data\":[".deel_end($tmp)."]},";
}
$q="select * from ".$table_pre."kh";
$r=$db->query($q);
$i=0;
$tmp="";
while($m=$db->fetch_array($r)){
$tmp1=explode(",",$m["color"]);
for($k=0;$k<count($tmp1);$k++){
$pic="../attachments/design/mini/".$m["no"]."_".$tmp1[$k].".jpg";
if(!is_file($pic)){
$tmp.="{\"v\":\"".$m["no"]."(".$tmp1[$k].")\",\"kh\":\"".$m["no"]."\"},";
$i++;
}
}
}
if($i>0){
$str.="{\"cate\":\"缺图片的款色\",\"data\":[".deel_end($tmp)."]},";
}
$json_data.="\"error\":[".deel_end($str)."],";
break;
case "detail":
//可选择字段
$arr_zd["xh"]=d_translate("xh");
$arr_zd["price"]="零售价";
$arr_zd["price_zk"]="结算价";
$arr_zd["title"]="款式名";
for($i=0;$i<count($arr_select_no1);$i++){
$arr_zd[$arr_select_no1[$i]]=$arr_select_title1[$i];
}
//-------------------处理尺码表头
//取得合并尺码
$arr_size_merged=get_size_merged();
$num_size_total=count($arr_size_merged);
//取得尺码合计sql
$sql_sum_num="";
for($k=0;$k<$num_size_total;$k++){
$sql_sum_num.="sum(num_".$arr_size_merged[$k].") 'num_".$arr_size_merged[$k]."',";
}
//取得尺码表头内容
$num_size_group=0;
$size_tr=array();
$r1=$db->query("select * from ".$table_pre."keyword where cate='size' order by ord");
while($m1=$db->fetch_array($r1)){
$size_tr[$num_size_group]="";
for($i=1;$i<=$num_size_total;$i++){
$tmp=get_db_msg("select title from ".$table_pre."size where iid='".$m1["id"]."' and no='".$i."'");
$t=$tmp["title"]?$tmp["title"]:"&nbsp;";
$size_tr[$num_size_group].="{\"zd\":\"num_".$i."\",\"title\":\"".$t."\",\"is_size\":\"y\"},";
}
$arr_size_merged[]=$m1["no"];
$num_size_group++;
}
//-------------------/处理尺码表头结束
$s_zd=$s_zd?$s_zd:"price";
$sql_con="";
$search_content="";
//字段
$zd="";
$zd1="";
$i=0;
$arrzd=array();
$arrzd=explode(",",$s_zd);
$zd_ct=0;
foreach($arr_zd as $k1 => $v1){
$zd1.="{\"no\":\"".$k1."\",\"title\":\"".$v1."\",";
if(in_array($k1,$arrzd)){
$zd.=" checked";
$zd1.="\"sign\":\"y\"";
$zd_ct++;
}else
$zd1.="\"sign\":\"n\"";
$zd1.="},";
}
$json_data.="\"th_zd\":[".substr($zd1,0,-1)."],";
$search_content.="显示列:".$zd;
$search_content.="<input type=submit value=\"提 交\" class=\"btn_act\"> ";
//-----------------------/search
//-----------------------tab
//-----------------------/tab
$json_data.="\"thead_str_group\":\"".$num_size_group."\",";
$th_zd="";
for($i=0;$i<count($s_zd);$i++){
$th_zd.="<td rowspan=\"".$num_size_group."\" bgcolor=\"#f0f0f0\" align=\"center\">".get_main_value($arr_zd,$s_zd[$i])."</td>";
}
$thead_str="";
$thead_str.="{\"zd\":\"bj\",\"title\":\"删除标记\",\"is_size\":\"n\"},{\"zd\":\"no\",\"title\":\"款号\",\"is_size\":\"n\"},";
$colnum=0;
foreach($arr_zd as $k1 => $v1){
if(in_array($k1,$arrzd)){
$thead_str.="{\"zd\":\"".$k1."\",\"title\":\"".$v1."\",\"is_size\":\"n\"},";
$colnum++;
}
}
$thead_str.="{\"zd\":\"color_title\",\"title\":\"颜色名称\",\"is_size\":\"n\"},";
$thead_str.="{\"zd\":\"color\",\"title\":\"颜色代码\",\"is_size\":\"n\"},{\"zd\":\"color2\",\"title\":\"尺码\",\"is_size\":\"n\"},";
if($bx_sizegroup_id>0){
$thead_str.="{\"zd\":\"bx\",\"title\":\"杯型\",\"is_size\":\"n\"},";
}
if($is_gg=="y"){
$thead_str.="{\"zd\":\"gg\",\"title\":\"".d_translate("gg")."\",\"is_size\":\"n\"},";
//$thead_str.="{\"zd\":\"ggprice\",\"title\":\"".get_main_value($sys_gg_zd,"price")."\",\"is_size\":\"n\"},";
}
$thead_str.=substr($size_tr[0],0,-1);
$thead_str2="\"0\":[".$thead_str."],";
for($i=1;$i<$num_size_group;$i++){
$thead_str2.="\"".$i."\":[".substr($size_tr[$i],0,-1)."],";
}
$json_data.="\"thead_str\":{".substr($thead_str2,0,-1)."},";
$q="select * from ".$table_pre."kh order by xh";
//echo $q."<br>";
$r=$db->query($q);
$count=0;
$l=0;
$_tcontent=array();
while($m=$db->fetch_array($r)){
$list=$count+1;
$bg=($l%2)?"#f0f0f0":"#ffffff";
//
$tmp_zd="";
for($i=0;$i<count($s_zd);$i++){
$tmp_zd.="<td bgcolor=\"".$bg."\">";
$tmp_zd.=($s_zd=="title" || $s_zd=="price" || $s_zd=="xh")?deel_td($m[$s_zd[$i]]):deel_td(get_cate_title_no($s_zd[$i],$m[$s_zd[$i]]));
$tmp_zd.="</td>";
}
//取得杯型
$arrBx1=array();
if($m["size_group"]==$bx_sizegroup_id){
$r1=$db->query("select * from ".$table_pre."size_bx where no='".$m["no"]."' order by bx");
$i1=0;
while($m1=$db->fetch_array($r1)){
$arrBx1[$i1][]=$m1["bx"];
$arrBx1[$i1][]=$m1["size"];
$i1++;
}
}else{
$arrBx1[0][0]="";
$arrBx1[0][1]=$m["size"];
}
//取得颜色
$arr_color=explode(",",$m["color"]);
$arr_color_ka=explode(",",$m["color_ka"]);
$num1=count($arr_color);
for($j=0;$j<count($arr_color);$j++){
$is_gg_ks=is_gg_ks($m["id"],$arr_color[$j]);
if($is_gg_ks!="n"){
$arrBx=array();
$r1=$db->query("select gg from ".$table_pre."kh_gg where iid='".$m["id"]."' and color='".$arr_color[$j]."' order by ord");
$i1=0;
while($m1=$db->fetch_array($r1)){
$arrBx[$i1][0]=$m1["gg"];
$arrBx[$i1][1]=$m["size"];
$i1++;
}
if($i1==0)
$arrBx[0][0]="";
$arrBx[0][1]=$m["size"];
}else{
$arrBx=$arrBx1;
}
for($j1=0;$j1<count($arrBx);$j1++){
$num=0;
$arr1=explode(",",$arrBx[$j1][1]);
$td_size1="";
$tbody_str3="";
for($k=1;$k<=$num_size_total;$k++){
if(in_array($k,$arr1)){
//检查尺码是否允许下单
$check=get_db_msg("select size from ".$table_pre."size_not where kh='".$m["no"]."' and color='".$arr_color[$j]."' and bx='".$arrBx[$j1][0]."'");
$arr2=explode(",",$check["size"]);
if(in_array($k,$arr2))
$size_str="/";
else
$size_str="&nbsp;";
}else{
$size_str="/";
}
$tbody_str3.="\"num_".$k."\":\"".$size_str."\",";
}
$money=$num*$m1["price"];
$total_num+=$num;
$total_money+=$money;
$size="";
for($k=0;$k<count($arr1);$k++){
$m2=get_db_msg("select * from ".$table_pre."size where iid='".$m["size_group"]."' and no='".$arr1[$k]."'");
$size.=$m2["title"].",";
}
if($size)
$size=substr($size,0,-1);
if($m["ka"]=="y" || in_array($arr_color[$j],$arr_color_ka))
$ka="";
else
$ka="";
$tbody_str2="";
foreach($arr_zd as $k1 => $v1){
if(in_array($k1,$arrzd)){
if($k1=="title" || $k1=="price"){
$tbody_str2.="\"".$k1."\":\"".deel_td($m[$k1])."\",";
}else if($k1=="xh"){
$tbody_str2.="\"".$k1."\":\"".get_kh_xh($m)."\",";
}else{
$tbody_str2.="\"".$k1."\":\"".deel_td(get_cate_title_no($k1,$m[$k1]))."\",";
}
}
}
$tbody_str.="{\"bj\":\"".$ka."\",\"no\":\"".$m["no"]."\",";
$tbody_str.=$tbody_str2;
$tbody_str.=$tbody_str3;
$tbody_str.="\"color_title\":\"".deel_td(get_cate_title_no("color",$arr_color[$j]))."\",";
$tbody_str.="\"color\":\"".deel_td($arr_color[$j])."\",";
if($bx_sizegroup_id>0){
$tbody_str.="\"bx\":\"".deel_td($arrBx[$j1][0])."\",";
}
if($is_gg=="y"){
//取得规格价格
$tmp=get_db_msg("select price from ".$table_pre."kh_gg where iid='".$m2["iid"]."' and gg='".$m2["bx"]."'");
$tbody_str.="\"gg\":\"".deel_td(get_gg_title($arrBx[$j1][0]))."\",";
//$tbody_str.="\"ggprice\":\"".deel_td($tmp["price"])."\",";
}
$tbody_str.="\"color2\":\"".deel_td($size)."\"";
$tbody_str.="},";
$count++;
}
}
$l++;
}
$json_data.="\"tbody_str\":[".substr($tbody_str,0,-1)."],";
break;
case "chache_pic_detail":
//缓存细节图
$db->query("set names latin1;");
$t1=$table_pre."pic_detail";
//建立表
$db->query("DROP TABLE IF EXISTS ".$t1.";");
$db->query("CREATE TABLE `".$t1."` (`id` int(10) unsigned NOT NULL auto_increment,`kh` varchar(255) NOT NULL default '',`pic` varchar(255) NOT NULL default '',PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
//
$pathdir="../attachments/design/mini";
$str="";
$i=0;
if(is_dir($pathdir)){
$d=dir($pathdir);
while($a=$d->read()){
if(is_file($pathdir.'/'.$a) && ($a!='.') && ($a!='..')){
//echo $a."|".$msg["no"]."_d<br>";
//echo stripos($a,$msg["no"]."_d")."<br>";
if(stristr($a,"-d")){
$tmp=explode("-d",$a);
$q="insert into ".$t1." (kh,pic) values ('".$tmp[0]."','".$a."')";
$db->query($q);
//echo $q."--<br>";
$str.=$a.",";
$i++;
}
}
}
$d->close();
//
}
if($i>0){
$msg="找到以下细节图片:<br>".deel_end($str);
}else{
$msg="没有找到细节图片(款号-d格式)!";
}
$json_data.="\"code\":1,\"msg\":\"".$msg."\",";
//
break;
//-------------主界面
default :
//
$json_data.="\"lang_spk\":\"".d_translate("spk")."\",";
$json_data.="\"lang_xh\":\"".d_translate("xh")."\",";
$is_spk=get_set("is_spk");
$json_data.="\"is_spk\":\"".$is_spk."\",";
$zk_type=get_set("zk_type");
$json_data.="\"zk_type\":\"".$zk_type."\",";
//取得定制选项
$select_dz="";
for($i=0;$i<count($arr_select_no1);$i++){
//取得选项
$tmp="";
$r1=$db->query("select no,title from ".$table_pre."keyword where cate='".$arr_select_no1[$i]."' order by no");
while($m1=$db->fetch_array($r1)){
$tmp.="{\"no\":\"".$m1["no"]."\",\"title\":\"".$m1["title"]."\"},";
}
$tmp=deel_end($tmp);
$var="s_".$arr_select_no1[$i];
$select_dz.="{\"no\":\"".$arr_select_no1[$i]."\",\"title\":\"".$arr_select_title1[$i]."\",\"value\":\"".$$var."\",\"op\":[".$tmp."]},";
}
$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_ka)
$sql_con.=" and ka='".$s_ka."'";
if($s_ka_color=="y")
$sql_con.=" and color_ka<>''";
if($s_is_sp)
$sql_con.=" and is_sp='".$s_is_sp."'";
if($s_in_ph)
$sql_con.=" and in_ph='".$s_in_ph."'";
if($s_xh)
$sql_con.=" and xh='".$s_xh."'";
if($s_no)
$sql_con.=" and no like '%".$s_no."%'";
for($i=0;$i<count($arr_select_no1);$i++){
$v="s_".$arr_select_no1[$i];
if($$v)
$sql_con.=" and ".$arr_select_no1[$i]."='".$$v."'";
}
//取得总条数
$tmp=get_db_msg("select count(*) 'num' from ".$table_pre."kh where id>0 ".$sql_con);
$total_num=$tmp["num"];
//是否有折扣
$zk_type=get_set("zk_type");
$is_zk="n";
if($zk_type){
$is_zk="y";
}
$query="select * from ".$table_pre."kh where id>0 ".$sql_con." order by xh,no limit ".$start.",".$end;
//echo $query."<br>";
$res=$db->query($query);
$count=0;
$json_data.="\"code\":0,\"msg\":\"\",\"count\":".$total_num.",\"data\":[";
$str_tmp="";
while($msg=$db->fetch_array($res)){
$list=$count_first+$count+1;
$str_tmp.="{";
$str_tmp.="\"id\":\"".$msg["id"]."\",";
//圆牌号
$str_tmp.="\"xh\":\"".get_kh_xh($msg)."\",";
//款号
$str_tmp.="\"kh\":\"".$msg["no"]."\",";
//取得选项值
$str1="";
for($i=0;$i<count($arr_select_no1);$i++){
//取得选项
$str1.="{\"k\":\"".$arr_select_title1[$i]."\",\"v\":\"".get_cate_title_no($arr_select_no1[$i],$msg[$arr_select_no1[$i]])."\"},";
}
$str_tmp.="\"arr_select\":[".deel_end($str1)."],";
//饰品款
$is_sp="";
if($is_spk=="y" && $msg["is_sp"]=="y")
$is_sp=d_translate("spk");
$str_tmp.="\"is_sp\":\"".$is_sp."\",";
$str_tmp.="\"dpk\":\"".$msg["dpk"]."\",";
//图片
$pic=get_kh_picture($msg["no"],$msg["main_pic"],$msg["color"]);
$arr_pic_set=out_good_pic_set_arr($pic,120,120);
$str_tmp.="\"pic_src\":\"".$pic."\",";
$str_tmp.="\"pic_w\":\"".$arr_pic_set[0]."\",";
$str_tmp.="\"pic_h\":\"".$arr_pic_set[1]."\",";
//价格
$str_price="";
if($is_multi_price=="y"){
foreach($sys_multi_price as $k1 => $v1){
$str_price.=$v1.":".$msg[$k1]."元|";
}
if($str_price)
$str_price=substr($str_price,0,-1);
}else{
$str_price=$msg["price"]."";
}
$str_tmp.="\"price\":\"".$str_price."\",";
//颜色
$color="";
$tmp1=explode(",",$msg["color"]);
$tmp2=explode(",",$msg["color_ka"]);
for($k=0;$k<count($tmp1);$k++){
if(in_array($tmp1[$k],$tmp2)){
$st1="y";
}else{
$st1="n";
}
$color.=$tmp1[$k]."|".get_cate_title_no("color",$tmp1[$k])."|".$st1.",";
}
if($color)
$color=substr($color,0,-1);
$str_tmp.="\"color\":\"".$color."\",";
//折扣
$tmp="n";
if($is_zk=="y"){
//取得该款折扣
$tmp=get_db_msg("select count(*) 'num' from ".$table_pre."zk where iid='".$msg["id"]."'");
if($tmp["num"]>0){
$tmp="y";
}
}
$str_tmp.="\"zk\":\"".$tmp."\",";
//删除款
$str_tmp.="\"ka\":\"".$msg["ka"]."\"";
$str_tmp.="},";
//
$count++;
}
$json_data.=substr($str_tmp,0,-1)."],";
break;
}
}
$json_data=substr($json_data,0,-1)."}";
echo $json_data;
?>