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);
|
|
|
|
|
}
|
|
|
|
|
// 解绑系统设备
|
2024-07-26 18:34:47 +08:00
|
|
|
public function device_unbinding($data = ['token'=>'e0966788d02cc93290d9d674921d9715','id'=>'8']){
|
2024-06-17 18:03:41 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
// 获取设备详情
|
2024-07-26 18:34:47 +08:00
|
|
|
public function device_mac_get_content($data = ['mac'=>'76:FE:B3:2F:E7:D8','acd_id'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
2024-07-04 18:44:21 +08:00
|
|
|
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();
|
2024-07-26 18:34:47 +08:00
|
|
|
$device_code_data_user = explode(',',$device_code_data['bind_account_id']);
|
2024-06-17 18:03:41 +08:00
|
|
|
if($device_code_data){
|
2024-07-26 18:34:47 +08:00
|
|
|
// 多用户可以绑定
|
|
|
|
|
if(in_array($result_user['id'], $device_code_data_user)){
|
|
|
|
|
return $this->msg(10003,'设备已绑定');
|
2024-06-17 18:03:41 +08:00
|
|
|
}else{
|
2024-07-26 18:34:47 +08:00
|
|
|
array_push($device_code_data_user,$result_user['id']);
|
2024-06-17 18:03:41 +08:00
|
|
|
$device_binding = Db::table('app_device_code_data')->where(['machine_code'=>$data['device_mac']])->update([
|
2024-07-26 18:34:47 +08:00
|
|
|
'bind_account_id'=>implode(',',$device_code_data_user),
|
2024-06-17 18:03:41 +08:00
|
|
|
]);
|
|
|
|
|
if($device_binding){
|
|
|
|
|
return $this->msg([]);
|
|
|
|
|
}else{
|
|
|
|
|
return $this->msg(10002,'更新失败');
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-26 18:34:47 +08:00
|
|
|
// 仅单用户可以绑定
|
|
|
|
|
// 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,'更新失败');
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-06-17 18:03:41 +08:00
|
|
|
}
|
|
|
|
|
$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);
|
|
|
|
|
}
|
2024-07-26 18:34:47 +08:00
|
|
|
$likePattern = '%' . $result_user['id'] . '%';
|
2024-06-17 18:03:41 +08:00
|
|
|
$device_code_data = Db::table('app_device_code_data')
|
|
|
|
|
->alias('adcd')
|
|
|
|
|
->join('app_device_data add','adcd.add_id = add.id','LEFT')
|
2024-07-26 18:34:47 +08:00
|
|
|
// ->where(['adcd.bind_account_id'=>$result_user['id']])
|
|
|
|
|
// ->where('adcd.bind_account_id LIKE "%'.$result_user['id'].'%"')
|
|
|
|
|
->where("adcd.bind_account_id LIKE ?", [$likePattern])
|
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']
|
|
|
|
|
]);
|
|
|
|
|
}
|
2024-07-26 18:34:47 +08:00
|
|
|
|
2024-06-17 18:03:41 +08:00
|
|
|
return $this->msg(['list'=>$result]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-26 18:34:47 +08:00
|
|
|
################################################device_unbinding
|
2024-06-17 18:03:41 +08:00
|
|
|
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);
|
|
|
|
|
}
|
2024-07-26 18:34:47 +08:00
|
|
|
|
|
|
|
|
$device_binding_user = Db::table('app_device_code_data')
|
|
|
|
|
->alias('adcd')
|
|
|
|
|
->join('app_device_data add2','add2.id = adcd.add_id','LEFT')
|
|
|
|
|
->where(['adcd.id'=>$data['id']])
|
|
|
|
|
->field('adcd.id,adcd.bind_account_id,add2.acd_id')
|
|
|
|
|
->find();
|
|
|
|
|
// dump(time());
|
|
|
|
|
// die;
|
|
|
|
|
$device_binding_user = explode(',',$device_binding_user['bind_account_id']);
|
|
|
|
|
// dump($device_binding_user);
|
|
|
|
|
$key = array_search($result_user['id'], $device_binding_user);
|
|
|
|
|
if($key !== false){
|
|
|
|
|
unset($device_binding_user[$key]);
|
|
|
|
|
}else{
|
|
|
|
|
return $this->msg([]);
|
|
|
|
|
}
|
|
|
|
|
// dump($device_binding_user);
|
|
|
|
|
// dump(implode(',',$device_binding_user));
|
|
|
|
|
// die;
|
|
|
|
|
$device_binding = Db::table('app_device_code_data')->where(['id'=>$data['id']])->update([
|
|
|
|
|
'bind_account_id'=>implode(',',$device_binding_user),
|
2024-06-17 18:03:41 +08:00
|
|
|
]);
|
|
|
|
|
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;
|
2024-07-26 18:34:47 +08:00
|
|
|
$likePattern = '%' . $user_id['id'] . '%';
|
2024-07-04 18:44:21 +08:00
|
|
|
$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'],
|
2024-07-26 18:34:47 +08:00
|
|
|
'adcd.bind_account_id'=>['LIKE',$likePattern],
|
2024-07-04 18:44:21 +08:00
|
|
|
'add.is_del'=>0,
|
|
|
|
|
'adcd.is_del'=>0,
|
|
|
|
|
])
|
2024-07-26 18:34:47 +08:00
|
|
|
// ->where("adcd.bind_account_id LIKE ?", [$likePattern])
|
2024-07-04 18:44:21 +08:00
|
|
|
->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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################其他接口################################################################
|
|
|
|
|
################################################################其他接口################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|