<?php
//====== 外卖快餐 ======
require "common.php";
$m=file_get_contents("php://input");if($m=="")$m='{"act":"index"}';$m=Dec($m,true);
if($m["act"]!="index"){$nid=$m["nid"];if(!is_numeric($nid)||$nid*1==0)die('{"msg":"Error Shop ID."}');}
switch($m["act"]){
	case "cfg"://设置
	$p=["msg"=>"ok","St"=>[],"Sb"=>[],"Sd"=>[],"Mo"=>0,"Mc"=>["Mc"=>[]]];
	$q=Qry("Select Tn From ".$pre."table Where Si=".$nid." And Th=0 Order By Tr Asc");
	while($r=Qra($q))$p["St"][]=$r;
	$q=Qry("Select ID,Bn,Bp From ".$pre."class Where Si=".$nid." Order By Br Asc");
	while($r=Qra($q))$p["Sb"][]=$r;
	$q=Qry("Select ID,Dn,Dc,Ds,Di,Dm,Dk From ".$pre."foods Where Dh=0 And Si=".$nid." Order By Dr Asc");
	while($r=Qra($q))$p["Sd"][]=$r;
	$r=Qra(Qry("Select Sn,Sa,Sb,Sc,Sx,Sy,Sh From ".$pre."shop Where Si=".$nid));
	if($r["Sh"]>0)die('{"msg":"该店已暂停歇业！"}');
	$p["Ss"]=["Sn"=>$r["Sn"],"Sa"=>$r["Sa"],"Sb"=>$r["Sb"],"Sx"=>$r["Sx"],"Sy"=>$r["Sy"]];
	$p["Sc"]=Dec($r["Sc"]);
	if($m["sid"]!=""){
		$r=Qra(Qry("Select ID,Ob From ".$pre."order Where Si=".$nid." And Ou='".$m["sid"]."'"));
		if($r){$p["Mo"]=$r["ID"];$p["Mc"]=Dec($r["Ob"]);}
	}
	echo Enc($p);
	break;

	case "kju"://会员
	$p=["msg"=>"ok","Um"=>0,"Us"=>[]];
	$q=Qry("Select Us,Ue From ".$pre."user Where Uc='".$m["Uc"]."' And Up='".md5($m["Up"])."'");
	if(Qrc($q)==0)die('{"msg":"会员卡号或消费密码错误！"}');
	$r=Qra($q);$p["Um"]=$r["Us"]+$r["Ue"];
	$q=Qry("Select ID,Cm,Cn,Cd From ".$pre."coupon Where  Co=0 And Cu='".$m["Uc"]."' And Cd>='".date("Y-m-d")."'");
	while($r=Qra($q))$p["Us"][]=$r;
	echo Enc($p);
	break;

	case "kxe"://预单
	$c=Enc(["Bz"=>$m["Bz"],"Mc"=>$m["Mc"],"Pf"=>$m["Pf"]]);
	$q=Qry("Select ID From ".$pre."order Where Si=".$nid." And Ou='".$m["Ou"]."'");
	if(Qrc($q)==0){
		Qry("Insert Into ".$pre."order (Si,Ot,O1,O4,Ox,Pm,Pd,Pc,Ps,Pt,Os,Od,Oe,Ob,Ou,Oo) Values (".$nid.",0,0,0,".$m["Ox"].",".($m["Pm"]+$m["Pf"]).",".$m["Pd"].",0,0,0,3,Now(),Now(),'".$c."','".$m["Ou"]."','')");
		$d=Qri();
	}else{
		Qry("Update ".$pre."order Set Ob='".$c."',Pm=".($m["Pm"]+$m["Pf"]).",Pd=".$m["Pd"].",Pt=".$m["Pt"].",Od=Now(),Oe=Now(),Ox=".$m["Ox"]." Where Si=".$nid." And Ou='".$m["Ou"]."'");
		$d=Qrs($q);
	}
	$o=$nid."-".$d."-".Rnd(6);
	if($m["Pt"]<4)Qry("Insert Into ".$pre."pay (Mc,Mp,Md,Mt,Nc,Np,Nd,Nt) Values ('".$o."',".($m["Pm"]+$m["Pf"]-$m["Pd"]).",Now(),".(3-$m["Pt"]*1).",'',0,Now(),0)");
	Qry("Update ".$pre."order Set Oo='".$o."' Where ID=".$d);
	echo '{"msg":"ok","oid":'.$d.',"odr":"'.$o.'","key":"'.md5($o.$cfg["Ak"]).'"}';
	break;

	case "kxx"://查询
	$o=Qrs(Qry("Select Oo From ".$pre."order Where ID=".$m["oid"]));
	$r=Qra(Qry("Select Mt,Np,Nc,Nt From ".$pre."pay Where Mc='".$o."'"));
	if($r&&$r["Nt"]==1){
		echo '{"msg":"ok","pay":1,"Np":'.$r["Np"].',"Pt":'.$r["Mt"].',"key":"'.md5($o.$cfg["Ak"]).'"}';
	}else echo '{"msg":"ok","pay":0}';
	break;

	case "kxd"://下单
	$r=Qra(Qry("Select Ps,Os,Ob,Oo,Ox From ".$pre."order Where Si=".$nid." And ID=".$m["oid"]));
	if($r["Ps"]>0||$r["Os"]==12)die('{"msg":"ok"}');
	if(md5($r["Oo"].$cfg["Ak"])!=$m["key"])die('{"msg":"非法提交！"}');
	$d=Dec($r["Ob"]);$h=$d["Bz"];$w=0;$v=$r["Ox"]*1;
	if($m["Pt"]==4){
		$r=Qra(Qry("Select Us,Ue From ".$pre."user Where Uc='".$m["Uc"]."' And Up='".md5($m["Up"])."'"));
		if(!$r)die('{"msg":"会员卡号或消费密码错误！"}');
		$e=Qra(Qry("Select Cm,Cn,Cd From ".$pre."coupon Where Co=0 And Cu='".$m["Uc"]."' ID=".$m["Ci"]));
		if($e){if($e["Cn"]<=$m["Ps"]&&$e["Cd"]>=date("Y-m-d")){$w=$e["Cm"];}else $w=0;}else $w=0;
		$m["Ps"]=$m["Ps"]-$w;if($m["Ps"]<0)$m["Ps"]=0;
		if(($r["Us"]+$r["Ue"])<$m["Ps"])die('{"msg":"会员卡当前余额'.($r["Us"]/100).'元，可用信用额度'.($r["Ue"]/100).'元，不足以支付，请先充值！"}');
		Qry("Update ".$pre."user Set Us=Us-".$m["Ps"].",Ux=Ux+".$m["Ps"].",Ut=Now() Where Uc='".$m["Uc"]."'");
		Qry("Update ".$pre."coupon Set Co=".$m["oid"]." Where ID=".$m["Ci"]);
		Qry("Insert Into ".$pre."expend (Si,Gc,Go,Gu,Gm,Gn,Gd,Ge) Values (".$nid.",'".$m["Uc"]."',".$m["oid"].",'".$nid."-0-".Rnd(6)."',0,-".$m["Ps"].",Now(),0)");
		$c=$cfg["Ac"];
		for($i=count($c)-1;$i>0;$i--){
			if($m["Ps"]<$c[$i][0]*100)continue;
			$d=$c[$i][4]=="0"?(strtotime($c[$i][5])?$c[$i][5]:"2099-12-31"):date("Y-m-d",strtotime("+ ".$c[$i][4]."days"));
			for($j=0;$j<$c[$i][3]*1;$j++)Qry("Insert Into ".$pre."coupon (Cu,Cm,Cn,Cd,Co) Values ('".$m["Uc"]."',".($c[$i][1]*100).",".($c[$i][2]*100).",'".$d."',0);");
			break;
		}
	}
	for($i=0;$i<count($d["Mc"]);$i++){
		$a=$d["Mc"][$i];
		$r=Qra(Qry("Select Dn,Dm,Dt From ".$pre."foods Where Si=".$nid." And ID=".$a[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,".$a[0].",'".$r["Dn"]."',".$r["Dm"].",".$a[1].",3,0,0,0,Now(),0,'".$a[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,".$a[0].",'".$r["Dn"]."',0,".$a[1].",3,0,0,0,Now(),0,'".$a[2]."')");
			$e=explode(",",$r["Dt"]);$b=0;
			$f=$r["Dm"]/Qrs(Qry("Select Sum(Dm) From ".$pre."foods Where Si=".$nid." And ID In (".$r["Dt"].")"));
			for($j=1;$j<count($e);$j++){
				$k=Qra(Qry("Select Dn,Dm,ID From ".$pre."foods Where Si=".$nid." And ID=".$e[$j]));
				$b+=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).",".$a[1].",3,0,0,0,Now(),0,'".$a[2]."')");
			}
			Qry("Update ".$pre."ofood Set Fm=Fm+".($r["Dm"]-$b)." Where Si=".$nid." And ID=".Qri());
		}
	}
	if($d["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,'送餐费',".$d["Pf"].",1,12,0,0,0,Now(),0,'')");
	Qry("Update ".$pre."order Set Ps=".$m["Ps"].",Pc=".$w.",Pd=Pm-Ps-Pc,Pt=".$m["Pt"].",Os=12,Oe=Now(),Ob='".($v==1?($h["bz"]." 店内用餐<br>餐桌：".$h["cz"]):($h["bz"]." 外卖送餐<br>地址：".$h["dz"]."<br>送时：".$h["sj"]))."<br>电话：".$h["dh"]."|".$h["gx"]."|".$h["gy"]."',Ou='".$h["dh"]."' Where Si=".$nid." And ID=".$m["oid"]);
	if($v==2){
		$n=Qra(Qry("Select Sn,Sw From ".$pre."shop Where Si=".$nid));
		$s='{"touser":"'.$n["Sw"].'","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":"'.($m["Ps"]/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);
		$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)."',".$d["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":"'.($d["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 "kmd"://订单
	$p=["msg"=>"ok","Mk"=>[]];
	$q=Qry("Select ID,Pm,Os,Od,Ox From ".$pre."order Where Si=".$nid." And (Ou='".$m["sid"]."' Or Ou='".$m["Ou"]."') Order By ID Desc");
	while($r=Qra($q))$p["Mk"][]=$r;
	echo Enc($p);
	break;

	case "kmi"://详单
	$p=["msg"=>"ok","Mb"=>[],"Md"=>[],"Wm"=>[],"Wn"=>[]];
	$r=Qra(Qry("Select ID,Ox,Pm,Pd,Pc,Ps,Pt,Os,Od,Ob From ".$pre."order Where Si=".$nid." And ID=".$m["oid"]));
	if($r){
		$p["Mb"]=$r;
		if($p["Mb"]["Ox"]==2){
			$p["Wm"]=Qra(Qry("Select Hu,Hc,Hs From ".$pre."osend Where Si=".$nid." And Ho=".$m["oid"]));
			if($p["Wm"]["Hu"]>0)$p["Wn"]=Qra(Qry("Select An,Am From ".$pre."admin Where Si=".$nid." And ID=".$p["Wm"]["Hu"]));
		}
	}else die('{"msg":"无此点单！"}');
	$q=Qry("Select Fn,Fm,Fc,Fr From ".$pre."ofood Where Si=".$nid." And Fo='".$m["oid"]."'");
	while($r=Qra($q))$p["Md"][]=$r;
	echo Enc($p);
	break;

	default:
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=360, initial-scale=1, user-scalable=yes">
<script type="text/javascript">document.write('<meta name="viewport" content="width=360, initial-scale='+parseInt(document.documentElement.clientWidth)/360+', user-scalable=yes">');</script>
<title>外卖点单</title>
<style type="text/css">
<style type="text/css">
html,body {margin:0px;padding:0px;font-size:16px;}
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:16px;resize:none;}
#msk {position:fixed;width:360px;left:0px;top:0px;background-color:#000;opacity:0.2;z-index:9;display:none;}
#tip {position:fixed;max-width:300px;background-color:#000;color:#FFF;padding:5px 10px;z-index:99;display:none;}
#cfn {position:fixed;background-color:#FFF;padding:20px;width:280px;border:1px solid #CCC;line-height:24px;box-shadow:2px 2px 2px #666;display:none;z-index:98;}
.bn0 {display:inline-block;line-height:24px;padding:0px 6px;border:1px solid #CCC;text-align:center;cursor:pointer;}
.bn1 {display:inline-block;line-height:24px;padding:0px 6px;border:1px solid #CCC;background-color:#09F;color:#FFF;text-align:center;cursor:pointer;}
.btn {display:inline-block;line-height:28px;text-align:center;font-size:16px;padding:0px 8px;margin:0px 5px;background-color:#F90;color:#FFF;border-radius:5px;box-shadow:2px 2px 2px #CCC;}
.bnc {float:right;line-height:22px;text-align:center;width:22px;border:1px solid #FFF;color:#FFF;margin:4px 0px;}
.fld {position:absolute;width:320px;left:0px;top:0px;display:none;background-color:#FFF;box-shadow:2px 2px 2px #666;}
.flt {line-height:32px;background-color:#F90;color:#FFF;padding:0px 10px;}
.flk {line-height:32px;background-color:#FEF7E7;text-align:right;padding:0px 10px;}
.flb {padding:10px;line-height:32px;font-size:16px;}
.bl0 {margin:2px 0px 2px 2px;line-height:25px;border:1px solid #F90;text-align:center;background-color:#F90;color:#FFF;border-right:0px;border-top-left-radius:5px;border-bottom-left-radius:5px;}
.bl1 {margin:2px 0px 2px 2px;line-height:25px;border:1px solid #F90;text-align:center;border-right:0px;border-top-left-radius:5px;border-bottom-left-radius:5px;}
.dl0 {margin:4px;padding:4px;background-color:#FFE;border:1px dashed #FDA;line-height:28px;font-size:14px;}
.dl1 {width:256px;height:144px;overflow:hidden;background-image:url(images/none.jpg);}
.dl2 {float:right;font-size:28px;width:28px;height:28px;line-height:28px;text-align:center;background-color:#F90;color:#FFF;}
.dl3 {font-size:24px;color:#F00;}
.sl1 {margin:2px 5px;border-bottom:1px dashed #CCC;line-height:36px;}
.sl2 {display:inline-block;width:234px;}
.sl3 {display:inline-block;width:40px;height:23px;font-size:12px;text-align:right;overflow:hidden;}
.sl4 {display:inline-block;width:16px;line-height:16px;border-radius:3px;background-color:#F90;color:#FFF;text-align:center;margin-left:4px;}
.sl5 {display:inline-block;width:16px;line-height:16px;text-align:center;margin-left:4px;font-size:12px;}
.sl6 {color:#09F;font-size:11px;}
.sl7 {display:inline-block;width:24px;line-height:16px;text-align:right;margin-left:4px;font-size:12px;}
.kw0 {display:inline-block;line-height:24px;border:1px dashed #F90;background-color:#F90;color:#FFF;margin:3px;padding:0px 5px;text-align:center;}
.kw1 {display:inline-block;line-height:24px;border:1px dashed #F90;background-color:#FFFCF9;margin:3px;padding:0px 5px;text-align:center;}
.Do_l {margin:5px 0px;padding:5px 10px;background-color:#FEFAE9;border:1px dashed #F90;font-size:14px;line-height:28px;}
.Do_l span {color:#09F;}
#dzf div {border-bottom:1px dashed #CCC;}
.dcb {float:right;width:24px;line-height:24px;font-size:24px;text-align:center;border:1px solid #F90;border-radius:4px;margin-top:7px;color:#F90;}
.dje {display:inline-block;width:56px;text-align:right;font-size:16px;color:#F00;}
marquee a:link,marquee a:visited {color:#FFF;}
</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);}
//----------------------------------------------------------------
var uri='guest2.php';
var nid='<?php echo Req("i");?>';
var Ck=['空桌待客','顾客入座','顾客呼叫','下单未结','顾客退单','商家退单','商家收单','正在制作','正在制作','正在送餐','订单完成','申请结账','支付完成','订单完成','退单完成'];
var sid=gck('Jir_RandId');if(sid=='')sid=rnd(16);
var mid=gck('Jir_Mobile');
var Sj=[24,0];
var Ss,Sc,Sb,Sd,St,Mc,Ci,Cm,oid,kid;
//布局
var pw,ph;
function rsz(){pw=parseInt(document.documentElement.clientWidth);ph=parseInt(document.documentElement.clientHeight);if(pw>360)pw=360;msk.style.width=pw+'px';msk.style.height=ph+'px';Fi.style.height=ph-20+'px';Fd_l.style.height=ph-172+'px';Do.style.height=ph-50+'px';Do_l.style.height=ph-86+'px';Fo_l.style.height=ph-100+'px';AD.style.top=(ph-480)/2+'px';setTimeout('rsz()',500);}
function jsn(x){return {act:x,nid:nid,rnd:rnd(6)};}
//设置
function cfg(){var p=jsn('cfg');p['sid']=sid;xml(uri,p,function(r){Ss=r.Ss;Sc=r.Sc;Sb=r.Sb;Sd=r.Sd;St=r.St;oid=r.Mo;document.title=Ss.Sn+' - 手机点单';Sn.innerText=Ss.Sn;Sj=('0'+Sc.i[3]+'-0').split('-');Sj[0]=parseInt(Sj[0]);Sj[1]=parseInt(Sj[1]);Sm.innerText=mid==''?'新顾客':mid;Fs_u.value=gck('Jir_MbrUsr');Fs_p.value=gck('Jir_MbrUpw');Fs_a.checked=gck('Jir_MbrAtl')=='1';if(gck('Jir_PayChk')==''){Ab.innerHTML=Sc.i[15].replace(/\&quot;/gi,'"');Aa.style.display=Sc.i[15]==''?'none':'block';AD.innerHTML=Sc.i[16].replace(/\&quot;/gi,'"')+'<div style="font-size:12px;text-align:center;" onclick="AD.style.display=\'none\';">关闭</div>';AD.style.display=Sc.i[16].indexOf(' on ')<0?'none':'block';}Lb_0.style.height=ph-(Sc.i[15]==''?100:124)+'px';Ld.style.height=ph-(Sc.i[15]==''?100:124)+'px';if(gck('Jir_AddFav')==''){Df.style.display='block';sck('Jir_AddFav',1);}oid=r.Mo;Mc=[];for(var i=0;i<r.Mc.Mc.length;i++){for(var j=0;j<Sd.length;j++){if(Sd[j].ID==r.Mc.Mc[i][0]){fce(j,r.Mc.Mc[i][2],r.Mc.Mc[i][1]);break;}}}fcb(0);var c=gck('Jir_PayChk');if(c!='')kxx(c,0);});}
//菜单
function fcb(n){var s='';for(var i=0;i<Sb.length;i++){if(Sb[i].Bp*1==n)s+='<div id="Db_'+Sb[i].ID+'" class="bl0" onClick="fcb('+Sb[i].ID+');">'+Sb[i].Bn+'</div><div id="Lb_'+Sb[i].ID+'" style="margin-left:6px;"></div>';}$('Lb_'+n).innerHTML=$('Lb_'+n).innerHTML==''?s:'';n?fcd(n):fcb(Sb[0].ID);}
//菜类
function fcd(n,m){for(var i=0;i<Sb.length;i++){if($('Db_'+Sb[i].ID))$('Db_'+Sb[i].ID).className='bl0';}$('Db_'+n).className='bl1';var s='';for(var i=0;i<Sd.length;i++){if(Sd[i].Dc.indexOf(','+n+',')>-1)s+='<div class="dl0"><div class="dl1" onclick="fci('+i+');"><img src="images/'+(Sd[i].Di*1==1?(nid+'/c'+Sd[i].ID+'.jpg'):'none.jpg')+'" onload="psz(this,256);"></div>'+Sd[i].Dn+'<br>￥ <span class="dl3">'+Sd[i].Dm/100+'</span><div class="dl2" onclick="fca('+i+');">+</div></div>';}Ld.innerHTML=s;}
//大图
function fci(n){if(Sd[n].Di*1==0)return;fio('Fi',1,1);Fi_t.style.display='block';Fi_t.innerHTML='<span style="font-size:20px;font-weight:bold;">'+Sd[n].Dn+'</span>'+(Sd[n].Ds==''?'':('<br>　　'+Sd[n].Ds));Fi.innerHTML='<img src="images/'+nid+'/c'+Sd[n].ID+'.jpg" onload="bsz(this,300,Fi.style.height);">';}
//点单
function fca(n){if(Sd[n].Dk.split(',').length>1){fws(Sd[n].Dn,-n-1,Sd[n].Dk);}else fce(n,'');}
function fce(n,k,m){var c=0;for(var i=0;i<Mc.length;i++){if(Mc[i][0]==Sd[n].ID&&Mc[i][5]==k){Mc[i][3]++;c=1;}}if(!c)Mc.push([Sd[n].ID,Sd[n].Dn,Sd[n].Dm,m||1,Sd[n].Di,k]);var c=0;var s=0;for(var i=0;i<Mc.length;i++){s+=Mc[i][2]*Mc[i][3];c+=Mc[i][3]*1;}fds();}
//点单口味
function fws(o,n,w){var k;if(n>-1){var m=Mc[n][0];for(var i=0;i<Sd.length;i++){if(m*1==Sd[i].ID*1)k=Sd[i].Dk;}if(!k)return;}else k=w;var s='';var t=k.split(',');for(var j=0;j<t.length;j++)s+='<span class="kw'+((','+Mc[n]).indexOf(','+t[j]+',')>-1?0:1)+'" onclick="fwc(this);">'+t[j]+'</span>';Fk_s.innerHTML=s;Fk_i.value=n;Fk_w.value=n<0?'':Mc[n][5];Fk_n.innerText=o;fio('Fk',1,1);}
//口味选择
function fwc(o){if(o.className=='kw1'){o.className='kw0';Fk_w.value+=(o.innerText+',');}else{o.className='kw1';Fk_w.value=(','+Fk_w.value).replace(','+o.innerText+',',',').substr(1);}}
//已点
function fds(n){var s='';for(var i=0;i<Mc.length;i++)s+='<div class="sl1"><span class="sl2">'+Mc[i][1]+'<span class="sl6" onclick="fws(\''+Mc[i][1]+'\','+i+');">['+(Mc[i][5]==''?'口味':Mc[i][5].substr(0,Mc[i][5].length-1))+']</span></span><span class="sl3">'+Mc[i][2]/100+'元</span><span class="sl4" onclick="fdc('+i+',-1,'+Mc[i][0]+',\''+Mc[i][5]+'\');">-</span><span id="Fd_c'+i+'" class="sl5">'+Mc[i][3]+'</span><span class="sl4" onclick="fdc('+i+',1,'+Mc[i][0]+',\''+Mc[i][5]+'\');">+</span></div>';Fd_l.innerHTML=s;var c=0;var s=0;for(var i=0;i<Mc.length;i++){s+=Mc[i][2]*Mc[i][3];c+=Mc[i][3]*1;}Dm.innerText=s/100;Dn.innerText=c;if(n){if(Mc.length==0){fio('Fd',-1);sck('Jir_PreOdr','');}else fio('Fd',1);}}
//数量
function fdc(o,n,r,k){var m=$('Fd_c'+o).innerText*1;m+=n;$('Fd_c'+o).innerText=m;Mc[o][3]=m;if(m==0){for(var i=0;i<Mc.length;i++){if(Mc[i][0]*1==r*1&&Mc[i][5]==k)Mc.splice(i,1);}}fds(1);}
//订单
function kxc(n){fio('Fs',1,1);var s='';for(var i=0;i<St.length;i++)s+='<option>'+St[i].Tn+'</option>';Fs_i.innerHTML='餐厅地址： '+Ss.Sa+'['+Ss.Sb+']'+'<br>选择餐桌： <select id="Fs_k"><option>无餐桌</option><option>打包外带</option>'+s+'</select>';$('Fs_'+n).className='kw0';$('Fs_'+(1-n)).className='kw1';Fs_i.style.display=n==0?'block':'none';Fs_o.style.display=n==1?'block':'none';Fs_m.innerText=Dm.innerText;var d=new Date();if(n){if(Dm.innerText*1<Sc.i[8]*1){alt('外卖订单起送金额为'+Sc.i[8]+'元！');kxc(0);return;}if(Sj[0]>=24){alt('抱歉，餐厅暂停外卖服务，请至店内就餐！');kxc(0);return;}var m=d.getHours();if(m<Sj[0]||m>=Sj[1]){alt('抱歉，外卖配送时间为 '+Sj[0]+'-'+Sj[1]+' 点\n欢迎明天再来：）');kxc(0);return;}}var s='';var t=d.getTime()+600000;d.setTime(t);while(d.getMinutes()%5!=0){t+=60000;d.setTime(t);}for(var i=0;i<33;i++){d.setTime(t);if(d.getHours()<Sj[1]&&d.getHours()>=Sj[0])s+='<option>'+d.getHours()+'时'+('0'+d.getMinutes()).substr(-2,2)+'分'+'</option>';t+=300000;}Fs_c.innerHTML=s;Fs_f.innerText=Sc.i[6];Fs_e.innerText=Sc.i[9];Fs_v.value=mid;Ci=0;Cm=0;n?gee():kxs();}
//折扣
function kxs(){Fs_h.style.display='none';Fs_b.style.display='none';var e=Fs_0.className=='kw0'?0:1;var n=Fs_t.value*1;var m=Fs_m.innerText*100;var c=e?(m>=Sc.i[9]*100?0:Fs_f.innerText*100):0;var d=Math.round(m-m*Sc.c[0][n]);Fs_n.innerText=c/100;Fs_d.innerText=d/100;Fs_s.innerText=(m+c-d)/100;if(n==4)kju();}
//会员
function kju(n){Fs_h.style.display='none';Fs_b.style.display='block';Ci=0;Cm=0;var p=jsn('kju');p.Uc=Fs_u.value;p.Up=Fs_p.value;if(p.Up=='')return;xml(uri,p,function(r){if(Fs_a.checked){sck('Jir_MbrUsr',Fs_u.value);sck('Jir_MbrUpw',Fs_p.value);sck('Jir_MbrAtl','1');}var s='';for(var i=0;i<r.Us.length;i++)s+='<br><span><input type="radio" name="Fs_c"'+((Fs_m.innerText*100>=r.Us[i].Cn)?'':' disabled')+' onclick="Ci='+r.Us[i].ID+';Cm='+r.Us[i].Cm+';"> '+(r.Us[i].Cm/100)+'元 [满'+(r.Us[i].Cn/100)+'元可用，有效期至：'+r.Us[i].Cd+']</span>';Fs_b.style.display='none';Fs_h.style.display='block';Fs_h.innerHTML='卡号：'+Fs_u.value+'　额度：'+(r.Um/100)+'元　[<a href="javascript:void(0);" onclick="sck(\'Jir_MbrUpw\',\'\');Fs_p.value=\'\';Fs_h.style.display=\'none\';Fs_b.style.display=\'block\';Ci=0;Cm=0;">退出</a>]'+s;});}
//预单
function kxe(){if(Mc.length==0)return;if(Fs_0.className=='kw1'&&!rdy){alt('请标注外卖送餐地址！');return;}if(Fs_v.value.replace(/\s/gi,'').length!=11){alt('请输入有效电话号码！');return;}var t=[];for(var i=0;i<Mc.length;i++)t[i]=[Mc[i][0],Mc[i][3],Mc[i][5]];var p=jsn('kxe');p.Ou=sid;p.Ox=Fs_0.className=='kw0'?1:2;p.Mc=t;p.Pm=Fs_m.innerText*100;p.Pf=Fs_n.innerText*100;p.Pd=Fs_d.innerText*100;p.Pt=Fs_t.value*1;p.Bz={bz:Fd_b.value,cz:Fs_k.value,dh:Fs_v.value,dz:Fs_r.value.replace(/\s/gi,''),sj:Fs_c.value,gx:cx,gy:cy,fn:Ss.Sn,fd:Ss.Sa,fx:Ss.Sx,fy:Ss.Sy};xml(uri,p,function(r){sck('Jir_PreMob',Fs_v.value);sck('Jir_RandId',sid);if(Fs_t.value*1<4){sck('Jir_PayChk',r.oid);window.location='mobile.php?o='+r.odr+'&r=guest2%2Ephp%3Fi%3D'+nid;}else kxd(r.oid,Fs_s.innerText*100,4,r.key);});}
//下单
function kxd(o,m,n,k){var p=jsn('kxd');p.oid=o;p.Ps=m;p.Pt=n;p.Uc=Fs_u.value;p.Up=Fs_p.value;p.Ci=Ci;p.key=k;xml(uri,p,function(r){alt('下单完成，正在等待商家收单，请稍候...');sck('Jir_PayChk','');sck('Jir_RandId','');mid=gck('Jir_PreMob');sck('Jir_Mobile',mid);sid=rnd(16);Mc=[];Dm.innerText=0;Dn.innerText=0;Fd_b.value='';fio('Fs',-1,'Fd');setTimeout('kmd()',3000);});}
//查询
function kxx(n,c){clearTimeout(kid);c=c||1;fio('Fc',1,1);Fc_t.innerText='正在查询支付结果并同步数据，请稍候......';var p=jsn('kxx');p.oid=n;xml(uri,p,function(r){if(r.pay==1){Fc_t.innerText='支付成功，正在提交点单，请稍候...';setTimeout('fio(\'Fc\',-1,1)',500);kxd(n,r.Np,3-r.Pt,r.key);}else{if(c<5){c++;kid=setTimeout('kxx('+n+','+c+')',5000);}else Fc_t.innerText='未查询到该单支付记录，如未支付请重新下单！';}});}
//订单
function kmd(){if(mid=='')return;Do.style.display='block';Sm.innerText=mid;Do_l.innerHTML='Loading......';var p=jsn('kmd');p.sid=sid;p['Ou']=mid;xml(uri,p,function(r){var t=r.Mk;var s='';for(var i=0;i<t.length;i++){s+='<div class="Do_l" onClick="kmi('+t[i].ID+','+t[i].Os+')">单号：'+t[i].ID+'　金额：'+(t[i].Pm/100)+'　状态：'+Ck[t[i].Os]+'<br>类型：'+['正餐','快餐','外卖'][t[i].Ox]+'　时间：'+t[i].Od+'</div>';}Do_l.innerHTML=s==''?'您没有在该餐厅的点单':s;});}
//详单
function kmi(n,m){if(m==3){cfm('该单尚无支付结果信息，您如已支付，请点击[确定]查询支付结果，如未支付，请点击[取消]重新下单支付！',function(){kxx(n,0);},function(){Do.style.display='none';fds(1);});return;}var p=jsn('kmi');p.oid=n;xml(uri,p,function(r){var b=r.Mb;var d=r.Md;var s='';for(var i=0;i<d.length;i++){s+='<div class="sl1">'+d[i].Fn+(d[i].Fr*1==2?'[已退]':'')+'<div style="float:right;"><div class="sl7">'+(d[i].Fm/100)+'</div><div class="sl7">×'+d[i].Fc+'</div></div></div>';}Fo_i.innerText=b.ID;Fo_l.innerHTML=s+'时间：'+b.Od+'　状态：'+Ck[b.Os]+'<br>合计（含送餐费）：'+(b.Pm/100)+'元　优惠：'+(b.Pd/100)+'元<br>抵扣：'+(b.Pc/100)+'元　实付：'+(b.Ps/100)+'元['+['现金','刷卡','微信','支付宝','会员卡'][b.Pt]+'支付]<br>备注：'+b.Ob.split('|')[0]+(b.Ox*1==2?('<br><br><strong>外卖送餐跟踪</strong>　状态：'+['待接单','待取餐','派送中','已送达','已送达'][r.Wm.Hs]+'<br>骑手：'+(r.Wm.Hu*1==0?'无':(r.Wn.An+' [<a href="tel:'+r.Wn.An+'">'+r.Wn.Am+'</a>]'))+'<br>'+r.Wm.Hc):'');fio('Fo',1,1);});}
</script>
</head>
<body onLoad="rsz();cfg();">
<div id="msk"></div><div id="tip"></div><div id="cfn"></div>
<div id="Df" style="position:absolute;top:0px;left:0px;z-index:40;display:none;" onClick="Df.style.display='none';"><img src="images/favi.png"></div>
<!--顶部-->
<div style="position:absolute;z-index:1;top:0px;left:0px;width:360px;height:50px;background-color:#666;">
  <div style="float:left;margin:3px;width:44px;height:44px;"><img src="images/icon.png" width="44" height="44"></div>
  <div style="float:left;color:#FFF;font-size:18px;line-height:20px;margin-top:6px;"><span id="Sn"></span><br><span id="Sm" style="font-size:14px;color:#F90;" onClick="if(this.innerText!='新顾客'){cfm('是否确认清除系统cookie记录的电话信息？\n注意：清除后无法查询我的订单，只有通过再次买单后方可再次保存电话信息！',function(){sck('Jir_Mobile','');location.reload();});}"></span></div>
  <div style="float:right;width:86px;line-height:30px;text-align:center;margin:10px 5px;background-color:#F90;color:#FFF;" onClick="kmd();">我的点单</div>
  <div style="float:right;width:45px;line-height:30px;text-align:center;margin:10px 5px;background-color:#F90;color:#FFF;" onClick="window.location='weixin.php';">会员</div>
</div>
<!--底部-->
<div style="position:absolute;z-index:2;bottom:0px;left:0px;line-height:50px;width:360px;height:50px;font-size:18px;color:#FFF;background-color:#333;clear:both;">
  <div style="float:left;width:50px;height:50px;background-image:url(images/cart.png);line-height:18px;margin-right:10px;" onClick="fds();"><span id="Dn" style="font-size:12px;display:inline-block;background-color:#F90;color:#FFF;height:18px;width:18px;text-align:center;margin:3px;border-radius:3px;">0</span></div>
  <div style="float:right;width:90px;background-color:#F90;color:#FFF;text-align:center;font-size:24px;" onClick="if(Mc.length>0||oid){if(Fd.style.display=='none'){fds(1);}else{if(Mc.length>0)kxc(0);}}">下 单</div><span id="Dm" style="font-size:32px;color:#F90;">0</span> 元
</div>
<!--菜单-->
<div style="position:absolute;z-index:3;top:50px;left:0px;width:360px;">
  <div id="Aa" style="width:360px;height:24px;background-color:#F90;color:#FFF;top:50px;border-radius:12px;display:none;"><div style="float:right;width:20px;text-align:center;" onClick="Aa.style.display='none';Lb_0.style.height=ph-100+'px';Ld.style.height=ph-102+'px';">×</div><marquee style="float:left;width:320px;margin:0px 10px;" id="Ab"></marquee></div>
  <div id="Lb_0" style="float:left;border-right:1px solid #F90;width:85px;overflow:auto;"></div>
  <div id="Ld" style="float:left;width:274px;overflow:auto;">正在加载，请稍候......</div>
</div>
<!--大图-->
<div id="Fi" style="position:absolute;width:340px;left:10px;top:10px;background-color:#FFF;overflow:auto;z-index:11;display:none;" onClick="fio('Fi',-1,'Fi_t');"></div>
<div id="Fi_t" style="position:absolute;width:320px;left:20px;bottom:20px;color:#FFF;z-index:12;display:none;font-size:14px;text-shadow:2px 2px 2px #666;"></div>
<!--口味-->
<div id="Fk" class="fld" style="width:320px;height:212px;z-index:13;">
  <div class="flt"><div class="bnc" onClick="fio('Fk',-1,1);">×</div>选择口味</div>
  <div class="flb" style="height:128px;">菜品： <span id="Fk_n"></span><br><span id="Fk_s"></span></div>
  <div class="flk"><input type="hidden" id="Fk_i"><input type="hidden" id="Fk_w"><span class="btn" onClick="if(Fk_i.value*1>-1){Mc[Fk_i.value][5]=Fk_w.value;fds();}else fce(-1*Fk_i.value-1,Fk_w.value);fio('Fk',-1,1);if(Fd.style.display!='none')fds();">确定</span></div>
</div>
<!--点单-->
<div id="Fd" style="position:absolute;z-index:4;top:55px;left:0px;width:348px;border:1px solid #CCC;background-color:#FFF;display:none;">
  <div style="margin:0px 5px;line-height:39px;border-bottom:1px solid #CCC;text-align:center;font-size:18px;"><div style="float:right;width:20px;line-height:20px;text-align:center;font-size:18px;border:1px solid #999;border-radius:6px;margin-top:8px;color:#999;" onClick="fio('Fd',-1);">×</div>已点餐品</div>
  <div id="Fd_l" style="overflow:auto;"></div>
  <div style="line-height:25px;text-align:center;font-size:12px;">备注：<input type="text" id="Fd_b" style="width:290px;font-size:12px;"></div>
</div>
<!--结算-->
<div id="Fs" class="fld" style="z-index:15;">
  <div class="flt"><div class="bnc" onClick="fio('Fs',-1,1);">×</div>在线支付</div>
  <div class="flb" style="height:400px;overflow:auto;">
    用餐方式： <span id="Fs_0" class="kw0" onClick="kxc(0);">店内用餐</span><span id="Fs_1" class="kw1" onClick="kxc(1);">外卖送餐</span><br>
    <div id="Fs_i"></div>
    <div id="Fs_o">
      送餐费用： <span id="Fs_f"></span>元 <span style="font-size:12px;">[订单满<span id="Fs_e"></span>元免送餐费] [<a href="javascript:void(0);" onClick="alt('外卖送餐资费标准：首'+Sc.i[5]+'公里：'+Sc.i[6]+'元，每公里：'+Sc.i[7]+'元。送餐距离以百度地图路线规划为准计费，送餐费不计算折扣。');">标准</a>]</span><br>
      送餐地址： <a href="javascript:void(0);" onClick="gee();">标注地理位置</a><br>
      <textarea id="Fs_r" style="width:280px;height:40px;"></textarea><br>
      送餐时间： <select id="Fs_c"></select>
    </div>
    您的电话： <input type="number" id="Fs_v" style="width:150px;"><br>
    支付方式： <select id="Fs_t" onChange="kxs();"><option value="2">微信支付</option><option value="3">支付宝支付</option><option value="4">会员卡支付</option></select>
    <div id="Fs_b" style="display:none;">卡号： <input type="text" id="Fs_u" style="width:120px;"> <input type="checkbox" id="Fs_a"> 自动<br>密码： <input type="password" id="Fs_p" style="width:120px;"> <span class="btn" onClick="kju(1);">登录</span></div>
    <div id="Fs_h" style="font-size:12px;display:none;"></div>
    <div>餐费： <span id="Fs_m" class="dje"></span> 元　优惠： <span id="Fs_d" class="dje"></span> 元<br>运费： <span id="Fs_n" class="dje"></span> 元　应付： <span id="Fs_s" class="dje"></span> 元</div>
  </div>
  <div class="flk"><span class="btn" onClick="kxe();">支付并下单</span></div>
</div>
<!--订单-->
<div id="Do" style="position:absolute;z-index:5;top:50px;left:0px;width:360px;background-color:#FFF;display:none;">
  <div style="line-height:36px;margin:0px 10px;"><div class="dcb" onClick="Do.style.display='none';">×</div>我的点单</div>
  <div id="Do_l" style="padding:0px 5px;width:350px;overflow:auto;"></div>
</div>
<!--详单-->
<div id="Fo" class="fld" style="width:348px;z-index:16;">
  <div class="flt"><div class="bnc" onClick="fio('Fo',-1,1);">×</div>点单详情[单号：<span id="Fo_i"></span>]</div>
  <div class="flb" id="Fo_l" style="font-size:14px;overflow:auto;"></div>
</div>
<!--查询-->
<div id="Fc" class="fld" style="width:320px;z-index:17;">
  <div class="flb" id="Fc_t"></div>
  <div class="flk"><span class="btn" onClick="clearTimeout(kid);sck('Jir_PayChk','');fio('Fc',-1,1);">返回</span></div>
</div>
<div id="Fm" class="fld" style="z-index:18;">
  <div class="flt">标注位置 <span style="font-size:12px;">[确定后请完善送餐地址信息]</span></div>
  <div id="MBD" class="flb" style="height:400px;margin:0px;"></div>
  <div class="flk"><span id="Fm_t" style="font-size:12px;float:left;"></span><span class="btn" onClick="if(rdy==0)kxc(0);fio('Fm',-1);">确定</span></div>
</div>
<!--广告-->
<div id="AD" style="position:absolute;width:320px;height:480px;z-index:33;left:20px;background-color:#FFF;display:none;" onClick="AD.style.display='none';"></div>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=p7qaGmr37q4uCgiBShG0tOsI&s=1"></script>
<script type="text/jscript">
var map;var rdy=0;var cx=0;var cy=0;
//获取定位
var gee=function(){Fm_t.innerText='';fio('Fm',1);map=new BMap.Map('MBD');map.enableScrollWheelZoom();map.addEventListener('click',function(e){map.clearOverlays();cx=e.point.lng;cy=e.point.lat;rdy=0;ges();});if(cx==0||cy==0){var geo=new BMap.Geolocation();geo.getCurrentPosition(function(r){if(this.getStatus()==BMAP_STATUS_SUCCESS){var cxy=gez(r.point.lng,r.point.lat);cx=cxy[0];cy=cxy[1];map.centerAndZoom(new BMap.Point(Ss.Sx,Ss.Sy),16);ges();}else{alt('无法获取位置信息，请确认确认您手机已打开定位功能！1');Fs_r.value='';rdy=0;kxc(0);return;}});}else ges();}
//获取路线
var ges=function(){var pnt=new BMap.Point(cx,cy);map.clearOverlays();var wlk=new BMap.WalkingRoute(map,{renderOptions:{map:map,autoViewport:true},onSearchComplete:function(r){if(wlk.getStatus()!=BMAP_STATUS_SUCCESS){alt('无法获取位置信息，请确认确认您手机已打开定位功能！2');Fs_r.value='';rdy=0;kxc(0);return;}var p=r.getPlan(0);var d=p.getDistance(false);if(Sc.i[4]*1000<d*1){alt('当前餐厅设置超过'+Sc.i[4]+'km不接单，您当前位置距离餐厅'+(Math.round(d/100)/10)+'km。\n请确认您所在位置在餐厅派送范围内或选择至店内用餐！');Fs_r.value='';rdy=0;}else{gec(pnt);var t=d;d=Math.ceil(d/1000)-Sc.i[5]*1;d=d<0?0:d;Fs_f.innerText=Sc.i[6]*1+Sc.i[7]*d;Fm_t.innerText='距离：'+(Math.round(t/10)/100)+'km，费用：'+Fs_f.innerText+'元';kxs();rdy=1;}}});wlk.search(new BMap.Point(Ss.Sx,Ss.Sy),pnt);}
//地址转换
var gec=function(pos){var loc=new BMap.Geocoder();loc.getLocation(pos,function(r){if(r){Fs_r.value=r.address;}});}
//支付宝偏移修正
var gez=function(lng,lat){var x_pi=3.14159265358979324*3000.0/180.0;var PI=3.1415926535897932384626;var aa=6378245.0;var ee=0.00669342162296594323;function b2g(lng,lat){var x=lng-0.0065;var y=lat-0.006;var z=Math.sqrt(x*x+y*y)-0.00002*Math.sin(y*x_pi);var v=Math.atan2(y,x)-0.000003*Math.cos(x*x_pi);return[z*Math.cos(v),z*Math.sin(v)];}function g2b(lng,lat){var z=Math.sqrt(lng*lng+lat*lat)+0.00002*Math.sin(lat*x_pi);var v=Math.atan2(lat,lng)+0.000003*Math.cos(lng*x_pi);return[z*Math.cos(v)+0.0065,z*Math.sin(v)+0.006];}function g2w(lng,lat){if((lng<72.004||lng>137.8347)||((lat<0.8293||lat>55.8271)||false)){return [lng,lat];}else{var dlat=tfy(lng-105.0,lat-35.0);var dlng=tfx(lng-105.0,lat-35.0);var radlat=lat/180.0*PI;var magic=Math.sin(radlat);magic=1-ee*magic*magic;var sqrtmagic=Math.sqrt(magic);dlat=(dlat*180.0)/((aa*(1-ee))/(magic*sqrtmagic)*PI);dlng=(dlng*180.0)/(aa/sqrtmagic*Math.cos(radlat)*PI);mglat=lat+dlat;mglng=lng+dlng;return [lng*2-mglng,lat*2-mglat];}}function tfy(lng,lat){var ret=-100.0+2.0*lng+3.0*lat+0.2*lat*lat+0.1*lng*lat+0.2*Math.sqrt(Math.abs(lng));ret+=(20.0*Math.sin(6.0*lng*PI)+20.0*Math.sin(2.0*lng*PI))*2.0/3.0;ret+=(20.0*Math.sin(lat*PI)+40.0*Math.sin(lat/3.0*PI))*2.0/3.0;ret+=(160.0*Math.sin(lat/12.0*PI)+320*Math.sin(lat*PI/30.0))*2.0/3.0;return ret;}function tfx(lng,lat){var ret=300.0+lng+2.0*lat+0.1*lng*lng+0.1*lng*lat+0.1*Math.sqrt(Math.abs(lng));ret+=(20.0*Math.sin(6.0*lng*PI)+20.0*Math.sin(2.0*lng*PI))*2.0/3.0;ret+=(20.0*Math.sin(lng*PI)+40.0*Math.sin(lng/3.0*PI))*2.0/3.0;ret+=(150.0*Math.sin(lng/12.0*PI)+300.0*Math.sin(lng/30.0*PI))*2.0/3.0;return ret;}if(navigator.userAgent.toLowerCase().indexOf('alipay')>0||navigator.userAgent.toLowerCase().indexOf('aliapp')>0){var b=b2g(lng,lat);var c=g2w(b[0],b[1]);return g2b(c[0],c[1]);}else return [lng,lat];}
</script>
</body>
</html>
<?php
}
?>