'jgd' and no<>'sx' order by ord"; $r=$db->query($q); while($m=$db->fetch_array($r)){ $arr_select_no[]=$m["no"]; $arr_select_title[]=$m["title"]; } $arr_column_zk=array("cid"=>"客户代码","iid"=>"款号"); $arr_column_zk_zc=array("cid"=>"客户代码","iid"=>"款号"); for($i=0;$i"店铺等级","dpsx"=>"店铺属性","zd1"=>"zd1","zd2"=>"zd2","zd3"=>"zd3","zd4"=>"zd4","zd5"=>"zd5"); // $json_data="{"; $json_data.="\"uid\":".$uid.","; switch($_a){ case "plset": //取得定制选项 $select_dz=""; for($i=0;$iquery("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); $var="s_".$arr_select_no[$i]; $select_dz.="{\"no\":\"".$arr_select_no[$i]."\",\"title\":\"".$arr_select_title[$i]."\",\"value\":\"".$$var."\",\"op\":[".$tmp."]},"; } $select_dz=deel_end($select_dz); $json_data.="\"select_dz\":[".$select_dz."],"; // $arr_is_sp=array("n"=>"否","y"=>"是"); $tmp_is_sp=""; foreach($arr_is_sp as $k => $v){ $tmp_is_sp.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},"; } $tmp_is_sp=deel_end($tmp_is_sp); $json_data.="\"select_is_sp\":{\"no\":\"s_is_sp\",\"title\":\"".d_translate("spk")."\",\"value\":\"".$s_is_sp."\",\"op\":[".$tmp_is_sp."]},"; $json_data.="\"zk_type\":\"".$zk_type."\","; break; case "save_plset": $username=trim($username); // $con_kh=""; $log1=""; $http_var=""; for($i=0;$i1){ $str_error.="折扣有误!"; } } if($str_error){ $json_data.="\"code\":0,\"msg\":\"".$str_error."\","; }else{ if($username){ //设置单个客户 $msg_client=get_db_msg("select id from ".$table_pre."client where username='".$username."'"); if(!$msg_client["id"]){ $json_data.="\"code\":0,\"msg\":\"客户代码有误!\","; }else{ $q="select id,price from ".$table_pre."kh b where b.no<>''".$con_kh; $r=$db->query($q); while($m=$db->fetch_array($r)){ if($zk_type=="je"){ $zk=$price/get_price_dp($msg_client["id"],$m["id"]); }else{ $price=get_price_dp($msg_client["id"],$m["id"])*$zk; } $check=get_db_msg("select id from ".$table_pre."zk where iid='".$m["id"]."' and cid='".$msg_client["id"]."'"); if($check["id"]>0) $q1="update ".$table_pre."zk set zk='".$zk."',price='".$price."' where id='".$check["id"]."'"; else $q1="insert ".$table_pre."zk (cid,iid,zk,price) values ('".$msg_client["id"]."','".$m["id"]."','".$zk."','".$price."')"; $db->query($q1); } $log_client=$msg_client["username"]; set_log("批量设置折扣",$log_client."|".substr($log1,0,-1)); $json_data.="\"code\":1,"; } }else{ //到所有客户 $q="select id,price from ".$table_pre."kh b where b.no<>''".$con_kh; $r=$db->query($q); while($m=$db->fetch_array($r)){ $q1="select id from ".$table_pre."client where available='y' and face='4' or face='3'"; $r1=$db->query($q1); while($m1=$db->fetch_array($r1)){ if($zk_type=="je"){ $zk=$price/get_price_dp($m1["id"],$m["id"]); }else{ $price=get_price_dp($m1["id"],$m["id"])*$zk; } $check=get_db_msg("select id from ".$table_pre."zk where iid='".$m["id"]."' and cid='".$m1["id"]."'"); if($check["id"]>0) $q2="update ".$table_pre."zk set zk='".$zk."',price='".$price."' where id='".$check["id"]."'"; else $q2="insert ".$table_pre."zk (cid,iid,zk,price) values ('".$m1["id"]."','".$m["id"]."','".$zk."','".$price."')"; $db->query($q2); } } $log_client="所有客户"; set_log("批量设置折扣",$log_client."|".substr($log1,0,-1)); $json_data.="\"code\":1,"; } } break; case "save_pl_kh": $kh_from=trim($kh_from); $kh_to=trim($kh_to); $m1=get_db_msg("select id from ".$table_pre."kh where no='".$kh_from."'"); if(!$m1["id"]){ $json_data.="\"code\":0,\"msg\":\"款号有误:".$kh_from."\","; }else{ $m2=get_db_msg("select id from ".$table_pre."kh where no='".$kh_to."'"); if(!$m2["id"]){ $json_data.="\"code\":0,\"msg\":\"款号有误:".$kh_to."\","; }else{ if($kh_from==$kh_to){ $json_data.="\"code\":0,\"msg\":\"2个款号不能相同!\","; }else{ //设置 $q="select * from ".$table_pre."zk where iid='".$m1["id"]."'"; $r=$db->query($q); $i=0; while($m=$db->fetch_array($r)){ $check=get_db_msg("select id from ".$table_pre."zk where iid='".$m2["id"]."' and cid='".$m["cid"]."'"); if($check["id"]>0) $q1="update ".$table_pre."zk set zk='".$m["zk"]."',price='".$m["price"]."' where id='".$check["id"]."'"; else $q1="insert ".$table_pre."zk (cid,iid,zk,price) values ('".$m["cid"]."','".$m2["id"]."','".$m["zk"]."','".$m["price"]."')"; //echo $q1."
"; $db->query($q1); $i++; } set_log("按款复制折扣",$kh_from."|".$kh_to); if($i==0){ $json_data.="\"code\":0,\"msg\":\"设置失败,没有记录!\","; }else{ $json_data.="\"code\":1,\"msg\":\"".$i."条记录设置成功\","; } } } } break; case "save_pl_client": $client_from=trim($client_from); $client_to=trim($client_to); $m1=get_db_msg("select id from ".$table_pre."client where username='".$client_from."'"); if(!$m1["id"]){ $json_data.="\"code\":0,\"msg\":\"客户有误:".$client_from."\","; }else{ $m2=get_db_msg("select id from ".$table_pre."client where username='".$client_to."'"); if(!$m2["id"]){ $json_data.="\"code\":0,\"msg\":\"客户有误:".$client_to."\","; }else{ if($client_from==$client_to){ $json_data.="\"code\":0,\"msg\":\"2个客户不能相同!\","; }else{ //设置 $q="select * from ".$table_pre."zk where cid='".$m1["id"]."'"; $r=$db->query($q); $i=0; while($m=$db->fetch_array($r)){ $check=get_db_msg("select id from ".$table_pre."zk where iid='".$m["iid"]."' and cid='".$m2["id"]."'"); if($check["id"]>0) $q1="update ".$table_pre."zk set zk='".$m["zk"]."',price='".$m["price"]."' where id='".$check["id"]."'"; else $q1="insert ".$table_pre."zk (cid,iid,zk,price) values ('".$m2["id"]."','".$m["iid"]."','".$m["zk"]."','".$m["price"]."')"; //echo $q1."
"; $db->query($q1); $i++; } set_log("按客户复制折扣",$client_from."|".$client_to); if($i==0){ $json_data.="\"code\":0,\"msg\":\"设置失败,没有记录!\","; }else{ $json_data.="\"code\":1,\"msg\":\"".$i."条记录设置成功\","; } } } } break; case "pl_client_zd": // $tmp_zd=""; foreach($arr_column_client_zd as $k => $v){ $tmp_zd.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},"; } $tmp_zd=deel_end($tmp_zd); $json_data.="\"select_zd\":{\"no\":\"zd\",\"title\":\"字段\",\"value\":\"\",\"op\":[".$tmp_zd."]},"; break; case "save_pl_client_zd": //检查 $q="select ".$zd." from ".$table_pre."client where (face='3' or face='4') and ".$zd."<>'' group by ".$zd; $r=$db->query($q); $arr_value=array(); $i=0; while($m=$db->fetch_array($r)){ $arr_value[$i]=$m[$zd]; $i++; } if(count($arr_value)==0){ $json_data.="\"code\":0,\"msg\":\"您选择的字段无数据,请检查!\","; }else{ $i1=0; for($i=0;$i'".$tmp["cid"]."' and ".$zd."='".$arr_value[$i]."'"; $r1=$db->query($q1); $j=0; while($m1=$db->fetch_array($r1)){ $arr_uid[$j]=$m1["id"]; $j++; } if($tmp["cid"]>0){ //设置 $q="select * from ".$table_pre."zk where cid='".$tmp["cid"]."'"; $r=$db->query($q); while($m=$db->fetch_array($r)){ for($k=0;$k0){ //不操作 //$q1="update ".$table_pre."zk set zk='".$m["zk"]."',price='".$m["price"]."' where id='".$check["id"]."'"; }else{ $q2="insert ".$table_pre."zk (cid,iid,zk,price) values ('".$arr_uid[$k]."','".$m["iid"]."','".$m["zk"]."','".$m["price"]."')"; $db->query($q2); $i1++; //echo $i1.".".$q2."
"; } } } } } set_log("按客户字段平铺折扣",$zd."|".$i1."条记录"); if($i1==0){ $json_data.="\"code\":0,\"msg\":\"设置失败,没有记录!\","; }else{ $json_data.="\"code\":1,\"msg\":\"".$i1."条记录设置成功\","; } } break; case "add": if($id){ $msg=get_db_msg("select * from ".$table_pre."zk where id='".$id."'"); $m_client=get_db_msg("select username from ".$table_pre."client where id='".$msg["cid"]."'"); $username=$m_client["username"]; $m_kh=get_db_msg("select no from ".$table_pre."kh where id='".$msg["iid"]."'"); $kh=$m_kh["no"]; $zk=deel_num($msg["zk"]); $price=deel_num($msg["price"]); }else{ $username=""; $kh=$zk=$price=""; } $json_data.="\"username\":\"".$username."\","; $json_data.="\"kh\":\"".$kh."\","; $json_data.="\"zk\":\"".$zk."\","; $json_data.="\"price\":\"".$price."\","; $json_data.="\"zk_type\":\"".$zk_type."\","; break; case "save_add": $username=trim($username); $kh=trim($kh); $msg_client=get_db_msg("select id from ".$table_pre."client where username='".$username."'"); if(!$msg_client["id"]){ $json_data.="\"code\":0,\"msg\":\"客户代码有误!\","; }else{ $msg_kh=get_db_msg("select id,price from ".$table_pre."kh where no='".$kh."'"); if(!$msg_kh["id"]){ $json_data.="\"code\":0,\"msg\":\"款号有误!\","; }else{ //验证 $c=get_db_msg("select count(*) 'num' from ".$table_pre."zk where cid='".$msg_client["id"]."' and iid='".$msg_kh["id"]."' and id<>'".$id."'"); if($c["num"]>0){ $json_data.="\"code\":0,\"msg\":\"该记录已经存在,请检查!\","; }else{ $err_code=""; if($zk_type=="je"){ if($price>0){ $zk=get_price_dp($msg_client["id"],$msg_kh["id"])/$price; }else{ //alert_and_back("结算价有误!"); $err_code="结算价有误!"; } }else{ if($zk>0 && $zk<1){ $price=get_price_dp($msg_client["id"],$msg_kh["id"])*$zk; }else{ //alert_and_back("折扣有误!"); $err_code="折扣有误!"; } } if($err_code){ $json_data.="\"code\":0,\"msg\":\"".$err_code."\","; }else{ if($id){ $query="update ".$table_pre."zk set cid='".$msg_client["id"]."',iid='".$msg_kh["id"]."',zk='".$zk."',price='".$price."' where id='".$id."'"; $db->query($query); $log_action="修改"; }else{ $query="insert ".$table_pre."zk (cid,iid,zk,price) values ('".$msg_client["id"]."','".$msg_kh["id"]."','".$zk."','".$price."')"; $db->query($query); $iid=$db->insert_id(); $log_action="新增"; } $lid=$id?$id:$iid; set_log($log_action."折扣",$username."|".$msg_kh["id"]."|".$zk."|".$price); $json_data.="\"code\":1,"; } } } } break; case "del" : $id=(is_array($id))?$id:array($id); $num=count($id); for($i=0;$i<$num;$i++){ $q="delete from ".$table_pre."zk where id='".$id[$i]."'"; $db->query($q); $lid.=$id[$i].", "; } $lid=substr($lid,0,-2); set_log("删除折扣",$lid); $json_data.="\"code\":1,"; break; //----------------------------------------------------------------------导入EXCEL case "import": //目录权限 $arr_path=array( "cache"=>"admin/cache" ); $json_data.="\"path_priv\":["; $tmp=""; foreach($arr_path as $path_real => $path_title){ $tmp.="{\"title\":\"".$path_title."\",\"priv\":"; if(new_is_writeable($path_real)==1){ $tmp.="\"y\""; }else{ $tmp.="\"n\""; } $tmp.="},"; } $json_data.=substr($tmp,0,-1)."],"; break; case "import_check": $file1=$_FILES["up_file"]; $tmp_file_name=save_tmp_file($file1); $tmp_content=get_tmp_content($tmp_file_name); $arr_content=explode("\n",$tmp_content); $arr_thead=get_table_thead($tmp_content); $arr_column=check_table_thead($arr_thead,$arr_column_zk_zc); $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_zk_zc 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;$i"price" && $ititle<>"zk"){ $tmp=get_db_msg("select id from ".$table_pre."keyword where cate='".$ititle."' and title='".trim($tmp_arr[$ind])."'"); if(!$tmp["id"]){ $wrong_str_cate.=get_cate_title_no("arr_select",$ititle)."名称有误(".trim($tmp_arr[$ind])."),请检查!"; //break; } } } } if($wrong_str_username || $wrong_str_kh || $wrong_str_cate){ del_tmp_file($tmp_file_name); if($wrong_str_username) $errmsg="客户代码有误(".substr($wrong_str_username,0,-1)."),请检查!"; if($wrong_str_kh) $errmsg="款号有误(".substr($wrong_str_kh,0,-1)."),请检查!"; if($wrong_str_cate) $errmsg=$wrong_str_cate; $json_data.="\"code\":0,\"msg\":\"".$errmsg."\","; }else{ if($import_type=="y"){ $db->query("TRUNCATE TABLE web_zk;"); } $json_data.="\"code\":1,\"reload_type\":\"1\","; //导入 if($zk_type=="je"){ $sql_zd="price"; }else{ $sql_zd="zk"; } for($i=1;$iquery($q); }else{ $q1="select id from ".$table_pre."kh ".$sql_kh; $r1=$db->query($q1); while($m1=$db->fetch_array($r1)){ $c=get_db_msg("select id from ".$table_pre."zk where cid='".$cid."' and iid='".$m1["id"]."'"); if($c["id"]>0) $q="update ".$table_pre."zk set ".$sql_zd."='".$num."' where id='".$c["id"]."'"; else $q="insert into ".$table_pre."zk (cid,iid,".$sql_zd.") values ('".$cid."','".$m1["id"]."','".$num."')"; $db->query($q); } } } //换算 if($is_multi_price=="y" || $is_gg=="y"){ //启用了多吊牌或者规格 $q="select * from ".$table_pre."zk"; $r=$db->query($q); while($m=$db->fetch_array($r)){ $price1=get_price_dp($m["cid"],$m["iid"]); if($zk_type=="je"){ $price_zk=get_price_zk($m["cid"],$m["iid"]); $zk=($price1>0)?$price_zk/$price1:1; $q1="update ".$table_pre."zk set zk='".$zk."' where id='".$m["id"]."'"; }else{ $price=$price1*$m["zk"]; $q1="update ".$table_pre."zk set price='".$price."' where id='".$m["id"]."'"; } $db->query($q1); } }else{ // if($zk_type=="je"){ $q="update ".$table_pre."zk a,".$table_pre."kh b set a.zk=a.price/b.price where a.iid=b.id "; }else{ $q="update ".$table_pre."zk a,".$table_pre."kh b set a.price=b.price*a.zk where a.iid=b.id"; } $db->query($q); } del_tmp_file($tmp_file_name); $log_remark=$import_flag; set_log("导入 折扣",$log_remark); } break; //----------------------------------------------------------------------导出数据 case "export": $column=""; foreach($arr_column_zk as $k => $v){ $column.="{\"k\":\"".$k."\",\"t\":\"".$v."\"},"; } if($column) $column=substr($column,0,-1); $json_data.="\"col\":[".$column."],"; break; case "export_do": //取得字段选择的值 foreach($arr_column_zk as $k => $v){ $var="col_".$k; if($$var=="on"){ $ex_col[]=$k; } } $num=count($ex_col); if($num==0) alert_and_back("请至少选择一个要导出的字段"); for($i=0;$i<$num;$i++){ $data["col"][]='str'; $data["header"][0][]=get_main_value($arr_column_zk,$ex_col[$i]); } $query="select * from ".$table_pre."zk ".$sql_con." order by cid,iid"; $r=$db->query($query); $row=0; while($m=$db->fetch_array($r)){ for($i=0;$i<$num;$i++){ $k=$ex_col[$i]; if($k=="cid"){ $tmp=get_db_msg("select username from ".$table_pre."client where id='".$m[$k]."'"); $data["body"][$row][]=$tmp["username"]; }else if($k=="iid"){ $tmp=get_db_msg("select no from ".$table_pre."kh where id='".$m[$k]."'"); $data["body"][$row][]=$tmp["no"]; }else{ $data["body"][$row][]=$m[$k]; } } $row++; } $file_name="zk_".date("Y-m-d-H-i"); output_excel($file_name,$data); set_log("导出 折扣"); exit; break; //-------- default: //取得定制选项 $select_dz=""; for($i=0;$iquery("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); $var="s_".$arr_select_no[$i]; $select_dz.="{\"no\":\"".$arr_select_no[$i]."\",\"title\":\"".$arr_select_title[$i]."\",\"value\":\"".$$var."\",\"op\":[".$tmp."]},"; } $select_dz=deel_end($select_dz); $json_data.="\"select_dz\":[".$select_dz."],"; // $arr_is_sp=array("n"=>"否","y"=>"是"); $tmp_is_sp=""; foreach($arr_is_sp as $k => $v){ $tmp_is_sp.="{\"no\":\"".$k."\",\"title\":\"".$v."\"},"; } $tmp_is_sp=deel_end($tmp_is_sp); $json_data.="\"select_is_sp\":{\"no\":\"s_is_sp\",\"title\":\"".d_translate("spk")."\",\"value\":\"".$s_is_sp."\",\"op\":[".$tmp_is_sp."]},"; $json_data.="\"s_username\":\"".$s_username."\","; $json_data.="\"s_kh\":\"".$s_kh."\","; // $page=$page>0?$page:1; $limit=$limit>0?$limit:10; $start=($page-1)*$limit; $end=$limit; $sql_con=""; if($s_username){ $tmp=get_db_msg("select id from ".$table_pre."client where username='".$s_username."'"); if($tmp["id"]>0) $sql_con.=" and a.cid='".$tmp["id"]."'"; } if($s_kh) $sql_con.=" and b.no='".$s_kh."'"; for($i=0;$i0 ".$sql_con); $total_num=$tmp["num"]; $json_data.="\"code\":0,\"msg\":\"\",\"count\":".$total_num.",\"data\":["; $count=1; $str_tmp=""; $sql="select a.id 'id',a.price 'price_zk',a.zk 'zk',b.no 'no',a.cid 'cid',a.iid 'iid',b.price 'dp_price' from ".$table_pre."zk a,".$table_pre."kh b where b.id=a.iid ".$sql_con." order by cid,iid limit ".$start.",".$end; $res=$db->query($sql); while($msg=$db->fetch_array($res)){ $list=$count+$start; $tmp=get_db_msg("select title,username from ".$table_pre."client where id='".$msg["cid"]."'"); $str_tmp.="{"; $str_tmp.="\"id\":\"".$msg["id"]."\","; $str_tmp.="\"client\":\"".$tmp["username"]."\","; $str_tmp.="\"clientname\":\"".$tmp["username"]."\","; $str_tmp.="\"clienttitle\":\"".$tmp["title"]."\","; $str_tmp.="\"kh\":\"".$msg["no"]."\","; $str_tmp.="\"price\":\"".deel_num($msg["dp_price"])."\","; if($zk_type=="kl"){ $zk1=deel_num($msg["zk"]); }else{ $zk1=""; } if($zk_type=="je"){ $jsj=deel_num($msg["price_zk"]); }else{ $jsj=""; } $str_tmp.="\"zk\":\"".$zk1."\","; $str_tmp.="\"jsj\":\"".$jsj."\""; $str_tmp.="},"; $count++; } $json_data.=substr($str_tmp,0,-1)."],"; break; } $json_data=substr($json_data,0,-1)."}"; echo $json_data; ?>