Browse Source

测试命令,下发协议修改,ip地址切换

Swdz-WangHaiJun 4 năm trước cách đây
mục cha
commit
91c0a673ec

+ 6 - 3
app/Admin/Actions/Device/getRule.php

xqd xqd
@@ -4,6 +4,7 @@ namespace App\Admin\Actions\Device;
 
 use App\Model\DeviceBox;
 use App\Model\DeviceInfo;
+use App\Model\LockInfo;
 use App\Server\DeviceServer;
 use Encore\Admin\Actions\RowAction;
 use Illuminate\Database\Eloquent\Model;
@@ -19,9 +20,11 @@ class getRule extends RowAction
     {
         $id = $this->row->id;
         $device_name = $this->row->device_name;
-        $box_info = DeviceBox::where(['device_id'=>$id])->get();
-        $box_arr = DeviceInfo::getTypeNumber();
-        $box_num = $box_arr[$this->row->device_type];
+        $box_arr = [1=>4,2=>5,3=>5,4=>6];
+        if($this->row->device_tye == 0 || empty($this->row->device_tye)){
+            return $this->response()->warning('请设置设备类型');
+        }
+        $box_num = $box_arr[intval($this->row->device_type)];
         if(!empty($box_info)){
             for ($i=1; $i<=$box_num ; $i++){
                 $rule = ['get'=>'box'.$i];

+ 7 - 5
app/Admin/Actions/Device/testRule.php

xqd
@@ -41,12 +41,14 @@ class testRule extends RowAction
     public function form()
     {
         $id = $this->row->id;
+        $type = $this->row->device_type;
+
+
+        $box_num=[1=>4,2=>5,3=>5,4=>6];
         $box_info = DeviceBox::where(['device_id'=>$id])->get();
-        if(!empty($box_info)){
-            foreach ($box_info as $box){
-                $box_name = $box->name;
-                $this->textarea($box_name,'请输入'.$box_name.'测试json');
-            }
+        $i = $box_num[intval($type)];
+        for ($j=1;$j<=$i;$j++){
+            $this->textarea('箱体'.$i,'请输入'.'箱体'.$i.'测试json')->help('仅限json数据')->required();
         }
     }
 

+ 7 - 2
app/Admin/Controllers/DeviceController.php

xqd xqd xqd
@@ -46,7 +46,9 @@ class DeviceController extends AdminController
     protected function grid()
     {
 
+        $device = new DeviceInfo();
         $grid = new Grid(new DeviceInfo());
+
         $status = DeviceInfo::getStatus();
         $grid->disableCreateButton(false);
         $grid->disableCreateButton();
@@ -76,9 +78,11 @@ class DeviceController extends AdminController
         $grid->actions(function ($actions){
             $actions->disableDelete(false);
             $actions->add(new Lock());
-            $actions->add(new sendRule());
             $actions->add(new getRule());
-            $actions->add(new testRule());
+            if($actions->row->status == 0 && $actions->row->device_type){
+                $actions->add(new sendRule());
+                $actions->add(new testRule());
+            }
         });
         $grid->filter(function (Grid\Filter $filter){
             $filter->column(1/2, function ($filter) {
@@ -149,6 +153,7 @@ class DeviceController extends AdminController
         $form->display('iot_id', __('(阿里云)iot_id'))->rules('required');
         $form->display('product_key', __('(阿里云)product_key'))->help('阿里产品密匙')->rules('required');
         $form->display('device_secret', __('(阿里云)设备密匙'))->rules('required');
+        $form->display('phone', __('物联网电话卡'))->rules('required');
         $form->display('imei', __('(阿里云)设备唯一码'))->rules('required');
         $form->hidden('device_tem', __('设备温度'))->default(28)->rules('required');
         $form->text('query', '刷新时间')->help('单位秒')->rules('required');

+ 1 - 1
app/Model/DeviceInfo.php

xqd
@@ -17,7 +17,7 @@ class DeviceInfo extends Model
     const BOXFOUR = 1, BOXFIVE = 2, BOXFOURRECYCLE = 3, BOXFIVERECYCLE = 4;//四箱 五箱
     const OK = 0, ERROR = 1; // 正常 故障 设备状态 (runningStatus)
     const LOCK = 1, UNLOCK = 0;
-//    protected $connection = 'lock';
+    protected $connection = 'lock';
     protected $table = "device_info";
     protected $guarded = [];
 

+ 1 - 0
app/Model/LockInfo.php

xqd
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model;
 use App\Events\LockEvent;
 class LockInfo extends Model
 {
+    protected $connection = 'lock';
     protected $table = 'device_lock_info';
 
     //锁类型 1 不重复 2每天 3每周

+ 3 - 29
app/Server/DeviceServer.php

xqd xqd xqd xqd
@@ -112,7 +112,7 @@ class DeviceServer
                     DeviceInfo::insert($create);
                 }
             }
-            $this->refreshDevice($val['IotId']);
+//            $this->refreshDevice($val['IotId']);
         }
         return true;
     }
@@ -133,6 +133,7 @@ class DeviceServer
         }
         $ali = new AliYunIotServer($conf['appKey'], $conf['appSecret']);
         $deviceProperty = $ali->getDeviceProperty($iot_id);
+        dd($deviceProperty);
         Log::info("设备数据刷新[1]:" . json_encode($deviceProperty));
         if (isset($deviceProperty['Success']) && $deviceProperty['Success']) {
             $data = [];
@@ -146,36 +147,10 @@ class DeviceServer
                 }
             }
 
+            dd($data);
             if (empty($data)) {
                 return ['data' => ['ErrorMessage' => '未获取到设备属性'], 'code' => 3];
             }
-            //修复
-//            if ($data['deliver_lock_switch'] == 1) {
-//                return ['data' => ['ErrorMessage' => '当前设备已开启,请等待'], 'code' => '2'];
-//            }
-      /*      if (isset($data['location'])) {
-                $location = json_decode($data['location'], true);
-                $data['device_latitude'] = $location['latitude'];
-                $data['device_longitude'] = $location['longitude'];
-                unset($data['location']);
-            }*/
-            /*if ($data['rest_capacity'] == 0) {
-                $data['status'] = DeviceInfo::MAX;
-            } else {
-                $data['status'] = DeviceInfo::WELL;
-            }*/
-            $insert['device_item'] = $data['device_tem'];
-            $insert['imei'] = $data['imei'];
-            if ($data['device_tem'] >= 80) {
-                $id = DeviceInfo::where('iot_id', $iot_id)->first(['id'])->id;
-//                Log::info("设备温度【{$id}】:{$data['device_tem']}" );
-//                WaringMessage::temWaring($id);
-            }
-
-            $res = DeviceInfo::where('iot_id', $iot_id)->update($insert);
-            if (!$res) {
-                Log::info('设备数据刷新[2]:' . json_encode($data));
-            }
             return ['data' => $data, 'code' => '0'];
         } else {
             return ['data' => $deviceProperty, 'code' => 1];
@@ -199,7 +174,6 @@ class DeviceServer
         }
         $ali = new AliYunIotServer($conf['appKey'], $conf['appSecret']);
         $deviceProperty = $ali->getDeviceProperty($iot_id);
-//        dd($deviceProperty);
         if (isset($deviceProperty['Success']) && $deviceProperty['Success']) {
             $data = [];
             foreach ($deviceProperty['Data']['List']['PropertyStatusInfo'] as $index => $item) {

+ 19 - 0
config/database.php

xqd
@@ -62,6 +62,25 @@ return [
                 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
             ]) : [],
         ],
+        'lock' => [
+            'driver' => 'mysql',
+            'url' => env('DATABASE_URL'),
+            'host' => '39.98.121.179',
+            'port' => '3306',
+            'database' => 'lsdq',
+            'username' => 'root',
+            'password' => '123456',
+            'unix_socket' => env('DB_SOCKET', ''),
+            'charset' => 'utf8mb4',
+            'collation' => 'utf8mb4_unicode_ci',
+            'prefix' => '',
+            'prefix_indexes' => true,
+            'strict' => true,
+            'engine' => null,
+            'options' => extension_loaded('pdo_mysql') ? array_filter([
+                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
+            ]) : [],
+        ],
 
         'pgsql' => [
             'driver' => 'pgsql',

+ 1 - 0
routes/web.php

xqd
@@ -24,4 +24,5 @@ Route::get('/getDevice', 'IndexController@getDevice');
 Route::get('/upVersion', 'IndexController@upVersion');
 Route::get('/getDevcielist', 'IndexController@getDevcielist');
 Route::get('/getPhonelist', 'IndexController@getPhonelist');
+Route::get('/getsql', 'IndexController@upsql');