yzms/show/chkserver.php

811 lines
29 KiB
PHP
Raw Normal View History

2024-04-01 15:54:27 +08:00
<?
if($_GET['act'] == 'chkserver') {
echo '{"status":1,"message":"ok","data":[]}';
exit;
}
//取餐客户端程序
require_once(dirname(__FILE__)."/common.php");
$act = trim($_GET['act']);
if(get_magic_quotes_gpc()) {
foreach($_POST as $key => $v) {
if(is_string($v)) $_POST[$key] = stripslashes($v);
}
foreach($_GET as $key => $v) {
if(is_string($v)) $_GET[$key] = stripslashes($v);
}
}
if(!in_array($act,array("sync","chkserver","syncorder","getConsumeList","getPeriodAmount","info"))) {
if($_SERVER["HTTP_GYHFTIPFSDX"]) {
$ip = trim(addslashes(current(explode(',', $_SERVER['HTTP_GYHFTIPFSDX']))));
} else {
$ip = $_SERVER["REMOTE_ADDR"];
}
$request = serialize($_REQUEST);
$now = date('Y-m-d H:i:s');
$sql = "insert into tb_chk_server_log(act,ip,request,record_datetime) values('".$act."','".$ip."','".$request."','".$now."')";
$db->query($sql);
}
switch($act) {
case "chkserver"://检查服务器连接
echoRs(1,"ok");
break;
case "sync": //接收客户端传送过来的数据:
$datas = file_get_contents('php://input');
$datas = json_decode($datas,true);
if(count($datas) < 1) {
echoRs(1,"ok");
2024-04-01 15:54:27 +08:00
exit;
}
$arr = array();
foreach($datas as $data) {
$mac = mysql_real_escape_string($data['mac']);
$dining_hall_id = intval($data['dining_hall_id']);
$channel_id = intval($data['channel_id']);
$type = $data['type'];
$code = mysql_real_escape_string($data['code']);
$recharge_amount = floatval($data['recharge_amount']);
$local_datetime = date("Y-m-d H:i:s",$data['local_datetime'] / 1000);
$local_id = mysql_real_escape_string($data['local_id']);
$order_id = intval($data['order_id']);
$take_food_time = mysql_real_escape_string($data['take_food_time']);
$take_type = mysql_real_escape_string($data['take_type']);
switch($data['local_type']) {
case "pay":
$rs = $db->get_one("select * from tb_recharge_local where local_id = '".$local_id."' and mac = '".$mac."'");
if(!$rs) {
switch($type) {
case "qr":
$type = 6;
break;
case "ic":
$type = "12";
break;
case "face":
$type = "15";
break;
}
$db->query("insert into tb_recharge_local(local_id,dining_hall_id,channel_id,mac,code,type,recharge_amount,local_datetime,record_datetime)
values('".$local_id."','".$dining_hall_id."','".$channel_id."','".$mac."','".$code."','".$type."','".$recharge_amount."','".$local_datetime."',now())
");
$result = 1;
} else {
$result = 2;
}
$arr[] = array(
'type' => 'pay',
'local_id' => $local_id,
'state_id' => $result,
);
break;
case "take":
$rs = $db->get_one("select * from tb_order_local where order_id = ".$order_id." and mac = '".$mac."'");
if(!$rs) {
$db->query("insert into tb_order_local(order_id,dining_hall_id,channel_id,mac,code,take_type,take_food_time,record_datetime)
values(".$order_id.",'".$dining_hall_id."','".$channel_id."','".$mac."','".$code."','".$take_type."','".$take_food_time."',now())
");
//echo "insert into tb_order_local(order_id,dining_hall_id,channel_id,mac,code,take_type,take_food_time,record_datetime)
// values(".$order_id.",'".$dining_hall_id."','".$channel_id."','".$mac."','".$code."','".$take_type."','".$take_food_time."',now())";
$result = 1;
} else {
$result = 2;
}
$arr[] = array(
'type' => 'take',
'order_id' => $order_id,
'state_id' => $result,
);
break;
}
//
}
echoRs(1,"ok",array('data' => $arr));
break;
case "info":
$custid = $_GET['custid'];
$custids = explode("-",$custid);
$company_id = intval($custids[1]);
$where = "";
if(count($custids) == 2) {
$company_id = intval($custids[1]);
$where .= " and company_id = ".$company_id;
}
if(count($custids) >= 3){
$dining_hall_id = intval($custids[2]);
$where .= " and id = ".$dining_hall_id;
$channel_id = intval($custids[3]);
}
$data = $ids = $channels = array();
2024-04-01 15:54:27 +08:00
//查询饭堂
$rs = $db->get_all("select * from tb_dining_hall where enabled = 1 ".$where);
if(empty($rs)){
echoRs(0,"暂没有对应饭堂信息",array('data' => $data));
}
if(count($custids) == 3){
$data['company_id'] = $rs[0]['company_id'];
}
// 取餐机是否展示自动页面
// $data['show_automatic'] = $rs[0]['company_id'] == '4142' ? 1 : 0;
// $data['show_automatic'] = 0;
// 先查看tb_pos_channel.show_automatic再查tb_company.show_automatic
$show_automatic = null;
if(!empty($channel_id)){
$channelInfo = $db->get_one("select * from tb_pos_channel where enabled=1 and id='{$channel_id}'");
if($channelInfo['show_automatic'] !== null && $channelInfo['show_automatic'] !== ''){
$show_automatic = $channelInfo['show_automatic'];
}
}
if($show_automatic === null){
$companyInfo = $db->get_one("select * from tb_company where id='{$company_id}'");
if($companyInfo['show_automatic'] !== null && $companyInfo['show_automatic'] !== ''){
$show_automatic = $companyInfo['show_automatic'];
}
}
$data['show_automatic'] = $show_automatic !== null && $show_automatic !== '' ? $show_automatic : 1;
foreach($rs as $k => $v) {
$data['dining_hall_ids'][] = array(
'id' => $v['id'],
'name' => $v['name'],
'channel_ids' => '',
'pay_values' => $v['pay_values'],
);
$ids[] = $v['id'];
}
//查询消费设备
$rs = $db->get_all("select * from tb_pos_channel where dining_hall_id in (".implode(",",$ids).") and enabled = 1");
//echo "select * from tb_pos_channel where dining_hall_id in (".implode(",",$ids).") and enabled = 1";
foreach($rs as $k => $v) {
$channel_ids[$v['dining_hall_id']][] = array(
'channel_id' => $v['id'],
'channel_name' => $v['channel_name'],
);
}
foreach($data['dining_hall_ids'] as $k => $v) {
$data['dining_hall_ids'][$k]['channel_ids'] = $channel_ids[$v['id']];
}
//$tarr = $data;
//unset($data);
//$data['dining_hall_id'] = $tarr;
//获取刷卡消费间隔 默认20秒
$interval = "20";
$rs = $db->get_one("select * from tb_config where class='IDCARD_ONLINE_TIMEOUT'");
if($rs) $interval = $rs['value'];
$data['ic_interval'] = $interval;
echoRs(1,"ok",array('data' => $data));
break;
case "syncorder":
$channel_id = intval($_POST['channel_id']);
$dining_hall_id = intval($_POST['dining_hall_id']);
$min = intval($_POST['min']);
$max = intval($_POST['max']);
//print_r($_POST);
//查询合符时间的菜谱类型
$time = date("H:i:s");
$date_ids = array();
$rs = $db->get_all("select a.* from tb_meal_type a,tb_meal_type_dining_hall b where a.id = b.meal_type_id and b.dining_hall_id = ".$dining_hall_id);
foreach($rs as $k => $v) {
$hour = substr($v['end_time'],0,2);
$minute = substr($v['end_time'],2,6);
if($hour > 23) {
$dateadd = 1;
$v['end_time'] = ($hour - 24).$minute;
} else {
$dateadd = 0;
}
$date_ids[$v['id']] = array(
'dc_type' => $v['id'],
'dateadd' => $dateadd,
'start_time' => $v['start_time'],
'end_time' => $v['end_time'],
);;
}
$dc_date = date("Y-m-d",time() - 86400);
$where = "";
if($min >= 0 && $max > 0 && $min != $max) {
$where = " and a.id between ".$min." and ".$max;
}
if($min == $max) {
$where = " and a.id > ".$max;
}
$rs = $db->get_all("select a.*,d.dc_date,b.name,d.dc_type,c.username,f.name type_name from tb_order a ,tb_date d,tb_meal_type b,tb_user c,tb_user_type f where a.uid = c.id and a.date_id = d.id and d.dc_type = b.id and c.type_id = f.id and d.dining_hall_id = ".$dining_hall_id.$where." and d.dc_date > '".$dc_date."' and a.state_id in (6) order by a.id asc limit 50");
//echo "select a.*,d.dc_date,b.name,d.dc_type,c.username,c.deptname,c.cellphone,cardno,f.name type_name from tb_order a ,tb_date d,tb_meal_type b,tb_user c,tb_user_type f where a.uid = c.id and a.date_id = d.id and d.dc_type = b.id and c.type_id = f.id and d.dining_hall_id = ".$dining_hall_id.$where." and d.dc_date > '".$dc_date."' and a.state_id in (6) order by a.id asc limit 50";
//exit;
$user_ids = array(0);
$data = array();
$ids = array(0);
foreach($rs as $k => $v) {
if(!$v['take_food_code']) continue;
$end_date = date("Y-m-d",strtotime($v['dc_date']) + 86400 * $date_ids[$v['dc_type']]['dateadd']);
$data[] = array(
'take_food_code' => $v['take_food_code'],
'id' => $v['id'],
'dc_date' => $v['dc_date'],
'date_id' => $v['date_id'],
'meal_name' => $v['name'],
'start_time' => $v['dc_date']." ".$date_ids[$v['dc_type']]['start_time'],
'end_time' => $end_date." ".$date_ids[$v['dc_type']]['end_time'],
'username' => mb_substr($v['username'],0,1,"utf-8")."XXXX",
'cellphone' => '',
'user_type_name' => $v['type_name'],
'deptname' => '',
'cardno' => '',
'user_id' => $v['uid'],
);
$ids[] = $v['id'];
$user_ids[] = $v['uid'];
};
//匹配相关ic卡信息
$idcards = array();
$rs = $db->get_all("select user_id,group_concat(cardno) cardno from tb_user_idcard where user_id in (".implode(",",$user_ids).") and state = 1");
foreach($rs as $k => $v) {
$idcards[$v['user_id']] = $v['cardno'];
}
$faces = array();
$rs = $db->get_all("select user_id,card from tb_user_face where user_id in (".implode(",",$user_ids).")");
foreach($rs as $k => $v) {
$faces[$v['user_id']] = $v['card'];
}
$details = array();
$rs = $db->get_all("select a.dish_id,a.order_id,b.dish_name,a.dish_price,a.dish_amount,c.type_name from tb_order_detail a, tb_dish b,tb_dish_type c where a.dish_id = b.id and b.dish_type = c.id and a.order_id in (".implode(",",$ids).")");
//echo "select a.order_id,b.dish_name,a.dish_price,a.dish_amount,c.type_name from tb_order_detail a, tb_dish b,tb_dish_type c where a.dish_id = b.id and b.type_id = c.id and a.order_id in (".implode(",",$ids).")";exit;
foreach($rs as $k => $v) {
$details[$v['order_id']][] = array(
'dish_id' => $v['dish_id'],
'dish_name' => $v['dish_name'],
'dish_price' => $v['dish_price'],
'dish_amount' => $v['dish_amount'],
'type_name' => $v['type_name'],
);
}
foreach($data as $k => $v) {
$data[$k]['order_detail'] = $details[$v['id']];
$data[$k]['cardno'] = $idcards[$v['user_id']];
$data[$k]['face'] = $faces[$v['user_id']];
}
echoRs(1,"ok",array('data' => $data));
break;
case "income";
$dining_hall_id = intval($_POST['dining_hall_id']);
$channel_id = intval($_POST['channel_id']);
$channel_name = "";
$rs = $db->get_all("select sum(recharge_amount) recharge_amount,channel_id,b.name dining_hall_name,c.channel_name from tb_recharge a,tb_dining_hall b,tb_pos_channel c
where type in (6,12,15) and ftid = ".$dining_hall_id." and a.ftid = b.id and a.channel_id = c.id and record_datetime like '".date("Y-m-d")."%' group by a.channel_id
");
$income = $channel_income = 0;
foreach($rs as $k => $v) {
$income += abs(floatval($v['recharge_amount']));
$dining_hall_name = $v['dining_hall_name'];
if($channel_id == $v['channel_id']) {
$channel_income = abs(floatval($v['recharge_amount']));
$channel_name = $v['channel_name'];
}
}
if(!$channel_name && $channel_id) {
$rs = $db->get_one("select * from tb_pos_channel where id = ".$channel_id);
$channel_name = $rs['channel_name'];
}
$income = number_format($income,2,".","");
$channel_income = number_format($channel_income,2,".","");
$result = array(
'dining_hall_name' => $dining_hall_name,
'income' => $income,
'channel_name' => $channel_name,
'channel_income' => $channel_income,
'date' => date("Y-m-d"),
);
echoRs(1,"ok",array('data' => $result));
break;
case "icgetcode":
$dining_hall_id = intval($_POST['dining_hall_id']);
$cardno = htmlentities($_POST['cardno']);
$now = date("Y-m-d H:i:00");
$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='{$cardno}' and a.enabled in (1,-1) and b.state=1");
//echo "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='{$cardno}' and a.enabled not in (0, -99) and b.state=1";
if(!$uInfo) {
echoRs(0, '无效ic卡');
exit;
}
$GLOBALS['is_meal_to_time'] = 0;
$take_codes = get_take_info($dining_hall_id, $uInfo['id']);
$info = array('user' => array());
$info['take_code'] = "";
if($take_codes) $info['take_code'] = implode(",", $take_codes);
$is_meal_time = 0; // 到了取餐时间
if(empty($take_codes)){
// 获取今天是否有餐,而没到时间
$is_meal_time = $GLOBALS['is_meal_to_time'];
}else{
$is_meal_time = 1;
}
$info['is_meal_type'] = $is_meal_time;
$res['status'] = 1;
$res['message'] = 'ok';
$res['data'] = $info;
echo json_encode($res);
exit;
// echoRs(1, 'ok', array('data' => $info));
2024-04-01 15:54:27 +08:00
//列出订单详情
2024-04-01 15:54:27 +08:00
break;
case "facegetcode":
$facecard = trim($_POST['facecard']);
$dining_hall_id = trim($_POST['dining_hall_id']);
if(!$facecard || !$dining_hall_id) exit;
$uInfo = $db->get_one("select b.* from tb_user_face a, tb_user b where a.user_id=b.id and b.enabled = '1' and a.card='{$facecard}'");
if(!$uInfo) {
echoRs(0, 'nouser');
}
$GLOBALS['is_meal_to_time'] = 0;
$take_codes = get_take_info($dining_hall_id, $uInfo['id']);
$info = array('user' => array());
$info['take_code'] = "";
if($take_codes) $info['take_code'] = implode(",", $take_codes);
$is_meal_time = 0; // 到了取餐时间
if(empty($take_codes)){
// 获取今天是否有餐,而没到时间
$is_meal_time = $GLOBALS['is_meal_to_time'];
}else{
$is_meal_time = 1;
}
$info['is_meal_type'] = $is_meal_time;
$res['status'] = 1;
$res['message'] = 'ok';
$res['data'] = $info;
echo json_encode($res);
exit;
// echoRs(1, 'ok', array('data' => $info));
break;
case 'getConsumeList':
$channel_id = intval($_POST['channel_id']);
if(empty($channel_id)){
echoRs(0, '参数有误', array());
exit;
}
$chk_server_log_table = $db->get_one("show tables like 'tb_chk_server_log'");
if($chk_server_log_table){
// 同一个机器,不能连续请求
$timestamp = time() - 60;
$before_one_min = date('Y-m-d H:i:s', $timestamp);
$checkRequest = $db->get_one("select * from tb_chk_server_log where act='getConsumeList' and record_datetime>='{$before_one_min}' and channel_id='{$channel_id}'");
if($checkRequest){
echoRs(0, '一分钟内只能查询一次,请刷新或稍后再试', array());
exit;
}else{
if($_SERVER["HTTP_GYHFTIPFSDX"]) {
$ip = trim(addslashes(current(explode(',', $_SERVER['HTTP_GYHFTIPFSDX']))));
} else {
$ip = $_SERVER["REMOTE_ADDR"];
}
$request = serialize($_REQUEST);
$now = date('Y-m-d H:i:s');
$sql = "insert into tb_chk_server_log(act,ip,request,record_datetime,channel_id) values('".$act."','".$ip."','".$request."','".$now."', '".$channel_id."')";
$db->query($sql);
}
}
$all_consume_price = 0;
// 获取今天总的消费额(人脸和刷卡消费)
// $data = $db->get_one("select sum(recharge_amount) all_consume_price from tb_recharge
// where
// channel_id='{$channel_id}' and
// DATE_FORMAT(record_datetime,'%Y-%m-%d')=CURRENT_DATE and
// user_id>0 and
// type in (12,15)");
// DATE_FORMAT(record_datetime,'%Y-%m-%d')=CURRENT_DATE and
// 今天的全部消费记录时间desc
$data = $db->get_all("select
a.id,
b.username,
a.recharge_amount,
a.record_datetime,
case a.type when '12' then '刷卡' when '15' then '人脸' when '6' then '付款码' end as consume_type
from tb_recharge a left join tb_user b on a.user_id=b.id
where
a.channel_id='{$channel_id}' and
record_datetime BETWEEN CURRENT_DATE and DATE_ADD(CURRENT_DATE,INTERVAL 1 day) and
user_id>0 and
type in (6,12,15)
order by record_datetime desc
");
$list = array();
foreach ($data as $k => $v){
$all_consume_price += abs($v['recharge_amount']);
if($k >= 50){
continue;
}
$list[] = $v;
}
foreach ($list as $k => $v){
$list[$k]['username'] = cutName($v['username']);
$list[$k]['recharge_amount'] = abs($v['recharge_amount']);
$list[$k]['record_datetime_short'] = explode(' ', $v['record_datetime'])[1];
}
$res['status'] = 1;
$res['message'] = "获取成功";
$res['data'] = array(
'all_consume_price' => abs($all_consume_price ? $all_consume_price : 0),
'consume_list' => $list
);
echo json_encode($res);
break;
case 'getPeriodAmount':
// 罗定邦竖屏机获取当前时间段的固定消费金额
$channel_id = intval($_POST['channel_id']);
$dining_hall_id = intval($_POST['dining_hall_id']);
if(empty($channel_id) || empty($dining_hall_id)){
echoRs(0, '参数有误', array());
exit;
}
$company = $db->get_one("select * from tb_dining_hall where id='{$dining_hall_id}' and enabled='1'");
if(empty($company)){
echoRs(0, '该饭堂不存在', array());
exit;
}
$company_id = $company['company_id'];
2024-04-01 15:54:27 +08:00
// $new_date = date('Y-m-d H:i:s');
// $new_time = date('H:i:s');
$info = $db->get_one("select * from tb_period_amount where company_id='{$company_id}' and dining_hall_id='{$dining_hall_id}' and channel_id like '%,{$channel_id},%' and (CURTIME() BETWEEN start_time and end_time) and status='1' order by id desc");
if(empty($info)){
echoRs(0, '暂没有可用的固定消费金额', array());
}
$res['status'] = 1;
$res['msg'] = "获取成功";
$res['data'] = array(
'price' => $info['price'],
);
echo json_encode($res);
break;
case "icUserInfo":
$cardno = htmlentities($_POST['cardno']);
$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='{$cardno}' and a.enabled in (1,-1) and b.state=1");
//echo "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='{$cardno}' and a.enabled != 0 and b.state=1";
if(!$uInfo) {
echoRs(0, '无效ic卡');
exit;
}
$info = array();
// 实验中学,增加用户信息(学生卡号,姓名,余额)
// if($UNIQUE_NAME == 'dlsyzx'){
// $ye = $db->get_one("select sum(account) total_account from tb_account where user_id='{$uInfo['id']}' group by user_id");
// $info['user'] = array(
// 'cardNo' => $cardno,
// 'username' => $uInfo['username'],
// 'ye' => $ye['total_account']
// );
// }
echoRs(1, 'ok', array('data' => $info));
break;
case "faceUserInfo":
$facecard = htmlentities($_POST['facecard']);
// $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='{$cardno}' and a.enabled in (1,-1) and b.state=1");
$uInfo = $db->get_one("select a.id,a.username,a.cellphone,a.deptname,a.area_id from tb_user a,tb_user_face b where b.user_id=a.id and b.card='{$facecard}' and a.enabled in (1,-1)");
//echo "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='{$cardno}' and a.enabled != 0 and b.state=1";
if(!$uInfo) {
echoRs(0, '无效人脸');
exit;
}
$info = array();
// 实验中学,增加用户信息(学生卡号,姓名,余额)
// if($UNIQUE_NAME == 'dlsyzx'){
// $ye = $db->get_one("select sum(account) total_account from tb_account where user_id='{$uInfo['id']}' group by user_id");
// $info['user'] = array(
// 'cardNo' => '',
// 'username' => $uInfo['username'],
// 'ye' => $ye['total_account']
// );
// }
echoRs(1, 'ok', array('data' => $info));
break;
case 'getMealOrPay':
$type = $_POST['type'];
$code = $_POST['code'];
$dining_hall_id = intval($_POST['dining_hall_id']);
$channel_id = intval($_POST['channel_id']);
$fee = '0.01';
if(empty($type) || empty($code)){
echoRs(0, '参数有误', array());
}
$host = $_SERVER['HTTP_HOST'];
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
// 获取 订餐的情况
if($type == 'ic'){
$info = gquery("{$protocol}{$host}/show/chkserver.php?act=icgetcode", array(
'dining_hall_id' => $dining_hall_id,
'cardno' => $code,
));
$info = json_decode($info, 1);
if($info['status'] == 1){
if($info['data']['take_code'] && count($info['data']['take_code']) > 0){
$info['payType'] = 'qc';
echo json_encode($info);
exit;
}
}else{
echo json_encode($info);
exit;
}
}elseif($type == 'face'){
$info = gquery("{$protocol}{$host}/show/chkserver.php?act=facegetcode", array(
'dining_hall_id' => $dining_hall_id,
'facecard' => $code,
));
$info = json_decode($info, 1);
if($info['status'] == 1){
if($info['data']['take_code'] && count($info['data']['take_code']) > 0){
$info['payType'] = 'qc';
echo json_encode($info);
exit;
}
}else{
echo json_encode($info);
exit;
}
}elseif($type == 'qr'){
// 判断是否取餐码
$qcRow = $db->get_one("select * from tb_order where take_food_code='{$code}'");
$user_id = 0;
if($qcRow){
// 是取餐码
$user_id = $qcRow['uid'];
$date_id = $qcRow['date_id'];
$take_codes = get_take_info($dining_hall_id,$user_id);
if(in_array($code, $take_codes)){
$info['take_code'] = implode(",", $take_codes);
if($take_codes && count($take_codes) > 0){
echoRs(1, '取餐成功', array('data' => $info, 'payType' => 'qc'));
}else{
echoRs(0, '当前暂无餐可取');
}
}else{
// 没到取餐时间
echoRs(0, '当前暂无餐可取');
}
}
// 不是取餐码,直接往下走 现场支付
// ------------------------------------------------
// // 读取二维码,获取人的信息
$row = $db->get_one("select * from tb_payqr where code = '{$code}'");
// and oid=0 and expire>".time()
if($row){
$user_id = $row['uid'];
if($row['oid'] != 0){
echoRs(0, '付款码已过期或已使用');
}
if(time() > $row['expire']){
echoRs(0, '付款码已过期');
}
$take_codes = get_take_info($dining_hall_id,$user_id);
if(!empty($take_codes) && count($take_codes) > 0){
// 有取餐码
$info['take_code'] = implode(",", $take_codes);
echoRs(1, 'ok', array('data' => $info, 'payType' => 'qc'));
}
}
if($user_id == 0){
echoRs(0, '二维码无效');
}
// if($row) {
// $uid = $row['uid'];
// $row2 = $db->get_one("select * from tb_payqr where uid = {$uid} and oid=0 order by expire desc limit 1");
// if($row['code'] != $row2['code']){
// echoRs(0, 'ok', array());
// };
// }
// $user_id = $row['uid'];
// // 获取用户的取餐信息
// $take_codes = get_take_info($dining_hall_id,$user_id);
// $info = array('user' => array());
// $info['take_code'] = "";
// if($take_codes) {
// $info['take_code'] = implode(",", $take_codes);
// }
// if($take_codes && count($info['take_code']) > 0){
// echoRs(1, 'ok', array('data' => $info));
// exit;
// }
}
// 没有取餐信息,现场支付
$payInfo = gquery("{$protocol}{$host}/api/user/qrpay", array(
'ftid' => $dining_hall_id,
'channelid' => $channel_id,
'fee' => $fee,
'code' => $code,
'type' => $type
));
$payInfo = json_decode($payInfo, 1);
$payInfo['payType'] = 'qrpay';
if(isset($payInfo['data']['name']) && $payInfo['data']['name'] != ''){
$payInfo['data']['name'] = cutName($payInfo['data']['name']);
}
echo json_encode($payInfo);
exit;
break;
case 'getLastMeal':
// 获取最新的菜品数据
$dining_hall_id = intval($_POST['dining_hall_id']);
$channel_id = intval($_POST['channel_id']);
$userid = intval($_POST['user_id']);
$chk_server_log_table = $db->get_one("show tables like 'tb_chk_server_log'");
if($chk_server_log_table){
$REST_MEAL_QUERY_TIME = $db->get_one("select * from tb_config where class='REST_MEAL_QUERY_TIME'");
$REST_MEAL_QUERY_TIME = isset($REST_MEAL_QUERY_TIME['value']) ? $REST_MEAL_QUERY_TIME['value'] : 60;
if($REST_MEAL_QUERY_TIME == 0){
echoRs(-1, '停用实时查询剩余菜品', array());
exit;
}
// 同一个机器,不能连续请求 给2秒延迟
$timestamp = time() - $REST_MEAL_QUERY_TIME + 2 ;
$before_one_min = date('Y-m-d H:i:s', $timestamp);
$checkRequest = $db->get_one("select * from tb_chk_server_log where act='getLastMeal' and record_datetime>='{$before_one_min}' and channel_id='{$channel_id}'");
if($checkRequest){
echoRs(0, $REST_MEAL_QUERY_TIME.'秒内只能查询一次,请刷新或稍后再试', array());
exit;
}else{
if($_SERVER["HTTP_GYHFTIPFSDX"]) {
$ip = trim(addslashes(current(explode(',', $_SERVER['HTTP_GYHFTIPFSDX']))));
} else {
$ip = $_SERVER["REMOTE_ADDR"];
}
$request = serialize($_REQUEST);
$now = date('Y-m-d H:i:s');
$sql = "insert into tb_chk_server_log(act,ip,request,record_datetime,channel_id) values('".$act."','".$ip."','".$request."','".$now."', '".$channel_id."')";
$db->query($sql);
}
}
$GLOBALS['current_date_id'] = 0;
get_take_info($dining_hall_id, $userid);
$date_id = $GLOBALS['current_date_id'];
$sql = "select c.id, c.dish_name, IFNULL(sum(b.dish_amount), 0) rest_num from (select c.id, c.dish_name from tb_dish c, tb_date_dish e where c.id = e.dish_id and e.date_id={$date_id} and c.dish_type not in (" . USER_DISHES_TYPE_OFFICIAL1 . "," . USER_DISHES_TYPE_OFFICIAL2 . ")) c
LEFT JOIN (select b.id, b.dish_id, b.dish_amount from tb_order a, tb_order_detail b where date_id = {$date_id} and a.id = b.order_id and a.state_id=" . ORDER_STATE_ORDERED . " and a.type=" . DISHES_TYPE_COMMON . " ) b
on b.dish_id = c.id
group by c.id";
$rest_info['rest_info'] = $db->get_all($sql);
// 是否开启实时剩余菜品
$REST_MEAL_QUERY_TIME = $db->get_one("select * from tb_config where class='REST_MEAL_QUERY_TIME'");
$rest_info['restMealQueryTime'] = isset($REST_MEAL_QUERY_TIME['value']) ? intval($REST_MEAL_QUERY_TIME['value']) * 1000 : 0;
echoRs(1, '获取成功', array('data' => $rest_info));
break;
}
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');
$GLOBALS['current_date_id'] = $date['id'];
$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) {
$GLOBALS['is_meal_to_time'] = 1;
$GLOBALS['current_date_id'] = $date['id'];
$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;
}
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;
}
?>