wang jun 1 年之前
父節點
當前提交
8a9f93d9e8

+ 15 - 9
application/api/controller/Shouhuan.php

@@ -43,14 +43,20 @@ class Shouhuan extends Controller
         if (in_array($command, $commandlist)) {
             $functionname = 'ctreate' . ucwords($command) . "Command";
             if (method_exists($this, $functionname)) {
-                $facility_id = $data['facility_id'];
-                $device_id_code = $data['device_id_code'];
-                $param = !isset($data['param']) || empty($data['param']) ? [] : $data['param'];
-                $userinfo = request()->suinfo;
-                $sys_user_id = $userinfo['id'];
-                $result = $this->$functionname($facility_id, $device_id_code, $param, $sys_user_id);
-
-                $this->successjson($result['msg']);
+                try {
+                    $facility_id = $data['facility_id'];
+                    $device_id_code = $data['device_id_code'];
+                    $param = !isset($data['param']) || empty($data['param']) ? [] : $data['param'];
+                    if (is_string($param)) {
+                        $param = json_decode($param, true);
+                    }
+                    $userinfo = request()->suinfo;
+                    $sys_user_id = $userinfo['user_id'];
+                    $result = $this->$functionname($facility_id, $device_id_code, $param, $sys_user_id);
+                    return $this->successjson($result['msg']);
+                } catch (\Exception $e) {
+                    return $this->errorjson($e->getMessage());
+                }
             }
         }
         $this->errorjson("命令错误");
@@ -148,7 +154,7 @@ class Shouhuan extends Controller
      */
     private function errorjson($msg)
     {
-        backjson2(500, $msg);
+        return backjson2(500, $msg);
     }
 
 }

+ 34 - 7
application/api/logic/Shouhuanlogic.php

@@ -51,6 +51,9 @@ class Shouhuanlogic
      */
     public function createlowbatcommand($facility_id, $device_id_code, $param, $sys_user_id)
     {
+        if (!isset($param['is_open'])) {
+            throw new \Exception("参数错误");
+        }
         $is_open = empty($param['is_open']) ? 0 : 1;
         $s_sc = new ShouhuanCommand();
         $s_sc->createlowbatcommand($facility_id, $device_id_code, $is_open, $sys_user_id);
@@ -66,6 +69,9 @@ class Shouhuanlogic
      */
     public function createfalldowncommand($facility_id, $device_id_code, $param, $sys_user_id)
     {
+        if (!isset($param['is_open'])) {
+            throw new \Exception("参数错误");
+        }
         $is_open = empty($param['is_open']) ? 0 : 1;
         $s_sc = new ShouhuanCommand();
         $s_sc->createfalldowncommand($facility_id, $device_id_code, $is_open, $sys_user_id);
@@ -107,6 +113,9 @@ class Shouhuanlogic
      */
     public function createsoscommand($facility_id, $device_id_code, $data, $sys_user_id)
     {
+        if (!isset($param['tels'])) {
+            throw new \Exception("参数错误");
+        }
         $param = $data['tels'];
         $s_sc = new ShouhuanCommand();
         $s_sc->createsoscommand($facility_id, $device_id_code, $param, $sys_user_id);
@@ -127,7 +136,7 @@ class Shouhuanlogic
      */
     public function createphlcommand($facility_id, $device_id_code, $data, $sys_user_id)
     {
-        $param = $data['param'];
+        $param = $data;
         $s_sc = new ShouhuanCommand();
         $s_sc->createphlcommand($facility_id, $device_id_code, $param, $sys_user_id);
         return backarr(1, "操作成功");
@@ -147,32 +156,44 @@ class Shouhuanlogic
     {
         $m_s = new SettingModel();
         $s_sc = new ShouhuanCommand();
+        $usedata = [];
         //定位
         if (!isset($data['cr_interval']) || empty($data['cr_interval'])) {
             $cr_interval = $m_s->getvalue('shouhuan_local_space'); //分钟
-            $data['cr_interval'] = bcmul((int) $cr_interval, 60);
+        } else {
+            $cr_interval = $data['cr_interval'];
         }
+        $usedata['cr_interval'] = bcmul((int) $cr_interval, 60);
         //心率
         if (!isset($data['hrt_interval']) || empty($data['hrt_interval'])) {
             $hrt_interval = $m_s->getvalue('shouhuan_heart_space'); //分钟
-            $data['hrt_interval'] = bcmul((int) $hrt_interval, 60);
+        } else {
+            $hrt_interval = $data['hrt_interval'];
         }
+        $usedata['hrt_interval'] = bcmul((int) $hrt_interval, 60);
         //体温
         if (!isset($data['wd_interval']) || empty($data['wd_interval'])) {
             $wd_interval = $m_s->getvalue('shouhuan_body_space'); //分钟
-            $data['wd_interval'] = bcmul((int) $wd_interval, 60);
+        } else {
+            $wd_interval = $data['wd_interval'];
         }
+        $usedata['wd_interval'] = bcmul((int) $wd_interval, 60);
         //血压
         if (!isset($data['bld_interval']) || empty($data['bld_interval'])) {
             $bld_interval = $m_s->getvalue('shouhuan_blood_space'); //分钟
-            $data['bld_interval'] = bcmul((int) $bld_interval, 60);
+        } else {
+            $bld_interval = $data['bld_interval'];
         }
+        $usedata['bld_interval'] = bcmul((int) $bld_interval, 60);
         //血氧
         if (!isset($data['ox_interval']) || empty($data['ox_interval'])) {
             $ox_interval = $m_s->getvalue('shouhuan_oxygen_space'); //分钟
-            $data['ox_interval'] = bcmul((int) $ox_interval, 60);
+        } else {
+            $ox_interval = $data['ox_interval'];
         }
-        $s_sc->setdatainterval($facility_id, $device_id_code, $data, $sys_user_id);
+        $usedata['ox_interval'] = bcmul((int) $ox_interval, 60);
+
+        $s_sc->setdatainterval($facility_id, $device_id_code, $usedata, $sys_user_id);
         return backarr(1, "操作成功");
     }
     /**
@@ -235,6 +256,9 @@ class Shouhuanlogic
      */
     public function createremovecommand($facility_id, $device_id_code, $param, $sys_user_id)
     {
+        if (!isset($param['is_open'])) {
+            throw new \Exception("参数错误");
+        }
         $is_open = empty($param['is_open']) ? 0 : 1;
         $s_sc = new ShouhuanCommand();
         $s_sc->createremovecommand($facility_id, $device_id_code, $is_open, $sys_user_id);
@@ -266,6 +290,9 @@ class Shouhuanlogic
      */
     public function createpedocommand($facility_id, $device_id_code, $param, $sys_user_id)
     {
+        if (!isset($param['is_open'])) {
+            throw new \Exception("参数错误");
+        }
         $is_open = empty($param['is_open']) ? 0 : 1;
         $s_sc = new ShouhuanCommand();
         $s_sc->createpedocommand($facility_id, $device_id_code, $is_open, $sys_user_id);

+ 18 - 12
application/common/server/ShouhuanCommand.php

@@ -505,7 +505,7 @@ class ShouhuanCommand
      * @author wj
      * @date 2023-08-21
      */
-    public function getPHLCommaninfo($param)
+    public function getPHLCommandinfo($param)
     {
         if (50 < count($param)) {
             throw new \Exception("PHL参数错误");
@@ -548,11 +548,14 @@ class ShouhuanCommand
      */
     public function getREMINDCommandinfo($param)
     {
-        if (3 > count($param)) {
-            throw new \Exception("PHL参数错误");
+        if (empty($param)) {
+            throw new \Exception("REMINDC参数错误");
         }
         $usedata = [];
         foreach ($param as $key => $value) {
+            if (3 > count($value)) {
+                throw new \Exception("REMINDC参数错误");
+            }
             $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
             $time = $this->formattime($value['time'], 'H:i');
             $isopen = $value['isopen'];
@@ -595,11 +598,14 @@ class ShouhuanCommand
      */
     public function getSILENCETIME2Commandinfo($param)
     {
-        if (3 <= count($param)) {
+        if (empty($param)) {
             throw new \Exception("SILENCETIME2参数错误");
         }
         $usedata = [];
         foreach ($param as $key => $value) {
+            if (4 > count($value)) {
+                throw new \Exception("SILENCETIME2参数错误");
+            }
             $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
             //未比较时间大小
             $starttime = $this->formattime($value['starttime'], 'H:i');
@@ -683,7 +689,7 @@ class ShouhuanCommand
      */
     public function createsleeptimecommand($facility_id, $device_id_code, $param, $sys_user_id)
     {
-        $command = ['command' => 'SLEEPTIME'];
+        $command = ['command' => 'SLEEPTIME', 'content_arr' => ['command' => 'SLEEPTIME']];
         $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
     }
     /**
@@ -695,7 +701,7 @@ class ShouhuanCommand
      */
     public function createcrcommand($facility_id, $device_id_code, $sys_user_id)
     {
-        $command = ['command' => 'CR'];
+        $command = ['command' => 'CR', 'content_arr' => ['command' => 'CR']];
         $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
     }
     /**
@@ -710,7 +716,7 @@ class ShouhuanCommand
      */
     public function createsoscommand($facility_id, $device_id_code, $param, $sys_user_id)
     {
-        $command = ['command' => 'SOS'];
+        $command = ['command' => 'SOS', 'content_arr' => ['command' => 'SOS']];
         $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
     }
     /**
@@ -723,7 +729,7 @@ class ShouhuanCommand
      */
     public function createphlcommand($facility_id, $device_id_code, $param, $sys_user_id)
     {
-        $command = ['command' => 'PHL'];
+        $command = ['command' => 'PHL', 'content_arr' => ['command' => 'PHL']];
         $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
     }
     //设备初始化
@@ -788,7 +794,7 @@ class ShouhuanCommand
      */
     public function createpoweroffcommand($facility_id, $device_id_code, $sys_user_id)
     {
-        $command = ['command' => 'POWEROFF'];
+        $command = ['command' => 'POWEROFF', 'content_arr' => ['command' => 'POWEROFF']];
         $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
     }
     /**
@@ -819,7 +825,7 @@ class ShouhuanCommand
      */
     public function createremindcommand($facility_id, $device_id_code, $param, $sys_user_id)
     {
-        $command = ['command' => 'REMIND'];
+        $command = ['command' => 'REMIND', 'content_arr' => ['command' => 'REMIND']];
         $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
     }
     /**
@@ -835,7 +841,7 @@ class ShouhuanCommand
      */
     public function createsilencetime2command($facility_id, $device_id_code, $param, $sys_user_id)
     {
-        $command = ['command' => 'SILENCETIME2'];
+        $command = ['command' => 'SILENCETIME2', 'content_arr' => ['command' => 'SILENCETIME2']];
         $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
     }
     /**
@@ -856,7 +862,7 @@ class ShouhuanCommand
         $shutdown_time = $param['shutdown_time'];
         $command = [
             'command' => 'BOOTOFF',
-            'content' => ['command' => 'BOOTOFF', 'is_open' => $is_open, 'bootup_time' => $bootup_time, 'shutdown_time' => $shutdown_time],
+            'content_arr' => ['command' => 'BOOTOFF', 'is_open' => $is_open, 'bootup_time' => $bootup_time, 'shutdown_time' => $shutdown_time],
         ];
         $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
     }

+ 4 - 2
application/workerman/ShTcp.php

@@ -1,6 +1,7 @@
 <?php
 namespace app\workerman;
 
+use app\common\server\ShouhuanCommand;
 use app\common\server\SouhuanAnalysis;
 use think\facade\Log;
 use think\worker\Server;
@@ -26,6 +27,7 @@ class ShTcp extends Server
         //异步处理
         //发送
         $server_sa = new SouhuanAnalysis();
+        $server_sc = new ShouhuanCommand();
         Timer::add(1, function () use ($worker, $server_sa) {
             if (isset($worker->device_id_code)) {
                 $device_id_code = $worker->device_id_code;
@@ -49,7 +51,7 @@ class ShTcp extends Server
         });
         //解析
         $server_sa->initanalysisShoneReceiveMsg();
-        Timer::add(10, function () use ($worker, $server_sa) {
+        Timer::add(10, function () use ($worker, $server_sa, $server_sc) {
             $page = 1;
             $size = 30;
             $list = $server_sa->getreceivequeuelist($page, $size);
@@ -72,7 +74,7 @@ class ShTcp extends Server
                         $fid = $server_sa->getfacilityid($device_id_code);
                         $result = $server_sa->saveshinfo($fid, $device_id_code, $linedata, $value);
                         if ($result) {
-                            $data = $server_sa->createsendmsg($fid, $device_id_code, $linedata);
+                            $data = $server_sc->createsendmsg($fid, $device_id_code, $linedata);
                         }
                         $server_sa->receivemsgsuccess($value);
                     } catch (\Exception $e) {