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
EDT/admin/module/client_brand.php
T
wsh5485 7e47ce238b chore: 添加多个图片和资源文件
添加了管理后台所需的图片资源、Excel文件、安装程序以及设计相关的图片文件
2025-06-15 13:04:37 +08:00

426 lines
14 KiB
PHP
Raw 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
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"]);
$zb_type=get_set("zb_type");
$arr_zb_type=explode(",",$zb_type);
//
$arr_column_client_brand=array("cid"=>"客户代码","brand"=>"品牌代码");
if(in_array("je",$arr_zb_type))
$arr_column_client_brand["zb"]="金额指标";
if(in_array("js",$arr_zb_type))
$arr_column_client_brand["zb_js"]="件数指标";
$json_data="{";
if($priv[0]=="n"){
//没有操作权限
$json_data.="\"error\":\"没有操作权限\",\"code\":0,\"msg\":\"\",\"count\":0,\"data\":[],";
}else{
$json_data.="\"uid\":".$uid.",";
switch($_a){
case "cancel_jd":
$msg=get_db_msg("select username,title from ".$table_pre."client where id='".$cid."'");
//取消交单
$db->query("update ".$table_pre."client_brand set is_jd='n',is_checked='n' where cid='".$cid."' and brand='".$brand."'");
$s_brand=$brand;
update_order_state($uid,$cid,"后台退回订单","");
set_log("后台退回订单",$msg["title"]."(".$msg["username"].")|".get_cate_title_no("brand",$brand)."");
$json_data.="\"code\":1,";
break;
case "export_pl_do":
$arr_column_client=array("username"=>"客户代码","title"=>"客户名称");
$arr_column_pp=array("no"=>"品牌代码","title"=>"品牌名称");
//头
foreach($arr_column_client as $k => $v){
$data["header"][0][]=$v;
}
foreach($arr_column_pp as $k => $v){
$data["header"][0][]=$v;
}
if(in_array("je",$arr_zb_type))
$data["header"][0][]="金额指标";
if(in_array("js",$arr_zb_type))
$data["header"][0][]="件数指标";
//内容
if($source=="1"){
$q="select * from ".$table_pre."client where face='3' or face='4' or face='9'";
$r=$db->query($q);
$row=0;
while($m=$db->fetch_array($r)){
$q1="select * from ".$table_pre."keyword where cate='brand' order by no";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
foreach($arr_column_client as $k => $v){
$data["body"][$row][]=$m[$k];
}
foreach($arr_column_pp as $k => $v){
$data["body"][$row][]=$m1[$k];
}
if(in_array("je",$arr_zb_type))
$data["body"][$row][]="";
if(in_array("js",$arr_zb_type))
$data["body"][$row][]="";
$row++;
}
}
}else{
$q="select * from ".$table_pre."client_brand order by brand,cid";
$r=$db->query($q);
$row=0;
while($m=$db->fetch_array($r)){
$m_client=get_db_msg("select * from ".$table_pre."client where id='".$m["cid"]."'");
foreach($arr_column_client as $k => $v){
$data["body"][$row][]=$m_client[$k];
}
$m_brand=get_db_msg("select * from ".$table_pre."keyword where cate='brand' and no='".$m["brand"]."'");
foreach($arr_column_pp as $k => $v){
$data["body"][$row][]=$m_brand[$k];
}
if(in_array("je",$arr_zb_type))
$data["body"][$row][]=$m["zb"];
if(in_array("js",$arr_zb_type))
$data["body"][$row][]=$m["zb_js"];
$row++;
}
}
$file_name="client_brand_pl_".date("Y-m-d-H-i");
output_excel($file_name,$data);
set_log("导出 多品牌客户批量模板");
break;
//删除
case "del" :
$id=(is_array($id))?$id:array($id);
$num=count($id);
for($i=0;$i<$num;$i++){
$q="delete from ".$table_pre."client_brand where id='".$id[$i]."'";
$db->query($q);
}
$lid=substr($lid,0,-2);
set_log("删除多品牌客户",$lid);
$json_data.="\"code\":1,";
break;
case "add" :
//--------------------------新增
if($id){
$msg=get_db_msg("select * from ".$table_pre."client_brand where id='".$id."'");
$m_client=get_db_msg("select * from ".$table_pre."client where id='".$msg["cid"]."'");
$username=$m_client["username"];
$brand=$msg["brand"];
}else{
$username="";
$brand="";
}
$tmp_brand="";
$q="select * from ".$table_pre."keyword where cate='brand' order by no";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$tmp_brand.="{\"no\":\"".$m["no"]."\",\"title\":\"".$m["title"]."\"},";
}
$tmp_brand=deel_end($tmp_brand);
$json_data.="\"select_brand\":{\"no\":\"s_brand\",\"title\":\"品牌\",\"value\":\"".$brand."\",\"op\":[".$tmp_brand."]},";
if(in_array("je",$arr_zb_type)){
$json_data.="\"s_zbje_sign\":\"y\",";
$json_data.="\"s_zbje\":\"".$msg["zb"]."\",";
}else{
$json_data.="\"s_zbje_sign\":\"n\",";
}
if(in_array("js",$arr_zb_type)){
$json_data.="\"s_zbjs\":\"".$msg["zb_js"]."\",";
$json_data.="\"s_zbjs_sign\":\"y\",";
}else{
$json_data.="\"s_zbjs_sign\":\"n\",";
}
$json_data.="\"s_client\":\"".$username."\",";
break;
case "save_add":
$username=trim($s_client);
$brand=trim($s_brand);
$zb=$s_zbje+1-1;
$zb_js=$s_zbjs;
$msg_client=get_db_msg("select * from ".$table_pre."client where username='".$username."'");
if(!$msg_client["id"]){
$json_data.="\"code\":0,\"msg\":\"客户代码有误!\",";
}else{
//验证
$c=get_db_msg("select count(*) 'num' from ".$table_pre."client_brand where cid='".$msg_client["id"]."' and brand='".$brand."' and id<>'".$id."'");
if($c["num"]>0){
$json_data.="\"code\":0,\"msg\":\"该记录已经存在,请检查!\",";
}else{
if($id){
$query="update ".$table_pre."client_brand set cid='".$msg_client["id"]."',brand='".$brand."',zb='".$zb."',zb_js='".$zb_js."' where id='".$id."'";
$db->query($query);
$log_action="修改";
}else{
$query="insert ".$table_pre."client_brand (cid,brand,zb,zb_js) values ('".$msg_client["id"]."','".$brand."','".$zb."','".$zb_js."')";
$db->query($query);
$iid=$db->insert_id();
$log_action="新增";
}
$lid=$id?$id:$iid;
set_log($log_action."多品牌客户",$brand."|".$msg_client["username"]."|".$zb."|".$zb_js);
$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_client_brand);
$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_client_brand 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_client_brand,$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";
//-------------------------------------------导入数据
$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_client_brand);
//检查
$wrong_str_username=$wrong_str_brand="";
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=="cid"){
$tmp=get_db_msg("select * from ".$table_pre."client where username='".trim($tmp_arr[$ind])."'");
if(!$tmp["id"])
$wrong_str_username.=trim($tmp_arr[$ind]).",";
}else if($ititle=="brand"){
$tmp=get_db_msg("select * from ".$table_pre."keyword where cate='brand' and no='".trim($tmp_arr[$ind])."'");
if(!$tmp["id"])
$wrong_str_brand.=trim($tmp_arr[$ind]).",";
}
}
}
if($wrong_str_username || $wrong_str_brand){
del_tmp_file($tmp_file_name);
$json_data.="\"code\":0,\"msg\":\"用户代码有误(".substr($wrong_str_username,0,-1).",品牌代码有误(".substr($wrong_str_brand,0,-1).",请检查!\",";
}else{
if($import_type=="y"){
$db->query("TRUNCATE TABLE web_client_brand;");
}
$json_data.="\"code\":1,\"reload_type\":\"1\",";
$insert_column="";
for($i=0;$i<count($arr_column[1]);$i++){
$insert_column.=$arr_column[1][$i].",";
}
$insert_column=substr($insert_column,0,-1);
for($i=1;$i<count($arr_content);$i++){
$tmp_arr=explode("|^_^|",$arr_content[$i]);
$insert_value="";
for($k=0;$k<count($arr_column[0]);$k++){
$ind=$arr_column[0][$k];
$ititle=$arr_column[1][$k];
if($ititle=="cid"){
$tmp=get_db_msg("select id from ".$table_pre."client where username='".trim($tmp_arr[$ind])."'");
$insert_value.="'".$tmp["id"]."',";
}else{
$insert_value.="'".mysql_escape_string(trim($tmp_arr[$ind]))."',";
}
}
$insert_value=substr($insert_value,0,-1);
$q="insert into ".$table_pre."client_brand (".$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;
//----------------------------------------------------------------------导出数据
case "export":
$column="";
foreach($arr_column_client_brand 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_client_brand 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_client_brand,$ex_col[$i]);
}
$query="select * from ".$table_pre."client_brand ".$sql_con." order by cid,brand";
$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='".trim($m[$k])."'");
$data["body"][$row][]=$tmp["username"];
}else{
$data["body"][$row][]=$m[$k];
}
}
$row++;
}
$file_name="client_brand_".date("Y-m-d-H-i");
output_excel($file_name,$data);
set_log("导出 多品牌客户");
exit;
break;
//-------------主界面
default:
$tmp_brand="";
$q="select * from ".$table_pre."keyword where cate='brand' order by no";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$tmp_brand.="{\"no\":\"".$m["no"]."\",\"title\":\"".$m["title"]."\"},";
}
$tmp_brand=deel_end($tmp_brand);
$json_data.="\"select_brand\":{\"no\":\"s_brand\",\"title\":\"品牌\",\"value\":\"".$s_brand."\",\"op\":[".$tmp_brand."]},";
//
$page=$page>0?$page:1;
$limit=$limit>0?$limit:10;
$start=($page-1)*$limit;
$end=$limit;
//条件
$sql_con="";
if($s_client || $s_brand){
if($s_client)
$sql_con.=" and c.username='".$s_client."'";
if($s_brand)
$sql_con.=" and a.brand='".$s_brand."'";
}
//取得总条数
$tmp=get_db_msg("select count(*) 'num' from ".$table_pre."client_brand a,".$table_pre."client c where a.cid=c.id ".$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.cid 'cid',c.username 'username',c.title 'title',a.brand 'brand',a.zb 'zb',a.zb_js 'zb_js',a.is_jd 'is_jd',a.is_checked 'is_checked' from ".$table_pre."client_brand a,".$table_pre."client c where a.cid=c.id ".$sql_con." order by a.brand,c.username limit ".$start.",".$end;
$res=$db->query($sql);
while($msg=$db->fetch_array($res)){
$list=$count+$start;
$str_tmp.="{";
$str_tmp.="\"ct\":\"".$list."\",";
$str_tmp.="\"id\":\"".$msg["id"]."\",";
$str_tmp.="\"cid\":\"".$msg["cid"]."\",";
$str_tmp.="\"brand\":\"".$msg["brand"]."\",";
$str_tmp.="\"brand_title\":\"".get_cate_title_no("brand",$msg["brand"])."\",";
$str_tmp.="\"client\":\"".$msg["title"]."(".$msg["username"].")\",";
$str_tmp.="\"zbje\":\"".$msg["zb"]."\",";
if($msg["is_jd"]=="y" || $msg["is_checked"]=="y"){
$str_tmp.="\"is_back_order\":\"y\",";
$str_tmp.="\"cz\":\"<a class='layui-btn layui-btn-warm layui-btn-xs' lay-event='edit_back_order'>退回订单</a>\",";
}else{
$str_tmp.="\"is_back_order\":\"n\",";
$str_tmp.="\"cz\":\"\",";
}
$str_tmp.="\"zbjs\":\"".$msg["zb_js"]."\"";
$str_tmp.="},";
$count++;
}
$json_data.=substr($str_tmp,0,-1)."],";
break;
}
}
$json_data=substr($json_data,0,-1)."}";
echo $json_data;
?>