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

780 lines
27 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
//----------------------------------------------------------库存管理
function arr_to_str1($arr){
$r="";
if(is_array($arr)){
foreach($arr as $n => $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="<td align=\"left\" bgcolor=\"#f0f0f0\">杯型</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="<td align=\"left\" bgcolor=\"#f0f0f0\">款型</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="<td align=\"left\" bgcolor=\"#f0f0f0\">".d_translate("gg")."</td>";
$gg=d_translate("gg");
$ggf="y";
}else{
$gg_td="";
$gg="";
$ggf="n";
}
//
$str_color=$str_color1="";
$sz="";
for($i=0;$i<count($arr_size);$i++){
$tmp=get_db_msg("select title from ".$table_pre."size where iid='".$msg_kh["size_group"]."' and no='".$arr_size[$i]."'");
$str_color.="<td width=\"40\" align=\"center\" bgcolor=\"#f0f0f0\">".$tmp["title"]."</td>";
$str_color1.="<td bgcolor=\"#ffffff\"><input type=\"text\" name=\"num_".$arr_size[$i]."\" value=\"".$msg["num_".$arr_size[$i]]."\" style=\"width:40px;\" /></td>";
$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 "--<br>";
$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."<br>";
$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<count($arr_color);$i++){
$tmpstrcolor.="{\"title\":\"".get_cate_title_no("color",$arr_color[$i])."\",\"value\":\"".$arr_color[$i]."\"},";
}
for($i=0;$i<count($arr_size);$i++){
$tmp=get_db_msg("select * from ".$table_pre."size where iid='".$msg_kh["size_group"]."' and no='".$arr_size[$i]."'");
$tmpstrsize.="{\"title\":\"".$tmp["title"]."\",\"value\":\"num_".$arr_size[$i]."\"},";
}
$json_data.="\"arr_color\":[".deel_end($tmpstrcolor)."],";
$json_data.="\"arr_size\":[".deel_end($tmpstrsize)."],";
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_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<count($arr_thead);$i++){
if(in_array(get_main_key($arr_column_kh_kc,$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";
$import_select=($import_select=="清空导入")?"y":"n";
$error_msg="";
$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);
$err_no=$err_color=0;
$strno=$strcolor="";
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="iid"){
$m_kh=get_db_msg("select id from ".$table_pre."kh where no='".trim($tmp_arr[$ind])."'");
if(!$m_kh["id"]){
$err_no++;
$strno.=trim($tmp_arr[$ind]).",";
}
}
if($ititle=="color"){
$tmp=get_db_msg("select no from ".$table_pre."keyword where cate='color' and title='".trim($tmp_arr[$ind])."'");
if(!$tmp["no"]){
$err_color++;
$strcolor.=trim($tmp_arr[$ind]).",";
}
}
}
}
if($err_no){
$error_msg.="款号有误!".deel_end($strno);
}
if($err_color){
$error_msg.="颜色有误!".deel_end($strcolor);
}
if($error_msg){
$json_data.="\"code\":0,\"msg\":\"".$error_msg."\",";
}else{
$json_data.="\"code\":1,\"reload_type\":\"1\",";
//-------------------------------------------导入数据
//print_r($arr_content);
$error_msg="";
if($import_type=="y"){
//清空款号相关数据
$db->query("TRUNCATE TABLE ".$table_pre."kh_kc;");
}
//
$insert_column="";
for($i=0;$i<count($arr_column[1]);$i++){
$insert_column.=$arr_column[1][$i].",";
}
$insert_column=deel_end($insert_column);
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
/*//取得款号
$kh="";
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="iid"){
$kh=trim($tmp_arr[$ind]);
}
}*/
$insert_value="";
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="iid"){
$m_kh=get_db_msg("select * from ".$table_pre."kh where no='".trim($tmp_arr[$ind])."'");
$insert_value.="'".$m_kh["id"]."',";
}elseif($ititle=="color"){
$tmp=get_db_msg("select no from ".$table_pre."keyword where cate='color' and title='".trim($tmp_arr[$ind])."'");
$insert_value.="'".$tmp["no"]."',";
}else{
$insert_value.="'".mysql_escape_string(trim($tmp_arr[$ind]))."',";
}
/*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='".$m_kh["size_group"]."' and title='".$tmp1[$k1]."'");
$v1.=$tmp["no"].",";
}
if($v1)
$v1=substr($v1,0,-1);
$insert_value.=",'".mysql_escape_string($v1)."'";
}else{
if(($is_gg=="y" || $is_gg=="b") && $ititle=="size"){
$insert_value.=",'".mysql_escape_string(get_gg_id(trim($tmp_arr[$ind])))."'";
}else{
$insert_value.=",'".mysql_escape_string(trim($tmp_arr[$ind]))."'";
}
}*/
}
$insert_value=deel_end($insert_value);
$q="insert into ".$table_pre."kh_kc (".$insert_column.") values (".$insert_value.")";
//echo $q."<br>";
$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;$j<count($arr_size1);$j++){
$tmp=get_db_msg("select title from ".$table_pre."size where iid='".$m_kh["size_group"]."' and no='".$arr_size1[$j]."'");
$size_title1.=$tmp["title"].",";
}
$data["body"][$row][]=substr($size_title1,0,-1);
}else{
$data["body"][$row][]=$m[$k];
}
}
$row++;
}
$file_name="kh_kc_".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_kc order by kh,color";
$r=$db->query($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;$j<count($arr_size);$j++){
if(!in_array($arr_size[$j],$check_size)){
$tmp2=get_db_msg("select * from ".$table_pre."size where iid='".$tmp1["size_group"]."' and no='".$arr_size[$j]."'");
$tmp.="{\"v\":\"".$m["kh"]."-".$m["color"]."-".$tmp2["title"]."\",\"kh\":\"".$m["kh"]."\"},";
$i++;
}
}
}
}
if($i>0){
$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;$i<count($arr_color);$i++){
if($is_ggk=="y" || $is_ggk=="b"){
//有规格
$q1="select * from ".$table_pre."kh_gg where iid='".$msg_kh["id"]."' and color='".$arr_color[$i]."'";
$r1=$db->query($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;$j<count($arr_size);$j++){
$check=get_db_msg("select size from ".$table_pre."kh_kc where kh='".$kh."' and color='".$arr_color[$i]."' and bx='".$m1["gg"]."'");
$check=explode(",",$check["size"]);
$ck="";
if(in_array($arr_size[$j],$check)){
$ck=" checked";
}
$tmp=get_db_msg("select * from ".$table_pre."size where iid='".$msg_kh["size_group"]."' and no='".$arr_size[$j]."'");
$tmpa.="{\"name\":\"size_".$arr_color[$i]."_".$m1["gg"]."[]\",\"value\":\"".$arr_size[$j]."\",\"title\":\"".$tmp["title"]."\",\"check\":\"".$ck."\"},";
}
$tmpa=deel_end($tmpa);
$strcb.="{\"name\":\"color_bx[]\",\"value\":\"".$arr_color[$i]."_".$m1["gg"]."\",\"title\":\"".$arr_color[$i]."-".get_cate_title_no("color",$arr_color[$i])."\",\"check\":\"".$ck1."\",\"size\":[".$tmpa."]},";
}
}else{
for($k=0;$k<count($arrBx);$k++){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."kh_kc where kh='".$kh."' and color='".$arr_color[$i]."' and bx='".$arrBx[$k][0]."'");
$ck1="";
if($check["num"]>0){
$ck1=" checked";
}
$sbx="";
if($show_bx=="y"){
$sbx=$arrBx[$k][0];
}
$arr_size=explode(",",$arrBx[$k][1]);
$tmpa="";
for($j=0;$j<count($arr_size);$j++){
$check=get_db_msg("select size from ".$table_pre."kh_kc where kh='".$kh."' and color='".$arr_color[$i]."' and bx='".$arrBx[$k][0]."'");
$check=explode(",",$check["size"]);
$ck="";
if(in_array($arr_size[$j],$check)){
$ck=" checked";
}
$tmp=get_db_msg("select * from ".$table_pre."size where iid='".$msg_kh["size_group"]."' and no='".$arr_size[$j]."'");
$tmpa.="{\"name\":\"size_".$arr_color[$i]."_".$arrBx[$k][0]."[]\",\"value\":\"".$arr_size[$j]."\",\"title\":\"".$tmp["title"]."\",\"check\":\"".$ck."\"},";
}
$tmpa=deel_end($tmpa);
$strcb.="{\"name\":\"color_bx[]\",\"value\":\"".$arr_color[$i]."_".$arrBx[$k][0]."\",\"title\":\"".$arr_color[$i]."-".get_cate_title_no("color",$arr_color[$i])."".$sbx."\",\"check\":\"".$ck1."\",\"size\":[".$tmpa."]},";
}
}
}
$strcb=deel_end($strcb);
$json_data.="\"color_size\":[".$strcb."],";
break;
default:
//
$page=$page>0?$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."<br>";
$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.="<td>".$m1["title"]."</td>";
$str_size_num.="<td>".deel_0($msg["num_".$m1["no"]])."</td>";
$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.="<tr><td>".$m["color"]."-".get_cate_title_no("color",$m["color"])."</td>";
$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.="<td>".get_gg_title($m["bx"])."</td>";
$str1.="\"bx\":\"".get_gg_title($m["bx"])."\",";
}else{
$str.="<td>".$m["bx"]."</td>";
$str1.="\"bx\":\"".$m["bx"]."\",";
}
}else{
$str1.="\"bx\":\"\",";
}
//尺码
$str_size="";
if(trim($m["size"])){
$arr1=explode(",",$m["size"]);
for($j=0;$j<count($arr1);$j++){
$tmp=get_db_msg("select * from ".$table_pre."size where iid='".$msg_kh["size_group"]."' and no='".$arr1[$j]."'");
$str_size.=$tmp["title"].",";
}
}
if($str_size){
$str.="<td>".substr($str_size,0,-1);
$str1.="\"cm\":\"".substr($str_size,0,-1)."\"";
}else{
$str.="<td>&nbsp;";
$str1.="\"cm\":\"\"";
}
$str1.="},";
$str.="</td></tr>";
}
}
$str1=deel_end($str1);
$str="<table>".$str."</table>";
$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;
?>