Browse Source

测试页面

whj 4 năm trước cách đây
mục cha
commit
8bb35b0a43

+ 81 - 55
app/Http/Controllers/IndexController.php

@@ -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;
-//}

+ 146 - 0
public/testweb/upgrade.html

@@ -0,0 +1,146 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>设备调试</title>
+    <style>
+        #main {
+            display: flex;
+            justify-content: center;
+            align-items: center;
+            height: 15rem;
+            padding: 0 .5rem;
+        }
+
+        .inputstyle {
+            width: 8rem;
+            height: .8rem;
+            border-radius: .8rem;
+            outline: none;
+            border: 1px solid #efefef;
+            padding: 0 .3rem;
+        }
+
+        .container {
+            display: flex;
+            justify-content: center;
+            align-items: center;
+            flex-direction: column;
+        }
+
+        .btnstyle {
+            width: 3rem;
+            height: 1rem;
+            outline: none;
+            border: solid rgb(118, 206, 169);
+            background-color: rgb(118, 206, 169);
+            color: #fff;
+            border-radius: .8rem;
+            margin-top: .3rem;
+        }
+    </style>
+</head>
+
+<body>
+    <div id="main">
+        <div class="container" v-if="isInstall">
+            <input class="inputstyle" type="text" v-model="value" placeholder="请输入你需要升级的设备IMEI号码">
+            <button class="btnstyle" @click="installbtn">点击设置</button>
+        </div>
+        <div class="container" style="align-items: flex-start;" v-else>
+            <div style="font-size: .5rem;">
+                设备IMEI号:{{equipment}}
+            </div>
+            <div style="font-size: .5rem;margin-top: .4rem;display: flex;align-items: center;">
+                设备状态:{{isxian}}
+            </div>
+            <div style="font-size: .5rem;margin-top: .4rem;display: flex;align-items: center;">
+                设备版本号:{{versionNum}}
+            </div>
+            <div style="margin-top: .4rem;width: 100%;text-align: center;">
+                <button class="btnstyle" @click="resetbtn">重置设备</button>
+                <button class="btnstyle" @click="upbtn">升级程序</button>
+            </div>
+            <div style="font-size: .3rem;margin-top: .4rem;">
+                备注:
+            </div>
+            <div style="font-size: .3rem;margin-top: .2rem;">
+                1. 点击任何按钮后,设备需保持通电状态3-5分钟,中途不能断电,否则可能造成设备损坏
+            </div>
+            <div style="font-size: .3rem; margin-top: .2rem;">
+                2. 设备重置/升级后,所有主板的奇数口会变更为通电状态,成功获取版本号后可继续测试设备
+            </div>
+            <div style="font-size: .3rem; margin-top: .2rem;">
+                3. 重置设备为将现有设备重新重置状态并升级到最新版本,会清空设备原有设置所有命令,并直接获取设备版本号
+            </div>
+        </div>
+    </div>
+    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
+    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0/axios.min.js"></script>
+    <script src="./auto-size.js"></script>
+    <script>
+        const vm = new Vue({
+            el: '#main',
+            data: {
+                isInstall: true,
+                value: "",
+                equipment: "",
+                isxian: "",
+                versionNum: "",
+                isnew: ""
+            },
+            mounted() {
+
+            },
+            methods: {
+                resetbtn() {
+                    if (this.isxian == '在营') {
+                        axios.get("http://172.31.31.199/upVersion?id=" + this.value + "&type=" + 2).then(res => {
+                            if (res.data.status == 200) {
+                                alert("重置命令发送成功,请耐心等待30s,系统将自动重置")
+                            }
+                        })
+                    } else {
+                        alert('设备已离线')
+                    }
+                },
+                installbtn() {
+                    if (this.value != "") {
+                        axios.get("http://172.31.31.199/getDevice?id=" + this.value).then(res => {
+                            console.log(res)
+                            if (res.data.status == 200) {
+                                this.isInstall = false
+                                this.equipment = res.data.data.id
+                                this.isxian = res.data.data.status
+                                this.versionNum = res.data.data.version
+                                this.isnew = res.data.data.is_last
+                            } else {
+                                alert("无效设备")
+                            }
+                        })
+                    } else {
+                        alert("请输入编号")
+                    }
+
+                },
+                upbtn() {
+                    if (this.isxian == '在营' && this.isnew == 0) {
+                        axios.get("http://172.31.31.199/upVersion?id=" + this.value + "&type=" + 1).then(res => {
+                            if (res.data.status == 200) {
+                                alert('升级命令发送成功,请耐心等待3-5分钟设备升级完成后,所有锁口会变为通电状态')
+                            }
+                        })
+                    } else if (this.isxian != "在营") {
+                        alert('设备已离线')
+                    } else {
+                        alert('设备已是最新版本,无需更新')
+                    }
+                }
+            }
+        })
+    </script>
+</body>
+
+</html>

+ 2 - 0
routes/web.php

@@ -20,4 +20,6 @@ Route::get('/test_op', 'IndexController@testOpreation');
 Route::get('/get_boxname', 'IndexController@get_boxname');
 Route::get('/get_boxname', 'IndexController@get_boxname');
 Route::get('/send_protocol', 'IndexController@send_protocol');
 Route::get('/send_protocol', 'IndexController@send_protocol');
 Route::get('/updateDevice', 'IndexController@updateDevice');
 Route::get('/updateDevice', 'IndexController@updateDevice');
+Route::get('/getDevice', 'IndexController@getDevice');
+Route::get('/upVersion', 'IndexController@upVersion');