$t){
$r.=$t.",";
}
$r=substr($r,0,-1);
}else{
$r=$arr;
}
return $r;
}
header("Content-type: text/html; charset=utf-8");
if(THIS_IN!="edt_admin")
exit("错误的访问!");
//-------------------------------execute action
//require THIS_FILE_ROOT."/include/excel_class.php";
//require THIS_FILE_ROOT."/include/excel_fun.php";
$image_file_type="jpg|jpeg";
$uid=check_cookie();
$db=_mysql_connect();
$sys_size_num=get_max_size_num();
$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.",";
$arr_column_kh_kc["iid"]="款号";
$arr_column_kh_kc["color"]="颜色名称";
for($i=1;$i<=$sys_size_num;$i++){
$arr_column_kh_kc["num_".$i]="尺码".$i;
}
/*if(trim($bx_sizegroup_title))
$arr_column_kh_kc["bx"]="杯型";
if(trim($child_sizegroup_title))
$arr_column_kh_kc["bx"]="款型";
if($is_gg=="y" || $is_gg=="b")
$arr_column_kh_kc["bx"]=d_translate("gg");
$arr_column_kh_kc["size"]="尺码";*/
//
$arr_kh_size=arr_select("size","title","title");
switch($_a){
case "add" :
//--------------------------新增
//$http_pre=$http_pre?$http_pre:$_SERVER['HTTP_REFERER'];
$add_date=date("Y-m-d H:i:s");
if($id){
$msg=get_db_msg("select * from ".$table_pre."kh_kc where id='".$id."'");
$msg_kh=get_db_msg("select * from ".$table_pre."kh where id='".$msg["iid"]."'");
$kh=$msg_kh["no"];
$color=$msg["color"]."-".get_cate_title_no("color",$msg["color"]);
if($msg_kh["size_group"]==$bx_sizegroup_id){
$tmp=get_db_msg("select size from ".$table_pre."size_bx where no='".$msg_kh["no"]."' and bx='".$msg["bx"]."'");
$arr_size=explode(",",$tmp["size"]);
$bx_td="
杯型 ";
$bx="杯型";
$bxf="y";
}else if($msg_kh["size_group"]==$child_sizegroup_id){
$tmp=get_db_msg("select size from ".$table_pre."size_bx where no='".$msg_kh["no"]."' and bx='".$msg["bx"]."'");
$arr_size=explode(",",$tmp["size"]);
$bx_td="款型 ";
$bx="款型";
$bxf="y";
}else{
$arr_size=explode(",",$msg_kh["size"]);
$bx_td="";
$bx="";
$bxf="n";
}
$is_ggk=is_ggk($msg_kh["id"]);
if($is_ggk!="n"){
$gg_td="".d_translate("gg")." ";
$gg=d_translate("gg");
$ggf="y";
}else{
$gg_td="";
$gg="";
$ggf="n";
}
//
$str_color=$str_color1="";
$sz="";
for($i=0;$i".$tmp["title"]."";
$str_color1.=" ";
$sz.="{\"no\":\"num_".$arr_size[$i]."\",\"title\":\"".$tmp["title"]."\",\"value\":\"".$msg["num_".$arr_size[$i]]."\"},";
}
$_nav_.=" > 修改库存";
$sz=deel_end($sz);
$json_data.="\"size\":[".$sz."],";
}else{
$kh="";
$color="";
$_nav_.=" > 新增库存";
}
$json_data.="\"kh\":\"".$kh."\",";
$json_data.="\"color\":\"".$color."\",";
/*$json_data.="\"ggf\":\"".$ggf."\",";
$json_data.="\"ggt\":\"".$gg."\",";
$json_data.="\"gg\":\"".get_gg_title($msg["bx"])."\",";
$json_data.="\"bxf\":\"".$bxf."\",";
$json_data.="\"bxt\":\"".$bx."\",";
$json_data.="\"bx\":\"".$msg["bx"]."\",";*/
break;
case "save_add":
$total=$num_1+$num_2+$num_3+$num_4+$num_5+$num_6+$num_7+$num_8+$num_9+$num_10+$num_11+$num_12+$num_13+$num_14+$num_15+$num_16+$num_17+$num_18+$num_19+$num_20;
if($id){
$msg=get_db_msg("select * from ".$table_pre."kh_kc where id='".$id."'");
$log_remark=$msg["no"]."|".$msg["color"]."|".$msg["size_bx"]."|".$total;
if($total>0){
$query="update ".$table_pre."kh_kc set num_1='".$num_1."',num_2='".$num_2."',num_3='".$num_3."',num_4='".$num_4."',num_5='".$num_5."',num_6='".$num_6."',num_7='".$num_7."',num_8='".$num_8."',num_9='".$num_9."',num_10='".$num_10."',num_11='".$num_11."',num_12='".$num_12."',num_13='".$num_13."',num_14='".$num_14."',num_15='".$num_15."',num_16='".$num_16."',num_17='".$num_17."',num_18='".$num_18."',num_19='".$num_19."',num_20='".$num_20."',add_date='".time()."' where id='".$id."'";
$db->query($query);
$lid=$id;
set_log("修改库存",$log_remark);
$json_data.="\"code\":1,";
}else{
$db->query("delete from ".$table_pre."kh_kc where id='".$id."'");
set_log("清空库存",$log_remark);
$json_data.="\"code\":1,";
}
}else{
$msg_kh=get_db_msg("select * from ".$table_pre."kh where no='".$kh."'");
if($total>0){
$query="insert into ".$table_pre."kh_kc (iid,color,size_bx,num_1,num_2,num_3,num_4,num_5,num_6,num_7,num_8,num_9,num_10,num_11,num_12,num_13,num_14,num_15,num_16,num_17,num_18,num_19,num_20,add_date) values ('".$msg_kh["id"]."','".$color."','".$size_bx."','".$num_1."','".$num_2."','".$num_3."','".$num_4."','".$num_5."','".$num_6."','".$num_7."','".$num_8."','".$num_9."','".$num_10."','".$num_11."','".$num_12."','".$num_13."','".$num_14."','".$num_15."','".$num_16."','".$num_17."','".$num_18."','".$num_19."','".$num_20."','".time()."')";
$db->query($query);
$lid=$db->insert_id();
$log_remark=$msg_kh["no"]."|".$color."|".$size_bx."|".$total;
set_log("新增库存",$log_remark);
$json_data.="\"code\":1,";
}else{
//alert_and_back("请输入数量!");
$json_data.="\"code\":99,\"msg\":\"请输入数量!\",";
}
}
/*$error_msg="";
if($color_bx){
$color_bx=is_array($color_bx)?$color_bx:array($color_bx);
}else{
$error_msg="请选择颜色!";
}
//print_r($color_bx);
//echo "-- ";
$kh=trim($kh);
$msg_kh=get_db_msg("select id,color,size,size_group from ".$table_pre."kh where no='".$kh."'");
if($msg_kh["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;
}
$arr_color_kh=explode(",",$msg_kh["color"]);
$arr_size_kh=explode(",",$msg_kh["size"]);
}else{
$error_msg="款号错误!";
}
if($error_msg){
$json_data.="\"code\":99,\"msg\":\"".$error_msg."\",";
}else{
if($msg_kh["size_group"]==$child_sizegroup_id){
//童装
//删除多余数据
$q="select * from ".$table_pre."kh_kc where kh='".$kh."'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
if(!in_array($m["color"]."_".get_child_bx_ind($m["bx"]),$color_bx)){
$db->query("delete from ".$table_pre."kh_kc where id='".$m["id"]."'");
}
}
if(count($color_bx)>0){
foreach($color_bx as $k1 => $color_bx1){
$v1="size_".$color_bx1;
$size1=arr_to_str1($$v1);
$tmp=explode("_",$color_bx1);
$check=get_db_msg("select * from ".$table_pre."kh_kc where kh='".$kh."' and color='".$tmp[0]."' and bx='".get_child_bx_title($tmp[1])."'");
if($check["id"]>0){
$q="update ".$table_pre."kh_kc set size='".$size1."' where id='".$check["id"]."'";
}else{
$q="insert into ".$table_pre."kh_kc (kh,color,bx,size) values ('".$kh."','".$tmp[0]."','".get_child_bx_title($tmp[1])."','".$size1."')";
}
$db->query($q);
}
}
}else{
//非童装
//删除多余数据
$q="select * from ".$table_pre."kh_kc where kh='".$kh."'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
if(!in_array($m["color"]."_".$m["bx"],$color_bx)){
$db->query("delete from ".$table_pre."kh_kc where id='".$m["id"]."'");
}
}
if(count($color_bx)>0){
foreach($color_bx as $k1 => $color_bx1){
$v1="size_".$color_bx1;
$size1=arr_to_str1($$v1);
$tmp=explode("_",$color_bx1);
$check=get_db_msg("select * from ".$table_pre."kh_kc where kh='".$kh."' and color='".$tmp[0]."' and bx='".$tmp[1]."'");
if($check["id"]>0){
$q="update ".$table_pre."kh_kc set size='".$size1."' where id='".$check["id"]."'";
}else{
$q="insert into ".$table_pre."kh_kc (kh,color,bx,size) values ('".$kh."','".$tmp[0]."','".$tmp[1]."','".$size1."')";
}
//echo $q." ";
$db->query($q);
}
}
}
set_log($log_action."不予下单尺码",$kh);
$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 iid from ".$table_pre."kh_kc where id='".$id[$i]."'");
//删除款号表
$db->query("delete from ".$table_pre."kh_kc where id='".$id[$i]."'");
$lid.=$tmp["iid"].",";
}
$json_data.="\"code\":1,";
$lid=substr($lid,0,-1);
set_log("库存删除",$lid);
break;
case "color_size" :
//
$msg_kh=get_db_msg("select * from ".$table_pre."kh where no='".$kh."'");
$is_ggk=is_ggk($msg_kh["id"]);
$arr_color=explode(",",$msg_kh["color"]);
$arr_size=explode(",",$msg_kh["size"]);
$tmpstrcolor=$tmpstrsize="";
for($i=0;$i"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_kc);
$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_kc 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 ".$table_pre."kh_kc;");
}
//
$insert_column="";
for($i=0;$i";
$db->query($q);
}
//
del_tmp_file($tmp_file_name);
$log_remark=$import_flag;
set_log("导入库存数据",$log_remark);
}
break;
//----------------------------------------------------------------------/导入EXCEL
//----------------------------------------------------------------------导出数据
case "export":
$column="";
foreach($arr_column_kh_kc as $k => $v){
$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_kc 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++){
$data["header"][0][]=get_main_value($arr_column_kh_kc,$ex_col[$i]);
}
//取得数据
$query="select * from ".$table_pre."kh_kc order by kh";
$r=$db->query($query);
$row=0;
while($m=$db->fetch_array($r)){
for($i=0;$i<$num;$i++){
$k=$ex_col[$i];
if($k=="size"){
$m_kh=get_db_msg("select size_group from ".$table_pre."kh where no='".$m["kh"]."'");
$arr_size1=explode(",",$m[$k]);
$size_title1="";
for($j=0;$jquery($q);
$i=0;
$content="";
//检查款号
$tmp="";
while($m=$db->fetch_array($r)){
$tmp1=get_db_msg("select * from ".$table_pre."kh where no='".$m["kh"]."'");
if(!$tmp1["id"]){
$tmp.="{\"kh\":\"".$m["kh"]."\",\"v\":\"".$m["kh"]."\"},";
$i++;
}
}
if($i>0){
$str.="{\"cate\":\"款号有误\",\"data\":[".deel_end($tmp)."]},";
}
//检查颜色
$error_color="";
$q="select * from ".$table_pre."kh_kc where color<>'' order by kh,color";
$r=$db->query($q);
$i=0;
$tmp="";
while($m=$db->fetch_array($r)){
$tmp1=get_db_msg("select * from ".$table_pre."kh where no='".$m["kh"]."'");
if($tmp1["id"]>0){
//检查颜色
$check_color=explode(",",$tmp1["color"]);
$color=trim($m["color"]);
if(!in_array($color,$check_color)){
$tmp.="{\"v\":\"".$m["id"]."-".$m["kh"]."-".$wrong_color."\",\"kh\":\"".$m["kh"]."\"},";
$i++;
}
}
}
if($i>0){
$str.="{\"cate\":\"颜色有误\",\"data\":[".deel_end($tmp)."]},";
}
//检查尺码
$error_size="";
$q="select * from ".$table_pre."kh_kc where size<>'' and color<>'' order by kh,color";
$r=$db->query($q);
$i=0;
$tmp="";
while($m=$db->fetch_array($r)){
$tmp1=get_db_msg("select * from ".$table_pre."kh where no='".$m["kh"]."'");
if($tmp1["id"]>0){
//检查尺码
$check_size=explode(",",$tmp1["size"]);
$arr_size=explode(",",trim($m["size"]));
for($j=0;$j0){
$str.="{\"cate\":\"尺码有误\",\"data\":[".deel_end($tmp)."]},";
}
$json_data.="\"error\":[".deel_end($str)."],";
break;
case "color_size" :
//
$msg_kh=get_db_msg("select * from ".$table_pre."kh where no='".$kh."'");
$is_ggk=is_ggk($msg_kh["id"]);
$arr_color=explode(",",$msg_kh["color"]);
$arr_size=explode(",",$msg_kh["size"]);
//取得杯型
$arrBx=array();
$r1=$db->query("select * from ".$table_pre."size_bx where no='".$kh."' order by bx");
$i1=0;
$strbx="";
while($m1=$db->fetch_array($r1)){
$arrBx[$i1][]=$m1["bx"];
$arrBx[$i1][]=$m1["size"];
$i1++;
}
$show_bx=($i1>0)?"y":"n";
if(count($arrBx)==0){
$arrBx[0][0]="";
$arrBx[0][1]=$msg_kh["size"];
}
$strcb="";
for($i=0;$iquery($q1);
while($m1=$db->fetch_array($r1)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."kh_kc where kh='".$kh."' and color='".$arr_color[$i]."' and bx='".$m1["gg"]."'");
$ck1="";
if($check["num"]>0){
$ck1=" checked";
}
$tmpa="";
$arr_size=explode(",",$msg_kh["size"]);
for($j=0;$j0){
$ck1=" checked";
}
$sbx="";
if($show_bx=="y"){
$sbx=$arrBx[$k][0];
}
$arr_size=explode(",",$arrBx[$k][1]);
$tmpa="";
for($j=0;$j0?$page:1;
$limit=$limit>0?$limit:10;
$start=($page-1)*$limit;
$end=$limit;
$order=$order?$order:"a.add_date!";
$sql_con="";
if($s_no){
$sql_con.=" and b.no like '%".$s_no."%'";
}
//if($sql_con)
//$sql_con="where ".substr($sql_con,0,-4);
$sql_order=str_replace("!"," desc",$order);
$query="select count(*) 'total' from ".$table_pre."kh_kc a,".$table_pre."kh b where a.iid=b.id ".$sql_con;
$res=$db->query($query);
$msg=$db->fetch_array($res);
$total=$msg["total"];
$json_data.="\"code\":0,\"msg\":\"\",\"count\":".$total.",\"data\":[";
//$query="select * from ".$table_pre."kh_kc ".$sql_con." group by kh order by kh limit ".$start.",".$end;
$query="select a.id 'id',a.iid 'iid',a.size_bx 'size_bx',a.color 'color',a.num_1 'num_1',a.num_2 'num_2',a.num_3 'num_3',a.num_4 'num_4',a.num_5 'num_5',a.num_6 'num_6',a.num_7 'num_7',a.num_8 'num_8',a.num_9 'num_9',a.num_10 'num_10',a.num_11 'num_11',a.num_12 'num_12',a.num_13 'num_13',a.num_14 'num_14',a.num_15 'num_15',a.num_16 'num_16',a.num_17 'num_17',a.num_18 'num_18',a.num_19 'num_19',a.num_20 'num_20',b.no 'no' from ".$table_pre."kh_kc a,".$table_pre."kh b where a.iid=b.id ".$sql_con."order by ".$sql_order." limit ".$start.",".$end;
//echo $query." ";
$res=$db->query($query);
$count=0;
$str_tmp="";
while($msg=$db->fetch_array($res)){
$msg_kh=get_db_msg("select * from ".$table_pre."kh where no='".$msg["no"]."'");
$is_ggk=is_ggk($msg_kh["id"]);
//取得杯型
$arrBx=array();
$r1=$db->query("select * from ".$table_pre."size_bx where no='".$msg["no"]."' order by bx");
$i1=0;
while($m1=$db->fetch_array($r1)){
$arrBx[$i1][]=$m1["bx"];
$arrBx[$i1][]=$m1["size"];
$i1++;
}
$show_bx=($i1>0)?"y":"n";
if(count($arrBx)==0){
$arrBx[0][0]="";
$arrBx[0][1]=$msg["size"];
}
//
$list=$start+$count+1;
$str_tmp.="{";
$str_tmp.="\"id\":\"".$msg["id"]."\",";
$str_tmp.="\"xh\":\"".$list."\",";
$str_tmp.="\"kh\":\"".$msg["no"]."\",";
$color=$msg["color"]."-".get_cate_title_no("color",$msg["color"]);
$str_tmp.="\"color\":\"".$color."\",";
$q1="select * from ".$table_pre."size where iid='".$msg_kh["size_group"]."' order by no";
//echo $q1;
$r1=$db->query($q1);
$tmpn="";
$num=0;
while($m1=$db->fetch_array($r1)){
$str_size_title.="".$m1["title"]." ";
$str_size_num.="".deel_0($msg["num_".$m1["no"]])." ";
$num+=$msg["num_".$m1["no"]];
$tmpn.="{\"v\":\"".$msg["num_".$m1["no"]]."\",\"t\":\"".$m1["title"]."\"},";
}
//echo $tmpn;
$tmpn=deel_end($tmpn);
//echo $tmpn;
$str_tmp.="\"size\":[".$tmpn."],";
$str_tmp.="\"num\":\"".$num."\"";
/*//颜色
$str=$str1=$str2="";
$q="select * from ".$table_pre."kh_kc where kh='".$msg["kh"]."' order by color";
$r=$db->query($q);
$tmpa="";
while($m=$db->fetch_array($r)){
if(trim($m["color"])){
$str.="".$m["color"]."-".get_cate_title_no("color",$m["color"])." ";
$str1.="{\"color\":\"".$m["color"]."-".get_cate_title_no("color",$m["color"])."\",";
$str2.=$m["color"]."-".get_cate_title_no("color",$m["color"])."|";
if($m["bx"]){
if($is_ggk=="y" || $is_ggk=="b"){
$str.="".get_gg_title($m["bx"])." ";
$str1.="\"bx\":\"".get_gg_title($m["bx"])."\",";
}else{
$str.="".$m["bx"]." ";
$str1.="\"bx\":\"".$m["bx"]."\",";
}
}else{
$str1.="\"bx\":\"\",";
}
//尺码
$str_size="";
if(trim($m["size"])){
$arr1=explode(",",$m["size"]);
for($j=0;$j".substr($str_size,0,-1);
$str1.="\"cm\":\"".substr($str_size,0,-1)."\"";
}else{
$str.=" ";
$str1.="\"cm\":\"\"";
}
$str1.="},";
$str.=" ";
}
}
$str1=deel_end($str1);
$str="";
$str_tmp.="\"c_s\":[".$str1."]";*/
$str_tmp.="},";
$count++;
}
$json_data.=substr($str_tmp,0,-1)."],";
break;
}
}
$json_data=substr($json_data,0,-1)."}";
echo $json_data;
?>