yzms/show/qc.php

686 lines
21 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?
require_once(dirname(__FILE__)."/common.php");
$act = $_GET['act'];
function get_today_dates($dining_hall_id)
{
global $db;
$data = $db->get_all("select * from tb_date where dining_hall_id={$dining_hall_id} and dc_date = '".date("Y-m-d")."'");
$nowtime = date('H:i');
$all = array();
//foreach($data as $item) {
//
//}
return $data;
}
function get_take_info($dining_hall_id, $userid)
{
global $db;
$today = time();
$dates = get_today_dates($dining_hall_id);
$take_codes = array();
$uInfo = $db->get_one("select * from tb_user where id=".intval($userid));
$user_type = $uInfo['type_id'];
foreach($dates as $date) {
$dc_type = $date['dc_type'];
$meal_info = $db->get_one("select * from tb_meal_type where status=1 and id=".intval($dc_type));
$start_time = $meal_info['start_time'];
$end_time = $meal_info['end_time'];
$nowtime = date('H:i');
$meal_info2 = $db->get_one("select * from tb_meal_type_user_time where meal_type_id={$dc_type} and user_type_id=".intval($user_type));
if($meal_info2) {
$start_time = $meal_info2['start_time'];
$end_time = $meal_info2['end_time'];
}
if( $nowtime >= $start_time && $nowtime < $end_time) {
$order = $db->get_one("select a.* from tb_order a where uid = {$userid} and type=1 and date_id=".$date['id']." and state_id in (6)");
if(!$order) $order = $db->get_one("select a.* from tb_order a where uid = {$userid} and type=1 and date_id=".$date['id']." and state_id in (3)");
if ($order) {
$take_code = $order['take_food_code'];
$take_codes[] = $take_code;
}
}
}
return $take_codes;
}
if($act == 'get_takecode') {
$icid = trim($_POST['icid']);
$ftid = trim($_POST['ftid']);
if(!$icid || !$ftid) exit;
$uInfo = $db->get_one("select a.id,a.username,a.cellphone,a.deptname,a.area_id from tb_user a,tb_user_idcard b where b.user_id=a.id and cardno='{$icid}' and a.enabled not in (0, -99) and b.state=1");
if(!$uInfo) {
echoRs(0, 'nouser');
}
$take_codes = get_take_info($ftid, $uInfo['id']);
$data = array('user' => $uInfo);
if($take_codes) $data['take_code'] = implode(",", $take_codes);
//echoRs(1, 'ok', $info);
//临时录入日志
$db->get_one("insert into tb_icard_record_log(params,record_datetime,result) values('{$icid}',now(),'".$data['take_code']."')");
$info = array(
'status' => 1,
'message' => 'ok'
);
$info = array_merge($info, $data);
$json = json_encode($info);
echo $json;
exit;
}
$ftid = intval($_GET['ftid']);
$channelid = intval($_GET['channelid']);
if(!$ftid) {
die("no ftid!");
}
$ftInfo = $db->get_one("select * from tb_dining_hall where id=".$ftid);
if(!$ftInfo) {
die("no ftid dining_hall!");
}
$company_id = intval($ftInfo['company_id']);
$companyInfo = $db->get_one("select * from tb_company where id=".$company_id);
//传媒集团临时改增加 +号,为免影响其他在用用户,做临时跳转
if($company_id == 34) {
$pay_url = "qc_pay_cm.php";
} else {
$pay_url = "qc_pay.php";
}
$qs = $_SERVER['QUERY_STRING'];
$qs = preg_replace('/&ftid=[^&]+/', '', $qs);
$qs = preg_replace('/ftid=[^&]+(&|$)/', '', $qs);
$qs = preg_replace('/&channelid=[^&]+/', '', $qs);
$qs = preg_replace('/channelid=[^&]+(&|$)/', '', $qs);
$iscomplete = $_GET['iscomplete'];
if(!$iscomplete && !$_GET['code']) {
/*if($ftid >= 1000) {
require_once(dirname(__FILE__)."/common.php");
$row = $db->get_one("select * from tb_goods_place where code = '{$ftid}'");
if(!$row) {
die("ftid err!");
}
if($row['type'] == 1) { //付款码
header("Location: qc_pay.php?".$_SERVER['QUERY_STRING']."&iscomplete=1&notshowbt=1");
exit;
} else if($row['type'] == 2) { //取货
header("Location: qc_mall.php?".$_SERVER['QUERY_STRING']."&iscomplete=1");
exit;
}
}
$time = date("Hi");
if($time >= '0600' && $time <= '0830') { //早餐
header("Location: qc_pay.php?".$_SERVER['QUERY_STRING']."&iscomplete=1");
exit;
}*/
header("Location: ?".$_SERVER['QUERY_STRING']."&iscomplete=1");
exit;
}
//增加判断是否显示取货码入口
$showqh = false;
$rs = $db->get_one("select * from tb_goods_place where code= '".$ftid."_".$channelid."' and enabled = 1");
if($rs) {
$showqh = true;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>取餐</title>
<style type="text/css">
html, body {
border: none;
/*cursor: none;*/
}
<? include("css/normalize.css");?>
</style>
<script type="text/javascript" src="js/func.js"></script>
</head>
<body>
<script type="text/javascript">
var isGetting = false;
function test(code) {
if(code.toLowerCase().indexOf("shift") != -1) return ;
//code = code.replace("Num ", "").replace("num ", "");
if(code.toLowerCase() == 'backspace') code = '[back]';
if(code.toLowerCase() == 'enter') code = '[enter]';
dealKey('2', code);//document.getElementById("div1").innerHTML = code;
//tt += code+"";
}
function fromKeyCode(code) {
if((code >= 48 && code <= 57) || (code >= 65 && code <= 90)) return String.fromCharCode(code);
var keys = {186: ';', 188: ',', 189: '-', 190: '.', 191: '/', 222: "'", 219: '[', 221: ']', 187: '=',
96:'Num 0', 97:'Num 1', 98:'Num 2', 99:'Num 3', 100:'Num 4', 101:'Num 5', 102:'Num 6', 103:'Num 7', 104:'Num 8', 105:'Num 9',
111:'Num /', 106:'Num *', 109:'Num -', 111:'Num /', 107:'Num +',13:'[enter]',8:'[back]',110:'Num .'
//,45:'0', 35:'1', 40:'2', 34:'3', 37:'4', 12:'5', 39:'6', 36:'7', 38:'8', 33:'9'
};
if(keys[code]) return keys[code];
return '*err*';
}
function hashCode(strKey)
{
var hash = 0;
if(strKey != null && strKey != "")
{
for (var i = 0; i < strKey.length; i++)
{
hash = hash * 31 + strKey.charCodeAt(i);
hash = intValue(hash);
}
}
return hash;
}
function intValue(num)
{
var MAX_VALUE = 0x7fffffff;
var MIN_VALUE = -0x80000000;
if(num > MAX_VALUE || num < MIN_VALUE)
{
return num &= 0xFFFFFFFF;
}
return num;
}
document.onkeydown = function() {
var code = event.keyCode; //alert(code+","+fromKeyCode(code));return;
//[st]sduf87fjsdfysd78,526976123;
if(code == 16) return ;
dealKey('1', fromKeyCode(code));//document.getElementById("div1").innerHTML += fromKeyCode(code);
//document.getElementById("div1").innerHTML += fromKeyCode(code)+"|";
}
var maxInputTime = 10;
var kb_status = {'1':'1','2':'1'};
var kb_readStr = {'1':'','2':''};
var kb_timeOut = {'1':'','2':''};
var last1time = 0;
var nowInput = false;
var inputCode = '';
var closeTime = 0;
var closeItv;
var nowInputFrom = '1';
var nowLaseInput = 0;
var lastCloseInput = 0;
var lastInput1 = 0;
var lastSucTime = 0;
var lastErrTime = 0;
var lastddh = '';
var lastdctype = '';
//[st]a7nd823sd,-235435454;
function dealInput(c) {
if(new Date().getTime() - lastInput1 < 50) return ;
lastInput1 = new Date().getTime();
c = c.replace("Num ", "").replace("num ", "");
if(c.toLowerCase() == 'enter') c = '[enter]';
if(c >= '0' && c <= '9') {
inputCode += c;
$("qcm_"+inputCode.length).innerHTML = c;
if(inputCode.length >= 8) {
nowInput = false;
kb_status['1'] = '1';
kb_status['2'] = '1';
getOrderInfo(inputCode, <?=$ftid?>, <?=$channelid?>);
closeInput();
return ;
}
closeTime = maxInputTime;
$("close_time").innerHTML = closeTime;
return ;
} else if(c == '[back]') {
if(inputCode != '') {
$("qcm_"+inputCode.length).innerHTML = '&nbsp;';
inputCode = inputCode.substr(0, inputCode.length-1);
}
return ;
} else if(c == '/' || c == '*' || c == '-' || c == '+' || c == '[enter]' || c == '.'){
closeInput();
return ;
}
//alert(c+","+c.length);
}
function showCloseTime() {
closeTime--;
if(closeTime <= 0) {
closeInput();
return ;
}
$("close_time").innerHTML = closeTime;
}
function startInput() {
nowInput = true;
closeTime = maxInputTime;
$("close_time").innerHTML = maxInputTime;
try{clearInterval(closeItv);}catch(e){}
closeItv = setInterval(showCloseTime, 1000);
showInput();
}
function dealKey(from, c) {
if(isGetting) {
kb_status[from] = '1';
readErr(from, 9);
return ;
}
if(nowInput) {
if(from == nowInputFrom) dealInput(c);
return ;
}
if(from == '1') last1time = new Date().getTime();//alert(from);
if(kb_status[from] == '1') { //开始
<? if($companyInfo['nokeybord'] == 0) { ?>
if(c.substr(0, 4) == 'Num ' && (new Date().getTime() - lastCloseInput > 200)) {
if(from == '1') {
nowInputFrom = '1';
nowLaseInput = new Date().getTime();
startInput();
if(c.match(/^Num \d$/)) dealInput(c);
} else if(from == '2') {
setTimeout(function() {
if(new Date().getTime() - nowLaseInput > 500) {
nowInputFrom = '2';
startInput();
if(c.match(/^Num \d$/)) dealInput(c);
}
}, 200);
}
return ;
}
<? } ?>
if(c == '[') {
kb_timeOut[from] = setTimeout("readErr('"+from+"', 1);", 2000);
kb_status[from] = '2';
} else if(c == ';') { //IC卡
kb_timeOut[from] = setTimeout("readErr('"+from+"', 1);", 2000);
kb_status[from] = '6';
}
else readErr(from, 2);
} else if(kb_status[from] == '2') { //读取s
if(c == 'S') kb_status[from] = '3';
else {
kb_status[from] = '1';
readErr(from, 3);
}
} else if(kb_status[from] == '3') { //读取t
if(c == 'T') kb_status[from] = '4';
else {
kb_status[from] = '1';
readErr(from, 4);
}
} else if(kb_status[from] == '4') { //读取]
if(c == ']') {
kb_status[from] = '5';
kb_readStr[from] = '';
} else {
kb_status[from] = '1';
readErr(from, 5);
}
} else if(kb_status[from] == '5') { //读取内容
if(c == ';') {
try{clearTimeout(kb_timeOut[from]);} catch(e){}
kb_status[from] = '1';
var a = kb_readStr[from].split(",");
if(a.length == 2) {
var s1 = a[0].toLowerCase();
var hcode = a[1];
hcode = hcode.replace("Num ", "");
if(hashCode(s1) == hcode) {
if(from == '1') {
readContent(from, s1, 'qr');
} else {
setTimeout(function() {
if(new Date().getTime() - last1time > 1000) {
readContent(from, s1, 'qr');
}
}, 300);
}
} else {
//alert(s1+","+hcode+","+hashCode(s1));
readErr(from, 6);
}
} else {
readErr(from, 7);
}
kb_readStr[from] = '';
} else {
if(c == '*err*') {
kb_status[from] = '1';
readErr(from, 8);
} else {
kb_readStr[from] += c;
}
}
} else if(kb_status[from] == '6') { //IC卡读取内容
if(c == '/' || c == '[enter]') {
try{clearTimeout(kb_timeOut[from]);} catch(e){}
kb_status[from] = '1';
var s1 = kb_readStr[from].toLowerCase();
if(from == '1') {
readContent(from, s1, 'ic');
} else {
setTimeout(function() {
if(new Date().getTime() - last1time > 1000) {
readContent(from, s1, 'ic');
}
}, 300);
}
kb_readStr[from] = '';
} else {
if(c >= '0' && c <= '9') {
kb_readStr[from] += c;
} else {
kb_status[from] = '1';
readErr(from, 8, 'ic');
}
}
}
//document.getElementById("div1").innerHTML += c+"|"+kb_status[from]+"$";
}
function readErr(from, rs, type) {
kb_status[from] = '1';
kb_readStr[from] = '';
try{clearTimeout(kb_timeOut[from]);} catch(e){}
//alert(from+":读取错误!"+rs);
var tname = '二维码';
if(type && type == 'ic') {
tname = 'IC卡';
}
if(rs != 9 && new Date().getTime() - lastErrTime > 1000 && new Date().getTime() - lastSucTime > 1000) {
/*lastErrTime = new Date().getTime();
lastddh = '';
lastdctype = '';
$("hasDiv").style.display = 'none';
setMsg('<div style="text-align:center;font-size:50px;color:red">无效'+tname+'</div>');*/
}
}
function setMsg(str) {
$("div1").innerHTML = str;
}
function readContent(from, str, type) {
//document.getElementById("div1").innerHTML += from+": "+str + '<br />';
if(lastddh == str && lastdctype != '2' && new Date().getTime() - lastSucTime < 30000) return ;
lastSucTime = new Date().getTime();
if(type && type == 'ic') {
$G.ajax("?act=get_takecode", {"ftid": "<?=$ftid?>", "icid": str}, function(rs) {
if(rs.status == 1) {
//alert(rs.user.username);
var take_code = rs.take_code;
//alert(take_code);return ;
if(take_code && take_code != '') {
readContent('1', take_code);
} else {
flashPage('err');
setMsg('<div style="text-align:center;font-size:50px;padding-top:200px; color:red">'+rs.user.username+', 没有符合的订餐记录!</div>');
}
} else {
if(rs.message == 'nouser') {
setMsg('<div style="text-align:center;font-size:50px;padding-top:200px; color:red">无效ic卡</div>');
}
}
}, 'json', 'POST');
} else {
getOrderInfo(str, <?=$ftid?>, <?=$channelid?>);
}
//alert(str);
//document.getElementById("div1").innerHTML += str;
}
function isnull(s) {
return (typeof(s) == 'undefined');
}
function getOrderInfo(oid, fid, channelid) {
setMsg("正在查询..");
$("hasDiv").style.display = 'none';
isGetting = true;
lastddh = '';
lastdctype = '';
$G.ajax("/api/order/take", {'take_code': oid, 'dining_hall_id': fid, 'channelid': channelid}, function(rs) {
try {
if(isnull(rs) || isnull(rs.status)) {
setMsg('<div style="text-align:center;font-size:50px;padding-top:200px; color:red">系统错误!</div>');
} else if(rs.status == '1') {
if(isnull(rs.data) || isnull(rs.data.list)) {
setMsg('<div style="text-align:center;font-size:50px;padding-top:200px; color:red">未知错误</div>');
} else {
var issg = (rs.data.issg && rs.data.issg==1); //韶关
lastddh = oid;
lastdctype = 1;
var str = '';
var ustr = '';
if(rs.data.user) ustr = '<span style="font-size:30px; color:#666666">'+rs.data.user.deptname+'/'+rs.data.user.username+"/"+rs.data.user.cellphone+'</span>';
str += '<h1 style="font-size:40px">'+(ustr+"<br />")+'</h1>';
var list = rs.data.list;
var dtlist = [];
var color = '';
var reststr = '';
for(var ai = 0; ai < list.length; ai++) {
for(var ai2 = 0; ai2 < list[ai].order_detail.length; ai2++) {
var info = list[ai].order_detail[ai2];
info.meal_name = list[ai].meal_name;
dtlist.push(info);
}
if(!isnull(list[ai].take_status) && list[ai].take_status == 0) {
$("hasDiv").style.display = '';
color = 'color:red;';
}
try {
if(!isnull(list[ai].rest_info)) {
var reststr2 = '';
for(var i in list[ai].rest_info) {
if(reststr2 != '') reststr += '&nbsp;&nbsp;';
var item = list[ai].rest_info[i];
reststr2 += item.dish_name + ':<span style="color:#009900">' + item.rest_num + '</span>';
}
reststr += '<div style="width:90%; text-align:left; margin-top:20px;font-size:25px; line-height:1.8">'+ reststr2 +'</div>';
}
} catch (e){}
}
//str += "取餐类型: "+(rs.data.type=='2'?'<span style="color:blue">工作餐</span>':'普通餐'+"<br />");
str += '<table border="2" width="90%" bgcolor="#ffffff"><tbody><tr><th class="x3">菜品图</th><th class="x2">类型</th><th class="x3">菜名</th>'+(issg?'':'<th class="x2">价格</th>')+'<th class="x2">份数</th></tr>';
var len = dtlist.length;
var height = 120;
if(len > 3) height = 50;
if(len > 6) height = 25;
for(var i = 0; i < len; i++) {
var info = dtlist[i];
//str += '<tr bgcolor="#ffffff"><td width="150">'+info.type_name + '</td><td width="300">' + info.dish_name + '</td><td width="200">' + info.dish_price + '元</td><td width="100">' + info.dish_amount + "</td></tr>"
str += '<tr><td class="x3"><img src="'+info.dish_picture+'" height="'+height+'"></td><td class="x2"><nobr>'+info.meal_name + '</nobr></td><td class="x3">' + info.dish_name + '</td>'+(issg?'':('<td class="x2"><nobr>' + info.dish_price + '元</nobr></td>'))+'<td class="x2"><nobr>' + info.dish_amount + '</nobr></td></tr>';
}
str += '</tbody></table>';
str += reststr;
}
setMsg(str);
flashPage(color==''?'suc':'err');
} else {
if(rs.message) setMsg('<div style="text-align:center;font-size:50px;padding-top:200px; color:red">'+rs.message+'</div>');
else setMsg('<div style="text-align:center;font-size:50px;padding-top:200px; color:red">未知错误</div>');
}
} catch (e){}
isGetting = false;
}, 'json', 'POST');
}
function showInput() {
inputCode = '';
for(var i = 1; i <= 8; i++) {
$("qcm_" + i).innerHTML = '&nbsp;';
}
$G.show_div("fdiv", 500, 150);
}
function closeInput() {
lastCloseInput = new Date().getTime();
try{clearInterval(closeItv);}catch(e){}
nowInput = false;
kb_status['1'] = '1';
kb_status['2'] = '1';
inputCode = '';
for(var i = 1; i <= 8; i++) {
$("qcm_" + i).innerHTML = '&nbsp;';
}
$G.hide_div("fdiv");
}
function playVoice() {
try {
$("voice").URL = "images/di.mp3";
$("voice").controls.play();
} catch (e) {
}
}
var flashN = 0;
var flashColor = 0;
function flashPage(type) {
flashN = 3;
if(type == 'err') flashColor = '#E27A7B';
else flashColor = "#DFEFD9";
doFlashPage();
}
function doFlashPage() {
document.body.style.backgroundColor = flashN%2==0?"#ffffff":flashColor;
flashN--;
if(flashN<0) {
document.body.style.backgroundColor = "#ffffff";
return ;
}
setTimeout(doFlashPage, 100);
}
window.onload = function() {
//读取逻辑等
getRestInfo();
//
//alert(hashCode("80438842"));
//getOrderInfo('72899475', '1');
var width = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;
var owidth = $("qiehuan").offsetWidth;
var oheight = $("qiehuan").offsetHeight;
$("qiehuan").style.top = (height - oheight - 10) + 'px';
$("qiehuan").style.left = (width - owidth - 10) + 'px';
// $("qiehuan2").style.top = (height - oheight - 10 - oheight - 10) + 'px';
//$("qiehuan2").style.left = (width - owidth - 10) + 'px';
//readContent('1', '3084614373', 'ic');
// getRestInfo();
}
function getRestInfo() {
$G.ajax("/api/order/get_rest_info", {'dining_hall_id': '<?=$ftid?>'}, function(rs) {
try{
if(rs.data.rest_info) {
var reststr = '<span style="color:red">剩余数量</span>';
for(var i in rs.data.rest_info) {
if(reststr != '') reststr += '&nbsp;&nbsp;';
var item = rs.data.rest_info[i];
reststr += item.dish_name + ':<span style="color:#009900">' + item.rest_num + '</span>';
}
reststr = '<div style="width:90%; text-align:center; margin-top:20px;font-size:25px; line-height:1.8">'+ reststr +'</div>';
setMsg('<div style="text-align:center;font-size:50px;padding-top:200px">请刷取餐二维码</div>'+reststr);
}
//获取订单情况
<? if($_GET['code']) { ?>
var s = '<?=$_GET['code']?>';//[st]40440368,1620547585;
for(var i = 0; i < s.length; i++) {
dealKey('1', s.substr(i, 1).toUpperCase());
}
<? } ?>
}catch (e) {}
}, 'json', 'POST');
}
</script>
<div id="div1" style="font-size:30px; font-weight:bold; text-align:center">
<div style="text-align:center;font-size:50px;padding-top:200px">请刷取餐二维码</div>
</div>
<div id="hasDiv" style="position:absolute; left:40% ; top:100px; display:none"><img src="images/has.png?r=<?=time()?>" /></div>
<div id="fdiv" style="position:absolute; z-index:15; width:500px; height:150px; display:none; background:#FFF; border:1px solid #dddddd;">
<div style="border-bottom:1px solid #dddddd; height:28px; background:#f5f5f5">
<div style="float:left; padding:5px 5px"><span style="color:#666666">输入取餐码</span></div>
<div style="float:right; padding:5px 5px; font-size:13px; color:#666666"><span id="close_time" style="color:#666666"></span>&nbsp;秒后或按*号关闭</div>
</div>
<div style="height:110px; overflow:hidden;text-align:center">
<div style="border:1px solid #dddddd;width:330px; height:40px; font-size:30px; margin-top:30px; padding:0px">
<div style="border-right:1px solid #dddddd; width:40px; height:40px; float:left;text-align:center" id="qcm_1">&nbsp;</div>
<div style="border-right:1px solid #dddddd; width:40px; height:40px; float:left;text-align:center" id="qcm_2">&nbsp;</div>
<div style="border-right:1px solid #dddddd; width:40px; height:40px; float:left;text-align:center" id="qcm_3">&nbsp;</div>
<div style="border-right:1px solid #dddddd; width:40px; height:40px; float:left;text-align:center" id="qcm_4">&nbsp;</div>
<div style="border-right:1px solid #dddddd; width:40px; height:40px; float:left;text-align:center" id="qcm_5">&nbsp;</div>
<div style="border-right:1px solid #dddddd; width:40px; height:40px; float:left;text-align:center" id="qcm_6">&nbsp;</div>
<div style="border-right:1px solid #dddddd; width:40px; height:40px; float:left;text-align:center" id="qcm_7">&nbsp;</div>
<div style=" width:40px; height:40px; float:left;text-align:center" id="qcm_8">&nbsp;</div>
</div>
</div>
</div><!-- fdiv -->
<div id="msgDiv" style="position:absolute; left:10px ; top:200px;">
</div>
<?if($showqh) {?>
<div id="qiehuan2" style="position:absolute; z-index:4;width:150px; height:60px; top:500px; left:700px"><input type="button" style="width:150px; height:60px;font-size:25px;font-weight:bold;color:blue" value="取货" onclick="location.href = 'qc_mall.php?<?=$qs?>&ftid=<?=$ftid?>_<?=$channelid?>';" /></div>
<?}?>
<div id="qiehuan" style="position:absolute; z-index:4;width:150px; height:60px; top:500px; left:700px"><input type="button" style="width:150px; height:60px;font-size:25px;font-weight:bold;color:blue" value="付款码支付" onclick="location.href = '<?=$pay_url?>?<?=$_SERVER['QUERY_STRING']?>';" /></div>
</body>
</html>