<?php
//====== 后台管理 ======
require "common.php";
$ver="0.8.0";
$m=file_get_contents("php://input");if($m=="")$m='{"act":"idx"}';$m=Dec($m,true);session_start();
if($m["act"]!="idx"&&$m["act"]!="lgn"){if(!isset($_SESSION["Jir_Admin"])&&$_SESSION["Jir_Admin"]!=$m["sid"])die('{"msg":"连接超时，请重登录！"}');}
switch($m["act"]){
	case "lgn"://管理登录
	if(md5($m["Ak"])==$cfg["Ak"]){
		$b=Rnd();$_SESSION["Jir_Admin"]=$b;
		$p=["msg"=>"ok","cfg"=>$cfg];$p["cfg"]["DB"]="";$p["cfg"]["Ak"]="";
		//$p["cfg"]["Ap"]=["Fs"=>0,"Gi"=>"","Gk"=>"","Wc"=>"","Wi"=>"","Wk"=>"","Wm"=>"","Wn"=>"","Zp"=>"","Zi"=>"","Zk"=>"","Zm"=>"","Zn"=>""];
		echo Enc($p);
	}else echo '{"msg":"登录密码错误！"}';
	break;

	case "cwv"://网站保存
	$cfg["An"]=$m["An"];$cfg["Aw"]=$m["Aw"];
	file_put_contents("config.php","<?php".PHP_EOL."//系统配置".PHP_EOL."\$cfg='".Enc($cfg)."';");
	echo '{"msg":"ok"}';
	break;

	case "cav";//修改密码
	if($cfg["Ak"]==md5($m["Ak"])){
		$cfg["Ak"]=md5($m["Ap"]);
		file_put_contents("config.php","<?php".PHP_EOL."//系统配置".PHP_EOL."\$cfg='".Enc($cfg)."';");
		echo '{"msg":"ok"}';
	}else echo '{"msg":"原始密码错误！"}';
	break;


	case "cbv"://充值设置
	$cfg["Ab"]=$m["Ab"];echo '{"msg":"ok"}';
	file_put_contents("config.php","<?php".PHP_EOL."//系统配置".PHP_EOL."\$cfg='".Enc($cfg)."';");
	break;

	case "ccv"://优惠设置
	$cfg["Ac"]=$m["Ac"];echo '{"msg":"ok"}';
	file_put_contents("config.php","<?php".PHP_EOL."//系统配置".PHP_EOL."\$cfg='".Enc($cfg)."';");
	break;

	case "cgv"://接口设置
	$m["Ag"]["Be"]=$cfg["Ag"]["Be"];$m["Ag"]["Bt"]=$cfg["Ag"]["Bt"];
	$m["Ag"]["We"]=$cfg["Ag"]["We"];$m["Ag"]["Wt"]=$cfg["Ag"]["Wt"];
	$cfg["Ag"]=$m["Ag"];echo '{"msg":"ok"}';
	file_put_contents("config.php","<?php".PHP_EOL."//系统配置".PHP_EOL."\$cfg='".Enc($cfg)."';");
	break;

	case "cpv"://支付配置
	//die('{"msg":"仅供演示，不可保存！"}');
	$cfg["Ap"]=$m["Ap"];echo '{"msg":"ok"}';
	file_put_contents("config.php","<?php".PHP_EOL."//系统配置".PHP_EOL."\$cfg='".Enc($cfg)."';");
	break;

	case "cpu"://支付升级
	if(file_exists("onepay.php"))die('{"msg":"已存在同名文件 onepay.php，请先删除或改名！"}');
	$e=Dec(Cul("https://www.pays.top/app/lic.php?p=Jir&w=".$cfg["Aw"]."&v=".$m["AL"]));
	if($e["msg"]=="ok"){
		$cfg['AL']=$m["AL"];file_put_contents("config.php","<?php".PHP_EOL."//系统配置".PHP_EOL."\$cfg='".Enc($cfg)."';");
		file_put_contents("onepay.php","<?php".PHP_EOL."//官方支付接口".PHP_EOL."require 'common.php';\$s='".$e["str"]."';\$s=openssl_decrypt(\$s,'AES-128-CBC',md5(\$cfg['AL'].\$_SERVER['HTTP_HOST']),0,substr(md5(\$_SERVER['HTTP_HOST'].\$cfg['AL']),8,16));eval(\$s);");
	}
	echo Enc($e);
	break;

	case "shl"://分店列表
	$n=["msg"=>"ok","lst"=>[],"cnt"=>[],"s0"=>Qrs(Qry("Select Sum(Ps) From ".$pre."expend Where Pd<'".date("Y-m-d")."'"))*1,"s1"=>Qrs(Qry("Select Sum(Pc) From ".$pre."expend Where Pc>0 And Pd<'".date("Y-m-d")."'"))*1];
	$q=Qry("Select ID,Si,Sn,Sw,Sa,Sb,Sx,Sy,Se,Sh From ".$pre."shop Where Sh<2 Order By ID Desc");
	while($r=Qra($q)){
		$n["lst"][]=$r;$e=[0,0,0,0,0];
		$e[0]=Qrs(Qry("Select Sum(Ps) As N From ".$pre."expend Where Pd<'".date("Y-m-d")."' And Pf=0 And Yi Like '".$r["Si"]."-%'"))/100;
		$e[1]=Qrs(Qry("Select Sum(Ps) As N From ".$pre."expend Where Pd<'".date("Y-m-d")."' And Pf=0 And Yi Like '".$r["Si"]."-C%'"))/100;
		$e[2]=Qrs(Qry("Select Sum(Pc) As N From ".$pre."expend Where Pd<'".date("Y-m-d")."' And Pf=0 And Yi Like '".$r["Si"]."-%' And Pc>0"))/100;
		$e[3]=-Qrs(Qry("Select Sum(Pc) As N From ".$pre."expend Where Pd<'".date("Y-m-d")."' And Pf=0 And Yi Like '".$r["Si"]."-%' And Pc<0"))/100;
		$e[4]=-Qrs(Qry("Select Sum(Pc) As N From ".$pre."expend Where Pd<'".date("Y-m-d")."' And Yi Like '".$r["Si"]."-%' And Pc<0"))/100;
		$n["cnt"][]=$e;
	}
	echo Enc($n);
	break;

	case "shv"://分店保存
	if($m["ID"]*1==0){
		if(Qrc(Qry("Select ID From ".$pre."shop Where Si=".$m["Si"]))>0)die('{"msg":"新增分店ID重复！"}');if($m["Sk"]=="")$m["Sk"]="123456";
		Qry("Insert Into ".$pre."shop (Si,Sn,Sw,Sa,Sb,Sx,Sy,Se,Sc,Sh) Values (".$m["Si"].",'".$m["Sn"]."','".$m["Sw"]."','".$m["Sa"]."','".$m["Sb"]."','".$m["Sx"]."','".$m["Sy"]."',0,'{\"i\":[\"0\",\"0\",\"0\",\"7-21\",\"10\",\"3\",\"5\",\"1\",\"0\",\"999\",\"请{{id}}号顾客到餐厅就餐\",\"请{{id}}号顾客到前台取餐\",\"收款成功，金额：{{id}}元\",\"来新单了，{{i1}}，{{i2}}份\",\"新单，送至{{i1}}，{{i2}}元\",\"\",\"\"],\"c\":[[1,1,1,1,1],[[\"限时九折\",1,0.9],[\"满百减五\",100,5]]],\"p\":[\"\",\"\",\"\",\"0\",\"0\",\"58\",\"12\",\"20\",\"欢迎光临\",\"18\",\"谢谢惠顾\",\"18\",\"58\",\"12\",\"20\",\"18\",0]}',".$m["Sh"].")");
		Qry("Insert Into ".$pre."admin (Si,An,Au,Ap,Aw,Am,Ar,Ad,A0,A1,Ak,Ah) Values (".$m["Si"].",'店长','admin','".md5($m["Sk"])."','','','ABCDEFS',Now(),0,0,'',0)");
		if(!file_exists("images/".$m["Si"]))mkdir("images/".$m["Si"]);
		file_put_contents("images/".$m["Si"]."/d.txt",'{"msg":"ok","si":0,"sj":"'.date("Y-m-d H:i:s").'","ph":[],"yd":[]}');
		file_put_contents("images/".$m["Si"]."/k.txt",'{"msg":"ok","skl":{}}');
		if($m["Su"]==1){
			for($j=1;$j<11;$j++)Qry("Insert Into ".$pre."table (Si,Tn,Tr,Tc,Tu,Ts,Ti,Tm,Ta,Th) Values (".$m["Si"].",'".$j."号桌',".$j.",4,0,0,0,0,0,0)");
			$t1=["","热卖","牛排","披萨","仔饭","意面","沙拉","鲜汤","小吃","饮料","套餐"];$t2=[0,7,7,5,5,5,5,5,7,5,3];
			for($j=1;$j<11;$j++)Qry("Insert Into ".$pre."class (Si,Bn,Bp,Br,Bs,Bh) Values (".$m["Si"].",'".$t1[$j]."',0,".$j.",".$t2[$j].",0)");
			$i1=Qri()-10;$i2=0;
			$t=[["精选牛仔骨",",1,2,",1,1,6800,"0",''],["极佳肥牛扒",",2,",2,1,6800,"0",''],["美国黑椒牛排",",2,",3,1,4800,"0",''],["澳洲西冷牛排",",2,",4,1,4800,"0",''],["日式香煎鸡排",",2,",5,1,3800,"0",''],["法国乡村鸭扒",",2,",6,1,3800,"0",''],["田园风光披萨",",3,",7,1,4800,"0",''],["海陆至尊披萨",",1,3,",8,1,6800,"0",''],["热带雨林披萨",",3,",9,1,5800,"0",''],["缤纷水果披萨",",3,",10,1,4800,"0",''],["红烧牛肉仔饭",",4,",11,1,2800,"0",''],["香菇滑鸡仔饭",",4,",12,1,2600,"0",''],["咖喱烤肉仔饭",",1,4,",13,1,2600,"0",''],["茄汁海鲜仔饭",",4,",14,1,2800,"0",''],["车打芝士意面",",5,",15,1,2400,"0",''],["法式蘑菇鸡面",",5,",16,1,2800,"0",''],["黑椒培根意面",",5,",17,1,3200,"0",''],["拿波里鲔鱼面",",1,5,",18,1,3000,"0",''],["大虾蔬果沙拉",",6,",19,1,2200,"0",''],["海鲜水果沙拉",",6,",20,1,2200,"0",''],["美式凯撒沙拉",",6,",21,1,2600,"0",''],["炭烤鸡肉沙拉",",6,",21,1,2000,"0",''],["培根土豆浓汤",",7,",23,1,1200,"0",''],["鲜美虾芦笋汤",",7,",24,1,2400,"0",''],["火腿玉米浓汤",",7,",25,1,1600,"0",''],["香肠菠菜浓汤",",7,",26,1,1600,"0",''],["尊享大拼盘",",8,",27,1,3600,"0",''],["鲍菇串香肠",",8,",28,1,1800,"0",''],["嫩牛香酥卷",",1,8,",29,1,1600,"0",''],["泰式口口香",",8,",30,1,1200,"0",''],["新趣海鲜棒",",8,",31,1,1800,"0",''],["浓情香鸡翼",",1,8,",32,1,2400,"0",''],["摩卡咖啡",",9,",33,1,1600,"0",''],["拿铁咖啡",",9,",34,1,1600,"0",''],["菊花柚子茶",",9,",35,1,1200,"0",''],["香橙柠檬茶",",9,",36,1,1200,"0",''],["单人套餐",",10,",37,1,6800,"0,3,32,25",'美国黑椒牛排,浓情香鸡翼,火腿玉米浓汤'],["情侣套餐",",10,",38,1,14800,"0,2,9,20,26,31",'极佳肥牛扒,热带雨林披萨,新趣海鲜棒,海鲜水果沙拉'],["全家套餐",",10,",39,1,18800,"0,1,9,13,21,27,36",'精选牛仔骨,热带雨林披萨,咖喱烤肉煲仔饭,美式凯撒沙拉,尊享大拼盘,香橙柠檬茶'],["测试支付",",1,2,3,4,5,6,7,8,9,",0,1,1,"0",'']];
			for($j=0;$j<40;$j++){
				$h=explode(",",$t[$j][1]);for($f=1;$f<count($h)-1;$f++)$h[$f]=$h[$f]*1+$i1;$h=join(",",$h);
				$g=explode(",",$t[$j][5]);for($f=1; $f<count($g); $f++)$g[$f]=$g[$f]*1+$i2;$g=join(",",$g);
				Qry("Insert Into ".$pre."foods (Si,Dn,Dc,Dr,Ds,Di,Dm,Dv,Da,D1,D2,Dt,Dk,Db,Dh) Values (".$m["Si"].",'".$t[$j][0]."','".$h."',".($t[$j][2]+1).",'".$t[$j][6]."',".$t[$j][3].",".$t[$j][4].",'0','0',0,0,'".$g."','','',0)");
				if($j==0)$i2=Qri()-1;
				copy("images/demo/c".($j+1).".jpg","images/".$m["Si"]."/c".($i2+$j+1).".jpg");
			}
		}
	}else{
		Qry("Update ".$pre."shop Set Sn='".$m["Sn"]."',Sw='".$m["Sw"]."',Sa='".$m["Sa"]."',Sb='".$m["Sb"]."',Sx='".$m["Sx"]."',Sy='".$m["Sy"]."',Sh=".$m["Sh"]." Where ID=".$m["ID"]);
		if(strlen($m["Sk"])>5){
			if(Qrc(Qry("Select ID From ".$pre."admin Where Si=".$m["Si"]." And Nu='admin'"))==0){
				Qry("Insert Into ".$pre."admin (Si,An,Au,Ap,Aw,Am,Ar,Ad,A0,A1,Ak,Ah) Values (".$m["Si"].",'店长','admin','".md5($m["Sk"])."','','','ABCDEFS',Now(),0,0,'',0)");
			}else Qry("Update ".$pre."admin Set Ap='".md5($m["Sk"])."',Ar='ABCDEFS',Ah=0 Where Si=".$m["Si"]." And Nu='admin'");
		}
	}
	echo '{"msg":"ok"}';
	break;

	case "shc"://分店主店
	$cfg["Ai"]=$m["Ai"];echo '{"msg":"ok"}';
	file_put_contents("config.php","<?php".PHP_EOL."\$cfg='".Enc($cfg)."';");
	break;

	case "shd"://分店删除
	$q=Qry("Update ".$pre."shop Set Sh=2 Where Si=".$m["Si"]);
	echo '{"msg":"ok"}';
	break;

	case "shx"://分店分账
	for($i=0;$i<count($m["Se"]);$i++)Qry("Update ".$pre."shop Set Se=Se+".$m["Se"][$i][1]." Where Si=".$m["Se"][$i][0]);
	Qry("Update ".$pre."expend Set Ge=1 Where Gd<'".date("Y-m-d")."'");
	echo '{"msg":"ok"}';
	break;

	case "odl"://支付列表
	$a=$m["Os"];$p=$m["Pg"]*1;
	if($a!=""&&is_numeric($a))$a=" Where Mc='".$a."'";
	$c=Qrs(Qry("Select Count(ID) From ".$pre."pay".$a));
	$d=floor(($c-1)/30)+1;
	if($p<1)$p=1;if($p>$d)$p=$d;
	$n=["msg"=>"ok","lst"=>[],"Pt"=>$d];
	$q=Qry("Select ID,Mc,Mp,Md,Mt,Nc,Np,Nd,Nt From ".$pre."pay".$a." Order By ID Desc Limit ".(($p-1)*30).",30");
	while($r=Qra($q))$n["lst"][]=$r;
	echo Enc($n);
	break;

	case "odd"://支付删除
	Qry("Delete From ".$pre."pay Where Md<'".date("Y-m-d H:i:s",strtotime("-2 hours"))."' And Nt=0 And ID=".$m["ID"]);
	echo '{"msg":"ok"}';
	break;

	case "rpl"://报表统计
	$a=strtotime($m["R1"])?date("Y-m-d",strtotime($m["R1"])):date("Y-m-d");
	$b=date("Y-m-d",strtotime("+1 days",strtotime($a)));
	$e=strtotime($m["R2"])?date("Y-m-d",strtotime($m["R2"])):date("Y-m-d");
	$e=date("Y-m-d",strtotime("+1 days",strtotime($e)));
	$p=["msg"=>"ok","lst"=>[]];$n=$m["Ri"]==""?"":" And Mi=".$m["Ri"];
	while(strtotime($a)<strtotime($e)){
		$c=Qry("Select Si From ".$pre."shop Where Sh<2".$n);
		while($f=Qra($c)){
			$s=Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$f["Si"]." And Ps>0 And Od>'".$a."' And Od<'".$b."'"))/100;//营业额 1
			$s.="|".Qrs(Qry("Select Count(ID) From ".$pre."order Where Si=".$f["Si"]." And Ps>0 And Od>'".$a."' And Od<'".$b."'"))*1;//点单数 2
			$s.="|".Qrs(Qry("Select Count(ID) From ".$pre."ofood Where Si=".$f["Si"]." And Fr<2 And Fd>'".$a."' And Fd<'".$b."'"))*1;//点菜数 3
			$s.="|".Qrs(Qry("Select Count(ID) From ".$pre."ofood Where Si=".$f["Si"]." And Fr=2 And Fd>'".$a."' And Fd<'".$b."'"))*1;//退菜数 4
			$s.="|".Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$f["Si"]." And Pt=0 And Od>'".$a."' And Od<'".$b."'"))/100;//现金 5
			$s.="|".Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$f["Si"]." And Pt=1 And Od>'".$a."' And Od<'".$b."'"))/100;//刷卡 6
			$s.="|".Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$f["Si"]." And Pt=2 And Od>'".$a."' And Od<'".$b."'"))/100;//微信 7
			$s.="|".Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$f["Si"]." And Pt=3 And Od>'".$a."' And Od<'".$b."'"))/100;//支付宝 8
			$s.="|".Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$f["Si"]." And Pt=4 And Od>'".$a."' And Od<'".$b."'"))/100;//会员卡 9
			$s.="|".Qrs(Qry("Select Sum(Pd) From ".$pre."order Where Si=".$f["Si"]." And Od>'".$a."' And Od<'".$b."'"))/100;//折扣 10
			$s.="|".Qrs(Qry("Select Sum(Pc) From ".$pre."order Where Si=".$f["Si"]." And Od>'".$a."' And Od<'".$b."'"))/100;//卡券 11
			$s.="|".Qrs(Qry("Select Sum(Gm) From ".$pre."expend Where Si=".$f["Si"]." And Go=0 And Gd>'".$a."' And Gd<'".$b."'"))/100;//会员充值 12
			$s.="|".Qrs(Qry("Select Sum(Gm) From ".$pre."expend Where Gu Like '".$f["Si"]."-C%' And Go=0 And Gd>'".$a."' And Gd<'".$b."'"))/100;//自助充值 13
			$p["lst"][]=[0,$f["Si"],$a,$s];
		}
		$a=$b;$b=date("Y-m-d",strtotime("+1 days",strtotime($b)));
	}
	echo Enc($p);
	break;

	case "mbl"://会员列表
	$a=$m["U0"];$p=$m["Pg"]*1;
	if($a!=""&&is_numeric($a))$a=" Where Uc Like '%".$a."%'";
	$c=Qrs(Qry("Select Count(ID) From ".$pre."user".$a));
	$d=floor(($c-1)/30)+1;
	if($p<1)$p=1;if($p>$d)$p=$d;
	$n=["msg"=>"ok","lst"=>[],"Pt"=>$d,"U1"=>Qrs(Qry("Select Sum(Us) From ".$pre."user Where Us>=0"))*1,"U2"=>Qrs(Qry("Select Sum(Us) From ".$pre."user Where Us<=0"))*1];
	$q=Qry("Select ID,Uc,Un,Up,Ud,Us,Ux,Ut,Ue,Uf From ".$pre."user".$a." Order By ID Desc Limit ".(($p-1)*30).",30");
	while($r=Qra($q))$n["lst"][]=$r;
	echo Enc($n);
	break;

	case "mbv"://会员保存
	if($m["ID"]*1==0){
		if(Qrc(Qry("Select ID From ".$pre."user Where Uc='".$m["Uc"]."'"))>0)die('{"msg":"手机号已存在！"}');
		Qry("Insert Into ".$pre."user (Uc,Un,Up,Ud,Us,Ux,Ut,Ue,Uf) Values ('".$m["Uc"]."','".$m["Un"]."','".md5($m["Up"])."',Now(),0,0,Now(),".$m["Ue"].",'".$m["Uf"]."')");
	}else{
		$a=Qrs(Qry("Select Up From ".$pre."user Where ID=".$m["ID"]));$b=$a==$m["Up"]?$a:md5($m["Up"]);
		Qry("Update ".$pre."user Set Un='".$m["Un"]."',Ue=".$m["Ue"].",Uf='".$m["Uf"]."',Up='".$b."' Where ID=".$m["ID"]);
	}
	echo '{"msg":"ok"}';
	break;

	case "mbd"://会员删除
	Qry("Delete From ".$pre."user Where Us=0 And Ux=0 And ID=".$m["ID"]);
	echo '{"msg":"ok"}';
	break;

	case "mcl"://会员券表
	$p=["msg"=>"ok","lst"=>[]];
	$q=Qry("Select Cm,Cn,Cd,Co From ".$pre."coupon Where Cu='".$m["Cu"]."' Order By ID Desc");
	while($r=Qra($q))$p["lst"][]=$r;
	echo Enc($p);
	break;

	case "mcu"://会员发券
	if(!strtotime($m["Cd"]))$m["Cd"]="2099-12-31";
	Qry("Insert Into ".$pre."coupon (Cu,Cm,Cn,Cd,Co) Values ('".$m["Cu"]."',".$m["Cm"].",".$m["Cn"].",'".$m["Cd"]."',0)");
	echo '{"msg":"ok"}';
	break;

	case "mcv"://全体发券
	if(!strtotime($m["Xd"]))$m["Xd"]="2099-12-31";$b=[];
	if($m["Xu"]==""){$q=Qry("Select Uc From ".$pre."user");while($r=Qra($q))$b[]=$r["Uc"];
	}else $b=explode(",",trim($m["Xu"]));
	for($i=0;$i<count($b);$i++)Qry("Insert Into ".$pre."coupon (Cu,Cm,Cn,Cd,Co) Values ('".$b[$i]."',".$m["Xm"].",".$m["Xn"].",'".$m["Xd"]."',0)");
	echo '{"msg":"ok"}';
	break;

	case "xfl"://会员消费
	$a=$m["Gc"];$p=$m["Pg"]*1;
	if($a!="")$a=" Where Uc='".$a."'";
	$c=Qrs(Qry("Select Count(ID) From ".$pre."expend".$a));
	$d=floor(($c-1)/30)+1;
	if($p<1)$p=1;if($p>$d)$p=$d;
	$n=["msg"=>"ok","lst"=>[],"Pt"=>$d];
	$q=Qry("Select ID,Gc,Go,Gu,Gm,Gn,Gd,Ge From ".$pre."expend".$a." Order By ID Desc Limit ".(($p-1)*30).",30");
	while($r=Qra($q))$n["lst"][]=$r;
	echo Enc($n);
	break;

	default:
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $cfg["An"];?></title>
<style type="text/css">
html,body {margin:0px;padding:0px;font-size:14px;font-family:Consolas,微软雅黑;}
a:link,a:visited {color:#09F;text-decoration:none;}
a:hover,a:active {color:#F00;text_decoration:underline;}
input[type=text],input[type=date],input[type=number],input[type=password],textarea,select {padding:3px;font-size:14px;font-family:Consolas,微软雅黑;resize:none;}
#msk {position:fixed;left:0px;top:0px;background-color:#000;opacity:0.2;z-index:9;display:none;}
#tip {position:fixed;background-color:#000;color:#FFF;padding:5px 10px;box-shadow:2px 2px 2px #666;border-radius:3px;z-index:99;display:none;}
#cfn {position:fixed;background-color:#FFF;padding:20px;width:320px;border:1px solid #CCC;line-height:24px;box-shadow:2px 2px 2px #666;display:none;z-index:98;}
.fld {position:fixed;background-color:#FFF;border:1px double #CCC;box-shadow:0px 0px 5px #999;display:none;}
.flt {line-height:40px;text-align:center;font-weight:bold;background-color:#F6F6F6;font-size:16px;}
.flb {padding:10px 20px;line-height:36px;}
.btn {display:inline-block;line-height:28px;color:#FFF;background-color:#09F;box-shadow:2px 2px 3px #CCC;padding:0px 10px;cursor:pointer;border-radius:5px;}
.bn0 {display:inline-block;line-height:24px;margin:8px 0px 0px 8px;padding:0px 6px;border:1px solid #CCC;text-align:center;cursor:pointer;}
.bn1 {display:inline-block;line-height:24px;margin:8px 0px 0px 8px;padding:0px 6px;border:1px solid #CCC;background-color:#09F;color:#FFF;text-align:center;cursor:pointer;}
.bnc {float:right;width:24px;line-height:24px;border:1px solid #CCC;text-align:center;cursor:pointer;margin:7px;font-size:20px;}
.pgs {width:1200px;line-height:28px;margin:auto;text-align:center;padding:4px;}
.pg0 {display:inline-block;line-height:26px;border:1px solid #CCC;width:26px;margin:0px 5px;cursor:pointer;color:#09F;}
.pg1 {display:inline-block;line-height:28px;background-color:#09F;width:28px;margin:0px 5px;cursor:pointer;color:#FFF;}
/*----------------------------------------------------------------*/
.nv0 {display:inline-block;font-size:16px;color:#EEE;line-height:45px;margin:10px 5px 0px 5px;border-bottom:5px solid #333;padding:0px 10px;cursor:pointer;}
.nv1 {display:inline-block;font-size:16px;color:#EEE;line-height:45px;margin:10px 5px 0px 5px;border-bottom:5px solid #6CF;padding:0px 10px;cursor:pointer;}
.ls0 {height:32px;line-height:32px;border-bottom:1px solid #CCC;text-align:center;}
.ls1 {float:left;width:100px;}.ls2 {float:left;width:200px;}.ls3 {float:left;width:300px;}.ls4 {float:left;width:400px;}
.ls5 {float:left;width:500px;}.ls6 {float:left;width:600px;}.ls9 {float:left;width:50px;}
</style>
<script type="text/javascript">
function $(o){return document.getElementById(o);}function $$(o){return document.getElementsByName(o);}
function xml(u,p,f){var x;try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(f){x=false;}}if(!x&&typeof XMLHttpRequest!='undefined'){x=new XMLHttpRequest();}if(!x){alt('创建XHR对象失败！');return;}x.open(p?'Post':'Get',u,true);x.setRequestHeader('Content-Type','application/json;');x.onreadystatechange=function(){if(x.readyState==4&&x.status==200){try{var s=JSON.parse(x.responseText.replace(/\&\#32;/gi,' ').replace(/\&\#34;/gi,'&quot;').replace(/\&\#37;/gi,'%').replace(/\&\#39;/gi,'\''));if(s.msg!='ok'){alt(s.msg);return;}}catch(e){alt('响应JSON解析错误！\n'+x.responseText+'\n'+e);return;}f(s);}};x.send(p?JSON.stringify(p):null);}
function rnd(n,c){var s='';for(var i=0;i<(n||16);i++)s+='1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'.substr(Math.floor((c?10:62)*Math.random()),1);return s;}
function num(n){var o=event.srcElement;if(o.tagName=='INPUT'&&(o.type=='text'||o.type=='number')){if(!n)n=0;var v=parseFloat(o.value);if(!v)v=0;v=Math.round(v*Math.pow(10,n))/Math.pow(10,n);o.value=v;}}
function sck(n,v){var d=new Date();d.setTime(d.getTime()+1080000000);document.cookie=n+'='+encodeURI(v)+'; expires='+d.toGMTString();}
function gck(n){var c=document.cookie.split("; ");for(var i=0;i<c.length;i++){var t=c[i].split("=");if(t[0]==n)return decodeURI(t[1]);}return '';}
function css(n){for(var i=0;i<document.styleSheets.length;i++){var r=document.styleSheets[i].cssRules?document.styleSheets[i].cssRules:document.styleSheets[i].rules;for(var j=0;j<r.length;j++){if(r[j].selectorText==n)return r[j].style;}}}
function psz(o,s){var w=o.width;var h=o.height;if(w<h){h=h*s/w;w=s;}else{w=s*w/h;h=s;}o.width=w;o.height=h;o.style.margin=(s-h)/2+'px '+(s-w)/2+'px';}
function bsz(o,w,h){w=parseInt(w);h=parseInt(h)-4;var s=w>h?w:h;psz(o,s);}
function fio(m,n,o){if(o&&o!=1){o=o.split(',');for(var i=0;i<o.length;i++)$(o[i]).style.display='none';}o=o?1:0;$(m).style.display='block';if(o)msk.style.display='block';var c=Math.round(parseFloat($(m).style.opacity||(n>0?0:1))*100)/100;c+=0.1*n;if(c<=1&&c>0){$(m).style.opacity=c;if(o)msk.style.opacity=c/5;$(m).style.left=(pw-parseInt($(m).offsetWidth))/2+'px';$(m).style.top=(ph-parseInt($(m).offsetHeight))/2+20-c*20+'px';setTimeout('fio(\''+m+'\','+n+','+o+')',20);}if(c==0){$(m).style.display='none';if(o)msk.style.display='none';}}
function alt(n){tip.innerText=n;if(tip.style.display=='block')return;fio('tip',1);setTimeout(function(){fio('tip',-1);},2000);}
function cfm(n,s,c){var m=msk.style.display=='block'?false:1;msk.style.zIndex=97;cfn.innerHTML=n.replace(/\n/gi,'<br>')+'<div style="text-align:right;"><br><span id="cfc" class="bn0">取消</span>　<span id="cfs" class="bn1">确定</span></div>';cfc.addEventListener('click',function(){fio('cfn',-1,m);msk.style.zIndex=9;if(c)c();});cfs.addEventListener('click',function(){fio('cfn',-1,m);msk.style.zIndex=9;s();});fio('cfn',1,m);}
function pgs(c,t,f){c=c||1;var s='<div class="pgs">分页： <span class="pg'+(c==1?1:0)+'" onclick="'+f.replace('{{id}}',1)+'">1</span>';if(c-5>1)s+='...';for(var i=c-4;i<c+5;i++){if(i>1&&i<t)s+='<span class="pg'+(i==c?1:0)+'" onclick="'+f.replace('{{id}}',i)+'">'+i+'</span>';}if(c+5<t)s+='...';if(t>1)s+='<span class="pg'+(c==t?1:0)+'" onclick="'+f.replace('{{id}}',t)+'">'+t+'</span>';return s+' <input type="text" style="width:32px;text-align:center;" onkeyup="num();if(event.keyCode==13)'+f.replace('{{id}}','this.value')+';"></div>';}
/*----------------------------------------------------------------*/
var uri='admin.php';
var sid,cfg,dat,tid;
var rd='<?php echo date("Y-m-d");?>';
var rm='<?php echo date("Y-m")."-01";?>';
var pw,ph,mx,my;
function rsz(){pw=parseInt(document.documentElement.clientWidth);ph=parseInt(document.documentElement.clientHeight);msk.style.width=pw+'px';msk.style.height=ph+'px';setTimeout('rsz()',500);}
function jsn(n){return {act:n,sid:sid,rnd:rnd()};}
//导航切换

function nvl(n){for(var i=0;i<5;i++){$('Nv'+i).className='nv0';$('Dv'+i).style.display='none';}$('Nv'+n).className='nv1';$('Dv'+n).style.display='block';eval(['shl()','odl()','rpl()','mbl()','xfl()'][n]);}
//系统登录
function lgn(){var p=jsn('lgn');p.Ak=Ak.value;xml(uri,p,function(r){sid=r.sid;cfg=r.cfg;fio('Dl',-1,1);nvl(0);});}
//网站设置
function cwv(){var p=jsn('cwv');p.An=An.value;p.Aw=Aw.value;xml(uri,p,function(r){alt('网站设置保存成功！');location.reload();});}
//修改密码
function cav(){if(Ao.value!=Ak.value){alt('原密码错误！');return;}if(!(/[0-9]+/.test(Ap.value)&&/[a-z]+/.test(Ap.value)&&/[A-Z]+/.test(Ap.value)&&Ap.value.length>7)){alt('超管密码必需包含大小写英文字母及数字且不少于8位！');return;}if(Ap.value!=Av.value){alt('新密码与验证密码不同！');return;}var p=jsn('cav');p.Ak=Ao.value;p.Ap=Ap.value;xml(uri,p,function(r){alt('修改密码成功！');Ak.value=Ap.value;fio('Fa',-1,1);});}
//显示充值
function cbs(){Ab.value=cfg.Ab.Bc;var s='';for(var i=0;i<cfg.Ab.Bs.length;i++)s+='充 <input type="text" id="Ab_c'+i+'" size="4" value="'+cfg.Ab.Bs[i][0]+'" onblur="num(2);"> 元送 <input type="text" id="Ab_s'+i+'" size="4" value="'+cfg.Ab.Bs[i][1]+'" onblur="num(2);"> 元　<a href="javascr'+'ipt:void(0);" onclick="cbd('+i+');">删除</a><br>';Fbl.innerHTML=s+'充 <input type="text" id="Ab_c'+i+'" size="4" onblur="num(2);"> 元送 <input type="text" id="Ab_s'+i+'" size="4" onblur="num(2);"> 元<br>';fio('Fb',1,1);}
//删除充值
function cbd(n){cfm('确认删除？',function(){cfg.Ac.Bs.splice(n,1);cbs();});}
//保存充值
function cbv(){var c=cfg.Ab.Bs.length;var s=[];for(var i=0;i<c;i++)s[i]=[$('Ab_c'+i).value*1,$('Ab_s'+i).value*1];if($('Ab_c'+c).value!=''&&$('Ab_c'+c).value!='0')s.push([$('Ab_c'+c).value*1,$('Ab_s'+c).value*1]);var p=jsn('cbv');p.Ab={Bc:Ab.value*1,Bs:s};xml(uri,p,function(r){alt('充值设置保存成功！');cfg.Ab=p.Ab;fio('Fb',-1,1);});}
//显示优惠
function ccs(){var s='';for(var i=1;i<cfg.Ac.length+1;i++){s+=i+' 消费满 <input type="text" id="Ac_0_'+i+'" size="3" value="'+cfg.Ac[i-1][0]+'" onblur="num(2);"> 元送 <input type="text" id="Ac_1_'+i+'" size="3" value="'+cfg.Ac[i-1][1]+'" onblur="num(2);"> 元（满 <input type="text" id="Ac_2_'+i+'" size="3" value="'+cfg.Ac[i-1][2]+'" onblur="num(2);"> 元可用）优惠券 <input type="text" id="Ac_3_'+i+'" size="3" value="'+cfg.Ac[i-1][3]+'" onblur="num();"> 张，有效期 <input type="text" id="Ac_4_'+i+'" size="3" value="'+cfg.Ac[i-1][4]+'" onblur="num();"> 天或至 <input type="text" id="Ac_5_'+i+'" size="9" value="'+cfg.Ac[i-1][5]+'" placeholder="yyyy-mm-dd"> 日　<a href="javascript:void(0);" onclick="ccd('+(i-1)+');">删除</a><br>';}Fcl.innerHTML=s;fio('Fc',1,1);}
//删除优惠
function ccd(n){cfm('确认删除？',function(){cfg.Av.splice(n,1);mhb();});}
//保存优惠
function ccv(){var s=[];for(var i=0;i<cfg.Ac.length+1;i++){if($('Ac_0_'+i).value*1>0&&$('Ac_1_'+i).value*1>0&&$('Ac_3_'+i).value*1>0)s.push([$('Ac_0_'+i).value*1,$('Ac_1_'+i).value*1,$('Ac_2_'+i).value*1,$('Ac_3_'+i).value*1,$('Ac_4_'+i).value*1,$('Ac_5_'+i).value]);}s.sort(function(x,y){return y[0]-x[0];});var p=jsn('ccv');p.Ac=s;xml(uri,p,function(r){alt('优惠设置保存成功！');cfg.Ac=s;fio('Fc',-1,1);Ac_0_0.value=0;});}
//显示插件
function cgs(){Ag_Wa.value=cfg.Ag.Wa;Ag_Wk.value=cfg.Ag.Wk;Ag_W1.value=cfg.Ag.W1;Ag_W2.value=cfg.Ag.W2;Ag_Bi.value=cfg.Ag.Bi;Ag_Bk.value=cfg.Ag.Bk;Ag_Ac.value=cfg.Ag.Ac;Ag_At.value=cfg.Ag.At;fio('Fg',1,1);}
//保存插件
function cgv(){var p=jsn('cgv');p.Ag={Wa:Ag_Wa.value,Wk:Ag_Wk.value,W1:Ag_W1.value,W2:Ag_W2.value,Bi:Ag_Bi.value,Bk:Ag_Bk.value,Ac:Ag_Ac.value,At:Ag_At.value};xml(uri,p,function(r){alt('接口设置保存成功！');cfg.Ag=p.Ag;fio('Fg',-1,1);});}
//显示支付
function cps(){if(cfg.AL=='')Fpu.innerText='解除限额';$$('Ap_Fs')[cfg.Ap.Fs].click();Ap_Gi.value=cfg.Ap.Gi;Ap_Gk.value=cfg.Ap.Gk;Ap_Wc.value=cfg.Ap.Wc;Ap_Wi.value=cfg.Ap.Wi;Ap_Wk.value=cfg.Ap.Wk;Ap_Zp.value=cfg.Ap.Zp;Ap_Zk.value=cfg.Ap.Zk;Ap_Zi.value=cfg.Ap.Zi;Ap_Zm.value=cfg.Ap.Zm;Ap_Zn.value=cfg.Ap.Zn;fio('Fp',1,1);}
//保存支付
function cpv(){var s={Fs:$$('Ap_Fs')[0].checked?0:1,Gi:Ap_Gi.value,Gk:Ap_Gk.value,Wc:Ap_Wc.value,Wi:Ap_Wi.value,Wk:Ap_Wk.value,Zp:Ap_Zp.value,Zk:Ap_Zk.value,Zi:Ap_Zi.value,Zm:Ap_Zm.value,Zn:Ap_Zn.value};var p=jsn('cpv');p.Ap=s;xml(uri,p,function(r){alt('支付配置保存成功！');cfg.Ap=p.Ap;fio('Fp',-1,'Fv');});}
//证书格式
function cpn(n){var m=['-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----','-----BEGIN RSA PRIVATE KEY-----','-----END RSA PRIVATE KEY-----'];var o=event.srcElement;var s=o.value;for(i=0;i<4;i++)s=s.replace(m[i],'');s=s.replace(/\s/gi,'');var c=m[n*2]+'\n';for(i=0;i<Math.ceil(s.length/64);i++)c+=s.substr(i*64,64)+'\n';c+=m[n*2+1]+'\n';o.value=c;}
//支付升级
function cpu(){var p=jsn('cpu');p.AL=AL.value;xml(uri,p,function(r){alt('升级官方支付接口成功！');location.reload();});}
//分店列表
function shl(){Ds.innerHTML='Loading...';var p=jsn('shl');xml(uri,p,function(r){dat=r.lst;var c=r.cnt;var b=r.s1==0?0:r.s0/r.s1;Sfc.innerText=r.s0/100;Sfr.innerText=r.s1/100;var s='';for(var i=0;i<dat.length;i++){s+='<div class="ls0"><div class="ls1">'+dat[i].Si+'</div><div class="ls2"><a href="javascript:void(0);" onclick="she('+i+');">'+dat[i].Sn+'</a>'+(cfg.Ai==dat[i].Si*1?'[主店]':'')+(dat[i].Sh*1==0?'':'[H]')+'</div><div class="ls3">'+dat[i].Sa+'，'+dat[i].Sb+'</div><div class="ls1">'+(c[i][0]*1-c[i][1]*1)+'</div><div class="ls1">'+c[i][1]+'</div><div class="ls1">'+c[i][2]+'</div><div class="ls1">'+c[i][3]+'</div><div class="ls1">'+(dat[i].Se/100)+'</div><div class="ls1" id="Se_'+dat[i][1]+'">'+(Math.round((c[i][4]*b-dat[i].Se/100)*100)/100)+'</div></div>';}Ds.innerHTML=s;});}
//分店编辑
function she(n){var s=n<0?{ID:0,Si:'',Sn:'',Sw:'',Sa:'',Sb:'',Sx:0,Sy:0,Sh:0}:dat[n];SS.value=s.ID;Si.value=s.Si;Sn.value=s.Sn;Sw.value=s.Sw;Sa.value=s.Sa;Sb.value=s.Sb;Sh.checked=s.Sh*1==0?false:true;Sk.value='';Su.checked=false;Sv.style.display=n<0?'inline-block':'none';fio('Fs',1,1);setTimeout(function(){mx=s.Sx;my=s.Sy;smb();},300);}
//显示地图
function smb(){var s=document.createElement('script');s.src='https://api.map.baidu.com/api?v=2.0&ak=p7qaGmr37q4uCgiBShG0tOsI&s=1&callback=smp';s.type='text/javascript';document.body.appendChild(s);}
function smp(){var map=new BMap.Map('map');map.enableScrollWheelZoom();if(mx&&my){map.centerAndZoom(new BMap.Point(mx,my),16);var mkr=new BMap.Marker(new BMap.Point(mx,my));map.addOverlay(mkr);}else{smg();return;}map.addEventListener("click",clk);function clk(e){map.clearOverlays();mx=e.point.lng;my=e.point.lat;var mkr=new BMap.Marker(new BMap.Point(e.point.lng,e.point.lat));map.addOverlay(mkr);}}
function smg(){var geo=new BMap.Geolocation();geo.getCurrentPosition(function(r){if(this.getStatus()==BMAP_STATUS_SUCCESS){mx=r.point.lng;my=r.point.lat;smp();}else{mx=116.4;my=39.9;smp();}});}
//微信绑定
function shw(o){var r=rnd(8);Foi.innerHTML='<img src="qrcode.php?u='+encodeURI(cfg.Aw)+'openid%2Ephp%3Fx%3Dr%26r%3D'+r+'" width="231" height="231"><br>微信扫描二维码获取OpenID';fio('Fo',1);tid=setTimeout('shb(\''+r+'\',\''+o+'\')',3000);}
//绑定检测
function shb(s,o){xml(url+'openid.php?x=c&r='+s+'&'+rnd(),null,function(r){if(r.woi!=''){$(o).value=r.woi;alt('获取OpenID成功！');fio('Fo',-1);}else tid=setTimeout('shb(\''+s+'\',\''+o+'\')',3000);});}
//分店保存
function shv(n){var p=jsn('shv');p.ID=SS.value;p.Si=Si.value;p.Sn=Sn.value;p.Sw=Sw.value;p.Sa=Sa.value;p.Sb=Sb.value;p.Sx=mx;p.Sy=my;p.Sk=Sk.value;p.Sh=Sh.checked?1:0;p.Su=Su.checked?1:0;if(p.Si==''||p.Sn==''||p.Sa==''||p.Sb==''){alt('店铺资料填写不全！');return;}xml(uri,p,function(r){alt('分店保存成功！');fio('Fs',-1,1);shl();});}
//设置主店
function shc(){var p=jsn('shc');p.Ai=Si.value*1;xml(uri,p,function(r){alt('设置主店成功！');fio('Fs',-1,1);cfg.Ai=p.Ai;shl();});}
//分店删除
function shd(){cfm('确认删除？',function(){var p=jsn('shd');p.Si=Si.value;xml(uri,p,function(r){fio('Fs',-1,1);shl();});});}
//分账完成
function shx(){cfm('分店分账数据统计至当日0点！\n确定完成分账？',function(){var p=jsn('shx');var s=[];for(var i=0;i<dat.length;i++)s.push([dat[i][1],$('Se_'+dat[i][1]).innerText*100]);p.Se=s;xml(uri,p,function(r){alt('分店分账完成！');shl();});});}
//支付列表
function odl(n){Do.innerHTML='Loading...';var p=jsn('odl');p.Os=Os.value;p.Pg=n||1;xml(uri,p,function(r){dat=r.lst;var s='';var t;for(var i=0;i<dat.length;i++){t=dat[i];s+='<div class="ls0"><div class="ls3">'+t.Mc+'</div><div class="ls1">'+(t.Mp/100)+'</div><div class="ls2">'+t.Md+'</div><div class="ls1">'+['Alipay','Weixin'][t.Mt]+'</div><div class="ls1">'+(t.Np/100)+'</div><div class="ls2">'+t.Nd+'</div><div class="ls9"><a href="javascr'+'ipt:void(0);" onclick="alt(\''+t.Nc+'\');">View</a></div><div class="ls1">'+['未支付','已支付'][t.Nt]+'</div><div class="ls9"><a href="javascr'+'ipt:void(0);" onclick="odd('+t.ID+','+n+');">删除</a></div></div>';}Do.innerHTML=s+pgs(n,r.Pt,'odl({{id}});');});}
//支付删除
function odd(n,m){cfm('确认删除？\n只能删除下单超过2小时的未支付订单！',function(){var p=jsn('odd');p.ID=n;xml(uri,p,function(r){odl(m);});});}
//报表列表
function rpl(){Dr.innerHTML='Loading...';var p=jsn('rpl');p.Ri=Ri.value;p.R1=R1.value;p.R2=R2.value;xml(uri,p,function(r){dat=r.lst;var s='';var c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];var t;for(var i=0;i<dat.length;i++){t=dat[i][3].split('|');s+='<div class="ls0"><div class="ls1">'+dat[i][1]+'</div><div class="ls1">'+dat[i][2]+'</div><div class="ls1">'+t[0]+'</div><div class="ls1">'+t[4]+'</div><div class="ls1">'+t[5]+'</div><div class="ls1">'+t[6]+'</div><div class="ls1">'+t[7]+'</div><div class="ls1">'+t[8]+'</div><div class="ls1">'+t[9]+'</div><div class="ls1">'+t[10]+'</div><div class="ls1">'+t[11]+'/'+t[12]+'</div><div class="ls1">'+t[1]+'/'+t[2]+'/'+t[3]+'</div></div>';for(var j=0;j<15;j++){c[j]+=t[j]*1;c[j]=Math.round(c[j]*100)/100;}}Dr.innerHTML=s+'<div class="ls0"><div class="ls1">合计</div><div class="ls1">&nbsp;</div><div class="ls1">'+c[0]+'</div><div class="ls1">'+c[4]+'</div><div class="ls1">'+c[5]+'</div><div class="ls1">'+c[6]+'</div><div class="ls1">'+c[7]+'</div><div class="ls1">'+c[8]+'</div><div class="ls1">'+c[9]+'</div><div class="ls1">'+c[10]+'</div><div class="ls1">'+c[11]+'/'+c[12]+'</div><div class="ls1">'+c[1]+'/'+c[2]+'/'+c[3]+'</div></div>';});}
//会员列表
function mbl(n){Du.innerHTML='Loading...';var p=jsn('mbl');p.U0=U0.value;p.Pg=n||1;xml(uri,p,function(r){dat=r.lst;U1.innerText=r.U1/100;U2.innerText=r.U2/100;var s='';var t;for(var i=0;i<dat.length;i++){t=dat[i];s+='<div class="ls0"><div class="ls2"><a href="javascr'+'ipt:void(0);" onclick="mbe('+i+');">'+t.Uc+'</a></div><div class="ls2">'+t.Un+'</div><div class="ls2">'+t.Ud+'</div><div class="ls1">'+(t.Us/100)+'</div><div class="ls1">'+(t.Ux/100)+'</div><div class="ls1">'+(t.Ue/100)+'</div><div class="ls2">'+t.Ut+'</div><div class="ls1"><a href="javascript:void(0);" onclick="mbd('+t.ID+');">删除</a></div></div>';}Du.innerHTML=s+pgs(n,r.Pt,'mbl({{id}});');});}
//会员信息
function mbe(n){var s=n<0?{ID:0,Uc:'',Un:'',Up:'',Ue:0,Uf:''}:dat[n];Ui.value=s.ID;Uc.value=s.Uc;Un.value=s.Un;Up.value=s.Up;Ue.value=s.Ue/100;Uf.value=s.Uf;fio('Fu',1,1);}
//会员保存
function mbv(){var p=jsn('mbv');p.ID=Ui.value;p.Uc=Uc.value;p.Un=Un.value;p.Up=Up.value;p.Ue=Ue.value*100;p.Uf=Uf.value;if(p.Uc==''||p.Un==''||p.Up==''){alt('信息不全！');return;}xml(uri,p,function(r){alt('会员保存成功！');fio('Fu',-1,1);mbl();});}
//会员删除
function mbd(n){cfm('确认删除？\n已充值及消费的会员不能删除！',function(){var p=jsn('mbd');p.ID=n;xml(uri,p,function(r){alt('会员删除成功！');mbl();});});}
//会员券表
function mcl(n){Cu.innerText=Uc.value;var p=jsn('mcl');p.Cu=Cu.innerText;xml(uri,p,function(r){var s='';for(var i=0;i<r.lst.length;i++)s+='<span style="'+(r.lst[i].Co*1==0?'':'color:#CCC;text-decoration:line-through;')+'">'+(i+1)+'、 '+(r.lst[i].Cm/100)+'元 [满'+(r.lst[i].Cn/100)+'元可用，有效期至：'+r.lst[i].Cd+'] 单号：'+r.lst[i].Co+'</span><br>';Cl.innerHTML=s;if(n)fio('Fr',1);});}
//会员发券
function mcu(){if(Ui.value*1==0||Cm.value*1==0)return;var p=jsn('mcu');p.Cu=Cu.innerText;p.Cm=Cm.value*100;p.Cn=Cn.value*100;p.Cd=Cd.value;xml(uri,p,function(r){mcl();});}
//全体发券
function mcv(){if(Xm.value*1==0)return;var p=jsn('mcv');p.Xu=Xu.value;p.Xm=Xm.value*100;p.Xn=Xn.value*100;p.Xd=Xd.value;xml(uri,p,function(r){alt('发放优惠券成功！');fio('Fx',-1,1);});}
//消费列表
function xfl(n){Dx.innerHTML='Loading...';var p=jsn('xfl');p.Gc=Gc.value;p.Pg=n||1;xml(uri,p,function(r){var s='';for(var i=0;i<r.lst.length;i++)s+='<div class="ls0"><div class="ls2">'+r.lst[i].Gc+'</div><div class="ls3">'+r.lst[i].Gu+'</div><div class="ls1">'+r.lst[i].Go+'</div><div class="ls1">'+(r.lst[i].Gm/100)+'</div><div class="ls1">'+(r.lst[i].Gn/100)+'</div><div class="ls3">'+r.lst[i].Gd+'</div><div class="ls1">'+r.lst[i].Ge+'</div></div>';Dx.innerHTML=s+pgs(n,r.Pt,'xfl({{id}});');});}
</script>
</head>
<body onLoad="rsz();fio('Dl',1,1);">
<div id="msk"></div><div id="cfn"></div><div id="tip"></div>
<div id="Dl" class="fld" style="z-index:88;">
  <div class="flt"><?php echo $cfg["An"];?> - 分店管理</div>
  <div class="flb" style="text-align:center;">
    密码：<input type="password" id="Ak" value="" onKeyDown="if(event.keyCode==13)lgn();"><br>
    <span class="btn" onClick="lgn();">登录</span><br>
    &copy; 2018 - 2020 All Rights Reserved.
  </div>
</div>
<div style="height:60px;background-color:#333;margin-bottom:10px;">
  <div style="width:1200px;margin:auto;">
    <div style="float:left;font-size:24px;color:#6CF;line-height:60px;"><?php echo $cfg["An"];?> - 分店管理</div>
    <div style="float:right;">
      <span id="Nv0" class="nv0" onClick="nvl(0);">分店</span>
      <span id="Nv1" class="nv0" onClick="nvl(1);">支付</span>
      <span id="Nv2" class="nv0" onClick="nvl(2);">报表</span>
      <span id="Nv3" class="nv0" onClick="nvl(3);">会员</span>
      <span id="Nv4" class="nv0" onClick="nvl(4);">消费</span>
      <span class="nv0" onMouseMove="this.className='nv1';" onMouseOut="this.className='nv0';" onClick="cfm('确认退出？',function(){location.reload();});">退出</span>
    </div>
  </div>
</div>
<div id="Dv0" style="width:1200px;margin:auto;display:none;">
  <div style="border-bottom:1px solid #CCC;line-height:36px;"><div style="float:right;">充值实收：<span id="Sfc"></span> 元 充值入账：<span id="Sfr"></span> 元 <span class="bn0" onClick="shx();">完成分账</span></div><span class="bn1" onClick="she(-1);">新增分店</span></div>
  <div class="ls0">
    <div class="ls1">分店ID</div>
    <div class="ls2">分店名称</div>
    <div class="ls3">地址电话</div>
    <div class="ls1">店内充值</div>
    <div class="ls1">自助充值</div>
    <div class="ls1">会员入账</div>
    <div class="ls1">会员消费</div>
    <div class="ls1">历史分账</div>
    <div class="ls1">本期分账</div>
  </div>
  <div id="Ds"></div>
  <div style="font-size:12px;">分店分账结算说明：店内充值指顾客在该店内现金或刷卡充值的实际金额，改金额由该分店实收。自助充值指顾客通过微信公众号自助充值的金额，该金额将计入主店账户下。会员入账指会员卡入账金额，如您店有充1000送200之类的活动的话，会员实际入账金额是与充值实付金额是不同的。会员消费指顾客在该店内的消费金额。分账结算是指如某顾客在A店充值后到B店消费，您需要在A、B店之间平衡账目；本期分账金额计算公式为：当前分店的历史会员消费总额*(所有会员充值的实际金额/所有会员入账的账面金额)-当前分店已分账的会员消费金额；分账数据统计至当日0时，不包含当日数据。</div>
</div>
<div id="Dv1" style="width:1200px;margin:auto;display:none;">
  <div style="border-bottom:1px solid #CCC;line-height:36px;">搜索订单： <input type="text" id="Os" size="16"><span class="bn0" onClick="odl();">查询</span></div>
  <div class="ls0">
    <div class="ls3">订单编号</div>
    <div class="ls1">应付金额</div>
    <div class="ls2">下单时间</div>
    <div class="ls1">支付方式</div>
    <div class="ls1">实付金额</div>
    <div class="ls2">支付时间</div>
    <div class="ls9">交易单</div>
    <div class="ls1">状态</div>
    <div class="ls9">删除</div>
  </div>
  <div id="Do"></div>
</div>
<div id="Dv2" style="width:1200px;margin:auto;display:none;">
  <div style="border-bottom:1px solid #CCC;line-height:36px;">分店ID： <input type="text" id="Ri" size="8"> 日期：<input type="date" id="R1" size="10"> - <input type="date" id="R2" size="10"> <a href="javascript:void(0);" onClick="R1.value=rd;R2.value=rd;rpl();">今天</a> <a href="javascript:void(0);" onClick="R1.value=rm;R2.value=rd;rpl();">本月</a><span class="bn0" onClick="rpl();">查询</span></div>
  <div class="ls0">
    <div class="ls1">分店ID</div>
    <div class="ls1">日期</div>
    <div class="ls1">营业额</div>
    <div class="ls1">现金</div>
    <div class="ls1">刷卡</div>
    <div class="ls1">微信</div>
    <div class="ls1">支付宝</div>
    <div class="ls1">会员卡</div>
    <div class="ls1">团购券</div>
    <div class="ls1">优惠券</div>
    <div class="ls1">充值/自充</div>
    <div class="ls1">单/菜/退</div>
  </div>
  <div id="Dr"></div>
</div>
<div id="Dv3" style="width:1200px;margin:auto;display:none;">
  <div style="border-bottom:1px solid #CCC;line-height:36px;"><div style="float:right;"><span class="bn1" onClick="mbe(-1);">新增</span><span class="bn1" onClick="fio('Fx',1,1);">发券</span></div>搜索会员： <input type="text" id="U0" size="16"><span class="bn0" onClick="mbl();">查询</span>　　　　顾客储金总额： <span id="U1"></span> 元　顾客欠款总额： <span id="U2"></span> 元</div>
  <div class="ls0">
    <div class="ls2">会员卡号</div>
    <div class="ls2">会员名称</div>
    <div class="ls2">注册时间</div>
    <div class="ls1">当前余额</div>
    <div class="ls1">消费金额</div>
    <div class="ls1">信用额度</div>
    <div class="ls2">消费时间</div>
    <div class="ls1">删除</div>
  </div>
  <div id="Du"></div>
</div>
<div id="Dv4" style="width:1200px;margin:auto;display:none;">
  <div style="border-bottom:1px solid #CCC;line-height:36px;">搜索会员： <input type="text" id="Gc" size="16"><span class="bn0" onClick="xfl();">查询</span></div>
  <div class="ls0">
    <div class="ls2">会员卡号</div>
    <div class="ls3">店铺员工</div>
    <div class="ls1">点单编号</div>
    <div class="ls1">充值金额</div>
    <div class="ls1">消费金额</div>
    <div class="ls3">消费时间</div>
    <div class="ls1">是否分账</div>
  </div>
  <div id="Dx"></div>
  <div style="font-size:12px;">店铺员工参数：形式AAAA-BB-CCCCCC，AAAA为店铺ID；BB为员工ID，等于0为顾客自助操作，等于Cxxxx为顾客自助充值，xxxx为顾客手机号；CCCCCC为随机字符。点单编号为对应的点单，等于0为充值操作。消费金额为正表示充值，为负表示消费。</div>
</div>
<div id="Fo" class="fld" style="z-index:39;">
  <div class="flt"><div class="bnc" onClick="fio('Fo',-1);clearTimeout(tid);">×</div>绑定微信</div>
  <div class="flb" id="Foi" style="text-align:center;line-height:24px;"></div>
</div>

<!--会员发券层-->
<div id="Fx" class="fld" style="z-index:20;">
  <div class="flt"><div class="bnc" onClick="fio('Fx',-1,1);">×</div>发放优惠券</div>
  <div class="flb">选择会员： <input type="radio" name="Xu" checked="checked" onClick="Xu.value='';Xu.disabled=true;"> 全部会员 <input type="radio" name="Xu" onClick="Xu.disabled=false;"> 指定会员（每个会员卡号间“，”分隔）<br>
    指定会员： <textarea id="Xu" style="width:400px;height:180px;vertical-align:top;" disabled="disabled" onBlur="this.value=this.value.replace(/，/gi,',');"></textarea><br>
    金　　额： <input type="text" id="Xm" size="3" value="0" onBlur="num(2);"> 满 <input type="text" id="Xn" size="3" value="0" onBlur="num(2);"> 元可用 有效期至： <input type="text" id="Xd" size="9" placeholder="yyyy-mm-dd"> <span class="btn" onClick="mcv();">发券</span></div>
</div>
<!--会员红包层-->
<div id="Fr" class="fld" style="z-index:23;">
  <div class="flt"><div class="bnc" onClick="fio('Fr',-1);">×</div>会员优惠券[卡号：<span id="Cu"></span>]</div>
  <div class="flb" id="Cl" style="width:420px;height:200px;line-height:30px;overflow:auto;"></div>
  <div class="flb" style="width:400px;"><input type="text" id="Cm" size="3" onBlur="num(2);" value="0"> 元 满 <input type="text" id="Cn" size="3" onBlur="num(2);" value="0"> 元可用 至 <input type="text" id="Cd" size="9" placeholder="yyyy-mm-dd">　<span class="btn" onClick="mcu();">发券</span></div>
</div>
<!--会员资料层-->
<div id="Fu" class="fld" style="z-index:22;">
  <div class="flt"><div class="bnc" onClick="fio('Fu',-1,1);">×</div>会员资料</div>
  <div class="flb">会员卡号： <input type="text" id="Uc"><br>会员名称： <input type="text" id="Un"><br>登录密码： <input type="text" id="Up"> <a href="javascript:void(0);" onClick="Up.value=rnd(6);">Rnd</a><br>信用额度： <input type="text" id="Ue" size="4" onBlur="num(2);"> 元<br>身份资料： <textarea id="Uf" style="width:200px;height:40px; vertical-align:top;" onBlur="this.value=this.value.replace(/\s/gi,'');"></textarea><br>　　　　　 <span class="btn" onClick="mbv();">保存</span>　<span class="btn" onClick="mcl(1);">优惠券</span><input type="hidden" id="Ui"></div>
</div>
<div id="Fs" class="fld" style="z-index:21;">
  <div class="flt"><div class="bnc" onClick="fio('Fs',-1,'Fo');">×</div>分店信息 <span style="font-size:12px;">[请在地图上标记分店所在的位置]</span></div>
  <div class="flb"><input type="hidden" id="SS">
    分店ＩＤ： <input type="text" id="Si" style="width:98px;" onBlur="num();if(this.value*1<1000)this.value=1000;if(this.value*1>9999)this.value=9999;">　分店名称： <input type="text" id="Sn">　<a href="javascript:void(0);" onClick="shw('Sw');">店长微信</a>： <input type="text" id="Sw"><br>
    分店地址： <input type="text" id="Sa" size="45">　分店电话： <input type="text" id="Sb">
    <div id="map" style="border:1px solid #CCC;width:798px;height:400px;"></div>
    超管：admin　密码： <input type="text" id="Sk" size="22" placeholder="不修改请留空，默认123456">　<input type="checkbox" id="Sh"> 暂停营业　<a href="javascript:void(0);" onClick="shc();">设置主店</a>　<span class="btn" onClick="shv();">保 存</span>　<a href="javascript:void(0);" onClick="shd();">删除</a><span id="Sv" style="display:none;">　<input type="checkbox" id="Su"> 导入示范数据</span>
  </div>
</div>
<div id="Fv" class="fld" style="z-index:17;">
  <div class="flt"><div class="bnc" onClick="fio('Fv',-1);clearTimeout(tid);">×</div>解除官方接口限额</div>
  <div class="flb">提示：未授权版本官方支付接口仅供测试使用，<br>所有订单的实际支付金额将被强制修改为1分钱！<br>解除限额需获取授权码后开通，请[<a href="https://www.pays.top/app/shouquanma/index.html?p=Jir" target="_blank">购买授权码</a>]<br>授权码： <input type="text" id="AL"> <span class="btn" onClick="cpu();">确定</span></div>
  </div>
</div>
<div id="Fp" class="fld" style="width:640px;height:360px;z-index:16;">
  <div class="flt"><div class="bnc" onClick="fio('Fp',-1,'Fv');clearTimeout(tid);">×</div>支付接口设置</div>
  <div class="flb">
    接入方式： <input type="radio" name="Ap_Fs" onClick="Fp1.style.display='none';Fp0.style.display='block';" checked> 免签支付　　<input type="radio" name="Ap_Fs" onClick="Fp0.style.display='none';Fp1.style.display='block';"> 官方支付
    　　<span class="btn" onClick="cpv();">保 存</span>　　<a href="http://software.bbxdn.com/Help/Jir.htm#pay" target="_blank">说明文档</a><br>
    <div id="Fp0" style="display:none;">免签支付：　　<a href="https://www.pays.top/app/mch.php#reg" target="_blank">注册账户</a>　<a href="https://www.pays.top/app/#app" target="_blank">下载监控App</a>(Android)<br>
      <input type="text" id="Ap_Gi" style="width:250px;" placeholder="云端支付Uid">　　<input type="text" id="Ap_Gk" style="width:250px;" placeholder="云端支付Key"><br>
      系统已集成<a href="https://www.pays.top/app/" target="_blank">云端免签支付</a>工具，使用个人收款码即可实现即时到账回调接口，交易低至0费率！！<br>
      请[<a href="https://www.pays.top/app/mch.php#reg" target="_blank">注册账户</a>]后上传收款码，然后下载安装设置[<a href="https://www.pays.top/app/#app" target="_blank">App工具</a>]，然后此处填写Uid和Key即可使用。
    </div>
    <div id="Fp1" style="display:none;">官方支付： 请确认您已开通<a href="http://software.bbxdn.com/Help/Jwz.htm" target="_blank">微信/支付宝</a>商户接口并获得相关参数！ <a id="Fpu" href="javascript:void(0);" onClick="fio('Fv',1);"></a><br>
      <input type="text" id="Ap_Zp" style="width:250px;" placeholder="支付宝合作商户pid">　　<input type="text" id="Ap_Wc" style="width:250px;" placeholder="微信公众号appid"><br>
      <input type="text" id="Ap_Zk" style="width:250px;" placeholder="支付宝合作商户key">　　<input type="text" id="Ap_Wi" style="width:250px;" placeholder="微信支付商户mch_id"><br>
      <input type="text" id="Ap_Zi" style="width:250px;" placeholder="支付宝开放平台appid">　　<input type="text" id="Ap_Wk" style="width:250px;" placeholder="微信支付商户key"><br>
      <textarea id="Ap_Zm" style="width:252px;height:100px;" placeholder="支付宝公钥，开放平台获得" onBlur="cpn(0);"></textarea>　　<textarea id="Ap_Zn" style="width:252px;height:100px;" placeholder="支付宝私钥，签名工具生成" onBlur="cpn(1);"></textarea>
    </div>
  </div>
</div>
<div id="Fg" class="fld" style="z-index:15;">
  <div class="flt"><div class="bnc" onClick="fio('Fg',-1,1);">×</div>功能接口设置</div>
  <div class="flb">
    <a href="https://mp.weixin.qq.com" target="_blank">微信公众号</a>： 用于发消息到员工微信（可选）<br>
    若使用官方支付接口则必填，且Appid应与支付配置中相同！<br>
    <input type="text" id="Ag_Wa" placeholder="微信公众号AppId">　　<input type="text" id="Ag_Wk" placeholder="微信公众号AppSecret"><br>
    <input type="text" id="Ag_W1" placeholder="外卖通知，模板库编号：OPENTM200833793" style="width:374px;"><br>
    <input type="text" id="Ag_W2" placeholder="厨房通知，模板库编号：OPENTM406274506" style="width:374px;"><br>
    <a href="https://ai.baidu.com" target="_blank">百度语音</a>　： 用于排号取餐语音叫号（可选）<br>
    <input type="text" id="Ag_Bi" placeholder="百度语音合成ApiKey">　　<input type="text" id="Ag_Bk" placeholder="百度语音合成SecretKey"><br>
    <a href="https://market.aliyun.com/products/57126001/cmapi030182.html" target="_blank">阿里云短信</a>： 用于会员注册取回密码（可选）<br>
    <input type="text" id="Ag_Ac" placeholder="阿里云市场AppCode">　　<input type="text" id="Ag_At" placeholder="验证码短信模板【签名】">
    <div style="text-align:center;"><span class="btn" onClick="cgv();">保 存</span></div>
  </div>
</div>
<div id="Fc" class="fld" style="z-index:14;">
  <div class="flt"><div class="bnc" onClick="fio('Fc',-1,1);">×</div>会员优惠设置</div>
  <div class="flb">+ 消费满 <input type="text" id="Ac_0_0" size="3" value="0" onBlur="num(2);"> 元送 <input type="text" id="Ac_1_0" size="3" value="0" onBlur="num(2);"> 元（满 <input type="text" id="Ac_2_0" size="3" value="0" onBlur="num(2);"> 元可用）优惠券 <input type="text" id="Ac_3_0" size="3" value="1" onBlur="num();"> 张，有效期 <input type="text" id="Ac_4_0" size="3" value="7" onBlur="num();"> 天或至 <input type="text" id="Ac_5_0" size="9" placeholder="yyyy-mm-dd"> 日　<span class="btn" onClick="ccv();">保存</span>
    <div id="Fcl"></div>
  </div>
</div>
<div id="Fb" class="fld" style="z-index:13;">
  <div class="flt"><div class="bnc" onClick="fio('Fb',-1,1);">×</div>会员充值设置</div>
  <div class="flb">首次充值送 <input type="text" id="Ab" size="4" onBlur="num(2);"> 元　<span class="btn" onClick="cbv();">保 存</span>
    <div id="Fbl"></div>
  </div>
</div>
<div id="Fa" class="fld" style="z-index:12;">
  <div class="flt"><div class="bnc" onClick="fio('Fa',-1,1);">×</div>修改超管密码</div>
  <div class="flb">　原密码： <input type="password" id="Ao"><br>　新密码： <input type="password" id="Ap"><br>验证密码： <input type="password" id="Av"><br>　　　　　 <span class="btn" onClick="cav();">保 存</span></div>
</div>
<div id="Fw" class="fld" style="z-index:11;">
  <div class="flt"><div class="bnc" onClick="fio('Fw',-1,1);">×</div>网站设置</div>
  <div class="flb">网站名称： <input type="text" id="An" size="30"><br>网站地址： <input type="text" id="Aw" size="30"><br>　　　　　 <span class="btn" onClick="cwv();">保存</span></div>
</div>
<div style="width:1200px;border-top:1px solid #CCC;margin:10px auto;line-height:32px;text-align:center;"><div style="float:left;">&copy; 2018 - 2020 All Rights Reserved Ver:<?php echo $ver;?>　<span id="nvs"></span></div><div style="float:right;"><span class="bn0" onClick="An.value=cfg.An;Aw.value=cfg.Aw;fio('Fw',1,1);">网站设置</span><span class="bn0" onClick="Ao.value='';Ap.value='';Av.value='';fio('Fa',1,1);">修改密码</span><span class="bn0" onClick="cbs();">充值设置</span><span class="bn0" onClick="ccs();">优惠设置</span><span class="bn0" onClick="cgs();">功能接口</span><span class="bn0" onClick="cps();">支付配置</span></div></div>
<script type="text/javascript" src="http://software.bbxdn.com/?x=Jir&v=<?php echo $ver;?>"></script>
</body>
</html>
<?php
}
?>