|
@@ -129,13 +129,23 @@ class IndexController extends Controller
|
|
$data['id'] = $device->id;
|
|
$data['id'] = $device->id;
|
|
$data['device_name'] = $device->device_name;
|
|
$data['device_name'] = $device->device_name;
|
|
$data['device_type'] = $device->device_type;
|
|
$data['device_type'] = $device->device_type;
|
|
|
|
+ $deviceService = (new DeviceServer());
|
|
|
|
+ $iot_id = $device->iot_id;
|
|
|
|
+ $res = $deviceService->getDeviceStatus($iot_id);
|
|
|
|
+ $data['status'] = $res;
|
|
|
|
+
|
|
$img_field_arr = [
|
|
$img_field_arr = [
|
|
1=>'box_img_four',
|
|
1=>'box_img_four',
|
|
2=>'box_img_five',
|
|
2=>'box_img_five',
|
|
3=>'box_img_refour',
|
|
3=>'box_img_refour',
|
|
4=>'box_img_refive',
|
|
4=>'box_img_refive',
|
|
];
|
|
];
|
|
- $data['device_image'] = $lock_config[$img_field_arr[$device->device_type]];
|
|
|
|
|
|
+ if(empty($device->type)){
|
|
|
|
+ $data['device_image'] = $lock_config['box_img_four'];
|
|
|
|
+ } else {
|
|
|
|
+ $data['device_image'] = $lock_config[$img_field_arr[$device->device_type]];
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
return json_encode(['code'=>200,'msg'=>'ok','data'=>$data]);
|
|
return json_encode(['code'=>200,'msg'=>'ok','data'=>$data]);
|
|
}
|
|
}
|
|
@@ -160,8 +170,8 @@ class IndexController extends Controller
|
|
return genApiData(602,'设备类型重复请重新选择');
|
|
return genApiData(602,'设备类型重复请重新选择');
|
|
}
|
|
}
|
|
$device_property = $deviceService->getProperty($device_info->iot_id);
|
|
$device_property = $deviceService->getProperty($device_info->iot_id);
|
|
- $last_version = SystemConfig::get('lock_config','soft_version');
|
|
|
|
$res = DeviceInfo::where('device_name',$device_name)->update($data);
|
|
$res = DeviceInfo::where('device_name',$device_name)->update($data);
|
|
|
|
+ $last_version = SystemConfig::get('lock_config','soft_version');
|
|
|
|
|
|
if($res){
|
|
if($res){
|
|
if($device_property['data']['version'] == '' || $device_property['data']['version'] != $last_version){
|
|
if($device_property['data']['version'] == '' || $device_property['data']['version'] != $last_version){
|
|
@@ -176,61 +186,77 @@ class IndexController extends Controller
|
|
return genApiData(200,'更新成功');
|
|
return genApiData(200,'更新成功');
|
|
}
|
|
}
|
|
return genApiData(601,'异常设备,请联系后台管理员',$res);
|
|
return genApiData(601,'异常设备,请联系后台管理员',$res);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
-// if(empty($device_info)){
|
|
|
|
-// return genApiData(601,'异常设备,请联系后台管理员','');
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-// return genApiData(601,'更新失败','');
|
|
|
|
-//
|
|
|
|
-// if($type == 1){
|
|
|
|
-// $rule = ["cmd"=>"start_update"];
|
|
|
|
-// } else if ($type == 2){
|
|
|
|
-// $rule = ["cmd"=>"reset"];
|
|
|
|
-// } else {
|
|
|
|
-// $rule = ["cmd"=>"start_update"];
|
|
|
|
-// }
|
|
|
|
-// $res = $deviceService->sendMsg($device_name,json_encode($rule));
|
|
|
|
-// if($res['Success'] == 'success') {
|
|
|
|
-// return json_encode(['code'=>200,'msg'=>'发送命令成功','data'=>'']);
|
|
|
|
-// }
|
|
|
|
-// return json_encode(['code'=>601,'msg'=>'发送命令成功','data'=>'']);
|
|
|
|
|
|
+ //设备版本号升级信息
|
|
|
|
+ public function getDevice()
|
|
|
|
+ {
|
|
|
|
+ $id = request('id');
|
|
|
|
+ if(empty($id)){
|
|
|
|
+ return genApiData(601,'设别号必须');
|
|
|
|
+ }
|
|
|
|
+ $device_info = DeviceInfo::where(['device_name'=>$id])->first();
|
|
|
|
+
|
|
|
|
+ if(empty($device_info)){
|
|
|
|
+ return genApiData('601','无效设备');
|
|
|
|
+ }
|
|
|
|
+ $iot_id = $device_info->iot_id;
|
|
|
|
+ $deviceService = (new DeviceServer());
|
|
|
|
+ $last_version = SystemConfig::get('lock_config','soft_version');
|
|
|
|
+
|
|
|
|
+ $res = $deviceService->getDeviceStatus($iot_id);
|
|
|
|
+ $property = $deviceService->getProperty($iot_id);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $sta_arr = DeviceInfo::getStatus();
|
|
|
|
+ $data['id'] = $id;
|
|
|
|
+ $data['status'] = $sta_arr[$res];
|
|
|
|
+ $data['version'] = $property['data']['version'];
|
|
|
|
+ $data['is_last'] = 1;
|
|
|
|
+ if($property['data']['version'] !== $last_version){
|
|
|
|
+ $data['is_last'] = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return genApiData(200,'ok',$data);
|
|
}
|
|
}
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
+ //更新设备版本
|
|
|
|
+ public function upVersion()
|
|
|
|
+ {
|
|
|
|
+ $id = request('id');
|
|
|
|
+ $type = request('type');
|
|
|
|
+
|
|
|
|
+ if(empty($id) || empty($type))
|
|
|
|
+ {
|
|
|
|
+ return genApiData(601,'参数缺失');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $last_version = SystemConfig::get('lock_config','soft_version');
|
|
|
|
+
|
|
|
|
+ $device_info = DeviceInfo::where(['device_name'=>$id])->first();
|
|
|
|
+ if(empty($device_info)){
|
|
|
|
+ return genApiData('601','无效设备');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $iot_id = $device_info->iot_id;
|
|
|
|
+ $device_name = $device_info->device_name;
|
|
|
|
+ $deviceService = (new DeviceServer());
|
|
|
|
+ $property = $deviceService->getProperty($iot_id);
|
|
|
|
+ if($last_version != $property['data']['version'] && $type == 1){
|
|
|
|
+ return genApiData(603,'设备已是最新版本,无需更新');
|
|
|
|
+ }
|
|
|
|
+ $type == 1 ? $rule = ['cmd'=>'start_update'] : $rule = ['ResDefault'=>0];
|
|
|
|
+ $res = $deviceService->sendMsg($device_name ,json_encode($rule));
|
|
|
|
+
|
|
|
|
+ if($res['Success'] == 'success') {
|
|
|
|
+ return genApiData(200,'操作成功');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return genApiData(602,'操作失败');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
|
|
-//use AlibabaCloud\Client\AlibabaCloud;
|
|
|
|
-//use AlibabaCloud\Client\Exception\ClientException;
|
|
|
|
-//use AlibabaCloud\Client\Exception\ServerException;
|
|
|
|
-//
|
|
|
|
-//// Download:https://github.com/aliyun/openapi-sdk-php
|
|
|
|
-//// Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
|
|
|
|
-//
|
|
|
|
-//AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
|
|
|
|
-// ->regionId('cn-shanghai')
|
|
|
|
-// ->asDefaultClient();
|
|
|
|
-//
|
|
|
|
-//try {
|
|
|
|
-// $result = AlibabaCloud::rpc()
|
|
|
|
-// ->product('Iot')
|
|
|
|
-// // ->scheme('https') // https | http
|
|
|
|
-// ->version('2018-01-20')
|
|
|
|
-// ->action('GetThingModelTsl')
|
|
|
|
-// ->method('POST')
|
|
|
|
-// ->host('iot.cn-shanghai.aliyuncs.com')
|
|
|
|
-// ->options([
|
|
|
|
-// 'query' => [
|
|
|
|
-// 'RegionId' => "cn-shanghai",
|
|
|
|
-// 'ProductKey' => "a15yVIP0Onl",
|
|
|
|
-// 'ModelVersion' => "Software_Version",
|
|
|
|
-// ],
|
|
|
|
-// ])
|
|
|
|
-// ->request();
|
|
|
|
-// print_r($result->toArray());
|
|
|
|
-//} catch (ClientException $e) {
|
|
|
|
-// echo $e->getErrorMessage() . PHP_EOL;
|
|
|
|
-//} catch (ServerException $e) {
|
|
|
|
-// echo $e->getErrorMessage() . PHP_EOL;
|
|
|
|
-//}
|
|
|