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