2024-06-17 18:03:41 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\app\controller;
|
|
|
|
|
|
|
|
|
|
use think\Db;
|
|
|
|
|
use think\Log;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Device extends Base{
|
|
|
|
|
|
|
|
|
|
protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
|
|
|
|
|
// 获取系统设备列表
|
|
|
|
|
public function device_data_list($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
|
|
|
|
|
if(count(input('post.')) > 0){
|
|
|
|
|
$data = input('post.');
|
|
|
|
|
}
|
|
|
|
|
if(!array_key_exists('token', $data)){
|
|
|
|
|
return $this->msg(10001);
|
|
|
|
|
}
|
|
|
|
|
// cache($data['token'],time());
|
|
|
|
|
if($this->token_time_validate($data['token']) === false){
|
|
|
|
|
return $this->msg(20001);
|
|
|
|
|
}
|
|
|
|
|
unset($data['token']);
|
|
|
|
|
return $this->device_data_list_action($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定系统设备
|
|
|
|
|
public function device_binding($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','device_id'=>'3','device_mac'=>'54654654']){
|
|
|
|
|
if(count(input('post.')) > 0){
|
|
|
|
|
$data = input('post.');
|
|
|
|
|
}
|
|
|
|
|
if(!array_key_exists('token', $data) || !array_key_exists('device_id', $data) || !array_key_exists('device_mac', $data)){
|
|
|
|
|
return $this->msg(10001);
|
|
|
|
|
}
|
|
|
|
|
// cache($data['token'],time());
|
|
|
|
|
if($this->token_time_validate($data['token']) === false){
|
|
|
|
|
return $this->msg(20001);
|
|
|
|
|
}
|
|
|
|
|
// unset($data['token']);
|
|
|
|
|
return $this->device_binding_action($data);
|
|
|
|
|
}
|
|
|
|
|
// 获取用户设备列表
|
|
|
|
|
public function device_user_data_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
|
|
|
|
if(count(input('post.')) > 0){
|
|
|
|
|
$data = input('post.');
|
|
|
|
|
}
|
|
|
|
|
if(!array_key_exists('token', $data)){
|
|
|
|
|
return $this->msg(10001);
|
|
|
|
|
}
|
|
|
|
|
// cache($data['token'],time());
|
|
|
|
|
if($this->token_time_validate($data['token']) === false){
|
|
|
|
|
return $this->msg(20001);
|
|
|
|
|
}
|
|
|
|
|
// unset($data['token']);
|
|
|
|
|
return $this->device_user_data_list_action($data);
|
|
|
|
|
}
|
|
|
|
|
// 解绑系统设备
|
|
|
|
|
public function device_unbinding($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','id'=>'3']){
|
|
|
|
|
if(count(input('post.')) > 0){
|
|
|
|
|
$data = input('post.');
|
|
|
|
|
}
|
|
|
|
|
if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){
|
|
|
|
|
return $this->msg(10001);
|
|
|
|
|
}
|
|
|
|
|
// cache($data['token'],time());
|
|
|
|
|
if($this->token_time_validate($data['token']) === false){
|
|
|
|
|
return $this->msg(20001);
|
|
|
|
|
}
|
|
|
|
|
// unset($data['token']);
|
|
|
|
|
return $this->device_unbinding_action($data);
|
|
|
|
|
}
|
2024-07-04 18:44:21 +08:00
|
|
|
|
|
|
|
|
// 获取设备详情
|
|
|
|
|
public function device_mac_get_content($data = ['mac'=>'26:FF:B3:2F:E7:D8','acd_id'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
|
|
|
|
if(count(input('post.')) > 0){
|
|
|
|
|
$data = input('post.');
|
|
|
|
|
}
|
|
|
|
|
if(!array_key_exists('mac', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){
|
|
|
|
|
return $this->msg(10001);
|
|
|
|
|
}
|
|
|
|
|
cache($data['token'],time());
|
|
|
|
|
if($this->token_time_validate($data['token']) === false){
|
|
|
|
|
return $this->msg(20001);
|
|
|
|
|
}
|
|
|
|
|
return $this->device_mac_get_content_action($data);
|
|
|
|
|
}
|
2024-06-17 18:03:41 +08:00
|
|
|
|
|
|
|
|
################################################################业务接口################################################################
|
|
|
|
|
################################################################业务接口################################################################
|
|
|
|
|
|
|
|
|
|
################################################device_data_list
|
|
|
|
|
public function device_data_list_action($data){
|
|
|
|
|
$result = Db::table('app_device_data')->where(['is_del'=>0])->field('id,name,pic,content,page_measure,bluetooth_type,device_model')->select();
|
|
|
|
|
foreach ($result as $key => $value) {
|
|
|
|
|
unset($result[$key]['ROW_NUMBER']);
|
|
|
|
|
}
|
|
|
|
|
if(empty($result)){
|
|
|
|
|
return $this->msg(10004);
|
|
|
|
|
}else{
|
|
|
|
|
return $this->msg(['list'=>$result]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
################################################device_binding
|
|
|
|
|
public function device_binding_action($data){
|
|
|
|
|
$result_user = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find();
|
|
|
|
|
if(!$result_user){
|
|
|
|
|
return $this->msg(10003);
|
|
|
|
|
}
|
|
|
|
|
$device_code_data = Db::table('app_device_code_data')->where(['machine_code'=>$data['device_mac']])->find();
|
|
|
|
|
if($device_code_data){
|
|
|
|
|
if($device_code_data['bind_account_id']){
|
|
|
|
|
return $this->msg(10003,'设备已被绑定');
|
|
|
|
|
}else{
|
|
|
|
|
$device_binding = Db::table('app_device_code_data')->where(['machine_code'=>$data['device_mac']])->update([
|
|
|
|
|
'bind_account_id'=>$result_user['id'],
|
|
|
|
|
]);
|
|
|
|
|
if($device_binding){
|
|
|
|
|
return $this->msg([]);
|
|
|
|
|
}else{
|
|
|
|
|
return $this->msg(10002,'更新失败');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$device_binding = Db::table('app_device_code_data')->insert([
|
|
|
|
|
'add_id'=>$data['device_id'],
|
|
|
|
|
'machine_code'=>$data['device_mac'],
|
|
|
|
|
'create_time'=>date('Y-m-d H:i:s'),
|
|
|
|
|
'bind_account_id'=>$result_user['id'],
|
|
|
|
|
]);
|
|
|
|
|
if($device_binding){
|
|
|
|
|
return $this->msg([]);
|
|
|
|
|
}else{
|
|
|
|
|
return $this->msg(10002);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
################################################device_user_data_list
|
|
|
|
|
public function device_user_data_list_action($data){
|
|
|
|
|
$result_user = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find();
|
|
|
|
|
if(!$result_user){
|
|
|
|
|
return $this->msg(10003);
|
|
|
|
|
}
|
|
|
|
|
$device_code_data = Db::table('app_device_code_data')
|
|
|
|
|
->alias('adcd')
|
|
|
|
|
->join('app_device_data add','adcd.add_id = add.id','LEFT')
|
|
|
|
|
->where(['adcd.bind_account_id'=>$result_user['id']])
|
2024-07-03 19:26:07 +08:00
|
|
|
->field('adcd.id,adcd.add_id,adcd.machine_code,adcd.create_time,add.name,add.pic,add.content,add.page_measure,add.bluetooth_type,add.device_model')
|
2024-06-17 18:03:41 +08:00
|
|
|
->select();
|
|
|
|
|
if(count($device_code_data) <= 0){
|
|
|
|
|
return $this->msg([]);
|
|
|
|
|
}
|
|
|
|
|
$device_code_data1 = [];
|
|
|
|
|
$result = [];
|
2024-07-03 19:26:07 +08:00
|
|
|
|
|
|
|
|
// 新版格式
|
|
|
|
|
// $result['list'] = [];
|
2024-06-17 18:03:41 +08:00
|
|
|
foreach ($device_code_data as $key => $value) {
|
2024-07-03 19:26:07 +08:00
|
|
|
array_push($result,[
|
|
|
|
|
'add_id'=>$value['add_id'],
|
|
|
|
|
'name'=>$value['name'],
|
|
|
|
|
'pic'=>$value['pic'],
|
|
|
|
|
'content'=>$value['content'],
|
|
|
|
|
'page_measure'=>$value['page_measure'],
|
|
|
|
|
'bluetooth_type'=>$value['bluetooth_type'],
|
|
|
|
|
'device_model'=>$value['device_model'],
|
|
|
|
|
'bind_time'=>$value['create_time'],
|
|
|
|
|
'id'=>$value['id'],
|
|
|
|
|
'mac'=>$value['machine_code']
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
// dump($device_code_data);
|
|
|
|
|
// die;
|
|
|
|
|
// 旧版格式
|
|
|
|
|
// foreach ($device_code_data as $key => $value) {
|
|
|
|
|
// if(!array_key_exists($value['add_id'], $device_code_data1)){
|
|
|
|
|
// $device_code_data1[$value['add_id']] = [
|
|
|
|
|
// 'add_id'=>$value['add_id'],
|
|
|
|
|
// 'name'=>$value['name'],
|
|
|
|
|
// 'pic'=>$value['pic'],
|
|
|
|
|
// 'content'=>$value['content'],
|
|
|
|
|
// 'page_measure'=>$value['page_measure'],
|
|
|
|
|
// 'bluetooth_type'=>$value['bluetooth_type'],
|
|
|
|
|
// 'device_model'=>$value['device_model'],
|
|
|
|
|
// 'list'=>[[
|
|
|
|
|
// 'id'=>$value['id'],
|
|
|
|
|
// 'mac'=>$value['machine_code']
|
|
|
|
|
// ]]
|
|
|
|
|
// ];
|
|
|
|
|
// }else{
|
|
|
|
|
// array_push($device_code_data1[$value['add_id']]['list'],['id'=>$value['id'],'mac'=>$value['machine_code']]);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// foreach ($device_code_data1 as $key => $value) {
|
|
|
|
|
// array_push($result,$value);
|
|
|
|
|
// }
|
2024-06-17 18:03:41 +08:00
|
|
|
return $this->msg(['list'=>$result]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
################################################device_binding
|
|
|
|
|
public function device_unbinding_action($data){
|
|
|
|
|
$result_user = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find();
|
|
|
|
|
if(!$result_user){
|
|
|
|
|
return $this->msg(10003);
|
|
|
|
|
}
|
|
|
|
|
$device_binding = Db::table('app_device_code_data')->where(['id'=>$data['id'],'bind_account_id'=>$result_user['id']])->update([
|
|
|
|
|
'bind_account_id'=>'',
|
|
|
|
|
]);
|
|
|
|
|
if($device_binding){
|
|
|
|
|
return $this->msg([]);
|
|
|
|
|
}else{
|
|
|
|
|
return $this->msg(10002);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-04 18:44:21 +08:00
|
|
|
|
|
|
|
|
################################################device_mac_get_content
|
|
|
|
|
public function device_mac_get_content_action($data){
|
|
|
|
|
|
|
|
|
|
$user_id = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find();
|
|
|
|
|
// dump($user_id);
|
|
|
|
|
// die;
|
|
|
|
|
$result_device = Db::table('app_device_code_data')
|
|
|
|
|
->alias('adcd')
|
|
|
|
|
->join('app_device_data add','adcd.add_id = add.id','LEFT')
|
|
|
|
|
->where([
|
|
|
|
|
'adcd.machine_code'=>$data['mac'],
|
|
|
|
|
'add.acd_id'=>$data['acd_id'],
|
|
|
|
|
'adcd.bind_account_id'=>$user_id['id'],
|
|
|
|
|
'add.is_del'=>0,
|
|
|
|
|
'adcd.is_del'=>0,
|
|
|
|
|
])
|
|
|
|
|
->field('adcd.id,add.acd_id,add.name,add.pic,add.content,add.page_measure,add.bluetooth_type,add.device_model')
|
|
|
|
|
->find();
|
|
|
|
|
if($result_device){
|
|
|
|
|
unset($result_device['ROW_NUMBER']);
|
|
|
|
|
return $this->msg($result_device);
|
|
|
|
|
}else{
|
|
|
|
|
return $this->msg(10004);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-17 18:03:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################其他接口################################################################
|
|
|
|
|
################################################################其他接口################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|