SchoolPhysicalExamination/application/DeviceEnter/controller/Savemsg.php

257 lines
10 KiB
PHP
Raw Normal View History

2025-09-03 19:09:13 +08:00
<?php
namespace app\DeviceEnter\controller;
use think\Db;
use think\Cache;
class Savemsg extends Base{
2025-09-26 16:35:42 +08:00
// 设备名称列表
2025-09-03 19:09:13 +08:00
protected $name_list = [
2025-09-26 16:35:42 +08:00
['name'=>'PC-C02Pro']
// [
// 'name'=>'PC-C02Pro',
// ],
2025-09-03 19:09:13 +08:00
];
2025-09-26 16:35:42 +08:00
// 默认选中的设备名称下标
2025-09-03 19:09:13 +08:00
protected $name_default = 0;
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################百度接口################################################################
################################################################百度接口################################################################
################################################################百度接口################################################################
// 获取配置信息
public function config_msg(){
try {
$result = $this->config_msg_action();
return $this->msg($result);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
2025-09-26 16:35:42 +08:00
$logContent["line"] = $e->getLine(); =
2025-09-03 19:09:13 +08:00
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "函数名: " . __FUNCTION__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
2025-09-26 16:35:42 +08:00
public function save_device_msg($data = ['mac'=>'564654564654654','device_name'=>'bl_5520','batch_code'=>'bc250826','token'=>'as56d4a56s1d5as4d6']){
2025-09-03 19:09:13 +08:00
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('mac', $data)){
return $this->msg(10001);
}
if(!array_key_exists('device_name', $data)){
return $this->msg(10001);
}
if(!array_key_exists('batch_code', $data)){
return $this->msg(10001);
}
2025-09-26 16:35:42 +08:00
if(!array_key_exists('token', $data)){
return $this->msg(10001);
}
2025-09-03 19:09:13 +08:00
if(!$this->verify_data_is_ok($data['mac'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['device_name'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['batch_code'],'str')){
return $this->msg(10005);
}
2025-09-26 16:35:42 +08:00
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
2025-09-03 19:09:13 +08:00
$result = $this->save_device_msg_action($data);
return $result;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "函数名: " . __FUNCTION__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
// dump($data);
// die;
$this->record_api_log($data, $logContent, null);
return $this->msg(99999);
}
}
2025-09-26 16:35:42 +08:00
// 历史箱号数据
2025-09-03 19:09:13 +08:00
public function device_batch_list(){
2025-09-26 16:35:42 +08:00
try {
// 你的业务逻辑
if(count(input()) > 0){
$data = input();
}
if(!array_key_exists('token', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005);
}
$result = $this->device_batch_list_action($data);
2025-09-03 19:09:13 +08:00
return $result;
2025-09-26 16:35:42 +08:00
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "函数名: " . __FUNCTION__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log([], $logContent, null);
return $this->msg(99999);
}
}
// 详细批次数据
public function device_content_msg($data = ['batch_code'=>'tcxbc250904']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('batch_code', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['batch_code'],'str')){
return $this->msg(10005);
}
$result = $this->device_content_msg_action($data);
return $this->msg($result);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
$logContent['all_content'] .= "函数名: " . __FUNCTION__ . "\n";
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
$this->record_api_log([], $logContent, null);
return $this->msg(99999);
}
2025-09-03 19:09:13 +08:00
}
########################################################################action########################################################################
########################################################################action########################################################################
########################################################################action########################################################################
public function config_msg_action(){
$data = [
'name_list'=>$this->name_list,
'name_default_key'=>$this->name_default,
];
return $data;
}
public function save_device_msg_action($data){
2025-09-26 16:35:42 +08:00
// 验证mac地址是否存在且不为空
if (!isset($data['mac']) || empty(trim($data['mac']))) {
return $this->msg(10002, 'MAC地址不能为空');
}
2025-09-03 19:09:13 +08:00
$device_enter = Db::connect('device_enter_db');
2025-09-26 16:35:42 +08:00
// $mac_code = $device_enter->table('device_C03')->where(['device_mac'=>$data['mac']])->find();
// if($mac_code){
// return $this->msg(10002,'该MAC地址已录入,批次号:'.$mac_code['batch_code']);
// }
$result = $device_enter->table('device_C03')->insert([
2025-09-03 19:09:13 +08:00
'device_mac'=>$data['mac'],
'device_name'=>$data['device_name'],
'batch_code'=>$data['batch_code'],
2025-09-26 16:35:42 +08:00
'token'=>$data['token'],
2025-09-03 19:09:13 +08:00
'create_time'=>date('Y-m-d H:i:s'),
]);
if($result){
2025-09-26 16:35:42 +08:00
$all_data = $this->device_content_msg_action($data);
return $this->msg($all_data);
2025-09-03 19:09:13 +08:00
}else{
return $this->msg(10002);
2025-09-26 16:35:42 +08:00
2025-09-03 19:09:13 +08:00
}
}
2025-09-26 16:35:42 +08:00
public function device_batch_list_action($data){
2025-09-03 19:09:13 +08:00
$device_enter = Db::connect('device_enter_db');
$result = $device_enter->query("
SELECT device_name, batch_code, COUNT(*) as num
2025-09-26 16:35:42 +08:00
FROM device_C03
WHERE token = '".$data['token']."'
2025-09-03 19:09:13 +08:00
GROUP BY batch_code,device_name
ORDER BY MAX(id) desc
");
return $this->msg($result);
}
2025-09-26 16:35:42 +08:00
public function device_content_msg_action($data){
$device_enter = Db::connect('device_enter_db');
$result = $device_enter->query("
SELECT device_mac
FROM device_C03
WHERE batch_code = '".$data['batch_code']."'
order by id desc
");
$return_result = [
'list'=>[],
'num'=>0,
];
for ($i=0; $i < count($result); $i++) {
array_push($return_result['list'],$result[$i]['device_mac']);
$return_result['num'] = $return_result['num']+1;
}
return $return_result;
}
################################################################测试################################################################
################################################################测试################################################################
################################################################测试################################################################
public function ceshi(){
// $device_enter = Db::connect('device_enter_db');
// $mac_code = $device_enter->table('device_C03')->select();
// $data = [];
// foreach ($mac_code as $key => $value) {
// $data[] = $value['device_mac'];
// }
// dump($data);
}
2025-09-03 19:09:13 +08:00
}