<?php
//====== 餐厅设置 ======
require "common.php";
$m=file_get_contents("php://input");if($m==""||Req("act")=="index")$m='{"act":"idx"}';$m=Dec($m,true);
if($m["act"]!="idx"){
	$r=Qra(Qry("Select Ar,An From ".$pre."admin Where Ah=0 And ID=".$m["uid"]." And Si=".$m["nid"]." And Ak='".$m["sid"]."'"));
	if(!$r||$m["sid"]=="")die('{"msg":"连接超时，请重登录！"}');
	if(strpos($r["Ar"],"A")===false&&strpos($r["Ar"],"B")===false&&strpos($r["Ar"],"F")===false)die('{"msg":"无此权限！"}');
	$nid=$m["nid"];$uid=$m["uid"];$rid=$r["Ar"];$unm=$r["An"];
}
switch($m["act"]){
	case "cfg"://设置读取
	$p=["msg"=>"ok"];
	$r=Qra(Qry("Select Sn,Sc From ".$pre."shop Where Si=".$nid));
	$p["Sc"]=Dec($r["Sc"]);$p["Sn"]=$r["Sn"];$p["An"]=$unm;$p["Ar"]=$rid;$p["vid"]=md5($m["sid"]);
	echo Enc($p);
	break;

	case "snd"://语音合成
	echo Snd($m["Sv"]);
	break;

	case "npv"://排队新增
	$f=Dec(file_get_contents("images/".$nid."/d.txt"));
	if(date("Y-m-d")>date("Y-m-d H:i:s",strtotime($f["sj"]))){$f["si"]=1;$f["sj"]=date("Y-m-d H:i:s");}else $f["si"]+=1;
	$f["ph"][]=[$f["si"],$m["Ps"],date("Y-m-d H:i:s"),$m["Pr"]];
	file_put_contents("images/".$nid."/d.txt",Enc($f));
	echo '{"msg":"ok"}';
	break;

	case "npc"://排队删除
	$f=Dec(file_get_contents("images/".$nid."/d.txt"));
	if($m["Pr"]*1!=-1){array_splice($f["ph"],$m["Pr"],1);}else $f["ph"]=[];
	file_put_contents("images/".$nid."/d.txt",Enc($f));
	echo '{"msg":"ok"}';
	break;

	case "nyv"://预定增加
	$f=Dec(file_get_contents("images/".$nid."/d.txt"));
	$f["yd"][]=[$m["gk"],$m["dh"],$m["rs"],$m["sj"],$m["cz"]];	
	file_put_contents("images/".$nid."/d.txt",Enc($f));
	echo '{"msg":"ok"}';
	break;

	case "nyc"://预定删除
	$f=Dec(file_get_contents("images/".$nid."/d.txt"));
	if($m["Pr"]*1!=-1){array_splice($f["yd"],$m["Pr"],1);}else $f["yd"]=[];
	file_put_contents("images/".$nid."/d.txt",Enc($f));
	echo '{"msg":"ok"}';
	break;

	case "nul"://会员列表
	$a=$m["Uc"];if($a!="")$a=" And (Uc Like '%".$a."%' Or Un Like '%".$a."%')";
	$p=["msg"=>"ok","Mu"=>[]];
	$q=Qry("Select ID,Uc,Un,Up,Ud,Us,Ux,Ut,Ue From ".$pre."user Where ID>0".$a." Order By ID Desc Limit 50");
	while($r=Qra($q))$p["Mu"][]=$r;
	echo Enc($p);
	break;

	case "nuv"://会员保存
	if($m["ID"]*1==0){
		if(Qrc(Qry("Select ID From ".$pre."user Where Uc='".$m["Uc"]."'"))==0){
			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(),0,'')");
		}else die('{"msg":"手机号已存在！"}');
	}else{
		$c=Qrs(Qry("Select Up From ".$pre."user Where ID=".$m["ID"]));
		Qry("Update ".$pre."user Set Un='".$m["Un"]."',Up='".($c==$m["Up"]?md5($m["Up"]):$c)."' Where ID=".$m["ID"]);
	}
	echo '{"msg":"ok"}';
	break;

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

	case "nuc"://会员充值
	Qry("Insert Into ".$pre."expend (Si,Gc,Go,Gu,Gm,Gn,Gd,Ge) Values (".$nid.",'".$m["Gc"]."',0,'".$m["Gu"]."',".$m["Gm"].",".$m["Gn"].",Now(),0)");
	echo '{"msg":"ok","ID":"'.Qri().'"}';
	Qry("Update ".$pre."user Set Us=Us+".$m["Gn"]." Where Uc='".$m["Gc"]."'");
	break;

	case "nct"://读取统计
	$a=date("Y-m-d",strtotime($m["C1"]));$b=date("Y-m-d",strtotime("+1 Day",strtotime($m["C2"])));
	$s=["msg"=>"ok"];
	$s["Pm"]=Qrs(Qry("Select Sum(Pm) From ".$pre."order Where Si=".$nid." And Ps>0 And Od>'".$a."' And Od<'".$b."'"))/100;//营业金额
	$s["Ps"]=Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$nid." And Ps>0 And Od>'".$a."' And Od<'".$b."'"))/100;//实收金额
	$s["Pd"]=Qrs(Qry("Select Sum(Pd) From ".$pre."order Where Si=".$nid." And Ps>0 And Od>'".$a."' And Od<'".$b."'"))/100;//优惠金额
	$s["Pc"]=Qrs(Qry("Select Sum(Pc) From ".$pre."order Where Si=".$nid." And Ps>0 And Od>'".$a."' And Od<'".$b."'"))/100;//抵扣金额
	$s["Mc"]=Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$nid." And Ps>0 And Pt=0 And Od>'".$a."' And Od<'".$b."'"))/100;//现金
	$s["Md"]=Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$nid." And Ps>0 And Pt=1 And Od>'".$a."' And Od<'".$b."'"))/100;//刷卡
	$s["Mw"]=Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$nid." And Ps>0 And Pt=2 And Od>'".$a."' And Od<'".$b."'"))/100;//微信
	$s["Mz"]=Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$nid." And Ps>0 And Pt=3 And Od>'".$a."' And Od<'".$b."'"))/100;//支付宝
	$s["Mm"]=Qrs(Qry("Select Sum(Ps) From ".$pre."order Where Si=".$nid." And Ps>0 And Pt=4 And Od>'".$a."' And Od<'".$b."'"))/100;//会员卡
	$s["Uc"]=Qrs(Qry("Select Sum(Gm) From ".$pre."expend Where Si=".$nid." And Go=0 And Gd>'".$a."' And Gd<'".$b."'"))/100;//会员充值
	$s["Co"]=Qrs(Qry("Select Count(ID) From ".$pre."order Where Si=".$nid." And Ps>0 And Od>'".$a."' And Od<'".$b."'"))*1;//点单数
	$s["Cd"]=Qrs(Qry("Select Count(ID) From ".$pre."ofood Where Si=".$nid." And Fr<2 And Fd>'".$a."' And Fd<'".$b."'"))*1;//点菜数
	$s["Cr"]=Qrs(Qry("Select Count(ID) From ".$pre."ofood Where Si=".$nid." And Fr=2 And Fd>'".$a."' And Fd<'".$b."'"))*1;//退菜数
	$s["Cm"]=Qrs(Qry("Select Sum(Fm) From ".$pre."ofood Where Si=".$nid." And Fr=2 And Fd>'".$a."' And Fd<'".$b."'"))/100;//退菜额
	echo Enc($s);
	break;

	case "lst"://餐桌读取
	$p=["msg"=>"ok","Mt"=>[],"Mk"=>[],"Kc"=>0,"Rt"=>date("Y-m-d H:i:s")];
	$q=Qry("Select ID,Tn,Tc,Tu,Ts,Ti,Tm From ".$pre."table Where Si=".$nid." And Th=0 Order By Tr Asc");
	while($r=Qra($q))$p["Mt"][]=$r;
	$q=Qry("Select ID,Ox,Pm,Os,Od From ".$pre."order Where Si=".$nid." And Ox>0 And Os<13 Order By ID Desc");
	while($r=Qra($q))$p["Mk"][]=$r;
	$p["Kc"]=Qrc(Qry("Select ID From ".$pre."stock Where Si=".$nid." And Ks<=Kw And Kh=0"));
	echo Enc($p);
	break;

	case "lsi"://点单读取
	$p=["msg"=>"ok","Mb"=>[],"Md"=>[]];$c=1;$d=0;
	$r=Qra(Qry("Select ID,Ot,O1,O4,Ox,Pm,Pd,Pc,Ps,Pt,Os,Od,Ob From ".$pre."order Where Si=".$nid." And ID=".$m["oid"]));
	if($r){
		$p["Mb"]=$r;$c=$r["Os"];$d=$r["Ot"];
		$q=Qry("Select ID,Fo,Ft,Fi,Fn,Fm,Fc,Fs,F1,F2,F3,Fd,Fr,Fb From ".$pre."ofood Where Si=".$nid." And Fo=".$m["oid"]." Order By ID Asc");
		while($r=Qra($q))$p["Md"][]=$r;
	}
	if($m["Ts"]!=1){
		Qry("Update ".$pre."table Set Ts=0 Where Si=".$nid." And Ts=2 And ID=".$d);
		Qry("Update ".$pre."table Set Ts=".$c." Where Si=".$nid." And Ts>2 And ID=".$d);
	}
	echo Enc($p);
	break;

	case "lsf"://提交厨房
	$p=["msg"=>"ok","Pb"=>[],"Pd"=>[],"err"=>""];$h="";
	$q=Qry("Select A.Db,B.Fc,A.Da,B.Fd,B.Fn,B.Fb,B.ID,B.Fs,A.Dv From ".$pre."foods As A,".$pre."ofood As B Where B.Si=".$nid." And A.ID=B.Fi And B.Fs<6 And B.Fo In (".$m["oid"].")");
	while($r=Qra($q)){
		if($r["Fs"]==3)$p["Pd"][]=$r["Dv"]."|spd|".$r["ID"];
		$n=explode(",",$r["Db"]);
		for($i=1;$i<count($n);$i++){
			$d=explode("=",$n[$i]);
			Qry("Update ".$pre."stock Set Ks=Ks-".($d[1]*$r["Fc"])." Where Si=".$nid." And ID=".$d[0]);
		}
		$d=Qry("Select Ak,Aw From ".$pre."admin Where Si=".$nid." And ID In (".$r["Da"].")");
		while($e=Qra($d)){
			if($e["Ak"]!=""&&$e["Aw"]!=""&&$m["Wx"]*1==0&&$cfg["Ag"]["W2"]!=""){
				$s='{"touser":"'.$e["Aw"].'","template_id":"'.$cfg["Ag"]["W2"].'","url":"'.$cfg["Aw"].'","data":{"first":{"value":"Hello, New Order~~~~","color":"#FF0000"},"keyword1":{"value":"'.$r["Fd"].'","color":"#0099FF"},"keyword2":{"value":"['.$r["ID"].']'.$r["Fn"].' × '.$r["Fc"].'","color":"#0099FF"},"keyword3":{"value":"'.$r["Fb"].'","color":"#0099FF"},"remark":{"value":"To process an order, click the Details button.","color":"#000000"}}}';
				$p["err"].=Cul("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".Tkn(),$s);
			}
		}
	}
	$q=Qry("Select ID,Ox From ".$pre."order Where Si=".$nid." And Ot=0 And ID In (".$m["oid"].")");
	while($r=Qra($q))$p["Pb"][]=$r;
	Qry("Update ".$pre."order Set Os=6 Where Si=".$nid." And ID In (".$m["oid"].")");
	Qry("Update ".$pre."ofood Set Fs=6 Where Si=".$nid." And Fs<6 And Fo In (".$m["oid"].")");
	Qry("Update ".$pre."table Set Ts=6 Where Si=".$nid." And Ti In (".$m["oid"].")");
	echo Enc($p);
	break;

	case "dje"://点单付款
	if(Qrs(Qry("Select Ts From ".$pre."table Where Si=".$nid." And ID=".$m["Ot"]))==12)die('{"msg":"ok"}');
	Qry("Update ".$pre."order Set Ps=Ps+".$m["Ps"].",Pc=".$m["Pc"].",Pd=Pm-Pc-Ps,Pt=".$m["Pt"].",Ob='".$m["Ob"]."',Oe=Now(),O4=".$uid.",Os=12,Oo='' Where Si=".$nid." And ID=".$m["oid"]." And Ot=".$m["Ot"]);
	Qry("Update ".$pre."table Set Ts=12 Where Si=".$nid." And ID=".$m["Ot"]);
	echo '{"msg":"ok"}';
	break;

	case "kxe"://快餐完成
	Qry("Update ".$pre."order Set Os=13 Where Si=".$nid." And ID=".$m["oid"]);
	Qry("Update ".$pre."ofood Set Fs=10 Where Si=".$nid." And Fo=".$m["oid"]);
	echo '{"msg":"ok"}';
	break;

	case "kxd"://快餐下单
	$r=Qra(Qry("Select Os,Ob,Ox From ".$pre."order Where Si=".$nid." And ID=".$m["oid"]));
	if($r["Os"]==12)die('{"msg":"ok"}');
	$b=Dec($r["Ob"]);$h=$b["Bz"];$v=$r["Ox"]*1;
	for($i=0;$i<count($b["Mc"]);$i++){
		$c=$b["Mc"][$i];
		$r=Qra(Qry("Select Dn,Dm,Dt From ".$pre."foods Where Si=".$nid." And ID=".$c[0]));
		if($r["Dt"]=="0"){
			Qry("Insert Into ".$pre."ofood (Si,Fo,Ft,Fi,Fn,Fm,Fc,Fs,F1,F2,F3,Fd,Fr,Fb) Values (".$nid.",".$m["oid"].",0,".$c[0].",'".$r["Dn"]."',".$r["Dm"].",".$c[1].",3,".$uid.",0,0,Now(),0,'".$c[2]."')");
		}else{
			Qry("Insert Into ".$pre."ofood (Si,Fo,Ft,Fi,Fn,Fm,Fc,Fs,F1,F2,F3,Fd,Fr,Fb) Values (".$nid.",".$m["oid"].",0,".$c[0].",'".$r["Dn"]."',0,".$c[1].",3,".$uid.",0,0,Now(),0,'".$c[2]."')");
			$e=explode(",",$r["Dt"]);
			$f=$r["Dm"]/Qrs(Qry("Select Sum(Ns) From ".$pre."foods Where Si=".$nid." And ID In (".$r["Dt"].")"));
			$d=0;
			for($j=1;$j<count($e);$j++){
				$k=Qra(Qry("Select ID,Dn,Dm From ".$pre."foods Where Si=".$nid." And ID=".$e[$j]));
				$d+=round($k["Dm"]*$f);
				Qry("Insert Into ".$pre."ofood (Si,Fo,Ft,Fi,Fn,Fm,Fc,Fs,F1,F2,F3,Fd,Fr,Fb) Values (".$nid.",".$m["oid"].",0,".$k["ID"].",'".$k["Dn"]."[T]',".round($k["Dm"]*$f).",".$c[1].",3,".$m["uid"].",0,0,Now(),0,'".$c[2]."')");
			}
			Qry("Update ".$pre."ofood Set Fm=Fm+".($r["Dm"]-$d)." Where Si=".$nid." And ID=".Qri());
		}
	}
	if($b["Pf"]>0)Qry("Insert Into ".$pre."ofood (Si,Fo,Ft,Fi,Fn,Fm,Fc,Fs,F1,F2,F3,Fd,Fr,Fb) Values (".$nid.",".$m["oid"].",0,0,'送餐费',".$b["Pf"].",1,12,0,0,0,Now(),0,'')");
	Qry("Update ".$pre."order Set Ps=".$m["Ps"].",Pd=Pm-Ps-Pc,Os=12,O4=".$uid.",Oe=Now(),Pt=".$m["Pt"].",Ob='".($v==1?($h["bz"]." 店内用餐<br>餐桌： ".$h["cz"]):($h["bz"]." 外卖送餐<br>地址： ".$h["dz"]."<br>送时： ".$h["sj"]))."<br>电话： ".$h["dh"]."||',Ou='".$h["dh"]."' Where Si=".$nid." And ID=".$m["oid"]);
	if($v==2){
		$c=["Fn"=>$h["fn"],"Fd"=>$h["fd"],"Fx"=>$h["fx"],"Fy"=>$h["fy"],"Tn"=>$h["dh"],"Td"=>$h["dz"],"Tx"=>$h["gx"],"Ty"=>$h["gy"]];
		if(Qrc(Qry("Select ID From ".$pre."osend Where Si=".$nid." And Ho=".$m["oid"]))==0)Qry("Insert Into ".$pre."osend (Si,Hu,Ho,Hd,Hm,Hc,Hs) Values (".$nid.",0,".$m["oid"].",'".Enc($c)."',".$b["Pf"].",'[".date("Y-m-d H:i:s")."] 点单已发布，等待接单中。',0)");
		$q=Qry("Select Aw,Ar,Ak From ".$pre."admin Where Si=".$nid);$e=[];
		while($r=Qra($q)){
			if($r["Aw"]!=""&&strpos($r["Ar"],"E")>-1&&$r["Ak"]!=""){
				$s='{"touser":"'.$r["Aw"].'","template_id":"'.$cfg["Ag"]["W1"].'","url":"'.$cfg["Aw"].'","data":{"first":{"value":"小哥！来订单啦~~~~","color":"#FF0000"},"keyword1":{"value":"'.$m["oid"].'","color":"#0099FF"},"keyword2":{"value":"'.$n["Sn"].'","color":"#0099FF"},"keyword3":{"value":"'.$h["dh"].'","color":"#0099FF"},"keyword4":{"value":"'.$h["dz"].'","color":"#0099FF"},"keyword5":{"value":"'.($b["Pf"]/100).'元","color":"#0099FF"},"remark":{"value":"处理订单请点击详情按钮。","color":"#000000"}}}';
				if($cfg["Ag"]["W1"]!="")$e[]=Cul("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".Tkn(),$s);
			}
		}
	}else $e="";
	echo Enc(["msg"=>"ok","err"=>$e]);
	break;

	case "kxs"://快餐删除
	Qry("Delete From ".$pre."order Where Si=".$nid." And Ox>0 And Od<'".date('Y-m-d H:i:s',strtotime("-1 Hour",strtotime("now")))."' And ID=".$m["oid"]);
	echo '{"msg":"ok"}';
	break;

	case "kwm"://外卖状态
	$a=Qra(Qry("Select Hu,Hd,Hm,Hc,Hs From ".$pre."osend Where Si=".$nid." And Ho=".$m["oid"]));
	if($a["Hu"]*1>0){$b=Qra(Qry("Select An,Am From ".$pre."admin Where Si=".$nid." And ID=".$a["Hu"]));$c=[$a["Hu"],$b["An"],$b["Am"]];}else $c=[0,'',''];
	$p=["msg"=>"ok","Hu"=>$c[0],"An"=>$c[1],"Am"=>$c[2],"Hd"=>Dec($a["Hd"]),"Hm"=>$a["Hm"],"Hc"=>$a["Hc"],"Hs"=>$a["Hs"]];
	echo Enc($p);
	break;

	case "kwf"://外卖重发
	Qry("Update ".$pre."osend Set Hu=0,Hs=0,Hc='[".date("Y-m-d H:i:s")."] 点单已发布，等待接单中。' Where Si=".$nid." And Hs<3 And Ho=".$m["oid"]);
	echo '{"msg":"ok"}';
	break;

	case "syn"://查询
	$o=Qrs(Qry("Select Oo From ".$pre."order Where ID=".$m["oid"]));
	$r=Qra(Qry("Select Nt,Np,Mc,Mt From ".$pre."pay Where Mc='".$o."'"));
	echo $r?'{"msg":"ok","pay":'.$r["Nt"].',"mny":'.$r["Np"].',"odr":"'.$r["Mc"].'","api":'.$r["Mt"].'}':'{"msg":"ok","pay":0}';
	break;
	
	default:
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>前台管理</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;}
.flk {background-color:#F3F9FF;padding:0px 10px;line-height:40px;height:40px;text-align:right;}
.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;}
/*----------------------------------------------------------------*/
.btm {font-size:14px;background-color:#09F;color:#FFF;padding:0px 4px;line-height:20px;cursor:pointer;display:inline-block;box-shadow:2px 2px 2px #999;}
.nav {width:50px;height:50px;margin:5px;text-align:center;cursor:pointer;}
.pm0 {border:1px solid #FFF;padding:0px 2px;margin:0px;cursor:pointer;}
.pm1 {border:1px solid #FFF;padding:0px 2px;margin:0px;cursor:pointer;background-color:#FFF;color:#000;}
.npl,.npy{line-height:32px;border-bottom:1px dashed #CCC;}
.npl span{display:inline-block;width:160px;text-align:center;}
.npy span{display:inline-block;width:132px;text-align:center;}
.nu0 {border:1px solid #CCC;background-color:#F3F9FF;line-height:32px;height:32px;clear:both;margin:5px 0px;cursor:pointer;}
.nu1 {float:left;width:145px;text-align:center;}
.nst {float:left;width:120px;height:84px;text-align:left;padding:5px 10px;line-height:28px;border:1px solid #CCC;margin:8px;cursor:pointer;text-align:center;font-size:14px;box-shadow:2px 2px 2px #999;}
.nsk {margin:5px 10px;line-height:32px;height:32px;font-size:14px;text-align:center;cleat:both;background-color:#E9F9FF;box-shadow:3px 3px 3px #AAA;cursor:pointer;}
.nsk span {display:inline-block;width:80px;text-align:center;}
.nl0 {border-bottom:1px dashed #09F;height:32px;background-color:#F0FFFA;}
.nl1 {border-bottom:1px dashed #09F;height:32px;background-color:#E9F9FF;}
.nl2 {float:left;width:332px;text-align:center;}
.nl3 {float:left;width:68px;text-align:center;}
.nl4 {float:left;width:120px;text-align:center;}
.zk1 {display:inline-block;line-height:28px;width:96px;border:1px dashed #09F;background-color:#F9FCFF;margin:3px 6px;text-align:center;cursor:pointer;}
.zk0 {display:inline-block;line-height:28px;width:96px;border:1px dashed #09F;background-color:#09F;color:#FFF;margin:3px 6px;text-align:center;cursor:pointer;}
.ct0 {margin:10px 0px;line-height:36px;clear:both;height:38px;}
.ct1 {float:left;width:80px;padding:0px 5px;text-align:right;background-color:#09F;border:1px solid #09F;color:#FFF;}
.ct2 {float:left;width:211px;padding:0px 10px;color:#F90;border:1px solid #09F;font-size:20px;margin-right:20px;}
</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='manage.php';
var url='<?php echo $cfg["Aw"];?>';
var nid='<?php echo Req("nid");?>';
var uid='<?php echo Req("uid");?>';
var sid='<?php echo Req("sid");?>';
var Cr=['F0FFFA','9CF','F30','F90','F90','F90','09F','09F','09F','09F','09F','F90','0C9','09F','09F','F30'];
var Ct=['空桌待客','顾客入座','申请开台','顾客下单','顾客退单','厨房退单','提交厨房','厨房接收','制作完成','上菜送餐','顾客用餐','申请结账','结账完成','点单完成','退单完成','顾客呼叫'];
var Ck=['空桌待客','顾客入座','申请开台','等待支付','等待打单','厨房退单','提交厨房','厨房接收','制作完成','上菜送餐','顾客用餐','申请结账','顾客下单','点单完成','退单完成','顾客呼叫'];
var pw,ph,Sc,Ar,Mu,Mt,Mk,Mb,Md,tid,kid,vid;
var TK=0;
function rsz(){pw=parseInt(document.documentElement.clientWidth);ph=parseInt(document.documentElement.clientHeight);msk.style.width=pw+'px';msk.style.height=ph+'px';
Dm.style.height=ph-60+'px';Dt.style.height=ph-60+'px';Dk.style.height=ph-60+'px';Dm.style.display=TK?'none':'block';Dt.style.display=TK==2?'none':'block';Dk.style.display=TK==1?'none':'block';Dt.style.width=[(pw-4)/2,pw,pw][TK]+'px';Dk.style.width=[(pw-4)/2,pw,pw][TK]+'px';TK_0.className=['pm1','pm0','pm0'][TK];TK_1.className=['pm0','pm1','pm0'][TK];TK_2.className=['pm0','pm0','pm1'][TK];css('.nst').width=(pw-48)/8-36+'px';css('.nsk span').width=([pw/2-2,pw,pw][TK]-48)/5+'px';
setTimeout('rsz()',500);}
function jsn(x){return {act:x,uid:uid,nid:nid,sid:sid,rnd:rnd(6)};}
//读取设置
function cfg(n){xml(uri,jsn('cfg'),function(r){Ar=r.Ar;vid=r.vid;document.title=r.Sn+' - 前台管理';Sn.innerText=r.Sn;An.innerText=r.An;Sc=r.Sc;var o=document.createElement('script');o.src=Sc.p[0]+'CLodopfuncs.js';document.body.appendChild(o);lst();});}

//排号预定
function nvp(){if(Ar.indexOf('F')<0){alt('无此权限！');return;}xml('images/'+nid+'/d.txt?'+rnd(),null,function(r){var d=r.yd;var s='';for(var i=0;i<d.length;i++){s+='<div class="npy"><span>'+d[i][0]+'</span><span>'+d[i][1]+'</span><span>'+d[i][2]+'人</span><span style="width:160px;">'+d[i][3]+'</span><span>'+d[i][4]+'</span><font class="bn1" onclick="nyc('+i+');">删除</font></div>';}Fh_d.innerHTML=s;Fh_c.innerText=d.length;var t=r.ph;var s='';for(var i=0;i<t.length;i++){s+='<div class="npl"><span>'+(i+1)+'、</span><span>'+t[i][0]+'#</span><span>'+t[i][1]+'人</span><span>'+t[i][2].substr(11)+'</span><font class="bn1" onclick="ply(\''+Sc.i[10].replace('{{id}}',t[i][0])+'\');">叫号</font><font class="bn1" onclick="npc('+i+');">销号</font></div>';}Fh_t.innerHTML=s;Fh_s.innerText=t.length;fio('Fh',1,1);Fh_n.focus();});}
function npv(){var s=rnd(6);var p=jsn('npv');p.Ps=Fh_n.value;p.Pr=s;xml(uri,p,function(r){nvp();if(!prt()){alt('打印服务器参数设置错误！');}else pre(Sc.p[3]+'|spu|'+s+'|'+Sc.p[5]);});}
function npc(n){cfm('确认销号？',function(){var p=jsn('npc');p.Pr=n;xml(uri,p,function(r){nvp();});});}
function nys(){var d;var s1='';var s2='';for(var i=0;i<10;i++){d=new Date((new Date()/1000+86400*i)*1000);s1+='<option>'+d.getFullYear()+'-'+String(d.getMonth()+101).substr(-2)+'-'+String(100+d.getDate()).substr(-2)+'</option>';}for(var i=20;i<41;i++){s2+='<option>'+Math.floor(i/2)+':'+['00','30'][i%2]+'</option>';}Fy_d.innerHTML='<select id="Fy_h">'+s1+'</select> <select id="Fy_k">'+s2+'</select>';var t='';for(var i=0;i<Mt.length;i++){t+='<option>'+Mt[i].Tn+'['+Mt[i].Tc+'人座]</option>'}Fy_b.innerHTML='<select id="Fy_t">'+t+'</select>';Fy_n.value='';Fy_m.value='';Fy_c.value='';fio('Fy',1);}
function nyv(){var p=jsn('nyv');p.gk=Fy_n.value;p.dh=Fy_m.value;p.rs=Fy_c.value;p.sj=Fy_h.value+' '+Fy_k.value+':00';p.cz=Fy_t.value;xml(uri,p,function(r){fio('Fy',-1);setTimeout('nvp()',200);});}
function nyc(n){cfm('确认删除？',function(){var p=jsn('nyc');p.Pr=n;xml(uri,p,function(r){nvp();});});}

//会员列表
function nvu(n){if(Ar.indexOf('F')<0){alt('无此权限！');return;}if(!n)fio('Fu',1,1);Fu_l.innerHTML='Loading....';var p=jsn('nul');p.Uc=Fu_n.value;xml(uri,p,function(r){Mu=r.Mu;var s='';for(var i=0;i<Mu.length;i++)s+='<div class="nu0" onclick="nue('+i+');"><div class="nu1">'+Mu[i].Uc+'</div><div class="nu1">'+Mu[i].Un+'</div><div class="nu1">'+Mu[i].Us/100+'</div><div class="nu1">'+Mu[i].Ux/100+'</div><div class="nu1">'+Mu[i].Ue+'</div></div>';Fu_l.innerHTML=s;});}
function nue(n){fio('Fo',1);var s=n<0?{ID:0,Uc:'',Un:'',Up:'',Ud:'',Us:0,Ux:0,Ut:'',Ue:0}:Mu[n];Fo_i.value=s.ID;Fo_c.value=s.Uc;Fo_n.value=s.Un;Fo_p.value=s.Up;Fo_d.innerText=s.Ud;Fo_s.innerText=s.Us/100;Fo_x.innerText=s.Ux/100;Fo_t.innerText=s.Ut;Fo_e.innerText=s.Ue/100;}
function nuv(){var p=jsn('nuv');p.ID=Fo_i.value;p.Uc=Fo_c.value;p.Un=Fo_n.value;p.Up=Fo_p.value;if(p.Uc.length<8||p.Un==''||p.Up.lenght<6){alt('资料不全，会员卡号至少8位，密码至少6位，请补齐！');return;}xml(uri,p,function(r){fio('Fo',-1);nvu();});}
function nud(){if(Fo_i.value*1==0)return;if(Fo_s.innerText*1>0||Fo_x.innerText*1>0){alt('已充值过的会员卡不可删除！');return;}cfm('确认删除？',function(){var p=jsn('nud');p.ID=Fo_i.value;xml(uri,p,function(r){fio('Fo',-1);nuv();});});}
function nus(){if(Fo_i.value*1==0)return;fio('Fi',1);Fi_c.innerText=Fo_c.value;Fi_m.value=1000;Fi_n.value=1000;Fi_p.style.display='none';Fi_b.style.display='block';}
function nuc(){if(Fi_m.value*1==0||Fi_n.value*1==0){alt('请输入金额！');return;}cfm('实收金额：'+Fi_m.value+'元\n充值金额：'+Fi_n.value+'元\n确认充值？',function(){var p=jsn('nuc');p.Gc=Fi_c.innerText;p.Gm=Fi_m.value*100;p.Gn=Fi_n.value*100;p.Gu=nid+'-'+uid+'-'+rnd(6);xml(uri,p,function(r){alt('充值已成功！');Fi_p.style.display='block';Fi_b.style.display='none';Fi_i.value=r.ID;Fo_s.innerText=Fi_n.value*1+Fo_s.innerText*1;nvu();});});}

//统计报表
function nvc(n){if(Ar.indexOf('F')<0){alt('无此权限！');return;}if(!n)fio('Fr',1,1);if(!n)n=1;var d=new Date();C2.value=d.getFullYear()+'-'+String(d.getMonth()+101).substr(-2)+'-'+String(d.getDate()+100).substr(-2);d.setDate(d.getDate()-n+1);C1.value=d.getFullYear()+'-'+String(d.getMonth()+101).substr(-2)+'-'+String(d.getDate()+100).substr(-2);nct();}
function nct(){var p=jsn('nct');p.C1=C1.value;p.C2=C2.value;xml(uri,p,function(r){C_Pm.innerText=r.Pm;C_Ps.innerText=r.Ps;C_Pd.innerText=r.Pd;C_Pc.innerText=r.Pc;C_Mc.innerText=r.Mc;C_Md.innerText=r.Md;C_Mw.innerText=r.Mw;C_Mz.innerText=r.Mz;C_Mm.innerText=r.Mm;C_Uc.innerText=r.Uc;C_Co.innerText=r.Co;C_Cd.innerText=r.Cd;C_Cr.innerText=r.Cr;C_Cm.innerText=r.Cm;});}

//加载大厅
function lst(){clearTimeout(tid);xml(uri,jsn('lst'),function(r){var y=0;var p=[];
Mt=r.Mt;var s='';for(var i=0;i<Mt.length;i++){s+='<div id="Dt_'+i+'" class="nst" style="background-color:#'+Cr[Mt[i].Ts]+';color:#'+(Mt[i].Ts>0?'FFF':'000')+';" onclick="lsi('+Mt[i].Ti+',1,\''+Mt[i].Tn+'\','+Mt[i].Ts+');"><span style="font-size:18px;">'+Mt[i].Tn+'</span>['+Mt[i].Tc+'/'+Mt[i].Tu+']<br>'+Ct[Mt[i].Ts]+'<br>金额： '+(Mt[i].Tm/100)+' 元</div></div>';if(Mt[i].Ts*1==3&&Sc.i[1]*1==0)p.push(Mt[i].Ti);if(',,2,3,4,5,11,15,'.indexOf(','+Mt[i].Ts+',')>0)y=1;}Dt.innerHTML=s;
Mk=r.Mk;var s='';for(var i=0;i<Mk.length;i++){s+='<div class="nsk" onclick="lsi('+Mk[i].ID+',2,\'快餐外卖\');"><span>'+Mk[i].ID+'</span><span>'+['正餐','快餐','外卖'][Mk[i].Ox]+'</span><span>'+(Mk[i].Pm/100)+' 元</span><span style="color:#'+[,,,'F00',,,'F90','CC6','0C6','3CF','09F',,,'F00'][Mk[i].Os]+';">'+Ck[Mk[i].Os]+'</span><span>'+Mk[i].Od.substr(11)+'</span></div>';if(Mk[i].Os*1==3&&new Date().getTime()-new Date(Mk[i].Od).getTime()<120000)kxc(Mk[i].ID);if(Mk[i].Os*1==12||Mk[i].Os*1==5)y=1;if((Mk[i].Os*1==12&&Sc.i[1]*1==0)||Mk[i].Os*1==4)p.push(Mk[i].ID);}Dk.innerHTML=s==''?'<div style="text-align:center;color:#CCC;line-height:36px;">-= 没有订单 =-</div>':s;
Sk.style.display=r.Kc*1>0?'inline-block':'none';St.innerText='Refresh At:'+r.Rt.substr(11);if(y&&Sv.checked){dsy.pause();dsy.src='images/warn.mp3';dsy.play();}if(p.length>0)lsf(p.join(','),1);tid=setTimeout('lst()',5000);});}
//餐桌操作
function lsi(n,c,t,k){var p=jsn('lsi');p.oid=n;p.Ts=c;xml(uri,p,function(r){if(r.Mb.length==0&&!c){alt('无此点单！');return;}Mb=r.Mb.length==0?{ID:0,Ot:Mt[n].ID,O1:'',O4:'',Ox:0,Pm:0,Pd:0,Pc:0,Ps:0,Pt:0,Os:0,Od:'',Ob:''}:r.Mb;if(Mb.Os*1==3&&Mb.Ox>0){kxc(n,Mb.Od);return;}Md=r.Md;var s='';var j=1;for(var i=0;i<Md.length;i++){j=1-j;s+='<div class="nl'+j+'"><div class="nl2">'+Md[i].Fn+(Md[i].Fb==''?'':('<span style="font-size:12px;color:#09F;">['+Md[i].Fb.substr(0,Md[i].Fb.length-1)+']</span>'))+'</div><div class="nl3">'+(Md[i].Fm/100)+'</div><div class="nl3"">'+Md[i].Fc+'</div><div class="nl3"">'+Md[i].F1+'</div><div class="nl3"">'+Md[i].F2+'</div><div class="nl3"">'+Md[i].F3+'</div><div class="nl4" style="color:#'+[,,,'F00',,,'F90','CC6','0C6','3CF','09F'][Md[i].Fs]+';text-decoration:'+['none','underline','line-through'][Md[i].Fr]+';">'+Ct[Md[i].Fs]+'</div><div class="nl3"">'+['',['','[<span style="color:#F00;">申退</span>]','<span style="color:#093;">已退</span>'][Md[i].Fr],['','<span style="color:#F00;">申退</span>','','<span style="color:#093;">已退</span>'][Md[i].Fr]][c]+'</div></div>';}Fc_l.innerHTML=s;Fc_d.innerHTML='单号：'+Mb.ID+'　　　　　流程：'+Ct[k||Mb.Os]+'　　　　　金额：'+(Mb.Pm/100)+'元';Fc_b.innerHTML='下单：'+Mb.O1+'　收银：'+Mb.O4+'　时间：'+Mb.Od+'　优惠：'+(Mb.Pd/100)+'元　抵扣：'+(Mb.Pc/100)+'元　实付：'+(Mb.Ps/100)+'元　方式：'+['现金','刷卡','微信','支付宝','会员卡'][Mb.Pt]+'<br>备注：'+Mb.Ob.replace(/\<br\>/gi,' ').split('|')[0];Fc_t.innerText=t;Fc_m.style.display=['none','block','none'][c];Fc_n.style.display=['none','none','block'][c];fio('Fc',1,1);});}
//提交厨房
function lsf(n,s){if(!n)return;if(Sc.i[0]=='1'){if(!prt()){alt('打印服务器设置错误！');return;}}var p=jsn('lsf');p.oid=n;p.Wx=Sc.i[0];xml(uri,p,function(r){for(var j=0;j<r.Pb.length;j++){if(r.Pb[j].Ox*1>0)pre(Sc.p[3]+'|spb|'+r.Pb[j].ID+'|'+Sc.p[5]);}if(Sc.i[0]=='1'){for(var i=0;i<r.Pd.length;i++)pre(r.Pd[i]+'|'+Sc.p[12]);}lst();fio('Fc',-1,1);if(!s)alt('已提交厨房！');});}
//查询
function lsc(o,n,c){n=n||0;var p=jsn('syn');p.oid=o;xml(uri,p,function(r){if(r.pay==1){clearTimeout(kid);alt('收款成功！');ply(Sc.i[12].replace('{{id}}',r.mny/100));if(c){kxt(o,r.mny,3-r.api);}else{dje(r.mny,3-r.api);}}else{if(!n)kid=setTimeout('lsc(\''+o+'\','+n+','+c+')',3000);if(n)alt('无支付信息！');}});}

//显示结账
function djz(){if(Ar.indexOf('B')<0){alt('无此权限！');return;}if(Mb.ID*1==0)return;fio('Fs',1);Fs_i.innerHTML='桌号：'+Fc_t.innerText+'　单号：'+Mb.ID+'　员工：'+Mb.O1+'　时间：'+Mb.Od;var s='';for(var i=0;i<Sc.c[1].length;i++){s+='<span id="Fs_z'+i+'" class="zk'+(Mb.Ob.indexOf(Sc.c[1][i][0]+', ')>-1?0:1)+'" onclick="djs(1);">'+Sc.c[1][i][0]+'</span>';}Fs_z.innerHTML='折扣： '+s;Fs_m.innerText=Mb.Pm/100;Fs_s.innerText=Mb.Ps/100;Fs_c.value=Mb.Pc/100;Fs_t.options[Mb.Pt].selected=true;Fs_t.disabled=Mb.Ps>0;Fs_b.value=Mb.Ob;Fs_a.style.display='none';Fs_e.style.display='none';djs();}
//计算折扣
function djs(n){var o=event.srcElement;if(o.tagName=='SPAN'&&n)o.className=o.className=='zk1'?'zk0':'zk1';var m=Mb.Pm*1-Fs_c.value*100;if(m<0)m=0;var c=0;for(var i=0;i<Sc.c[1].length;i++){Fs_b.value=Fs_b.value.replace(Sc.c[1][i][0]+', ','');if($('Fs_z'+i).className=='zk0'){Fs_b.value+=Sc.c[1][i][0]+', ';if(Sc.c[1][i][2]*1<1){c+=Math.round(m-m*Sc.c[1][i][2]);}else{if(m>Sc.c[1][i][1]*100)c+=Sc.c[1][i][2]*100;}}}c=Math.round(c);var d=Math.round(m-m*Sc.c[0][Fs_t.value]);Fs_d.innerText=(c+d)/100;m=(Mb.Pm*1-c-d-Fs_c.value*100-Mb.Ps*1)/100;if(m<0)m=0;Fs_n.innerText=m;Fs_e.style.display=Fs_t.value*1>1&&Fs_t.value*1<4?'inline-block':'none';Fs_a.style.display=Fs_t.value*1<2||(Fs_t.value*1==4&&Fs_n.innerText*1==0)?'inline-block':'none';}
//正餐结账
function dje(m,c){if(Ar.indexOf('B')==-1){alt('无此权限！');return;}var p=jsn('dje');p.Ot=Mb.Ot;p.oid=Mb.ID;p.Pt=c||Fs_t.value;p.Ps=m||Fs_n.innerText*100;p.Pc=Fs_c.value*100;p.Ob=Fs_b.value;xml(uri,p,function(r){alt('收款成功！');fio('Fc',-1,'Fs');lst();});}

//快餐完成
function kxe(){if(Ar.indexOf('F')<0){alt('无此权限！');return;}cfm('确认完成此单？\n外卖单请务必确认已送达！',function(){var p=jsn('kxe');p.oid=Mb.ID;xml(uri,p,function(r){lst();fio('Fc',-1,1);});});}
//快餐结账
function kxc(n,m){var p=jsn('syn');p.oid=n;xml(uri,p,function(r){if(r.pay==1){kxd(n,r.mny,3-r.api);}else{if(m)kxs(n,m);}});}
function kxd(n,m,c){var p=jsn('kxd');p.oid=n;p.Ps=m;p.Pt=c;xml(uri,p,function(r){lst();});}
function kxs(n,m){var d=new Date().getTime();var t=new Date(m).getTime();if(t+3600000<d){cfm('此单超过1小时未支付，是否删除？',function(){var p=jsn('kxs');p.oid=n;xml(uri,p,function(r){lst();});});}else alt('此单未支付，请等待顾客支付！');}
//外卖状态
function kwm(n){var p=jsn('kwm');p.oid=n;xml(uri,p,function(r){fio('Fw',1);Fw_l.innerHTML='单号：'+n+'　骑手：'+r.An+'['+r.Am+']　状态：'+['待接单','取餐中','派送中','已送达','已结算'][r.Hs]+'<br>送至：['+r.Hd.Tn+']'+r.Hd.Td+'<br>'+r.Hc;});}
//外卖重发
function kwf(n){if(Ar.indexOf('F')<0){alt('无此权限！');return;}cfm('确认重新发布？',function(){var p=jsn('kwf');p.oid=n;xml(uri,p,function(r){kwm(n);});});}

//声音
function ply(n){var p=jsn('snd');p.Sv=n;xml(uri,p,function(r){dsy.pause();dsy.src=r.mp3;dsy.play();});}
//打印
var pri=0;var prc=[];
function prt(){var o;try{o=getCLodop();}catch(e){return false;};o.SET_LICENSES(Sc.p[1],Sc.p[2],'','');return o;}
function pre(a){if((','+prc.join(',')+',').indexOf(','+a+',')==-1)prc.push(a);prn();}
function prn(){if(prc.length==0)return;if(pri){setTimeout('prn()',100);return;}pri=1;var o=prt();if(!o)return;var c=prc[0].split('|');o.PRINT_INIT('Print:'+prc[0]);o.SET_PRINTER_INDEX(c[0]);o.SET_PRINT_PAGESIZE(3,c[3]*10,48,'CreateCustomPage');o.ADD_PRINT_HTM(0,0,0,500,'URL:output.php?x='+c[1]+'&n='+nid+'&u='+uid+'&s='+vid+'&a='+c[2]);o.PRINT();prc.splice(0,1);pri=0;setTimeout('prn()',100);}
</script>
</head>
<body onLoad="rsz();cfg();">
<div id="msk"></div><div id="tip"></div><div id="cfn"></div><audio id="dsy"></audio>
<!--顶部层-->
<div style="height:60px;overflow:hidden;background-color:#333;">
  <div style="float:left;margin:6px;"><img src="images/icon.png" width="48" height="48"></div>
  <div style="float:left;font-size:28px;color:#6CF;line-height:60px;" id="Sn"></div>
  <div style="float:left;font-size:14px;color:#FFF;padding:12px 0px 0px 10px;">员工： <span id="An" style="font-size:14px;"></span>　　模式： <span id="TK_1" class="pm0" onClick="TK=1;rsz();">正餐</span><span id="TK_0" class="pm1" onClick="TK=0;rsz();">混合</span><span id="TK_2" class="pm0" onClick="TK=2;rsz();">快餐</span>　　<span id="Sk" style="background-color:#F00;color:#FFF;display:none;cursor:pointer;">有库存已低于预警值！</span><br>查单： <input type="text" onKeyUp="num();if(event.keyCode==13)lsi(this.value,0,'查询点单');" style="font-size:12px;background-color:#333;border:1px solid #FFF;padding:1px;width:40px;color:#FFF;">　　<input type="checkbox" id="Sv" checked="checked"> 提示音　　<span id="St" style="color:#999;"></span>
  </div>
  <div style="float:right;height:60px;width:420px;background-image:url(images/navi.png);">
    <div class="nav" style="float:left;" onClick="lst();"></div>
    <div class="nav" style="float:left;" onClick="nvp();"></div>
    <div class="nav" style="float:left;" onClick="nvu();"></div>
    <div class="nav" style="float:left;" onClick="nvc();"></div>
    <div class="nav" style="float:left;" onClick="if(Ar.indexOf('S')>-1){document.fm.uid.value=uid;document.fm.nid.value=nid;document.fm.sid.value=sid;document.fm.submit();}else alt('无此权限！');"></div>
    <div class="nav" style="float:left;" onClick="window.open('output.php?x=ewm&n='+nid+'&u='+uid+'&s='+vid);"></div>
    <div class="nav" style="float:left;" onClick="cfm('确认关闭？',function(){window.close();});"></div>
    <form name="fm" action="system.php" method="post" target="_blank"><input type="hidden" name="act" value="index"><input type="hidden" name="uid"><input type="hidden" name="nid"><input type="hidden" name="sid"></form>
  </div>
</div>
<!--大厅层-->
<div id="Dt" style="float:left; overflow:auto;"></div>
<div id="Dm" style="float:left; width:2px;border-left:1px solid #CCC;border-right:1px solid #CCC;"></div>
<div id="Dk" style="float:right;overflow:auto;"></div>
<!--排号层-->
<div id="Fh" class="fld" style="width:800px;z-index:20;">
  <div class="flt"><div class="bnc" onClick="fio('Fh',-1,'Fy');">×</div>排号/预定</div>
  <div class="flb" id="Fh_t" style="height:199px;overflow:auto;"></div>
  <div style="border-top:3px double #CCC;margin:0px 20px;"></div>
  <div class="flb" id="Fh_d" style="height:198px;overflow:auto;"></div>
  <div class="flk"><div style="float:left;"><span class="bn1" onClick="nys();">新桌预定</span> 当前共有 <span id="Fh_c">0</span> 桌预定 [<a href="javascript:void(0);" onClick="nyc(-1)">全部删除</a>]</div><div style="float:right;">当前共有 <span id="Fh_s">0</span> 人排队 [<a href="javascript:void(0);" onClick="npc(-1)">全部销号</a>] 人数：<input type="text" id="Fh_n" onBlur="num();if(this.value*1<1)this.value=1;" size="2" style="text-align:center;" value="1" onKeyDown="num();if(event.keyCode==38)this.value=this.value*1+1;if(event.keyCode==40)this.value=this.value*1-1;if(this.value*1<1)this.value=1;if(event.keyCode==13)npv();">　<span class="bn1" onClick="npv();">生成新号</span></div></div>
</div>
<div id="Fy" class="fld" style="z-index:21;">
  <div class="flt"><div class="bnc" onClick="fio('Fy',-1);">×</div>预定</div>
  <div class="flb">顾客： <input type="text" id="Fy_n" size="6"> 电话： <input type="text" id="Fy_m" size="16"><br>人数： <input type="text" id="Fy_c" size="3"> 时间： <span id="Fy_d"></span><br>餐桌： <span id="Fy_b"></span></div>
  <div class="flk"><span class="btn" onClick="nyv();">预定</span></div>
</div>
<!--会员层-->
<div id="Fu" class="fld" style="width:800px;z-index:22;">
  <div class="flt"><div class="bnc" onClick="fio('Fu',-1,'Fo,Fi');">×</div><div style="float:right;font-size:14px;"><input type="text" id="Fu_n"> <span class="bn1" onClick="nvu(1);">查 找</span> <span class="bn1" onClick="nue(-1);">新 增</span>&nbsp;</div>会员管理</div>
  <div class="flb">
    <div class="nu0"><div class="nu1">卡号</div><div class="nu1">名称</div><div class="nu1">余额</div><div class="nu1">消费</div><div class="nu1">额度</div></div>
    <div id="Fu_l" style="height:400px;overflow:auto;"></div>
  </div>
</div>
<div id="Fo" class="fld" style="z-index:23;">
  <div class="flt"><div class="bnc" onClick="fio('Fo',-1);Fi.style.display='none';">×</div>添加/编辑会员<input type="hidden" id="Fo_i"></div>
  <div class="flb">会员卡号： <input type="text" style="width:200px;" id="Fo_c"><br>会员名称： <input type="text" style="width:200px;" id="Fo_n"><br>登录密码： <input type="password" style="width:200px;" id="Fo_p"><br>注册时间： <font id="Fo_d"></font><br>帐户余额： <span id="Fo_s" style="font-size:18px;width:100px;display:inline-block;text-align:right;"></span> 元　<span class="bn1" onClick="nus();">充 值</span><br>信用额度： <span id="Fo_e" style="font-size:18px;width:100px;display:inline-block;text-align:right;"></span> 元<br>消费金额： <span id="Fo_x" style="font-size:18px;width:100px;display:inline-block;text-align:right;"></span> 元　<span class="bn0" onClick="window.open('output.php?x=ucl&n='+nid+'&u='+uid+'&s='+vid+'&a='+Fo_c.value);">记 录</span></span><br>最后消费： <font id="Fo_t"></font></div>
  <div class="flk"><span class="bn0" onClick="nud();">删 除</span><span class="bn1" onClick="nuv();">保 存</span></div>
</div>
<div id="Fi" class="fld" style="z-index:24;">
  <div class="flt"><div class="bnc" onClick="fio('Fi',-1);">×</div>会员充值<input type="hidden" id="Fi_i"></div>
  <div class="flb">充值卡号： <span id="Fi_c"></span><br>支付金额： <input type="text" size="6" id="Fi_m" onBlur="num(2);"> 元<br>充值金额： <input type="text" size="6" id="Fi_n" onBlur="num(2);"> 元</div>
  <div class="flk"><div id="Fi_p" style="float:left;display:none;"><span class="btn" onClick="if(!prt()){alt('打印服务器参数设置错误！');}else pre(Sc.p[3]+'|spc|'+Fi_i.value+'|'+Sc.p[5]);">打 单</span></div><div id="Fi_b" style="float:right;display:none;"><span class="btn" onClick="nuc();">充 值</span></div></div>
</div>
<!--统计层-->
<div id="Fr" class="fld" style="z-index:22;">
  <div class="flt"><div class="bnc" onClick="fio('Fr',-1,1);">×</div>统计报表</div>
  <div class="flb">
    选择日期： <input type="date" id="C1" style="width:132px;" placeholddr="yyyy-mm-dd"> - <input type="date" style="width:132px;" id="C2" placeholddr="yyyy-mm-dd"> <a href="javascript:void(0);" onClick="nvc(1);">日报</a> <a href="javascript:void(0);" onClick="nvc(7);">周报</a> <a href="javascript:void(0);" onClick="nvc(30);">月报</a> <a href="javascript:void(0);" onClick="nvc(365);">年报</a>　<span class="bn1" onClick="nct();">统 计</span>　<span class="bn0" onClick="window.open('output.php?x=rpt&n='+nid+'&u='+uid+'&s='+vid+'&a='+C1.value+'&b='+C2.value);">详 单</span><br>
    <div class="ct0"><div class="ct1">营业金额：</div><div class="ct2" id="C_Pm">0</div><div class="ct1">实收金额：</div><div class="ct2" id="C_Ps">0</div></div>
    <div class="ct0"><div class="ct1">优惠金额：</div><div class="ct2" id="C_Pd">0</div><div class="ct1">抵扣金额：</div><div class="ct2" id="C_Pc">0</div></div>
    <div class="ct0"><div class="ct1">现金收款：</div><div class="ct2" id="C_Mc">0</div><div class="ct1">刷卡收款：</div><div class="ct2" id="C_Md">0</div></div>
    <div class="ct0"><div class="ct1">微信支付：</div><div class="ct2" id="C_Mw">0</div><div class="ct1">　支付宝：</div><div class="ct2" id="C_Mz">0</div></div>
    <div class="ct0"><div class="ct1">会员卡付：</div><div class="ct2" id="C_Mm">0</div><div class="ct1">会员充值：</div><div class="ct2" id="C_Uc">0</div></div>
    <div class="ct0"><div class="ct1">点单数：</div><div class="ct2" id="C_Co">0</div><div class="ct1">退单数：</div><div class="ct2" id="C_Cr">0</div></div>
    <div class="ct0"><div class="ct1">点菜数：</div><div class="ct2" id="C_Cd">0</div><div class="ct1">退单金额：</div><div class="ct2" id="C_Cm">0</div></div>
  </div>
</div>
<!--餐桌详情层-->
<div id="Fc" class="fld" style="width:900px;height:540px;z-index:50;">
  <div class="flt"><div class="bnc" onClick="fio('Fc',-1,'Fs,Fw');">×</div><font id="Fc_t"></font></div>
  <div id="Fc_d" style="height:59px;line-height:59px;margin:0px 10px;font-size:24px;color:#F90;text-align:center;border-bottom:1px dashed #09F;"></div>
  <div style="width:880px;height:340px;padding:0px 10px;line-height:32px;overflow-y:scroll;">
    <div class="nl1"><div class="nl2">菜品</div><div class="nl3">单价</div><div class="nl3">数量</div><div class="nl3">下单</div><div class="nl3">厨师</div><div class="nl3">送餐</div><div class="nl4">状态</div><div class="nl3">退单</div></div>
    <div id="Fc_l"></div>
  </div>
  <div id="Fc_b" style="height:60px;line-height:20px;font-size:14px;margin:0px 10px;"></div>
  <div id="Fc_m" class="flk" style="text-align:center;"><span class="btn" onClick="lsf(Mb.ID);">交 厨</span>　　　　<span class="btn" onClick="djz();">结 账</span>　　　　<span class="btn" onClick="if(Mb.ID*1>0){if(!prt()){alt('打印服务器参数设置错误！');}else{if(Mb.ID*1>0)pre(Sc.p[3]+'|spb|'+Mb.ID+'|'+Sc.p[5]);}}">打 单</span></div>
  <div id="Fc_n" class="flk" style="text-align:center;"><span class="btn" onClick="if(Mb.Os*1>5&&Mb.Os*1!=12){cfm('此单已收，补打小票单？',function(){if(!prt()){alt('打印服务器参数设置错误！');}else{if(Mb.ID*1>0)pre(Sc.p[3]+'|spb|'+Mb.ID+'|'+Sc.p[5]);}});}else lsf(Mb.ID);">收 单</span>　　　　<span class="btn" onClick="if(Mb.Ox*1==2){kwm(Mb.ID);}else ply(Sc.i[11].replace('{{id}}',Mb.ID));">取 餐</span>　　　　<span class="btn" onClick="kxe();">完 成</span></div>
</div>
<!--餐桌结算层-->
<div id="Fs" class="fld" style="width:600px;z-index:51;">
  <div class="flt"><div class="bnc" onClick="fio('Fs',-1);clearTimeout(kid);">×</div>结账</div>
  <div class="flb">
    <div id="Fs_i"></div>
    <div id="Fs_z"></div>
    餐费： <span id="Fs_m"></span>元　优惠： <span id="Fs_d"></span>元　抵扣： <input type="text" id="Fs_c" style="width:60px;" onBlur="num(2);djs();"> 元　已付： <span id="Fs_s"></span>元　应付： <span id="Fs_n"></span>元<br>
    方式： <select id="Fs_t" onChange="djs();"><option value="0">现金支付</option><option value="1">刷卡支付</option><option value="2">微信支付</option><option value="3">支付宝支付</option><option value="4">会员卡支付</option></select>　备注： <input type="text" id="Fs_b" style="width:300px;">
  </div>
  <div class="flk"><span id="Fs_e" class="btn" onClick="if(Fs_n.innerText*1==0){alt('收款成功！');dje(0,Fs_t.value);}else lsc(Mb.ID,1,0);">查询结果</span><span id="Fs_a" class="btn" onClick="dje();">确定结账</span></div>
</div>
<!--外卖层-->
<div id="Fw" class="fld" style="width:480px;height:320px;z-index:56;">
  <div class="flt"><div class="bnc" onClick="fio('Fw',-1);">×</div>外卖送餐跟踪</div>
  <div class="flb" id="Fw_l" style="height:220px;"></div>
  <div class="flk"><div class="fr"><span class="btn" onClick="kwf(Mb.ID);">重 发</span></div></div>
</div>
</body>
</html>
<?php
}
?>