docs: 新增注释

Change-Id: Ia27ac9b49a9b9374cc4ce0a5f41a6fc49927edf5
This commit is contained in:
ui_none 2024-08-14 17:33:38 +08:00
parent f611f52158
commit 305157392e
1 changed files with 318 additions and 283 deletions

View File

@ -2,27 +2,28 @@
// echo "1"; // echo "1";
// exit; // exit;
require_once(dirname(__FILE__)."/common.php"); require_once(dirname(__FILE__) . "/common.php");
// 接收查询参数即URL路径参数后的查询参数params // 接收查询参数即URL路径参数后的查询参数params
$qs = $_SERVER['QUERY_STRING']; $qs = $_SERVER['QUERY_STRING'];
// 读取发送到脚本的数据 // 读取发送到脚本的数据
$json = file_get_contents("php://input"); $json = file_get_contents("php://input");
$post = json_decode($json, true, 512 , JSON_BIGINT_AS_STRING); $post = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);
$serialno = $post['serialno']; $serialno = $post['serialno'];
if(!$serialno) exit; if (!$serialno)
exit;
// 获取数据库表数据POS机设备信息 // 获取数据库表数据POS机设备信息
$deviceInfo = $db->get_one("select * from tb_pos_device where serialno = '".addslashes($serialno)."'"); $deviceInfo = $db->get_one("select * from tb_pos_device where serialno = '" . addslashes($serialno) . "'");
$device_id = intval($deviceInfo['id']); $device_id = intval($deviceInfo['id']);
// 获取远程地址即访问的客户端ip地址 // 获取远程地址即访问的客户端ip地址
$ip = $_SERVER["REMOTE_ADDR"]; $ip = $_SERVER["REMOTE_ADDR"];
$s1 = $json; $s1 = $json;
if(strlen($s1) > 2000) { if (strlen($s1) > 2000) {
$s1 = substr($s1, 0, 2000).'..'; $s1 = substr($s1, 0, 2000) . '..';
} }
// 于请求中获取了serialno、remote_addr信息 // 于请求中获取了serialno、remote_addr信息
@ -32,11 +33,12 @@ if(strlen($s1) > 2000) {
// 插入POS机日志记录 // 插入POS机日志记录
// device_id serialno ip path request response addtime // device_id serialno ip path request response addtime
$db->query("insert into tb_pos_device_log set device_id = {$device_id}, serialno = '".addslashes($serialno)."', ip = '".addslashes($ip)."', path = '".addslashes($qs)."', request = '".addslashes($s1)."', response = '', addtime = now() "); $db->query("insert into tb_pos_device_log set device_id = {$device_id}, serialno = '" . addslashes($serialno) . "', ip = '" . addslashes($ip) . "', path = '" . addslashes($qs) . "', request = '" . addslashes($s1) . "', response = '', addtime = now() ");
// 获取最近一次成功插入的记录的自增id // 获取最近一次成功插入的记录的自增id
$log_id = $db->insert_id(); $log_id = $db->insert_id();
if(!$deviceInfo) { // 如果设备表中没有对应设备的信息,则更新设备记录表并直接返回
$db->query("update tb_pos_device_log set response='no_device' where id=".$log_id); if (!$deviceInfo) {
$db->query("update tb_pos_device_log set response='no_device' where id=" . $log_id);
exit; exit;
} }
@ -46,38 +48,41 @@ $dining_hall_id = intval($deviceInfo['dining_hall_id']);
$channel_id = intval($deviceInfo['channel_id']); $channel_id = intval($deviceInfo['channel_id']);
// md5编码签名 // md5编码签名
$sign2 = md5($post['time'].$post['noncestr'].$deviceInfo['cardpwd']); $sign2 = md5($post['time'] . $post['noncestr'] . $deviceInfo['cardpwd']);
if($sign2 !== $post['sign']) { //签名错误 if ($sign2 !== $post['sign']) { //签名错误
$db->query("update tb_pos_device_log set response='sign_err' where id=".$log_id); $db->query("update tb_pos_device_log set response='sign_err' where id=" . $log_id);
exit; exit;
} }
// 将api和data数据处理编码后插入到tb_pos_device_log表并终止脚本运行 // 将api和data数据处理编码后插入到tb_pos_device_log表并终止脚本运行
// 回应时填充参数、返回的API接口数据、错误提示等。 // 回应时填充参数、返回的API接口数据、错误提示等。
function response_pos($api, $data) { function response_pos($api, $data)
{
global $deviceInfo, $post, $log_id, $db; global $deviceInfo, $post, $log_id, $db;
$noncestr = md5(microtime().'_'.rand()); $noncestr = md5(microtime() . '_' . rand());
$time = time(); $time = time();
$sign = md5($time.$noncestr.$deviceInfo['cardpwd']); $sign = md5($time . $noncestr . $deviceInfo['cardpwd']);
$data['sign'] = $sign; $data['sign'] = $sign;
$data['api'] = $api; $data['api'] = $api;
$data['interval'] = '10000'; $data['interval'] = '10000';
$data['transaction_id'] = $post['transaction_id']?$post['transaction_id']:"100"; $data['transaction_id'] = $post['transaction_id'] ? $post['transaction_id'] : "100";
$json = json_encode($data, JSON_UNESCAPED_UNICODE); $json = json_encode($data, JSON_UNESCAPED_UNICODE);
$db->query("update tb_pos_device_log set response='".addslashes($json)."' where id=".$log_id); $db->query("update tb_pos_device_log set response='" . addslashes($json) . "' where id=" . $log_id);
echo $json; echo $json;
exit; exit;
} }
// 向本机地址发送请求拼接端口号、路径、post参数和header调用自定义gquery函数 // 向本机地址发送请求拼接端口号、路径、post参数和header调用自定义gquery函数
function self_query($path, $post) { function self_query($path, $post)
return gquery("http://127.0.0.1:".$_SERVER['SERVER_PORT'].$path, $post, array('Host: '.$_SERVER['SERVER_NAME'])); {
return gquery("http://127.0.0.1:" . $_SERVER['SERVER_PORT'] . $path, $post, array('Host: ' . $_SERVER['SERVER_NAME']));
} }
// 从post参数中获取pay_mode等参数实时消费接口中使用包括infoquery takemeal takemealok posonline // 从post参数中获取pay_mode等参数实时消费接口中使用包括infoquery takemeal takemealok posonline
function pos_check_user() { function pos_check_user()
{
global $post, $db, $company_id; global $post, $db, $company_id;
$pay_mode = $post['params']['pay_mode']; $pay_mode = $post['params']['pay_mode'];
@ -85,18 +90,21 @@ function pos_check_user() {
// 如果是二维码则检查二维码的字符串是否符合规则并从中截取获得code和哈希 // 如果是二维码则检查二维码的字符串是否符合规则并从中截取获得code和哈希
// 返回code值和type // 返回code值和type
if($pay_mode == '5') { //二维码 if ($pay_mode == '5') { //二维码
$qr_code = trim($post['params']['qr_code']); $qr_code = trim($post['params']['qr_code']);
if(!$qr_code) exit; if (!$qr_code)
exit;
if(substr($qr_code, 0, 4) != '[st]' || substr($qr_code, -1) != ';') exit; if (substr($qr_code, 0, 4) != '[st]' || substr($qr_code, -1) != ';')
exit;
// 截取qr_code截取第4位到倒数第2位字符 // 截取qr_code截取第4位到倒数第2位字符
$s = substr($qr_code, 4, -1); $s = substr($qr_code, 4, -1);
// 将字符串分割成数组 // 将字符串分割成数组
$a = explode(",", $s); $a = explode(",", $s);
if(count($a) != 2) exit; if (count($a) != 2)
exit;
$code = $a[0]; $code = $a[0];
$hash = $a[1]; $hash = $a[1];
@ -106,18 +114,19 @@ function pos_check_user() {
} }
// 搜索父字符串中子字符串的位置如果pay_code中不以ymzs_开头则退出 // 搜索父字符串中子字符串的位置如果pay_code中不以ymzs_开头则退出
if(strpos($pay_code, 'yzms_') !== 0) exit; if (strpos($pay_code, 'yzms_') !== 0)
exit;
$uid = intval(substr($pay_code, 5)); $uid = intval(substr($pay_code, 5));
$uInfo = $db->get_one("select * from tb_user where id = '{$uid}' and enabled != '0' and company_id=".$company_id); $uInfo = $db->get_one("select * from tb_user where id = '{$uid}' and enabled != '0' and company_id=" . $company_id);
if(!$uInfo) { if (!$uInfo) {
$arr = array ( $arr = array(
'result_code' => '2', 'result_code' => '2',
'result_msg' => "err", //10寸屏蔽失败时界面显示此内容result_code=2 'result_msg' => "err", //10寸屏蔽失败时界面显示此内容result_code=2
'tts' => "用户不存在", //语音播报为空时不报TTS语音 'tts' => "用户不存在", //语音播报为空时不报TTS语音
'result' => array (), //服务器返回结果数据,查询信息无 'result' => array(), //服务器返回结果数据,查询信息无
'timeout' => '5', //取餐超时时间,秒为单位,注:特殊修改机型才有此功能 'timeout' => '5', //取餐超时时间,秒为单位,注:特殊修改机型才有此功能
'msg' => array (array ('line' => '用户不存在!',)), 'msg' => array(array('line' => '用户不存在!', )),
); );
response_pos($post['api'], $arr); response_pos($post['api'], $arr);
} }
@ -125,24 +134,24 @@ function pos_check_user() {
} }
// 顶层代码判断qs中参数 // 顶层代码判断qs中参数
if($qs == 'heartbeat' || $qs == 'addperson' || $qs == 'delperson') { //心跳 if ($qs == 'heartbeat' || $qs == 'addperson' || $qs == 'delperson') { //心跳
// 新增人员 // 新增人员
// 设备收到服务器心跳包响应需要执行人员增加之后,向服务器发送设备增加名单完成应答接口 // 设备收到服务器心跳包响应需要执行人员增加之后,向服务器发送设备增加名单完成应答接口
if($qs == 'addperson' && $post['whitelist']) { if ($qs == 'addperson' && $post['whitelist']) {
// 循环遍历人员名单 // 循环遍历人员名单
foreach($post['whitelist'] as $item) { foreach ($post['whitelist'] as $item) {
// 将account_id中的yzms_前缀去掉 // 将account_id中的yzms_前缀去掉
$uid = intval(str_replace('yzms_', '', $item['account_id'])); $uid = intval(str_replace('yzms_', '', $item['account_id']));
// 获取记录 // 获取记录
$rec_id = intval($item['rec_id']); $rec_id = intval($item['rec_id']);
// 更新用户设备表中对应记录rec_id和对应用户uid的状态status=2表示确认增加成功 // 更新用户设备表中对应记录rec_id和对应用户uid的状态status=2表示确认增加成功
$db->query("update tb_pos_device_user set status=2,rs='".$item['result_code']."' where id = '{$rec_id}' and uid = '{$uid}'"); $db->query("update tb_pos_device_user set status=2,rs='" . $item['result_code'] . "' where id = '{$rec_id}' and uid = '{$uid}'");
} }
} }
// 删除人员 // 删除人员
if($qs == 'delperson' && $post['whitelist']) { if ($qs == 'delperson' && $post['whitelist']) {
// 循环遍历人员名单 // 循环遍历人员名单
foreach($post['whitelist'] as $item) { foreach ($post['whitelist'] as $item) {
// 从account_id中去掉yzms_前缀 // 从account_id中去掉yzms_前缀
$uid = intval(str_replace('yzms_', '', $item['account_id'])); $uid = intval(str_replace('yzms_', '', $item['account_id']));
// 获取记录id // 获取记录id
@ -152,14 +161,15 @@ if($qs == 'heartbeat' || $qs == 'addperson' || $qs == 'delperson') { //心跳
} }
// 如果当前查询并非心跳或者当前时间和设备的synctime差超过1分钟则执行 // 如果当前查询并非心跳或者当前时间和设备的synctime差超过1分钟则执行
if($qs != 'heartbeat' || (time() - strtotime($deviceInfo['synctime']) > 60)) { //1分钟检测一次用户同步 if ($qs != 'heartbeat' || (time() - strtotime($deviceInfo['synctime']) > 60)) { //1分钟检测一次用户同步
// 更新posdevice表的同步时间 // 更新posdevice表的同步时间
$db->query("update tb_pos_device set synctime=now() where id = ".$device_id); $db->query("update tb_pos_device set synctime=now() where id = " . $device_id);
// 从tb_user表中获取所有启用且属于公司公司的用户列表 // 从tb_user表中获取所有启用且属于公司公司的用户列表id username cellphonne deptname
$userList_s = $db->get_all("select id, username, cellphone, deptname from tb_user where enabled = '1' and company_id = '{$company_id}'"); $userList_s = $db->get_all("select id, username, cellphone, deptname from tb_user where enabled = '1' and company_id = '{$company_id}'");
// 从tb_pos_device_user表中获取对应用户设备信息 // 从tb_pos_device_user表中获取对应用户设备信息
// 获取指定设备的同步状态
// 新版Android取餐机宇航用于下发人脸、用户信息到Android取餐机用的记录表方便知道每台机现在的同步情况 // 新版Android取餐机宇航用于下发人脸、用户信息到Android取餐机用的记录表方便知道每台机现在的同步情况
$userList_d = $db->get_all("select * from tb_pos_device_user where device_id = '{$device_id}'"); $userList_d = $db->get_all("select * from tb_pos_device_user where device_id = '{$device_id}'");
@ -168,8 +178,9 @@ if($qs == 'heartbeat' || $qs == 'addperson' || $qs == 'delperson') { //心跳
$data = $db->get_all("select a.* from tb_user_face a, tb_user b where a.user_id=b.id and b.company_id = '{$company_id}'"); $data = $db->get_all("select a.* from tb_user_face a, tb_user b where a.user_id=b.id and b.company_id = '{$company_id}'");
$faceInfo = array(); $faceInfo = array();
// 提取上一步得到的关联信息并添加到faceInfo数组中判断此文件是否存在于服务器后台目录存在则将item信息存进dict数据中key是user_idvalue是item // 提取上一步得到的关联信息并添加到faceInfo数组中判断此文件是否存在于服务器后台目录存在则将item信息存进dict数据中key是user_idvalue是item
foreach($data as $item) { foreach ($data as $item) {
if(is_file("../backstage/".$item['path'])) { if (is_file("../backstage/" . $item['path'])) {
// 建立用户id到用户人脸信息的映射 id => faceInfo
$faceInfo[$item['user_id']] = $item; $faceInfo[$item['user_id']] = $item;
} }
} }
@ -178,33 +189,39 @@ if($qs == 'heartbeat' || $qs == 'addperson' || $qs == 'delperson') { //心跳
$data = $db->get_all("select a.* from tb_user_idcard a, tb_user b where a.user_id=b.id and b.company_id = '{$company_id}' and a.state=1 order by a.id"); $data = $db->get_all("select a.* from tb_user_idcard a, tb_user b where a.user_id=b.id and b.company_id = '{$company_id}' and a.state=1 order by a.id");
$cardInfo = array(); $cardInfo = array();
// 提取上一步获取的信息并将数据循环加入到卡信息数组中类似List[Dict]key是user_idvalue是item // 提取上一步获取的信息并将数据循环加入到卡信息数组中类似List[Dict]key是user_idvalue是item
foreach($data as $item) { foreach ($data as $item) {
// 建立用户id到用户卡信息的映射
$cardInfo[$item['user_id']] = $item; $cardInfo[$item['user_id']] = $item;
} }
// 从获取的该公司user_list表信息中循环遍历获取对应用户id的facecode,path,cardno信息添加到userList_s数组中 // 从获取的该公司user_list表信息中循环遍历获取对应用户id的facecode,path,cardno信息添加到userList_s数组中
// 最终facecode,path和cardno作为用户设备需要下发的信息添加到userList_s中 // 最终facecode,path和cardno作为用户设备需要下发的信息添加到userList_s中
foreach($userList_s as $key => $item) { // updateList_s: [[id => 1, name => x, age => 2], ...]
foreach ($userList_s as $key => $item) {
// 更新userList_s给其加上facecode和facepath字段并且加上cardno字段
// 即给对应的用户表查询结果增加facecode facepath cardno
$uid = $item['id']; $uid = $item['id'];
$info1 = $faceInfo[$uid]; $info1 = $faceInfo[$uid];
$userList_s[$key]['facecode'] = $info1['facecode'].''; $userList_s[$key]['facecode'] = $info1['facecode'] . '';
$userList_s[$key]['facepath'] = $info1['path'].''; $userList_s[$key]['facepath'] = $info1['path'] . '';
$info1 = $cardInfo[$uid]; $info1 = $cardInfo[$uid];
$userList_s[$key]['cardno'] = $info1['cardno'].''; $userList_s[$key]['cardno'] = $info1['cardno'] . '';
} }
$sUserInfo = array(); $sUserInfo = array();
// 遍历更新完成的userList_s中数据存入sUserInfo数组中key是用户idvalue是对应的item信息 // 遍历更新完成的userList_s中数据存入sUserInfo数组中key是用户idvalue是对应的item信息
// ["id1" => {xx}, "id2" => {xx}, "id3" => {xx}] // sUserInfo: ["id1" => [id => 1, name => x], "id2" => {xx}, "id3" => {xx}]
foreach($userList_s as $item) { // {"id1": {"id": "1", "name": "2"}, ...}
foreach ($userList_s as $item) {
$sUserInfo[$item['id']] = $item; $sUserInfo[$item['id']] = $item;
} }
$dUserInfo = array(); $dUserInfo = array();
// 遍历获取的tb_pos_device_user表即用户设备表将其数据通过循环变为uid => item数据的数组 // 遍历获取的tb_pos_device_user表即用户设备表将其数据通过循环变为uid => item数据的数组
// 最终得到uid => item信息的数组 // 最终得到uid => item信息的数组
foreach($userList_d as $item) { foreach ($userList_d as $item) {
// dUserInfo: [id1 => [id => 1, name => 2, ...], ...]
$dUserInfo[$item['uid']] = $item; $dUserInfo[$item['uid']] = $item;
} }
@ -216,96 +233,108 @@ if($qs == 'heartbeat' || $qs == 'addperson' || $qs == 'delperson') { //心跳
$addList = array(); //增加列表 $addList = array(); //增加列表
$maxcount = 100; $maxcount = 100;
// 遍历用户表 // 遍历当前公司用户表
foreach($userList_s as $item) { // 其逻辑是:获取当前公司的用户表,然后获取对应设备中的用户列表,对比两张表中获取的数据,如果不同,则将用户添加到添加列表中
// 如果已下发并且距离上次下发时间已超过5分钟也将用户添加到添加列表
// 其实这样做有bug因为这样做设备的用户信息被记录在服务器而不是通过设备自主上传因此服务器并不知道设备实时的人员名单对于初始设备来说没有问题但是如果设备重置过人员名单那么将无法从服务器获取人员名单
foreach ($userList_s as $item) {
// 增加名单有三种情况:
/*
1. 设备用户表中不存在用户表中对应租户部分用户的信息
2. 设备用户表中记录的用户人脸代码等信息和用户表中的人脸代码等信息不一致
3. 设备用户表中状态为已下发但是过了5分钟之后仍未将设备用户表中的信息更新为已确认即未收到已确认的信号
*/
$uid = $item['id']; $uid = $item['id'];
// 设备用户表不存在对应用户的信息 // 设备用户表不存在对应用户的信息
if(!$dUserInfo[$uid]) { if (!$dUserInfo[$uid]) {
// 往数组末尾添加一个item // 往数组末尾添加一个item
$addList[] = $item; $addList[] = $item;
if(count($addList) >= $maxcount) break; //限制一次20个 if (count($addList) >= $maxcount)
break; //限制一次20个
continue; continue;
} }
// 设备表的用户信息 // 设备表的用户信息
$item2 = $dUserInfo[$uid]; $item2 = $dUserInfo[$uid];
// 如果设备用户表的记录和用户表的记录不一致 // 如果设备用户表的记录和用户表的记录不一致
if( if (
($item2['facecode'].'') !== ($item['facecode'].'') ($item2['facecode'] . '') !== ($item['facecode'] . '')
|| ($item2['cardno'].'') !== ($item['cardno'].'') || ($item2['cardno'] . '') !== ($item['cardno'] . '')
|| ($item2['username'].'') !== ($item['name'].'') || ($item2['username'] . '') !== ($item['name'] . '')
|| ($item2['cellphone'].'') !== ($item['cellphone'].'') || ($item2['cellphone'] . '') !== ($item['cellphone'] . '')
|| ($item2['deptname'].'') !== ($item['deptname'].'') || ($item2['deptname'] . '') !== ($item['deptname'] . '')
) { ) {
// 则将item加到addList末尾 // 则将item加到addList末尾
$addList[] = $item; $addList[] = $item;
if(count($addList) >= $maxcount) break; if (count($addList) >= $maxcount)
break;
continue; continue;
} }
// 设备用户表的status为1表示已下发增加但还未收到确认并且距上次下发5分钟后还没收到确认 // 设备用户表的status为1表示已下发增加但还未收到确认并且距上次下发5分钟后还没收到确认
if($item2['status'] == 1 && time()-strtotime($item2['sendtime']) > 300) { //距上次下发5分钟后还没收到确认 if ($item2['status'] == 1 && time() - strtotime($item2['sendtime']) > 300) { //距上次下发5分钟后还没收到确认
// 增加item到addList // 增加item到addList
$addList[] = $item; $addList[] = $item;
if(count($addList) >= $maxcount) break; if (count($addList) >= $maxcount)
break;
continue; continue;
} }
} }
// 增加列表 // 增加列表
if($addList) { if ($addList) {
$whitelist = array(); $whitelist = array();
foreach($addList as $item) { foreach ($addList as $item) {
$uid = $item['id']; $uid = $item['id'];
$face_url = ''; $face_url = '';
// 拼接人脸路径 // 拼接人脸路径
if($item['facepath']) { if ($item['facepath']) {
$face_url = 'https://'.$host.'/backstage/'.$item['facepath']; $face_url = 'https://' . $host . '/backstage/' . $item['facepath'];
} }
// 获取设备用户表中对应设备和对应用户的数据
$row1 = $db->get_one("select * from tb_pos_device_user where device_id = '".addslashes($device_id)."' and uid = '".addslashes($uid)."'"); $row1 = $db->get_one("select * from tb_pos_device_user where device_id = '" . addslashes($device_id) . "' and uid = '" . addslashes($uid) . "'");
// sql拓展字符串 // sql拓展字符串
$sqlext = " name = '".addslashes($item['username'])."', cellphone = '".addslashes($item['cellphone'])."', deptname = '".addslashes($item['deptname'])."', cardno = '".addslashes($item['cardno'])."', facecode = '".addslashes($item['facecode'])."', sendtime = now(), status = 1, rs = '' "; $sqlext = " name = '" . addslashes($item['username']) . "', cellphone = '" . addslashes($item['cellphone']) . "', deptname = '" . addslashes($item['deptname']) . "', cardno = '" . addslashes($item['cardno']) . "', facecode = '" . addslashes($item['facecode']) . "', sendtime = now(), status = 1, rs = '' ";
// 如果用户设备表中没有对应设备id和用户id的数据 // 如果用户设备表中没有对应设备id和用户id的数据,则插入记录,如果有,则更新
if(!$row1) { if (!$row1) {
// 插入记录 // 插入记录
$db->query("insert into tb_pos_device_user set device_id = '".addslashes($device_id)."', uid = '".addslashes($uid)."', {$sqlext}, addtime = now() ", 'SILENT'); $db->query("insert into tb_pos_device_user set device_id = '" . addslashes($device_id) . "', uid = '" . addslashes($uid) . "', {$sqlext}, addtime = now() ", 'SILENT');
$log_id1 = $db->insert_id(); $log_id1 = $db->insert_id();
} else { } else {
// 有则更新 // 有则更新
$db->query("update tb_pos_device_user set {$sqlext} where id=".$row1['id']); $db->query("update tb_pos_device_user set {$sqlext} where id=" . $row1['id']);
$log_id1 = $row1['id']; $log_id1 = $row1['id'];
} }
// 人员名单 // 人员名单
$whitelist[] = array ( $whitelist[] = array(
'rec_id' => $log_id1.'', //可为数据库中的唯一id可以是字符串可以是整数可为空字符 'rec_id' => $log_id1 . '', //可为数据库中的唯一id可以是字符串可以是整数可为空字符
'account_id' => 'yzms_'.$uid, //帐号唯一50个字符必填 'account_id' => 'yzms_' . $uid, //帐号唯一50个字符必填
'emp_id' => 'emp_'.$uid, //工号唯一50个字符必填 'emp_id' => 'emp_' . $uid, //工号唯一50个字符必填
'emp_fname' => $item['username'], //姓名50个字符必填 'emp_fname' => $item['username'], //姓名50个字符必填
'depart_name' => $item['deptname'], //部门50个字符必填 'depart_name' => $item['deptname'], //部门50个字符必填
'job_name' => '', //职务仅10.1寸去向牌门禁机有效 'job_name' => '', //职务仅10.1寸去向牌门禁机有效
'tel' => $item['cellphone'], //电话仅10.1寸去向牌门禁机有效 'tel' => $item['cellphone'], //电话仅10.1寸去向牌门禁机有效
'sex' => '', //性别,可为空字符 'sex' => '', //性别,可为空字符
'birth_date' => '', //出生日期,可为空字符 'birth_date' => '', //出生日期,可为空字符
'valid_date' => '2099-01-01', //有效日期,必填 'valid_date' => '2099-01-01', //有效日期,必填
'level_id' => '1', //级别整数必须是整数必填用不到的话填0 'level_id' => '1', //级别整数必须是整数必填用不到的话填0
'card_sn' => $item['cardno'], //卡序列号整数没有时用空字符注意卡号时前面不能有0 'card_sn' => $item['cardno'], //卡序列号整数没有时用空字符注意卡号时前面不能有0
'door_right' => '', //门权限, 预留,没有时用空字符 'door_right' => '', //门权限, 预留,没有时用空字符
'url' => $face_url, //个人相片的url地址可为空字符表示无相片 'url' => $face_url, //个人相片的url地址可为空字符表示无相片
'groups' => '0', //组别为第3组长整型二进制时从最低位开始为1组0表示无1表示有例如第3组的二进制表示0000100转换为十进制则是4第3组的groups为4必填不需要时填0 'groups' => '0', //组别为第3组长整型二进制时从最低位开始为1组0表示无1表示有例如第3组的二进制表示0000100转换为十进制则是4第3组的groups为4必填不需要时填0
'access_pwd' => '1234', //个人密码整数4位不足补0必填 'access_pwd' => '1234', //个人密码整数4位不足补0必填
'state' => '0', //整数状态0正常 2挂失只有刷卡时才会判断人脸不判断另离线时才判断在线由平台判断为整数不能非整数必填 'state' => '0', //整数状态0正常 2挂失只有刷卡时才会判断人脸不判断另离线时才判断在线由平台判断为整数不能非整数必填
'twins' => '', //注意固定为空!,必填 'twins' => '', //注意固定为空!,必填
'retain_photo' => '0', //整数,下载个人相片处理方式, 仅url为空时才有效 = 0默认删除相片 、 =1保留相片还要识别必填无相片时统一此值用0当url有值时按url的值处理可以固定为0 'retain_photo' => '0', //整数,下载个人相片处理方式, 仅url为空时才有效 = 0默认删除相片 、 =1保留相片还要识别必填无相片时统一此值用0当url有值时按url的值处理可以固定为0
'begin_date' => '2022-04-01 00:00:00',//开始时间 'begin_date' => '2022-04-01 00:00:00',//开始时间
'end_date' => '2099-01-01 23:59:59', //结束时间 'end_date' => '2099-01-01 23:59:59', //结束时间
'time' => array (), 'time' => array(),
); );
} }
$arr = array ( $arr = array(
'whitelist' => $whitelist, 'whitelist' => $whitelist,
); );
// 响应增加人员的api向设备回送数据往设备增加人员信息 // 响应增加人员的api向设备回送数据往设备增加人员信息
@ -319,53 +348,55 @@ if($qs == 'heartbeat' || $qs == 'addperson' || $qs == 'delperson') { //心跳
$delList = array(); //删除列表 $delList = array(); //删除列表
$maxcount = 100; $maxcount = 100;
foreach($userList_d as $item) { foreach ($userList_d as $item) {
$uid = $item['uid']; $uid = $item['uid'];
// status为4表示已下发删除 // status为4表示已下发删除
if($item['status'] == 4) { if ($item['status'] == 4) {
if(time()-strtotime($item['sendtime']) > 300) { //距上次下发删除5分钟后还没收到确认 if (time() - strtotime($item['sendtime']) > 300) { //距上次下发删除5分钟后还没收到确认
// 错误次数小于3 // 错误次数小于3
if($item['err_num'] < 3) { if ($item['err_num'] < 3) {
// 更新用户设备表错误次数 // 更新用户设备表错误次数
$db->query("update tb_pos_device_user set sendtime = now(), status = 4, rs = '',err_num=err_num+1 where id=".$item['id']); $db->query("update tb_pos_device_user set sendtime = now(), status = 4, rs = '',err_num=err_num+1 where id=" . $item['id']);
// 追加删除列表 // 追加删除列表
$delList[] = $item; $delList[] = $item;
if(count($delList) >= $maxcount) break; //限制一次20个 if (count($delList) >= $maxcount)
break; //限制一次20个
} else { } else {
// 错误次数大于等于3直接删除记录 // 错误次数大于等于3直接删除记录
$db->query("delete from tb_pos_device_user where id=".$item['id']); $db->query("delete from tb_pos_device_user where id=" . $item['id']);
} }
} }
continue; continue;
} }
// 不在用户表中添加item到删除列表 // 不在用户表中添加item到删除列表
if(!$sUserInfo[$uid]) { if (!$sUserInfo[$uid]) {
$delList[] = $item; $delList[] = $item;
if(count($delList) >= $maxcount) break; //限制一次20个 if (count($delList) >= $maxcount)
break; //限制一次20个
continue; continue;
} }
} }
// 数据更新完成,开始删除列表 // 数据更新完成,开始删除列表
if($delList) { if ($delList) {
$whitelist = array(); $whitelist = array();
foreach($delList as $item) { foreach ($delList as $item) {
$log_id1 = $item['id']; $log_id1 = $item['id'];
$uid = $item['uid']; $uid = $item['uid'];
$whitelist[] = array ( $whitelist[] = array(
'rec_id' => $log_id1.'', //服务器端数据库的唯一id 'rec_id' => $log_id1 . '', //服务器端数据库的唯一id
'account_id' => 'yzms_'.$uid, //帐号 'account_id' => 'yzms_' . $uid, //帐号
'emp_id' => 'emp_'.$uid, //工号 'emp_id' => 'emp_' . $uid, //工号
'only_del_photo' => '0', //=0删除名单 =1名单不删除只删除个人相片 'only_del_photo' => '0', //=0删除名单 =1名单不删除只删除个人相片
); );
} }
$arr = array ( $arr = array(
'whitelist' => $whitelist, 'whitelist' => $whitelist,
); );
// 删除人员 // 删除人员
@ -377,15 +408,15 @@ if($qs == 'heartbeat' || $qs == 'addperson' || $qs == 'delperson') { //心跳
// 记录 // 记录
$records = $post['records']; $records = $post['records'];
$arr = array ( $arr = array(
'setmname' => '', 'setmname' => '',
); );
// 如果有记录 // 如果有记录
if($records) { if ($records) {
$records2 = array(); $records2 = array();
// 遍历记录并将record的记录变成"id" => realid加入到record2中 // 遍历记录并将record的记录变成"id" => realid加入到record2中
// like: [[id => 1], [id => 2], [id => 3]...] // like: [[id => 1], [id => 2], [id => 3]...]
foreach($records as $item) { foreach ($records as $item) {
$records2[] = array('id' => $item['id']); $records2[] = array('id' => $item['id']);
} }
$arr['records'] = $records2; $arr['records'] = $records2;
@ -396,22 +427,22 @@ if($qs == 'heartbeat' || $qs == 'addperson' || $qs == 'delperson') { //心跳
} }
// 在线消费,无消费确认,无查询,直接消费 // 在线消费,无消费确认,无查询,直接消费
else if($qs == 'real') { else if ($qs == 'real') {
$api = $post['api']; $api = $post['api'];
if($api == 'takemeal' || $api == 'takemealok') { //取餐 if ($api == 'takemeal' || $api == 'takemealok') { //取餐
$uInfo = pos_check_user(); $uInfo = pos_check_user();
$uid = $uInfo['id']; $uid = $uInfo['id'];
function get_today_dates($dining_hall_id) function get_today_dates($dining_hall_id)
{ {
global $db; global $db;
$data = $db->get_all("select * from tb_date where dining_hall_id={$dining_hall_id} and dc_date = '".date("Y-m-d")."'"); $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'); $nowtime = date('H:i');
$all = array(); $all = array();
foreach($data as $item) { foreach ($data as $item) {
$dc_type = $item['dc_type']; $dc_type = $item['dc_type'];
$meal_info = $db->get_one("select * from tb_meal_type where status=1 and id=".intval($dc_type)); $meal_info = $db->get_one("select * from tb_meal_type where status=1 and id=" . intval($dc_type));
if( $nowtime >= $meal_info['start_time'] && $nowtime < $meal_info['end_time']) { if ($nowtime >= $meal_info['start_time'] && $nowtime < $meal_info['end_time']) {
$all[] = $item; $all[] = $item;
} }
} }
@ -422,61 +453,63 @@ else if($qs == 'real') {
$dates = get_today_dates($dining_hall_id); $dates = get_today_dates($dining_hall_id);
$order = ''; $order = '';
for($i = 1; $i <= 2; $i++) { for ($i = 1; $i <= 2; $i++) {
foreach($dates as $date) { foreach ($dates as $date) {
$sqlext = " uid = {$uid} "; $sqlext = " uid = {$uid} ";
if($uInfo['type'] == 'qr') { //取餐码 if ($uInfo['type'] == 'qr') { //取餐码
$sqlext = " take_food_code = '".addslashes($uInfo['code'])."' "; $sqlext = " take_food_code = '" . addslashes($uInfo['code']) . "' ";
} }
$row = $db->get_one("select * from tb_order where {$sqlext} and date_id=".$date['id']." and state_id =".($i==1?6:3)); $row = $db->get_one("select * from tb_order where {$sqlext} and date_id=" . $date['id'] . " and state_id =" . ($i == 1 ? 6 : 3));
if($row) { if ($row) {
$order = $row; $order = $row;
if($uInfo['type'] == 'qr') { //取餐码 if ($uInfo['type'] == 'qr') { //取餐码
$uInfo = $db->get_one("select * from tb_user where id = '".$order['uid']."'"); $uInfo = $db->get_one("select * from tb_user where id = '" . $order['uid'] . "'");
if(!$uInfo) exit; if (!$uInfo)
exit;
$uid = $uInfo['id']; $uid = $uInfo['id'];
} }
break; break;
} }
} }
if($order) break; if ($order)
break;
} }
if(!$order) { if (!$order) {
if($uInfo['type'] == 'qr') { //取餐码 if ($uInfo['type'] == 'qr') { //取餐码
$arr = array ( $arr = array(
'result_code' => '2', 'result_code' => '2',
'result_msg' => "err", //10寸屏蔽失败时界面显示此内容result_code=2 'result_msg' => "err", //10寸屏蔽失败时界面显示此内容result_code=2
'tts' => "取餐码错误", //语音播报为空时不报TTS语音 'tts' => "取餐码错误", //语音播报为空时不报TTS语音
'result' => array (), //服务器返回结果数据,查询信息无 'result' => array(), //服务器返回结果数据,查询信息无
'msg' => array ( 'msg' => array(
array ( array(
'line' => '取餐码错误', 'line' => '取餐码错误',
),
), ),
), 'timeout' => '5', //取餐超时时间,秒为单位,注:特殊修改机型才有此功能
'timeout' => '5', //取餐超时时间,秒为单位,注:特殊修改机型才有此功能
); );
} else { } else {
$arr = array ( $arr = array(
'result_code' => '2', 'result_code' => '2',
'result_msg' => "err", //10寸屏蔽失败时界面显示此内容result_code=2 'result_msg' => "err", //10寸屏蔽失败时界面显示此内容result_code=2
'tts' => "没有该时段的订餐记录", //语音播报为空时不报TTS语音 'tts' => "没有该时段的订餐记录", //语音播报为空时不报TTS语音
'result' => array (), //服务器返回结果数据,查询信息无 'result' => array(), //服务器返回结果数据,查询信息无
'msg' => array ( 'msg' => array(
array ( array(
'line' => '没有该时段的订餐记录', 'line' => '没有该时段的订餐记录',
),
array(
'line' => '姓名: ' . $uInfo['username'],
),
array(
'line' => '手机号: ' . $uInfo['cellphone'],
),
), ),
array ( 'timeout' => '5', //取餐超时时间,秒为单位,注:特殊修改机型才有此功能
'line' => '姓名: '.$uInfo['username'],
),
array (
'line' => '手机号: '.$uInfo['cellphone'],
),
),
'timeout' => '5', //取餐超时时间,秒为单位,注:特殊修改机型才有此功能
); );
} }
response_pos($api, $arr); response_pos($api, $arr);
@ -485,17 +518,18 @@ else if($qs == 'real') {
$s = self_query("/api/order/take", array('take_code' => $order['take_food_code'], 'dining_hall_id' => $dining_hall_id, 'channelid' => $channel_id)); $s = self_query("/api/order/take", array('take_code' => $order['take_food_code'], 'dining_hall_id' => $dining_hall_id, 'channelid' => $channel_id));
$rs = json_decode($s, true); $rs = json_decode($s, true);
if($rs['status'] != 1) { if ($rs['status'] != 1) {
$message = '取餐失败'; $message = '取餐失败';
if($rs['message']) $message = $rs['message']; if ($rs['message'])
$message = $rs['message'];
$arr = array ( $arr = array(
'result_code' => '2', 'result_code' => '2',
'result_msg' => "err", //10寸屏蔽失败时界面显示此内容result_code=2 'result_msg' => "err", //10寸屏蔽失败时界面显示此内容result_code=2
'tts' => $message, //语音播报为空时不报TTS语音 'tts' => $message, //语音播报为空时不报TTS语音
'result' => array (), //服务器返回结果数据,查询信息无 'result' => array(), //服务器返回结果数据,查询信息无
'timeout' => '5', //取餐超时时间,秒为单位,注:特殊修改机型才有此功能 'timeout' => '5', //取餐超时时间,秒为单位,注:特殊修改机型才有此功能
'msg' => array (array ('line' => $message,)), 'msg' => array(array('line' => $message, )),
); );
response_pos($api, $arr); response_pos($api, $arr);
} }
@ -503,97 +537,99 @@ else if($qs == 'real') {
$takeInfo = $rs['data']['list'][0]; $takeInfo = $rs['data']['list'][0];
$detail = array(); $detail = array();
foreach($takeInfo['order_detail'] as $item) { foreach ($takeInfo['order_detail'] as $item) {
$detail[] = array ( $detail[] = array(
'menu' => $item['dish_name'], 'menu' => $item['dish_name'],
'amount' => $item['dish_amount'], 'amount' => $item['dish_amount'],
); );
} }
$take_status = $takeInfo['take_status']; $take_status = $takeInfo['take_status'];
$tts = ''; $tts = '';
$result_msg = ''; $result_msg = '';
$timeout = '5'; $timeout = '5';
if($take_status == 1) { if ($take_status == 1) {
$tts = ($api == 'takemealok'?($uInfo['username']."取餐成功"):""); $tts = ($api == 'takemealok' ? ($uInfo['username'] . "取餐成功") : "");
$result_msg = ($api == 'takemealok'?"取餐成功":"查询成功"); $result_msg = ($api == 'takemealok' ? "取餐成功" : "查询成功");
$timeout = ($api == 'takemealok'?"1":"10"); $timeout = ($api == 'takemealok' ? "1" : "10");
} else { } else {
$tts = '您已取过餐'; $tts = '您已取过餐';
$result_msg = '您已取过餐'; $result_msg = '您已取过餐';
$timeout = '5'; $timeout = '5';
} }
$arr = array ( $arr = array(
'result_code' => ($take_status==1?'0':'1'), //0成功 非0失败1表示已取餐也要显示菜品信息2其它失败 'result_code' => ($take_status == 1 ? '0' : '1'), //0成功 非0失败1表示已取餐也要显示菜品信息2其它失败
'result_msg' => $result_msg, //10寸屏蔽失败时界面显示此内容result_code=2 'result_msg' => $result_msg, //10寸屏蔽失败时界面显示此内容result_code=2
'tts' => $tts, //语音播报为空时不报TTS语音 'tts' => $tts, //语音播报为空时不报TTS语音
'result' => array (), //服务器返回结果数据,查询信息无 'result' => array(), //服务器返回结果数据,查询信息无
'msg' => array ( 'msg' => array(
array ( array(
'line' => '订单号:'.$order['code'], 'line' => '订单号:' . $order['code'],
),
array(
'line' => '姓名: ' . $uInfo['username'],
),
array(
'line' => '手机号: ' . $uInfo['cellphone'],
),
), ),
array ( 'detail' => $detail,
'line' => '姓名: '.$uInfo['username'], 'timeout' => $timeout, //取餐超时时间,秒为单位,注:特殊修改机型才有此功能
),
array (
'line' => '手机号: '.$uInfo['cellphone'],
),
),
'detail' => $detail,
'timeout' => $timeout, //取餐超时时间,秒为单位,注:特殊修改机型才有此功能
); );
response_pos($api, $arr); response_pos($api, $arr);
} } else if ($api == 'infoquery') { //消费前查询用户
else if($api == 'infoquery') { //消费前查询用户
$uInfo = pos_check_user(); $uInfo = pos_check_user();
$uid = $uInfo['id']; $uid = $uInfo['id'];
$row = $db->get_one("select sum( account ) as c from tb_account where user_id = '{$uid}'"); $row = $db->get_one("select sum( account ) as c from tb_account where user_id = '{$uid}'");
$arr = array ( $arr = array(
'tts' => '', 'tts' => '',
'msg' => array (), 'msg' => array(),
'balance' => '', //余额显示测试无效 'balance' => '', //余额显示测试无效
'query_code' => '0', //注意取餐机时应答为1消费机时为0 'query_code' => '0', //注意取餐机时应答为1消费机时为0
'result_code' => '0', 'result_code' => '0',
'result' => array ( 'result' => array(
array ( array(
'account_id' => '', 'account_id' => '',
'consume' => '', 'consume' => '',
'balance' => round($row['c']*100).'', 'balance' => round($row['c'] * 100) . '',
'sign' => '', 'sign' => '',
'Corrections' => '', 'Corrections' => '',
) )
), ),
'title' => '云中美食', 'title' => '云中美食',
'emp_fname' => $uInfo['username'], 'emp_fname' => $uInfo['username'],
'result_msg' => '', 'result_msg' => '',
'detail' => array (), 'detail' => array(),
); );
response_pos('infoquery', $arr); response_pos('infoquery', $arr);
} } else if ($api == 'posonline') { //消费
else if($api == 'posonline') { //消费
$uInfo = pos_check_user(); $uInfo = pos_check_user();
$uid = $uInfo['id']; $uid = $uInfo['id'];
$amount = intval($post['params']['amount']); $amount = intval($post['params']['amount']);
if($amount <= 0) exit; if ($amount <= 0)
exit;
$amount = $amount/100; $amount = $amount / 100;
$pay_mode = $post['params']['pay_mode']; // 0人脸 1云卡 2卡序列号 3取餐码 5二维码 $pay_mode = $post['params']['pay_mode']; // 0人脸 1云卡 2卡序列号 3取餐码 5二维码
$post = array('ftid' => $dining_hall_id, 'channelid' => $channel_id, 'fee' => $amount); $post = array('ftid' => $dining_hall_id, 'channelid' => $channel_id, 'fee' => $amount);
if($pay_mode == 0) { //0人脸 if ($pay_mode == 0) { //0人脸
$row1 = $db->get_one("select * from tb_user_face where user_id = '{$uid}'"); $row1 = $db->get_one("select * from tb_user_face where user_id = '{$uid}'");
if(!$row1) exit; if (!$row1)
exit;
$post['type'] = 'face'; $post['type'] = 'face';
$post['code'] = $row1['card']; $post['code'] = $row1['card'];
} else if($pay_mode == 2) { //2卡序列号 } else if ($pay_mode == 2) { //2卡序列号
$row1 = $db->get_one("select * from tb_user_idcard where user_id = '{$uid}' and state = '1'"); $row1 = $db->get_one("select * from tb_user_idcard where user_id = '{$uid}' and state = '1'");
if(!$row1) exit; if (!$row1)
exit;
$post['type'] = 'ic'; $post['type'] = 'ic';
$post['code'] = $row1['cardno']; $post['code'] = $row1['cardno'];
} else if($pay_mode == 5) { //5付款码 } else if ($pay_mode == 5) { //5付款码
if($uInfo['type'] != 'qr') exit; if ($uInfo['type'] != 'qr')
exit;
$post['type'] = 'qr'; $post['type'] = 'qr';
$post['code'] = $uInfo['code']; $post['code'] = $uInfo['code'];
@ -604,53 +640,52 @@ else if($qs == 'real') {
// 服务器向本机/api/usr/qrpay接口发送数据 // 服务器向本机/api/usr/qrpay接口发送数据
$s = self_query("/api/user/qrpay", $post); $s = self_query("/api/user/qrpay", $post);
$rs = json_decode($s, true); $rs = json_decode($s, true);
if($rs['status'] != 1) { if ($rs['status'] != 1) {
$message = '付款失败'; $message = '付款失败';
if($rs['message']) $message = $rs['message']; if ($rs['message'])
$message = $rs['message'];
$arr = array ( $arr = array(
'result_code' => '2', 'result_code' => '2',
'result_msg' => "err", //10寸屏蔽失败时界面显示此内容result_code=2 'result_msg' => "err", //10寸屏蔽失败时界面显示此内容result_code=2
'tts' => $message, //语音播报为空时不报TTS语音 'tts' => $message, //语音播报为空时不报TTS语音
'result' => array (), //服务器返回结果数据,查询信息无 'result' => array(), //服务器返回结果数据,查询信息无
'timeout' => '5', //取餐超时时间,秒为单位,注:特殊修改机型才有此功能 'timeout' => '5', //取餐超时时间,秒为单位,注:特殊修改机型才有此功能
'msg' => array (array ('line' => $message,)), 'msg' => array(array('line' => $message, )),
); );
response_pos($api, $arr); response_pos($api, $arr);
} }
if($uInfo['type'] == 'qr') { if ($uInfo['type'] == 'qr') {
$row1 = $db->get_one("select * from tb_payqr where code = '".addslashes($uInfo['code'])."'"); $row1 = $db->get_one("select * from tb_payqr where code = '" . addslashes($uInfo['code']) . "'");
$uid = intval($row1['uid']); $uid = intval($row1['uid']);
$uInfo = $db->get_one("select * from tb_user where id = '".$uid."'"); $uInfo = $db->get_one("select * from tb_user where id = '" . $uid . "'");
} }
$arr = array ( $arr = array(
'result_code' => '0', //0成功7需要密码消费消费机出现输入密码的界面密码输入正确后消费机再次调用接口psd_state=1服务器收到为1时则消费成功其它失败 'result_code' => '0', //0成功7需要密码消费消费机出现输入密码的界面密码输入正确后消费机再次调用接口psd_state=1服务器收到为1时则消费成功其它失败
'result_msg' => '', 'result_msg' => '',
'result' => array (), 'result' => array(),
'tts' => $uInfo['username'].' 消费'.$amount.'元成功', 'tts' => $uInfo['username'] . ' 消费' . $amount . '元成功',
'timeout' => '10', 'timeout' => '10',
'msg' => array ( 'msg' => array(
array ( array(
'line' => '姓名: '.$uInfo['username'], 'line' => '姓名: ' . $uInfo['username'],
),
array(
'line' => '消费: ' . $amount . '元',
),
array(
'line' => '余额: ' . $rs['data']['balance'] . '元',
),
), ),
array (
'line' => '消费: '.$amount.'元',
),
array (
'line' => '余额: '.$rs['data']['balance'].'元',
),
),
); );
response_pos('posonline', $arr); response_pos('posonline', $arr);
} }
} } else if ($qs == 'takephoto') {
$arr = array(
else if($qs == 'takephoto') { 'result_code' => '0', //0成功
$arr = array ( 'result_msg' => '',
'result_code' => '0', //0成功 'result' => array(),
'result_msg' => '',
'result' => array (),
); );
response_pos('takephoto', $arr); response_pos('takephoto', $arr);
} }