wang jun 1 年之前
父節點
當前提交
5de5d75edd

+ 115 - 0
application/common/model/ShalarmlistModel.php

@@ -0,0 +1,115 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 手环报警
+ *
+ * @author wj
+ * @date 2023-08-19
+ */
+class ShalarmlistModel extends Model
+{
+    protected $table = "t_shouhuan_alarm_list";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+    /**
+     * 格式化信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function formatinfo($data)
+    {
+        //血压
+        if (isset($data['blood_height_pressure']) || isset($data['blood_low_pressure'])) {
+            $data['blood_update_time'] = date('Y-m-d H:i:s');
+        }
+        //心率
+        if (isset($data['heart_rate'])) {
+            $data['heart_update_time'] = date('Y-m-d H:i:s');
+        }
+        //血养
+        if (isset($data['oxygen'])) {
+            $data['oxygen_update_time'] = date('Y-m-d H:i:s');
+        }
+        //体温
+        if (isset($data['temp'])) {
+            $data['temp_update_time'] = date('Y-m-d H:i:s');
+        }
+        //gps
+        if (isset($data['gps_long']) || isset($data['gps_lat'])) {
+            $data['gps_update_time'] = date('Y-m-d H:i:s');
+        }
+        return $data;
+    }
+}

+ 180 - 0
application/common/model/ShinfoModel.php

@@ -0,0 +1,180 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 手环信息
+ *
+ * @author wj
+ * @date 2023-08-19
+ */
+class ShinfoModel extends Model
+{
+    protected $table = "t_shouhuan_info";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+    /**
+     * 格式化信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function formatinfo($data)
+    {
+        //血压
+        if (isset($data['blood_height_pressure']) || isset($data['blood_low_pressure'])) {
+            $data['blood_update_time'] = date('Y-m-d H:i:s');
+        }
+        //心率
+        if (isset($data['heart_rate'])) {
+            $data['heart_update_time'] = date('Y-m-d H:i:s');
+        }
+        //血养
+        if (isset($data['oxygen'])) {
+            $data['oxygen_update_time'] = date('Y-m-d H:i:s');
+        }
+        //体温
+        if (isset($data['temp'])) {
+            $data['temp_update_time'] = date('Y-m-d H:i:s');
+        }
+        //gps
+        if (isset($data['gps_long']) || isset($data['gps_lat'])) {
+            $data['gps_update_time'] = date('Y-m-d H:i:s');
+        }
+        //电量
+        if (isset($data['electric_quantity'])) {
+            $data['electric_quantity_update_time'] = date('Y-m-d H:i:s');
+        }
+        //步数
+        if (isset($data['step_number'])) {
+            $data['step_number_update_time'] = date('Y-m-d H:i:s');
+        }
+        //翻滚数
+        if (isset($data['roll_number'])) {
+            $data['roll_number_update_time'] = date('Y-m-d H:i:s');
+        }
+        //终端状态
+        if (isset($data['terminal_status'])) {
+            $data['terminal_status_update_time'] = date('Y-m-d H:i:s');
+        }
+        return $data;
+    }
+    /**
+     * 获取下线时间验证列表
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function getcheckupdatetimelist()
+    {
+        //判断时长1分钟
+        $time = date('Y-m-d H:i:s');
+        $sql = "select * from " . $this->table . " where TIMESTAMPDIFF(MINUTE, updatetime, " . $time . ")>1 and online_statis=1";
+        $list = $this->query($sql);
+        return $list;
+    }
+    /**
+     * 设置上线信息
+     *
+     * @param  [type] $ids
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function setonlineinfobyid($id)
+    {
+        $updateData = [
+            'online_statis' => 1,
+            'onlinetime' => date('Y-m-d H:i:s'),
+        ];
+        $where = ['id' => $id];
+        $row = $this->where($where)->update($updateData);
+    }
+    /**
+     * 设置下线信息
+     *
+     * @param  [type] $ids
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function setofflineinfobyids($ids)
+    {
+        $updateData = [
+            'online_statis' => 0,
+            'offlinetime' => date('Y-m-d H:i:s'),
+        ];
+        $where = ['id' => ['in', $ids]];
+        $row = $this->where($where)->update($updateData);
+    }
+}

+ 115 - 0
application/common/model/ShreceivequeueModel.php

@@ -0,0 +1,115 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 手环接收对接
+ *
+ * @author wj
+ * @date 2023-08-19
+ */
+class ShreceivequeueModel extends Model
+{
+    protected $table = "t_shouhuan_receive_queue";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+    /**
+     * 格式化信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function formatinfo($data)
+    {
+        //血压
+        if (isset($data['blood_height_pressure']) || isset($data['blood_low_pressure'])) {
+            $data['blood_update_time'] = date('Y-m-d H:i:s');
+        }
+        //心率
+        if (isset($data['heart_rate'])) {
+            $data['heart_update_time'] = date('Y-m-d H:i:s');
+        }
+        //血养
+        if (isset($data['oxygen'])) {
+            $data['oxygen_update_time'] = date('Y-m-d H:i:s');
+        }
+        //体温
+        if (isset($data['temp'])) {
+            $data['temp_update_time'] = date('Y-m-d H:i:s');
+        }
+        //gps
+        if (isset($data['gps_long']) || isset($data['gps_lat'])) {
+            $data['gps_update_time'] = date('Y-m-d H:i:s');
+        }
+        return $data;
+    }
+}

+ 115 - 0
application/common/model/ShreceiveredocdeModel.php

@@ -0,0 +1,115 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 手环解析历史数据
+ *
+ * @author wj
+ * @date 2023-08-19
+ */
+class ShreceiveredocdeModel extends Model
+{
+    protected $table = "t_shouhuan_receive_redocde";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+    /**
+     * 格式化信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function formatinfo($data)
+    {
+        //血压
+        if (isset($data['blood_height_pressure']) || isset($data['blood_low_pressure'])) {
+            $data['blood_update_time'] = date('Y-m-d H:i:s');
+        }
+        //心率
+        if (isset($data['heart_rate'])) {
+            $data['heart_update_time'] = date('Y-m-d H:i:s');
+        }
+        //血养
+        if (isset($data['oxygen'])) {
+            $data['oxygen_update_time'] = date('Y-m-d H:i:s');
+        }
+        //体温
+        if (isset($data['temp'])) {
+            $data['temp_update_time'] = date('Y-m-d H:i:s');
+        }
+        //gps
+        if (isset($data['gps_long']) || isset($data['gps_lat'])) {
+            $data['gps_update_time'] = date('Y-m-d H:i:s');
+        }
+        return $data;
+    }
+}

+ 115 - 0
application/common/model/ShsendlistModel.php

@@ -0,0 +1,115 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 手环发送列表
+ *
+ * @author wj
+ * @date 2023-08-19
+ */
+class ShsendlistModel extends Model
+{
+    protected $table = "t_shouhuan_send_list";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+    /**
+     * 格式化信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function formatinfo($data)
+    {
+        //血压
+        if (isset($data['blood_height_pressure']) || isset($data['blood_low_pressure'])) {
+            $data['blood_update_time'] = date('Y-m-d H:i:s');
+        }
+        //心率
+        if (isset($data['heart_rate'])) {
+            $data['heart_update_time'] = date('Y-m-d H:i:s');
+        }
+        //血养
+        if (isset($data['oxygen'])) {
+            $data['oxygen_update_time'] = date('Y-m-d H:i:s');
+        }
+        //体温
+        if (isset($data['temp'])) {
+            $data['temp_update_time'] = date('Y-m-d H:i:s');
+        }
+        //gps
+        if (isset($data['gps_long']) || isset($data['gps_lat'])) {
+            $data['gps_update_time'] = date('Y-m-d H:i:s');
+        }
+        return $data;
+    }
+}

+ 115 - 0
application/common/model/ShsendqueueModel.php

@@ -0,0 +1,115 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 手环发送队列
+ *
+ * @author wj
+ * @date 2023-08-19
+ */
+class ShsendqueueModel extends Model
+{
+    protected $table = "t_shouhuan_send_queue";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+    /**
+     * 格式化信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function formatinfo($data)
+    {
+        //血压
+        if (isset($data['blood_height_pressure']) || isset($data['blood_low_pressure'])) {
+            $data['blood_update_time'] = date('Y-m-d H:i:s');
+        }
+        //心率
+        if (isset($data['heart_rate'])) {
+            $data['heart_update_time'] = date('Y-m-d H:i:s');
+        }
+        //血养
+        if (isset($data['oxygen'])) {
+            $data['oxygen_update_time'] = date('Y-m-d H:i:s');
+        }
+        //体温
+        if (isset($data['temp'])) {
+            $data['temp_update_time'] = date('Y-m-d H:i:s');
+        }
+        //gps
+        if (isset($data['gps_long']) || isset($data['gps_lat'])) {
+            $data['gps_update_time'] = date('Y-m-d H:i:s');
+        }
+        return $data;
+    }
+}

+ 115 - 0
application/common/model/TestShoneReceiveInfoModel.php

@@ -0,0 +1,115 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 手环类型 1 接受信息 实时数据
+ *
+ * @author wj
+ * @date 2023-08-14
+ */
+class TestShoneReceiveInfoModel extends Model
+{
+    protected $table = "test_shouhuan_one_receive_info";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+    /**
+     * 格式化信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function formatinfo($data)
+    {
+        //血压
+        if (isset($data['blood_height_pressure']) || isset($data['blood_low_pressure'])) {
+            $data['blood_update_time'] = date('Y-m-d H:i:s');
+        }
+        //心率
+        if (isset($data['heart_rate'])) {
+            $data['heart_update_time'] = date('Y-m-d H:i:s');
+        }
+        //血养
+        if (isset($data['oxygen'])) {
+            $data['oxygen_update_time'] = date('Y-m-d H:i:s');
+        }
+        //体温
+        if (isset($data['temp'])) {
+            $data['temp_update_time'] = date('Y-m-d H:i:s');
+        }
+        //gps
+        if (isset($data['gps_long']) || isset($data['gps_lat'])) {
+            $data['gps_update_time'] = date('Y-m-d H:i:s');
+        }
+        return $data;
+    }
+}

+ 84 - 0
application/common/model/TestShoneReceiveInfoRecode.php

@@ -0,0 +1,84 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 手环类型 1 接受信息 历史数据
+ *
+ * @author wj
+ * @date 2023-08-14
+ */
+class TestShoneReceiveInfoRecode extends Model
+{
+    protected $table = "test_shouhuan_one_receive_info_recode";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+}

+ 84 - 0
application/common/model/TestShoneReceiveQueueModel.php

@@ -0,0 +1,84 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 接收信息队列
+ *
+ * @author wj
+ * @date 2023-08-14
+ */
+class TestShoneReceiveQueueModel extends Model
+{
+    protected $table = "test_shouhuan_one_receive_queue";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+}

+ 85 - 0
application/common/model/TestShoneSendListModel.php

@@ -0,0 +1,85 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 手环一发送列表
+ *
+ * @author wj
+ * @date 2023-08-14
+ */
+class TestShoneSendListModel extends Model
+{
+    protected $table = "test_shouhuan_one_send_list";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+
+}

+ 84 - 0
application/common/model/TestShoneSendQueueModel.php

@@ -0,0 +1,84 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 发送信息队列
+ *
+ * @author wj
+ * @date 2023-08-14
+ */
+class TestShoneSendQueueModel extends Model
+{
+    protected $table = "test_shouhuan_one_send_queue";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据id删除信息
+     *
+     * @param  [type] $id
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function deleteinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+}

+ 799 - 0
application/common/server/ShOneanalysisTest.php

@@ -0,0 +1,799 @@
+<?php
+
+namespace app\common\server;
+
+use app\common\model\FacilityModel;
+use app\common\model\TestShoneReceiveInfoModel;
+use app\common\model\TestShoneReceiveInfoRecode;
+use app\common\model\TestShoneReceiveQueueModel;
+use app\common\model\TestShoneSendListModel;
+use app\common\model\TestShoneSendQueueModel;
+use think\facade\Log;
+
+/**
+ * 手环字符串解析 测试用
+ *
+ * @author wj
+ * @date 2023-08-11
+ */
+class ShOneanalysisTest
+{
+    private $num_scale = 16; //16进制
+    /**
+     * 校验长度
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function checklen($len, $str)
+    {
+        $strlen = mb_strlen($str);
+        if ($len != $strlen) {
+            return false;
+        }
+        return true;
+    }
+    /**
+     * 获取信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function getline($str)
+    {
+        //[厂商*设备 ID*内容长度*内容]
+        $preg = "/^\[(.*)\*(.*)\*(.*)\*(.*)\]$/";
+        preg_match($preg, $str, $match);
+        if (empty($match)) {
+            throw new \Exception('解析失败:' . $str);
+        }
+        unset($match[0]);
+        $data = array_values($match);
+        $sandom_string = $data[0]; //厂商 随机字符串
+        $device_id_code = $data[1]; //设置id编码
+        $content_len = $data[2]; //内容长度
+        $content_str = $data[3]; //内容字符串
+        $content_len = $this->analysislen($content_len);
+        $result = $this->checklen($content_len, $content_str);
+        if (empty($result)) {
+            throw new \Exception('内容位数错误');
+        }
+        $data = [
+            'device_id_code' => $device_id_code,
+            'content_len' => $content_len,
+            'content_str' => $content_str,
+        ];
+        return $data;
+    }
+    //KA,230814,0,0,96
+    //WT,130823,160054,V,22.601242,N,113.8302765,E,0.00,0.0,29.2,0,70,96,0,0,00000000,1,1,460,0,8593,265807240,136,0,9999.0
+    //ICCID,02203002080045057806
+    public function getcommandcontent($content_str)
+    {
+        $content = explode(',', $content_str);
+        return $content;
+    }
+
+    /**
+     * 保存手环设备one信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function saveshouhuanoneinfo()
+    {
+        //保存时时
+        //保存历史
+    }
+    //内容解析
+    //解析长度
+    public function analysislen($len)
+    {
+        //低位数在前
+        $len = base_convert($len, 16, 10);
+        return $len;
+    }
+    /**
+     * 获取命令信息
+     *
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function getcommandinfo($command)
+    {
+        $command = strtoupper($command);
+        $data = [
+            'LK' => [
+                'content' => [
+                    'command' => 'LK',
+                ],
+                'kind' => 'back',
+            ],
+            'PING' => [
+                'content' => [
+                    'command' => 'PING',
+                    'isbind' => 1,
+                ],
+                'kind' => 'back',
+            ],
+            'KA' => [
+                'content' => [
+                    'command' => 'KA',
+                ],
+                'kind' => 'back',
+            ],
+            'MONITOR' => [
+                'content' => [
+                    'command' => 'MONITOR',
+                    'telno' => '',
+                ],
+                'kind' => 'send',
+            ],
+            'SOS' => [
+                'content' => [
+                    'command' => 'SOS',
+                    'telno1' => '',
+                    'telno2' => '',
+                    'telno3' => '',
+                ],
+                'kind' => 'send',
+            ],
+            'VERNO' => [
+                'content' => [
+                    'command' => 'VERNO',
+                ],
+                'kind' => 'send',
+            ],
+            'ZONE' => [
+                'content' => [
+                    'command' => 'ZONE',
+                    'zone' => '',
+                ],
+                'kind' => 'send',
+            ],
+            'POWEROFF' => [
+                'content' => [
+                    'command' => 'POWEROFF',
+                ],
+                'kind' => 'send',
+            ],
+            'TEMP' => [
+                'content' => [
+                    'command' => 'temp',
+                ],
+                'kind' => 'back',
+            ],
+            'BPHRT' => [
+                'content' => [
+                    'command' => 'bphrt',
+                ],
+                'kind' => 'back',
+            ],
+            'HEART' => [
+                'content' => [
+                    'command' => 'heart',
+                ],
+                'kind' => 'back',
+            ],
+            'BLOOD' => [
+                'content' => [
+                    'command' => 'blood',
+                ],
+                'kind' => 'back',
+            ],
+            'OXYGEN' => [
+                'content' => [
+                    'command' => 'oxygen',
+                ],
+                'kind' => 'back',
+            ],
+        ];
+        if (!isset($data[$command])) {
+            return false;
+        }
+        return $data[$command];
+    }
+
+    public function gettsendcommandinfo($command)
+    {
+        $command = strtoupper($command);
+        $data = [
+            'UD' => [
+                'content' => [
+                    'command' => 'WT',
+                    'date' => '',
+                    'time' => '',
+                    'is_location' => '',
+                    'gps_long' => '',
+                    'gps_long_tag' => '',
+                    'gps_lat' => '',
+                    'gps_lat_tag' => '',
+                    'speed' => '',
+                    'direction' => '',
+                    'poster' => '',
+                    'direction' => '',
+                    'gps_satellite_num' => '',
+                    'gsm_signal_strength' => '',
+                    'electric_quantity' => '',
+                    'step_number' => '',
+                    'roll_number' => '',
+                    'terminal_status' => '',
+                ],
+                'kind' => 'tsend',
+                'need_bacl' => 0,
+            ],
+            'AL' => [
+                'content' => [
+                    'command' => 'WT',
+                    'date' => '',
+                    'time' => '',
+                    'is_location' => '',
+                    'gps_long' => '',
+                    'gps_long_tag' => '',
+                    'gps_lat' => '',
+                    'gps_lat_tag' => '',
+                    'speed' => '',
+                    'direction' => '',
+                    'poster' => '',
+                    'direction' => '',
+                    'gps_satellite_num' => '',
+                    'gsm_signal_strength' => '',
+                    'electric_quantity' => '',
+                    'step_number' => '',
+                    'roll_number' => '',
+                    'terminal_status' => '',
+                ],
+                'kind' => 'tsend',
+                'need_bacl' => 0,
+            ],
+            'KA' => [
+                'content' => [
+                    'command' => 'KA',
+                    'date' => '',
+                    'step_number' => '',
+                    'roll_number' => '',
+                    'electric_quantity' => '',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+            'LK' => [
+                'content' => [
+                    'command' => 'LK',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+            'MONITOR' => [
+                'content' => [
+                    'command' => 'MONITOR',
+                ],
+                'kind' => 'tback',
+            ],
+            'SOS3' => [
+                'content' => [
+                    'command' => 'SOS',
+                ],
+                'kind' => 'tback',
+            ],
+            'VERNO' => [
+                'content' => [
+                    'command' => 'VERNO',
+                    'version' => '',
+                ],
+                'kind' => 'tback',
+            ],
+            'TEMP' => [
+                'content' => [
+                    'command' => 'temp',
+                    'temp' => '',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+            'BPHRT' => [
+                'content' => [
+                    'command' => 'bphrt',
+                    'blood_height_pressure' => '',
+                    'blood_low_pressure' => '',
+                    'heart_rate' => '',
+                    'height' => '',
+                    'gender' => '',
+                    'age' => '',
+                    'weight' => '',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+            'HEART' => [
+                'content' => [
+                    'command' => 'heart',
+                    'heart_rate' => '',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+            'BLOOD' => [
+                'content' => [
+                    'command' => 'blood',
+                    'blood_height_pressure' => '',
+                    'blood_low_pressure' => '',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+            'OXYGEN' => [
+                'content' => [
+                    'command' => 'oxygen',
+                    'oxygen' => '',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+        ];
+        if (!isset($data[$command])) {
+            return false;
+        }
+        return $data[$command];
+    }
+    /**
+     * 获取回复权重
+     *
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function getsendweight($command)
+    {
+        $weight = -1;
+        switch ($command) {
+            case 'POWEROFF':
+                //关机
+                $weight = 99;
+                break;
+            case 'RESET':
+                //重启
+                $weight = 98;
+                break;
+            case 'LK':
+            case 'PING':
+            case 'KA':
+            case 'AL':
+            case 'UD2';
+                $weight = 1;
+                break;
+            case 'UPLOAD':
+            case 'MONITOR':
+            case 'SOS':
+            case 'LANG':
+            case 'ZONE':
+            case 'CENTER':
+            case 'SOSSMS':
+            case 'REMOVE':
+            case 'REMOVESMS':
+            case 'VERNO':
+            case 'CR':
+            case 'SILENCETIME2':
+            case 'WALKTIME':
+            case 'SLEEPTIME':
+            case 'FIND':
+            case 'REMIND':
+            case 'SCHEDULE':
+            case 'PHB':
+            case 'PHBX':
+            case 'DPHBX':
+            case 'MESSAGE':
+            case 'FACTORY':
+            case 'PROFILE':
+            case 'BTEMP2':
+            case 'BODYTEMP':
+            case 'BTWARNSET':
+            case 'APPLOCK':
+            case 'HRTSTART':
+            case 'BPHRT':
+            case 'LSSET':
+                $weight = 0;
+                break;
+            default:
+                $weight = -1;
+                break;
+        }
+        if ($weight < 0) {
+            //不需设置 发送信息
+            return false;
+        }
+        return $weight;
+    }
+    /**
+     * 获取设别表id
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function getfacilityid($device_id_code)
+    {
+        $m_f = new FacilityModel();
+        $where = ['code' => $device_id_code, 'status' => 1];
+        $finfo = $m_f->getInfo($where, ['id']);
+        if (empty($finfo)) {
+            throw new \Exception("设备信息错误:" . $device_id_code);
+            return false;
+        }
+        $id = $finfo['id'];
+        return $id;
+    }
+    /**
+     * 创建发送信息
+     *
+     * @param  [type] $data
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function createbacksendmsg($facility_id, $device_id_code, $data, $command)
+    {
+        $infoarr = $this->gettsendcommandinfo($command);
+        if (!$infoarr) {
+            Log::write("无对应命令数据1:" . $command, 'shouhuan');
+            Log::write($data, 'shouhuan');
+            return false;
+        }
+        $data = $this->getdata($data, $command, $infoarr);
+        $info_content = $data['info_content'];
+        $need_back = isset($data['need_back']) && $data['need_back'] ? true : false;
+        if ($need_back) {
+            $infoarr = $this->getcommandinfo($command);
+            $data = $this->getdata($data, $command, $infoarr);
+            $info_content = $data['info_content'];
+            $weight = $this->getsendweight($command);
+            $content = implode(',', $info_content);
+            $msgdata = [
+                0 => '3G',
+                'device_id_code' => $device_id_code,
+                'len' => str_pad(dechex(mb_strlen($content)), 4, "0", STR_PAD_LEFT),
+                'content' => $content,
+            ];
+            $msg = '[' . implode('*', $msgdata) . ']';
+            $sslInsertData = [
+                'facility_id' => $facility_id,
+                'device_id_code' => $device_id_code,
+                'send_msg' => $msg,
+                'send_time' => date('Y-m-d H:i:s'),
+                'send_weight' => $weight,
+            ];
+            $m_ssl = new TestShoneSendListModel();
+            $sslid = $m_ssl->insertData($sslInsertData);
+            if (empty($sslid)) {
+                throw new \Exception("发送数据添加失败");
+            }
+            $data = [
+                'msg' => $msg,
+                'weight' => $weight,
+                'createtime' => date('Y-m-d H:i:s'),
+                'device_id_code' => $device_id_code,
+                'list_id' => $sslid,
+            ];
+            $m_ssq = new TestShoneSendQueueModel();
+            $id = $m_ssq->insertData($data);
+            if (empty($id)) {
+                throw new \Exception("发送队列数据添加失败");
+            }
+            return $data;
+        }
+        return false;
+    }
+    /**
+     * 获取数据值
+     *
+     * @param  [type] $data
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function getdata($data, $command, $infoarr)
+    {
+        $info_content = $infoarr['content'];
+        foreach (array_keys($info_content) as $key => $value) {
+            if (empty($info_content[$value])) {
+                if (isset($data[$key])) {
+                    $info_content[$value] = $data[$key];
+                }
+            }
+        }
+        if (isset($info_content['time'])) {
+            $time = $info_content['time'];
+            $info_content['time'] = $this->gettime($time);
+        }
+        if (isset($info_content['date'])) {
+            $date = $info_content['date'];
+            $info_content['date'] = $this->getdate($date);
+        }
+        $infoarr['info_content'] = $info_content;
+        return $infoarr;
+    }
+    /**
+     * 保存接收信息队列
+     *
+     * @param  [type] $data
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function savereceivequeue($data)
+    {
+        $m_srq = new TestShoneReceiveQueueModel();
+        $data = [
+            'msg' => $data,
+            'createtime' => date('Y-m-d H:i:s'),
+        ];
+        $id = $m_srq->insertData($data);
+        //Log::write('id:' . $id, 'shouhuan');
+        if (empty($id)) {
+            return false;
+        }
+        return true;
+    }
+    /**
+     * 保存手环信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function saveshinfo($facility_id, $device_id_code, $data, $original_str)
+    {
+        $command = $data[0];
+        $infoarr = $this->gettsendcommandinfo($command);
+        if (!$infoarr) {
+            Log::write("无对应命令数据2:" . $command, 'shouhuan');
+            Log::write($original_str, 'shouhuan');
+            return false;
+        }
+        $data = $this->getdata($data, $data[0], $infoarr);
+        $m_sri = new TestShoneReceiveInfoModel();
+        $m_srir = new TestShoneReceiveInfoRecode();
+        $data = $data['info_content'];
+        $data['facility_id'] = $facility_id;
+        $data['device_id_code'] = $device_id_code;
+
+        //$m_sri处理
+        $sriwhere = [
+            'facility_id' => $facility_id,
+            'device_id_code' => $device_id_code,
+        ];
+        $sriinfo = $m_sri->getInfo($sriwhere);
+        unset($data['command']);
+        if (empty($sriinfo)) {
+            $sriinsertData = $data;
+            $sriinsertData['createtime'] = date('Y-m-d H:i:s');
+            $sriinsertData = $m_sri->formatinfo($sriinsertData);
+            $sriid = $m_sri->insertData($sriinsertData);
+            if (empty($sriid)) {
+                throw new \Exception("设备信息添加失败:" . $device_id_code);
+            }
+        } else {
+            unset($data['device_id_code']);
+            unset($data['facility_id']);
+            $sriid = $sriinfo['id'];
+            $sriupdateData = $data;
+            $sriupdateData['updatetime'] = date('Y-m-d H:i:s');
+            $sriupdateData = $m_sri->formatinfo($sriupdateData);
+            $row = $m_sri->updateinfo(['id' => $sriid], $sriupdateData);
+            if (empty($row)) {
+                throw new \Exception("设备信息修改失败:" . $device_id_code);
+            }
+        }
+
+        //m_srir处理
+        $data['original_str'] = $original_str;
+        $sririnsertData = $data;
+        $sririnsertData['facility_id'] = $facility_id;
+        $sririnsertData['device_id_code'] = $device_id_code;
+        $sririnsertData['createtime'] = date('Y-m-d H:i:s');
+        $sririnsertData['command'] = $command;
+        $sririd = $m_srir->insertData($sririnsertData);
+        if (empty($sririd)) {
+            throw new \Exception("设备历史信息添加失败:" . $device_id_code);
+        }
+    }
+    /**
+     * 获取接收信息队列列表
+     *
+     * @param  [type] $page
+     * @param  [type] $size
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function getreceivequeuelist($page = null, $size = null)
+    {
+        $m_srq = new TestShoneReceiveQueueModel();
+        $where = ['status' => 0];
+        $size = empty($size) ? 20 : $size;
+        if (empty($page)) {
+            $count = $m_srq->getList($where, 'count');
+            $totalpage = ceil($count / $size);
+            $data = ['totalpage' => $totalpage, 'size' => $size];
+            return $data;
+        } else {
+            $list = $m_srq->getList($where, '*', $page, $size, 'id asc');
+            if (empty($list)) {
+                //Log::write("手环接收信息队列-无数据", 'shouhuan');
+                return false;
+            }
+            $list = $list->toArray();
+            $ids = array_column($list, 'id');
+            $updatecount = $m_srq->updateinfo(['id' => ['in', $ids], 'status' => 0], ['status' => 1]);
+            if ($updatecount != count($ids)) {
+                //Log::write("手环接收信息队列-部分未修改", 'shouhuan');
+                $updatecount = empty($updatecount) ? 0 : (int) $updatecount;
+                Log::write("count:" . count($ids) . " update count:" . $updatecount, 'shouhuan');
+            }
+            if (empty($updatecount)) {
+                //Log::write("手环接收信息队列-无修改数据", 'shouhuan');
+                return false;
+            }
+            return $list;
+        }
+    }
+    /**
+     * 获取发送信息队列列表
+     *
+     * @param  [type] $page
+     * @param  [type] $size
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function getsendqueuelist($device_id_code, $page = null, $size = null)
+    {
+        $m_ssq = new TestShoneSendQueueModel();
+        $where = ['status' => 0, 'device_id_code' => $device_id_code];
+        $size = empty($size) ? 20 : $size;
+        if (empty($page)) {
+            $count = $m_ssq->getList($where, 'count');
+            $totalpage = ceil($count / $size);
+            $data = ['totalpage' => $totalpage, 'size' => $size];
+            return $data;
+        } else {
+            $list = $m_ssq->getList($where, '*', $page, $size, 'id asc,weight desc');
+            if (empty($list)) {
+                Log::write("手环发送信息队列-无数据", 'shouhuan');
+                return false;
+            }
+            $list = $list->toArray();
+            $ids = array_column($list, 'id');
+            $updatecount = $m_ssq->updateinfo(['id' => ['in', $ids], 'status' => 0], ['status' => 1]);
+            if ($updatecount != count($ids)) {
+                Log::write("手环发送信息队列-部分未修改", 'shouhuan');
+                Log::write("count:" . count($ids) . " update count:" . $updatecount, 'shouhuan');
+            }
+            if (empty($updatecount)) {
+                Log::write("手环发送信息队列-无修改数据", 'shouhuan');
+                return false;
+            }
+            return $list;
+        }
+    }
+
+    public function sendmsgsuccess($item)
+    {
+        $m_ssq = new TestShoneSendQueueModel();
+        $m_ssl = new TestShoneSendListModel();
+        $ssqid = $item['id'];
+        if ($item['list_id']) {
+            $list_id = $item['list_id'];
+            $sslwhere = ['id' => $list_id, 'is_send' => 0];
+            $sslinfo = $m_ssl->getInfo($sslwhere);
+            if ($sslinfo) {
+                $row = $m_ssl->updateinfo(['id' => $sslinfo['id']], ['is_send' => 1, 'send_time' => date('Y-m-d H:i:s')]);
+            }
+        }
+        $ssqwhere = ['id' => $ssqid];
+        $ssqinfo = $m_ssq->getInfo($ssqwhere);
+        if ($ssqinfo) {
+            $m_ssq->deleteinfobyid($ssqid);
+        }
+    }
+    public function receivemsgsuccess($item)
+    {
+        $m_srq = new TestShoneReceiveQueueModel();
+        $srqid = $item['id'];
+        $srqwhere = ['id' => $srqid, 'status' => 1];
+        $srqinfo = $m_srq->getInfo($srqwhere);
+        if ($srqinfo) {
+            $m_srq->deleteinfobyid($srqid);
+        }
+    }
+    /**
+     * 日期解析
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function getdate($date)
+    {
+        $day = substr($date, 0, 2);
+        $month = substr($date, 2, 2);
+        $year = substr($date, 4, 2);
+        $year1 = date('Y');
+        $year2 = substr($year1, 0, 2);
+        $year = $year2 . $year;
+        if ($year != $year1) {
+            $day = date('Y-m-d');
+        } else {
+            $day = $year . '-' . $month . '-' . $day;
+        }
+        return $day;
+    }
+    public function gettime($time)
+    {
+        $hour = substr($time, 0, 2);
+        $minute = substr($time, 2, 2);
+        $second = substr($time, 4, 2);
+        $time = $hour . ':' . $minute . ':' . $second;
+        return $time;
+    }
+    /**
+     * 初始化手环接收信息解析
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function initanalysisShoneReceiveMsg()
+    {
+        $m_srq = new TestShoneReceiveQueueModel();
+        $where = ['status' => 1];
+        $m_srq->updateinfo($where, ['status' => 0]);
+    }
+    /**
+     * 拆包
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function unpack($data)
+    {
+        $arr = explode("][", $data);
+        foreach ($arr as $key => $value) {
+            if ($value[0] !== "[") {
+                $arr[$key] = '[' . $value;
+            }
+            if ($value[mb_strlen($value) - 1] !== "]") {
+                $arr[$key] .= "]";
+            }
+        }
+        return $arr;
+    }
+
+    public function showfortest($data)
+    {
+
+        $strdata = $this->getline($data);
+        $content = $strdata['content_str'];
+        $content = $this->getcommandcontent($content);
+        $command = $content[0];
+        $showcommands = [
+            'SOS', 'CR', 'UPLOAD', 'SLEEPTIME', 'ZONE', 'FALLDOWN',
+            'APPLOCK', 'FACTORY', 'VERNO', 'LOWBAT', 'UD', 'POWEROFF', 'MESSAGE',
+            'WALKTIME', 'PEDO', 'PHB', 'PHL', 'REMIND', 'SILENCETIME2', 'BOOTOFF',
+            'REMOVE', 'INFO', 'AL', 'LSSET',
+        ];
+        if (in_array($command, $showcommands)) {
+            var_dump(date('Y-m-d H:i:s'));
+            var_dump($data);
+        }
+    }
+}

+ 1442 - 0
application/common/server/SouhuanAnalysis.php

@@ -0,0 +1,1442 @@
+<?php
+
+namespace app\common\server;
+
+use app\common\model\FacilityModel;
+use app\common\model\ShalarmlistModel;
+use app\common\model\ShinfoModel;
+use app\common\model\ShreceivequeueModel;
+use app\common\model\ShreceiveredocdeModel;
+use app\common\model\ShsendlistModel;
+use app\common\model\ShsendqueueModel;
+use think\facade\Log;
+
+/**
+ * 手环字符串解析
+ *
+ * @author wj
+ * @date 2023-08-11
+ */
+class SouhuanAnalysis
+{
+    /**
+     * 校验长度
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function checklen($len, $str)
+    {
+        $strlen = mb_strlen($str);
+        if ($len != $strlen) {
+            Log::write("长度校验失败: len:" . $len . " str:" . $str, 'shouhuan');
+            return false;
+        }
+        return true;
+    }
+    /**
+     * 获取信息 整个信息解析
+     * 并验证是否可解析 无解析命令配置 不报错
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function getline($str, $field = null)
+    {
+        //[厂商*设备 ID*内容长度*内容]
+        $preg = "/^\[(.*)\*(.*)\*(.*)\*(.*)\]$/";
+        preg_match($preg, $str, $match);
+        if (empty($match)) {
+            Log::write("解析失败:" . $str, 'shouhuan');
+            throw new \Exception('解析失败:' . $str);
+        }
+        unset($match[0]);
+        $data = array_values($match);
+        $sandom_string = $data[0]; //厂商 随机字符串
+        $device_id_code = $data[1]; //设置id编码
+        $content_len = $data[2]; //内容长度
+        $content_str = $data[3]; //内容字符串
+        $content_len = $this->analysislen($content_len);
+        $result = $this->checklen($content_len, $content_str);
+        if (empty($result)) {
+            $errmsg = '内容位数错误';
+            Log::write($errmsg . ":" . $str, 'shouhuan');
+            throw new \Exception($errmsg);
+        }
+        $data = [
+            'device_id_code' => $device_id_code,
+            'content_len' => $content_len,
+            'content_str' => $content_str,
+        ];
+        $contentarr = $this->getcommandcontent($content_str);
+        $command = $contentarr['command'];
+        $data['command'] = $command;
+        $data['content_arr'] = $contentarr['content'];
+        $config = $this->getreceivecommandinfo($command);
+        $data['config'] = $config;
+        if (!$config) {
+            $errmsg = '命令无解析配置 command:' . $command;
+            Log::write($errmsg, 'shouhuan');
+            return false;
+        }
+        if (isset($field)) {
+            return $data[$field];
+        }
+        return $data;
+    }
+    /**
+     * 内容解析
+     *
+     * @param  [type] $content_str
+     * @return void
+     * @author wj
+     * @date 2023-08-19
+     */
+    public function getcommandcontent($content_str)
+    {
+        $content = explode(',', $content_str);
+        $command = $content[0];
+        unset($content[0]);
+        $data = [
+            'command' => $command,
+            'content' => $content,
+        ];
+        return $data;
+    }
+    /**
+     * 解析终端发送命令长度
+     *
+     * @param  [type] $len
+     * @return void
+     * @author wj
+     * @date 2023-08-18
+     */
+    public function analysislen($len)
+    {
+        $len = base_convert($len, 16, 10);
+        return $len;
+    }
+    /**
+     * 获取平台发送命令信息
+     *
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function getsendcommandinfo($command)
+    {
+        $command = strtoupper($command);
+        $data = [
+            //平台发送
+            'ZONE' => [
+                'content' => [
+                    'command' => 'ZONE',
+                    'zone' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'UPLOAD' => [
+                'content' => [
+                    'command' => 'UPLOAD',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'CR' => [
+                'content' => [
+                    'command' => 'CR',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'SLEEPTIME' => [
+                'content' => [
+                    'command' => 'CR',
+                ],
+                'kind' => 'send',
+                'content_custom' => true,
+                'need_back' => 1,
+            ],
+            'FALLDOWN' => [
+                'content' => [
+                    'command' => 'FALLDOWN',
+                    'is_open' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'FACTORY' => [
+                'content' => [
+                    'command' => 'FACTORY',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'SOS' => [
+                'content' => [
+                    'command' => 'SOS',
+                ],
+                'kind' => 'send',
+                'content_custom' => true,
+                'need_back' => 1,
+            ],
+            'VERNO' => [
+                'content' => [
+                    'command' => 'VERNO',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'LOWBAT' => [
+                'content' => [
+                    'command' => 'LOWBAT',
+                    'is_open' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'POWEROFF' => [
+                'content' => [
+                    'command' => 'POWEROFF',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'LSSET' => [
+                'content' => [
+                    'command' => 'LSSET',
+                    'content_custom' => true,
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'PEDO' => [
+                'content' => [
+                    'command' => 'PEDO',
+                    'is_open' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'PHL' => [
+                'content' => [
+                    'command' => 'PEDO',
+                ],
+                'kind' => 'send',
+                'content_custom' => true,
+                'need_back' => 1,
+            ],
+            'REMIND' => [
+                'content' => [
+                    'command' => 'REMIND',
+                ],
+                'kind' => 'send',
+                'content_custom' => true,
+                'need_back' => 1,
+            ],
+            'SILENCETIME2' => [
+                'content' => [
+                    'command' => 'SILENCETIME2',
+                ],
+                'kind' => 'send',
+                'content_custom' => true,
+                'need_back' => 1,
+            ],
+            'BOOTOFF' => [
+                'content' => [
+                    'command' => 'BOOTOFF',
+                    'is_open' => '',
+                    'bootup_time' => '',
+                    'shutdown_time' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'REMOVE' => [
+                'content' => [
+                    'command' => 'REMOVE',
+                    'is_open' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            //平台回复
+            'LK' => [
+                'content' => [
+                    'command' => 'LK',
+                ],
+                'kind' => 'back',
+            ],
+            'PING' => [
+                'content' => [
+                    'command' => 'PING',
+                    'isbind' => 1,
+                ],
+                'kind' => 'back',
+            ],
+            'KA' => [
+                'content' => [
+                    'command' => 'KA',
+                ],
+                'kind' => 'back',
+            ],
+            'TEMP' => [
+                'content' => [
+                    'command' => 'temp',
+                ],
+                'kind' => 'back',
+            ],
+            'BPHRT' => [
+                'content' => [
+                    'command' => 'bphrt',
+                ],
+                'kind' => 'back',
+            ],
+            'HEART' => [
+                'content' => [
+                    'command' => 'heart',
+                ],
+                'kind' => 'back',
+            ],
+            'BLOOD' => [
+                'content' => [
+                    'command' => 'blood',
+                ],
+                'kind' => 'back',
+            ],
+            'OXYGEN' => [
+                'content' => [
+                    'command' => 'oxygen',
+                ],
+                'kind' => 'back',
+            ],
+            'AL' => [
+                'content' => [
+                    'command' => 'AL',
+                ],
+                'kind' => 'back',
+            ],
+        ];
+        if (!isset($data[$command])) {
+            return false;
+        }
+        return $data[$command];
+    }
+    /**
+     * 设置可解析数据 终端发送信息解析
+     *
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-18
+     * analysis_digit 解析位数
+     * content 解析对应字段
+     * kind 类型 tsend 平台发送 tback平台回复
+     * need_back 是否需回复 1是 0否 没设置为0
+     * command 未设置则和键值相同
+     */
+    public function getreceivecommandinfo($command)
+    {
+        $command = strtoupper($command);
+        $data = [
+            'UD' => [
+                'analysis_digit' => [1, 2, 4, 6, 8, 9, 10, 13, 14, 15, 16],
+                'content' => [
+                    'date',
+                    'time',
+                    'gps_long',
+                    'gps_lat',
+                    'speed',
+                    'direction',
+                    'poster',
+                    'electric_quantity',
+                    'step_number',
+                    'roll_number',
+                    'terminal_status',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 0,
+            ],
+            'AL' => [
+                'analysis_digit' => [1, 2, 4, 6, 8, 9, 10, 13, 14, 15, 16],
+                'content' => [
+                    'date',
+                    'time',
+                    'gps_long',
+                    'gps_lat',
+                    'speed',
+                    'direction',
+                    'poster',
+                    'electric_quantity',
+                    'step_number',
+                    'roll_number',
+                    'terminal_status',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 0,
+            ],
+            'KA' => [
+                'analysis_digit' => [1, 2, 3, 4],
+                'content' => [
+                    'date',
+                    'step_number',
+                    'roll_number',
+                    'electric_quantity',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+            'LK' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+            'BPHRT' => [
+                'analysis_digit' => [1, 2, 3],
+                'content' => [
+                    'blood_height_pressure',
+                    'blood_low_pressure',
+                    'heart_rate',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+                'command' => 'bphrt',
+            ],
+            'TEMP' => [
+                'analysis_digit' => [1],
+                'content' => [
+                    'temp',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+                'command' => 'temp',
+            ],
+            'HEART' => [
+                'analysis_digit' => [1],
+                'content' => [
+                    'heart_rate',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+                'command' => 'heart',
+            ],
+            'BLOOD' => [
+                'analysis_digit' => [1, 2],
+                'content' => [
+                    'blood_height_pressure',
+                    'blood_low_pressure',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+                'command' => 'blood',
+            ],
+            'OXYGEN' => [
+                'analysis_digit' => [1],
+                'content' => [
+                    'oxygen',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+                'command' => 'oxygen',
+            ],
+            //终端回复
+            //ZONE UPLOAD CR SLEEPTIME FALLDOWN FACTORY SOS VERNO LOWBAT
+            //POWEROFF LSSET PEDO PHL REMIND SILENCETIME2 BOOTOFF REMOVE
+            'ZONE' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'UPLOAD' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'CR' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'SLEEPTIME' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'FALLDOWN' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'SOS' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'VERNO' => [
+                'analysis_digit' => [1],
+                'content' => ['version'],
+                'kind' => 'tback',
+            ],
+            'LOWBAT' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'POWEROFF' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'LSSET' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'PEDO' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'PHL' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'REMIND' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'SILENCETIME2' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'BOOTOFF' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'REMOVE' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+        ];
+        if (!isset($data[$command])) {
+            return false;
+        }
+        return $data[$command];
+    }
+    /**
+     * 获取回复权重
+     *
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function getsendweight($command)
+    {
+        $weight = -1;
+        switch ($command) {
+            case 'POWEROFF':
+                //关机
+                $weight = 99;
+                break;
+            case 'RESET':
+                //重启
+                $weight = 98; //硬件未测试
+                break;
+            //平台回复命令
+            case 'AL':
+            case 'KA':
+            case 'LK':
+            case 'PING':
+            case 'BPHRT':
+            case 'TEMP':
+            case 'HEART':
+            case 'BLOOD':
+            case 'OXYGEN':
+                $weight = 1;
+                break;
+            //平台发送命令
+            case 'ZONE':
+            case 'UPLOAD':
+            case 'CR':
+            case 'SLEEPTIME':
+            case 'FALLDOWN':
+            case 'FACTORY':
+            case 'SOS':
+            case 'VERNO':
+            case 'LOWBAT':
+            case 'POWEROFF':
+            case 'LSSET':
+            case 'PEDO':
+            case 'PHL':
+            case 'REMIND':
+            case 'SILENCETIME2':
+            case 'BOOTOFF':
+            case 'REMOVE':
+                $weight = 0;
+                break;
+            default:
+                $weight = -1;
+                break;
+        }
+        if ($weight < 0) {
+            //不需设置 发送信息
+            return false;
+        }
+        return $weight;
+    }
+    /**
+     * 获取数据值
+     *
+     * @param  [type] $data
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function getdata($config, $content_arr)
+    {
+        $analysis_digit = $config['analysis_digit'];
+        $config_content = $config['content'];
+        $data = [];
+        if (is_array($analysis_digit)) {
+            foreach ($analysis_digit as $key => $value) {
+                if (isset($content_arr[$value])) {
+                    if (isset($config_content[$key])) {
+                        $item_key = $config_content[$key];
+                        $item_value = $content_arr[$value];
+                        $data[$item_key] = $item_value;
+                    }
+                }
+            }
+        }
+        if (isset($data['time'])) {
+            $time = $data['time'];
+            $data['time'] = $this->gettime($time);
+        }
+        if (isset($data['date'])) {
+            $date = $data['date'];
+            $data['date'] = $this->getdate($date);
+        }
+        if (isset($data['terminal_status'])) {
+            $terminalstatus = $data['terminal_status'];
+            $terminal_status_arr = $this->getterminalstatus($terminalstatus);
+            unset($data['terminal_status']);
+            $data['status_type'] = $terminal_status_arr['status_type'];
+            $data['alarm_type'] = $terminal_status_arr['alarm_type'];
+        }
+        return $data;
+    }
+    /**
+     * 时间解析
+     *
+     * @param  [type] $time
+     * @return void
+     * @author wj
+     * @date 2023-08-19
+     */
+    public function gettime($time)
+    {
+        $hour = substr($time, 0, 2);
+        $minute = substr($time, 2, 2);
+        $second = substr($time, 4, 2);
+        $time = $hour . ':' . $minute . ':' . $second;
+        return $time;
+    }
+    /**
+     * 日期解析
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function getdate($date)
+    {
+        $day = substr($date, 0, 2);
+        $month = substr($date, 2, 2);
+        $year = substr($date, 4, 2);
+        $year1 = date('Y');
+        $year2 = substr($year1, 0, 2);
+        $year = $year2 . $year;
+        if ($year != $year1) {
+            $day = date('Y-m-d');
+        } else {
+            $day = $year . '-' . $month . '-' . $day;
+        }
+        return $day;
+    }
+    /**
+     * 解析终端状态
+     *
+     * @param  [type] $terminal_status
+     * @return void
+     * @author wj
+     * @date 2023-08-19
+     */
+    public function getterminalstatus($terminal_status)
+    {
+        $terminal_status = str_split($terminal_status);
+        foreach ($terminal_status as $key => $value) {
+            $value = base_convert($value, 16, 2);
+            $value = str_pad($value, 4, "0", STR_PAD_LEFT);
+            $terminal_status[$key] = $value;
+        }
+        $terminal_status_str = implode("", $terminal_status);
+        $mid = mb_strlen($terminal_status_str) / 2;
+        $alarm = substr($terminal_status_str, 0, $mid);
+        $first_num = strpos($alarm, 1);
+        $end_num = strrpos($alarm, 1);
+        if ($first_num != $end_num) {
+            Log::write("状态解析错误:报警:" . $terminal_status . " " . $terminal_status_str, 'shouhuan');
+        }
+        //16:SOS报警;17:低电报警;20:手环拆除报警;21:跌倒报警;22:心率异常报警
+        $alarm_type = $first_num;
+        $status = substr($terminal_status_str, $mid);
+        $first_num = strpos($status, 1);
+        $end_num = strrpos($status, 1);
+        if ($first_num != $end_num) {
+            Log::write("状态解析错误:状态:" . $terminal_status . " " . $terminal_status_str, 'shouhuan');
+        }
+        //1:低电状态;2:出围栏状态;3:进围栏状态;4:手环戴上取下状态;5:手表运行静止状态
+        $status_type = $first_num + 1;
+        $data = [
+            'alarm_type' => $alarm_type,
+            'status_type' => $status_type,
+        ];
+        return $data;
+    }
+    // /**
+    //  * 解析报警
+    //  *
+    //  * @param  [type] $first_num
+    //  * @return void
+    //  * @author wj
+    //  * @date 2023-08-19
+    //  */
+    // public function getalarm($first_num)
+    // {
+    //     $data = [
+    //         16 => 'SOS报警',
+    //         17 => '低电报警',
+    //         18 => '出围栏报警',
+    //         19 => '进围栏报警',
+    //         20 => '手环拆除报警',
+    //         21 => '跌倒报警',
+    //         22 => '心率异常报警',
+    //     ];
+    //     if (isset($data[$first_num])) {
+    //         return $data[$first_num];
+    //     }
+    //     return false;
+    // }
+    // /**
+    //  * 解析状态
+    //  *
+    //  * @param  [type] $first_num
+    //  * @return void
+    //  * @author wj
+    //  * @date 2023-08-19
+    //  */
+    // public function getstatus($first_num)
+    // {
+    //     $data = [
+    //         0 => '低电状态',
+    //         1 => '出围栏状态',
+    //         2 => '进围栏状态',
+    //         3 => '手环戴上取下状态',
+    //         4 => '手表运行静止状态',
+    //     ];
+    //     if (isset($data[$first_num])) {
+    //         return $data[$first_num];
+    //     }
+    //     return false;
+    // }
+    // ̄へ ̄-----------内容解析结束---------------- ̄へ ̄
+    // ̄へ ̄-----------业务处理开始---------------- ̄へ ̄
+    /**
+     * 获取设别表id
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function getfacilityid($device_id_code)
+    {
+        $m_f = new FacilityModel();
+        $where = ['code' => $device_id_code, 'status' => 1];
+        $finfo = $m_f->getInfo($where, ['id']);
+        if (empty($finfo)) {
+            throw new \Exception("设备信息错误:" . $device_id_code);
+            return false;
+        }
+        $id = $finfo['id'];
+        return $id;
+    }
+    /**
+     * 保存接收信息队列
+     *
+     * @param  [type] $data
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function savereceivequeue($data)
+    {
+        $m_srq = new ShreceivequeueModel();
+        $data = [
+            'msg' => $data,
+            'createtime' => date('Y-m-d H:i:s'),
+        ];
+        $id = $m_srq->insertData($data);
+        if (empty($id)) {
+            return false;
+        }
+        return true;
+    }
+    /**
+     * 获取接收信息队列列表
+     *
+     * @param  [type] $page
+     * @param  [type] $size
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function getreceivequeuelist($page = null, $size = null)
+    {
+        $m_srq = new ShreceivequeueModel();
+        $where = ['status' => 0];
+        $size = empty($size) ? 20 : $size;
+        if (empty($page)) {
+            $count = $m_srq->getList($where, 'count');
+            $totalpage = ceil($count / $size);
+            $data = ['totalpage' => $totalpage, 'size' => $size];
+            return $data;
+        } else {
+            $list = $m_srq->getList($where, '*', $page, $size, 'id asc');
+            if (empty($list)) {
+                //Log::write("手环接收信息队列-无数据", 'shouhuan');
+                return false;
+            }
+            $list = $list->toArray();
+            foreach ($list as $key => $value) {
+                $id = $value['id'];
+                if (1 != $value['status']) {
+                    $row = $m_srq->updateinfo(['id' => $id], ['status' => 1]);
+                    if (1 != $row) {
+                        $msg = "Shreceivequeue id:" . $id . " 修改失败";
+                        Log::write($msg, 'shouhuan');
+                        unset($list[$key]);
+                    }
+                }
+            }
+            return $list;
+        }
+    }
+    /**
+     * 获取发送信息队列列表
+     *
+     * @param  [type] $page
+     * @param  [type] $size
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function getsendqueuelist($device_id_code, $page = null, $size = null)
+    {
+        $m_ssq = new ShsendqueueModel();
+        $where = ['status' => 0, 'device_id_code' => $device_id_code];
+        $size = empty($size) ? 20 : $size;
+        if (empty($page)) {
+            $count = $m_ssq->getList($where, 'count');
+            $totalpage = ceil($count / $size);
+            $data = ['totalpage' => $totalpage, 'size' => $size];
+            return $data;
+        } else {
+            $list = $m_ssq->getList($where, '*', $page, $size, 'id asc,weight desc');
+            if (empty($list)) {
+                Log::write("手环发送信息队列-无数据", 'shouhuan');
+                return false;
+            }
+            $list = $list->toArray();
+            foreach ($list as $key => $value) {
+                $id = $value['id'];
+                if (1 != $value['status']) {
+                    $row = $m_ssq->updateinfo(['id' => $id], ['status' => 1]);
+                    if (1 != $row) {
+                        $msg = "Shsendqueue id:" . $id . " 修改失败";
+                        Log::write($msg, 'shouhuan');
+                        unset($list[$key]);
+                    }
+                }
+            }
+            return $list;
+        }
+    }
+    /**
+     * 保存手环信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function saveshinfo($facility_id, $device_id_code, $data, $original_str)
+    {
+        $command = $data['command'];
+        $content_arr = $data['content_arr'];
+        $config = $data['config'];
+        $data = $this->getdata($config, $content_arr);
+        $m_sri = new ShinfoModel();
+        $m_srir = new ShreceiveredocdeModel();
+        $m_sa = new ShalarmlistModel();
+        if ('AL' == $command) {
+            //手环警报信息
+            $data['alarm_from_type'] = 1;
+            $said = $m_sa->insertData($data);
+            if (empty($said)) {
+                $msg = "报警信息添加失败:" . $original_str;
+                Log::write($msg, 'shouhuan');
+                throw new \Exception($msg);
+            }
+        } else {
+            //手环基础信息修改
+            $sriData = $data;
+            $sriwhere = [
+                'facility_id' => $facility_id,
+                'device_id_code' => $device_id_code,
+            ];
+            $sriinfo = $m_sri->getInfo($sriwhere);
+            if (empty($sriinfo)) {
+                $sriData = [
+                    'device_id_code' => $device_id_code,
+                    'facility_id' => $facility_id,
+                ];
+                $sriinsertData = $sriData;
+                $sriinsertData['createtime'] = date('Y-m-d H:i:s');
+                $sriinsertData['updatetime'] = date('Y-m-d H:i:s');
+                $sriinsertData = $m_sri->formatinfo($sriinsertData);
+                $sriid = $m_sri->insertData($sriinsertData);
+                if (empty($sriid)) {
+                    throw new \Exception("设备信息添加失败:" . $device_id_code);
+                }
+            } else {
+                $sriid = $sriinfo['id'];
+                $sriupdateData = $sriData;
+                $sriupdateData['updatetime'] = date('Y-m-d H:i:s');
+                $sriupdateData = $m_sri->formatinfo($sriupdateData);
+                $row = $m_sri->updateinfo(['id' => $sriid], $sriupdateData);
+                if (empty($row)) {
+                    throw new \Exception("设备信息修改失败:" . $device_id_code);
+                }
+            }
+
+            //接收信息历史添加
+            $sririnsertData['facility_id'] = $facility_id;
+            $sririnsertData['device_id_code'] = $device_id_code;
+            $sririnsertData['original_str'] = $original_str;
+            $sririnsertData['content'] = json_encode($sriData);
+            $sririnsertData['command'] = $command;
+            $sririnsertData['createtime'] = date('Y-m-d H:i:s');
+            if ('tback' == $config['kind']) {
+                $is_back_msg = true;
+                $sririnsertData['is_back_msg'] = 0;
+            } else {
+                $is_back_msg = false;
+                $sririnsertData['is_back_msg'] = 1;
+            }
+            $sririd = $m_srir->insertData($sririnsertData);
+            if (empty($sririd)) {
+                throw new \Exception("设备历史信息添加失败:" . $device_id_code);
+            }
+            if ($is_back_msg) {
+                //处理回复信息
+                $m_ssl = new ShsendlistModel();
+                $where = [
+                    'is_success' => 0,
+                    'is_send' => 1,
+                    'command' => $command,
+                ];
+                $sslinfo = $m_ssl->getInfo($where);
+                if ($sslinfo) {
+                    //发送成功状态回写
+                    $sslid = $sslinfo['id'];
+                    $sslupdateData = ['is_success' => 1];
+                    $m_ssl->updateinfo(['id' => $sslid], $sslupdateData);
+                    $srirupdateData = ['send_list_id' => $sslid];
+                    $m_srir->updateinfo(['id' => $sririd], $srirupdateData);
+                }
+            }
+        }
+    }
+
+    /**
+     * 创建发送信息
+     *
+     * @param  [type] $data
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     */
+    public function createsendmsg($facility_id, $device_id_code, $data, $command, $param = [])
+    {
+        $infoarr = $this->getsendcommandinfo($command);
+        if (!$infoarr) {
+            Log::write("无对应命令数据1:" . $command, 'shouhuan');
+            Log::write($data, 'shouhuan');
+            return false;
+        }
+        $command = $data['command'];
+        $content_arr = $data['content_arr'];
+        $config = $data['config'];
+        $m_ssl = new ShsendlistModel();
+        $commandxy = "3G";
+        //仅创建
+        if ('back' == $config['kind']) {
+            $content = $config['content'];
+            $content = implode(',', $content);
+            $send_type = 0;
+            $is_success = 1;
+        }
+        if ('send' == $config['kind']) {
+            $content = $config['content'];
+            $useconmmand = $content['command'];
+            $content_custom = $config['content_custom'];
+            $need_back = $config['need_back'];
+            if ($content_custom) {
+                $functionname = 'get' . $command . "Commandinfo";
+                if (method_exists($this, $functionname)) {
+                    $content = $useconmmand . "," . $this->$functionname($param);
+                } else {
+                    throw new \Exception($command . "自定义方法不存在");
+                }
+            } else {
+                $content = implode(',', $content_arr);
+            }
+            $send_type = 1;
+            if ($need_back) {
+                $is_success = 0;
+            } else {
+                $is_success = 1;
+            }
+
+        }
+        $weight = $this->getsendweight($command);
+        $msgdata = [
+            0 => $commandxy,
+            'device_id_code' => $device_id_code,
+            'len' => str_pad(dechex(mb_strlen($content)), 4, "0", STR_PAD_LEFT),
+            'content' => $content,
+        ];
+        $msg = '[' . implode('*', $msgdata) . ']';
+        $sslInsertData = [
+            'facility_id' => $facility_id,
+            'device_id_code' => $device_id_code,
+            'command' => $command,
+            'send_msg' => $msg,
+            'send_weight' => $weight,
+            'send_time' => date('Y-m-d H:i:s'),
+            'is_success' => $is_success,
+            'send_type' => $send_type,
+        ];
+        $sslid = $m_ssl->insertData($sslInsertData);
+        if (empty($sslid)) {
+            throw new \Exception("发送数据添加失败");
+        }
+        $data = [
+            'msg' => $msg,
+            'weight' => $weight,
+            'createtime' => date('Y-m-d H:i:s'),
+            'facility_id' => $facility_id,
+            'device_id_code' => $device_id_code,
+            'send_list_id' => $sslid,
+        ];
+        $m_ssq = new ShsendqueueModel();
+        $id = $m_ssq->insertData($data);
+        if (empty($id)) {
+            throw new \Exception("发送队列数据添加失败");
+        }
+        return true;
+    }
+    /**
+     * 创建sos电话设置命令
+     * 最多三个电话
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function getSOSCommandinfo($param)
+    {
+        if (count($param) <= 3) {
+            throw new \Exception("未设置电话");
+
+        }
+        if (count($param) > 3) {
+            throw new \Exception("设置电话数量过多");
+
+        }
+        foreach ($param as $key => $value) {
+            //判断是否为手机号
+            //暂不处理
+        }
+        $info = implode(",", $param);
+        return $info;
+    }
+    /**
+     * 设置跌倒灵敏度命令
+     * [3G*358800006072996*0009*LSSET,3+6]
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function getLSSETCommandinfo($param)
+    {
+        if (2 != count($param)) {
+            throw new \Exception("LSSET参数错误");
+        }
+        foreach ($param as $key => $value) {
+            if (!is_numeric($value)) {
+                throw new \Exception("LSSET参数错误:" . $value);
+            }
+        }
+        $info = $param[0] . "+" . $param[1];
+        return $info;
+    }
+    /**
+     * 设置电话本
+     * 最多10条
+     *{telno=>'',name=>''}
+     * @param  [type] $param
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function getPHLCommaninfo($param)
+    {
+        if (50 > count($param)) {
+            throw new \Exception("PHL参数错误");
+        }
+        if (0 != count($param) % 2) {
+            throw new \Exception("PHL参数长度错误");
+        }
+        $usedata = [];
+        foreach ($param as $key => $value) {
+            $telno = $value['telno'];
+            $name = $value['name'];
+            //电话号码
+            if (20 > mb_strlen($telno)) {
+                throw new \Exception("PHL电话号码错误:" . $telno);
+            }
+            $name = $this->srtingToUnicode($name);
+            $usedata[] = $telno;
+            $usedata[] = $name;
+        }
+        $info = implode(",", $usedata);
+        return $info;
+    }
+    /**
+     * 设置电话本
+     * 最多10条
+     *{[time=>'',isopen=>'','type'=>'','weeks'=>[]]}
+     *  weeks 数组 每个1到7 周日到周六
+     * 最多设置三个
+     * @param  [type] $param
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    /*
+    08:10-1-1:闹钟时间 8:10,打开,响铃一次
+    08:10-1-2:闹钟时间 8:10,打开,每天响铃
+    08:10-1-3-0111110:闹钟时间 8:10,打开,自定义周一至周五打开
+    最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周二,周三,周四,周五,周
+    六(1 为打开,0 为关闭),其中周一至周五打开闹钟
+     */
+    public function getREMINDCommandinfo($param)
+    {
+        if (3 > count($param)) {
+            throw new \Exception("PHL参数错误");
+        }
+        $usedata = [];
+        $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
+        foreach ($param as $key => $value) {
+            $time = date('H:i', $value['time']);
+            $isopen = $value['isopen'];
+            $type = $value['type'];
+            $weeks = $param['weeks'];
+            if (3 == $type) {
+                foreach ($weeks as $wkey => $wvalue) {
+                    $useweeks[$wvalue - 1] = 1;
+                }
+                $useweeks = implode("", $useweeks);
+                $type = $useweeks;
+            }
+            $usedata[] = $time . "-" . $isopen . "-" . $type;
+        }
+        $usedata = implode(",", $usedata);
+        return $usedata;
+    }
+    /**
+     * 静默时间段测试
+     *{[starttime=>'',endtime=>'',isopen=>'',weeks=>[]]}
+     * weeks 数组 每个1到7 周日到周六
+     * 最多设置三个
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    /*
+    [DW*334588000000156*0038*SILENCETIME2,7:30-21:10-1-0111110,7:30-21:10-1-0111110,7:
+    30-21:10-0-0111110]
+    设置上课禁用时间段范围,拦截终端的任何来电。格式为“起始时间-结束时间-自定义星期几”, 比
+    如上面的 7:30-21:00-0111110,则表示周一到周五 7:30 到 21:00 之间上课禁用生效,起始时间
+    默认大于结束时间。
+    总开关:0 为关,1 为开
+    关于自定义星期几的规则:最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周
+    二,周三,周四,周五,周六(1 为打开,0 为关闭),所以上面的意思是周一至周五打开上课禁
+    用。
+     */
+    public function getSILENCETIME2Commandinfo($param)
+    {
+        if (3 > count($param)) {
+            throw new \Exception("SILENCETIME2参数错误");
+        }
+        $usedata = [];
+        $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
+        foreach ($param as $key => $value) {
+            //未比较时间大小
+            $starttime = date('H:i', $value['starttime']);
+            $endtime = date('H:i', $value['endtime']);
+
+            $isopen = $value['isopen'];
+            $weeks = $param['weeks'];
+            foreach ($weeks as $wkey => $wvalue) {
+                $useweeks[$wvalue - 1] = 1;
+            }
+            $useweeks = implode("", $useweeks);
+            $usedata[] = $starttime . "-" . $endtime . "-" . $isopen . "-" . $useweeks;
+        }
+        $usedata = implode(",", $usedata);
+        return $usedata;
+    }
+    /**
+     * 睡眠时间段设置
+     *{starttime=>'',endtime=>''}
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function getSLEEPTIMECommandinfo($param)
+    {
+        if (2 > count($param)) {
+            throw new \Exception("SLEEPTIME参数错误");
+        }
+        $starttime = date('H:i', $param['starttime']);
+        $endtime = date('H:i', $param['endtime']);
+        $usedata = $starttime . "-" . $endtime;
+        return $usedata;
+    }
+    /**
+     * 发送成功 删除发送数据
+     *
+     * @param  [type] $item
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function sendmsgsuccess($item)
+    {
+        $m_ssq = new ShsendqueueModel();
+        $m_ssl = new ShsendlistModel();
+        $ssqid = $item['id'];
+        if ($item['list_id']) {
+            $list_id = $item['list_id'];
+            $sslwhere = ['id' => $list_id, 'is_send' => 0];
+            $sslinfo = $m_ssl->getInfo($sslwhere);
+            if ($sslinfo) {
+                $row = $m_ssl->updateinfo(['id' => $sslinfo['id']], ['is_send' => 1, 'send_time' => date('Y-m-d H:i:s')]);
+            }
+        }
+        $ssqwhere = ['id' => $ssqid];
+        $ssqinfo = $m_ssq->getInfo($ssqwhere);
+        if ($ssqinfo) {
+            $m_ssq->deleteinfobyid($ssqid);
+        }
+    }
+    /**
+     * 解析成功 删除接收数据
+     *
+     * @param  [type] $item
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function receivemsgsuccess($item)
+    {
+        $m_srq = new ShreceivequeueModel();
+        $srqid = $item['id'];
+        $srqwhere = ['id' => $srqid, 'status' => 1];
+        $srqinfo = $m_srq->getInfo($srqwhere);
+        if ($srqinfo) {
+            $m_srq->deleteinfobyid($srqid);
+        }
+    }
+    /**
+     * 初始化手环接收信息解析
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function initanalysisShoneReceiveMsg()
+    {
+        $m_srq = new ShreceivequeueModel();
+        $where = ['status' => 1];
+        $m_srq->updateinfo($where, ['status' => 0]);
+    }
+    /**
+     * 测试使用
+     *
+     * @param  [type] $data
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function showfortest($data)
+    {
+        $strdata = $this->getline($data);
+        $content = $strdata['content_str'];
+        $content = $this->getcommandcontent($content);
+        $command = $content[0];
+        $showcommands = [
+            'SOS', 'CR', 'UPLOAD', 'SLEEPTIME', 'ZONE', 'FALLDOWN',
+            'APPLOCK', 'FACTORY', 'VERNO', 'LOWBAT', 'UD', 'POWEROFF', 'MESSAGE',
+            'WALKTIME', 'PEDO', 'PHB', 'PHL', 'REMIND', 'SILENCETIME2', 'BOOTOFF',
+            'REMOVE', 'INFO', 'AL', 'LSSET',
+        ];
+        if (in_array($command, $showcommands)) {
+            var_dump(date('Y-m-d H:i:s'));
+            var_dump($data);
+        }
+    }
+    /**
+     * 设置设备上线
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function setonlineinfo($device_id_code)
+    {
+        $m_si = new ShinfoModel();
+        $where = ['device_id_code' => $device_id_code, 'online_statis' => 0];
+        $finfo = $m_si->getInfo($where, ['id', 'online_statis']);
+        if ($finfo) {
+            $facility_id = $finfo['id'];
+            $m_si->setonlineinfobyid($facility_id);
+        }
+    }
+    /**
+     * 设置设备下线
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function setofflineinfo()
+    {
+        $m_si = new ShinfoModel();
+        $list = $m_si->getcheckupdatetimelist();
+        $list = (array) $list;
+        if (!empty($list)) {
+            $facility_ids = array_column($list, 'id');
+            $m_si->setofflineinfobyids($facility_ids);
+        }
+    }
+    //工具方法
+    /**
+     * unicode 编码
+     *
+     * @param  [type] $str
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function srtingToUnicode($str)
+    {
+        $unicode = '';
+        $arr = str_split($str);
+        foreach ($arr as $key => $value) {
+            $char = bin2hex(iconv('UTF-8', 'UCS-2BE', $value));
+            $char = str_pad($char, 4, '0', STR_PAD_LEFT);
+            $arr[$key] = $char;
+        }
+        $unicode = implode("", $arr);
+        return $unicode;
+    }
+    /**
+     * unicode 解码
+     *
+     * @param  [type] $str
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function unicodeToChn($str)
+    {
+        $arr = str_split($str);
+        $items = [];
+        $item = "";
+        foreach ($arr as $key => $value) {
+            $index = $key + 1;
+            if (0 != $index % 4) {
+                $item .= $value;
+            } else {
+                $item = "";
+                $items[] = $item;
+            }
+        }
+        foreach ($items as $key => $value) {
+            $char = hex2bin($value);
+            $char = iconv('UCS-2BE', 'UTF-8', $char);
+            $items[$key] = $char;
+        }
+        $info = implode("", $items);
+        return $info;
+    }
+    /**
+     * 拆包
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-15
+     */
+    public function unpack($data)
+    {
+        $arr = explode("][", $data);
+        foreach ($arr as $key => $value) {
+            if ($value[0] !== "[") {
+                $arr[$key] = '[' . $value;
+            }
+            if ($value[mb_strlen($value) - 1] !== "]") {
+                $arr[$key] .= "]";
+            }
+        }
+        return $arr;
+    }
+
+}

+ 36 - 25
application/workerman/ShTcp.php

@@ -1,7 +1,7 @@
 <?php
 namespace app\workerman;
 
-use app\common\server\ShOneanalysis;
+use app\common\server\SouhuanAnalysis;
 use think\facade\Log;
 use think\worker\Server;
 use Workerman\Lib\Timer;
@@ -25,7 +25,7 @@ class ShTcp extends Server
         define('HEARTBEAT_TIME', 1000);
         //异步处理
         //发送
-        $server_sa = new ShOneanalysis();
+        $server_sa = new SouhuanAnalysis();
         Timer::add(1, function () use ($worker, $server_sa) {
             if (isset($worker->device_id_code)) {
                 $device_id_code = $worker->device_id_code;
@@ -36,6 +36,7 @@ class ShTcp extends Server
                         $size = $info['size'];
                         for ($page = 1; $page <= $totalpage; $page++) {
                             $list = $server_sa->getsendqueuelist($device_id_code, 1, $size);
+                            $list = (array) $list;
                             foreach ($list as $key => $value) {
                                 $connection->send($value['msg']);
                                 $server_sa->showfortest($value['msg']);
@@ -56,16 +57,17 @@ class ShTcp extends Server
                 $list = (array) $list;
                 foreach ($list as $key => $value) {
                     try {
-                        $linedata = $server_sa->getline($value['msg']);
+                        $msg = $value['msg'];
+                        $linedata = $server_sa->getline($msg);
                         //长度相等可解析
                         $content = $linedata['content_str'];
                         $device_id_code = $linedata['device_id_code'];
+                        $command = $linedata['command'];
+                        $content = $linedata['content_arr'];
                         $fid = $server_sa->getfacilityid($device_id_code);
-                        $content = $server_sa->getcommandcontent($content);
-                        $result = $server_sa->saveshinfo($fid, $device_id_code, $content, $value['msg']);
+                        $result = $server_sa->saveshinfo($fid, $device_id_code, $linedata, $msg);
                         if ($result) {
-                            $command = $content[0];
-                            $data = $server_sa->createbacksendmsg($fid, $device_id_code, $content, $command);
+                            $data = $server_sa->createsendmsg($fid, $device_id_code, $linedata, $command);
                         }
                         $server_sa->receivemsgsuccess($value);
                     } catch (\Exception $e) {
@@ -76,37 +78,45 @@ class ShTcp extends Server
                 }
             }
         });
+        //下线校验 间隔10秒
+        Timer::add(10, function () use ($worker, $server_sa) {
+            $server_sa->setofflineinfo();
+            //校验离线
+            // $time_now = time();
+            // foreach ($worker->connections as $connection) {
+            //     //当前时间和更改时间超过1分钟 则视为断开连接
 
-        Timer::add(1, function () use ($worker) {
-            $time_now = time();
-            foreach ($worker->connections as $connection) {
-                // 有可能该connection还没收到过消息,则lastMessageTime设置为当前时间
-                if (empty($connection->lastMessageTime)) {
-                    $connection->lastMessageTime = $time_now;
-                    continue;
-                }
-                // 上次通讯时间间隔大于心跳间隔,则认为客户端已经下线,关闭连接
-                if ($time_now - $connection->lastMessageTime > HEARTBEAT_TIME) {
-                    //$connection->close();
-                    //设置对应设备下线
-                }
-            }
+            //     // 有可能该connection还没收到过消息,则lastMessageTime设置为当前时间
+            //     if (empty($connection->lastMessageTime)) {
+            //         $connection->lastMessageTime = $time_now;
+            //         continue;
+            //     }
+            //     // 上次通讯时间间隔大于心跳间隔,则认为客户端已经下线,关闭连接
+            //     if ($time_now - $connection->lastMessageTime > HEARTBEAT_TIME) {
+            //         //$connection->close();
+            //         //设置对应设备下线
+            //     }
+            // }
         });
     }
     public function onMessage($connection, $data)
     {
         //Log::write($data, 'shouhuan');
-        $server_sa = new ShOneanalysis();
+        $server_sa = new SouhuanAnalysis();
         $datas = (array) $server_sa->unpack($data);
         foreach ($datas as $key => $data) {
+            //测试
             $server_sa->showfortest($data);
             try {
                 $result = $server_sa->savereceivequeue($data);
                 if (empty($result)) {
                     Log::write("手环接收信息队列,数据保存失败", 'shouhuan');
                 }
-                $line = $server_sa->getline($data);
-                $this->device_id_code = $line['device_id_code'];
+                $device_id_code = $server_sa->getline($data, 'device_id_code');
+                //设置上线
+                $server_sa->setonlineinfo($device_id_code);
+                $this->device_id_code = $device_id_code;
+                //测试
                 //$this->device_id_code = "358800006072996";
             } catch (\Exception $e) {
                 Log::write($data, 'shouhuan');
@@ -118,6 +128,7 @@ class ShTcp extends Server
 
     public function onClose($connection)
     {
-
+        $msg = 'colse time' . date('Y-m-d H:i:s');
+        Log::write($msg, 'shouhuan');
     }
 }

+ 125 - 0
application/workerman/ShTcpTest.php

@@ -0,0 +1,125 @@
+<?php
+namespace app\workerman;
+
+use app\common\server\ShOneanalysisTest;
+use think\facade\Log;
+use think\worker\Server;
+use Workerman\Lib\Timer;
+
+class ShTcpTest extends Server
+{
+    protected $socket = 'tcp://0.0.0.0:21444';
+    //protected $socket = 'tcp://0.0.0.0:9501';
+
+    protected function init()
+    {
+        $this->count = 4; //线程数
+    }
+
+    public function onConnect($connection)
+    {
+
+    }
+    public function onWorkerStart($worker)
+    {
+        define('HEARTBEAT_TIME', 1000);
+        //异步处理
+        //发送
+        $server_sa = new ShOneanalysisTest();
+        Timer::add(1, function () use ($worker, $server_sa) {
+            if (isset($worker->device_id_code)) {
+                $device_id_code = $worker->device_id_code;
+                foreach ($worker->connections as $connection) {
+                    $info = $server_sa->getsendqueuelist($device_id_code);
+                    $totalpage = $info['totalpage'];
+                    if ($totalpage > 0) {
+                        $size = $info['size'];
+                        for ($page = 1; $page <= $totalpage; $page++) {
+                            $list = $server_sa->getsendqueuelist($device_id_code, 1, $size);
+                            $list = (array) $list;
+                            foreach ($list as $key => $value) {
+                                $connection->send($value['msg']);
+                                $server_sa->showfortest($value['msg']);
+                                $server_sa->sendmsgsuccess($value);
+                            }
+                        }
+                    }
+                }
+            }
+        });
+        //解析
+        $server_sa->initanalysisShoneReceiveMsg();
+        Timer::add(10, function () use ($worker, $server_sa) {
+            $page = 1;
+            $size = 30;
+            $list = $server_sa->getreceivequeuelist($page, $size);
+            if ($list) {
+                $list = (array) $list;
+                foreach ($list as $key => $value) {
+                    try {
+                        $linedata = $server_sa->getline($value['msg']);
+                        //长度相等可解析
+                        $content = $linedata['content_str'];
+                        $device_id_code = $linedata['device_id_code'];
+                        $fid = $server_sa->getfacilityid($device_id_code);
+                        $content = $server_sa->getcommandcontent($content);
+                        $result = $server_sa->saveshinfo($fid, $device_id_code, $content, $value['msg']);
+                        if ($result) {
+                            $command = $content[0];
+                            $data = $server_sa->createbacksendmsg($fid, $device_id_code, $content, $command);
+                        }
+                        $server_sa->receivemsgsuccess($value);
+                    } catch (\Exception $e) {
+                        $msg = $e->getMessage();
+                        echo $msg . "\n";
+                        Log::write($msg, 'shouhuan');
+                    }
+                }
+            }
+        });
+
+        Timer::add(1, function () use ($worker) {
+            $time_now = time();
+            foreach ($worker->connections as $connection) {
+                // 有可能该connection还没收到过消息,则lastMessageTime设置为当前时间
+                if (empty($connection->lastMessageTime)) {
+                    $connection->lastMessageTime = $time_now;
+                    continue;
+                }
+                // 上次通讯时间间隔大于心跳间隔,则认为客户端已经下线,关闭连接
+                if ($time_now - $connection->lastMessageTime > HEARTBEAT_TIME) {
+                    //$connection->close();
+                    //设置对应设备下线
+                }
+            }
+        });
+    }
+    public function onMessage($connection, $data)
+    {
+        //Log::write($data, 'shouhuan');
+        $server_sa = new ShOneanalysisTest();
+        $datas = (array) $server_sa->unpack($data);
+        foreach ($datas as $key => $data) {
+            $server_sa->showfortest($data);
+            try {
+                $result = $server_sa->savereceivequeue($data);
+                if (empty($result)) {
+                    Log::write("手环接收信息队列,数据保存失败", 'shouhuan');
+                }
+                $line = $server_sa->getline($data);
+
+                $this->device_id_code = $line['device_id_code'];
+                //$this->device_id_code = "358800006072996";
+            } catch (\Exception $e) {
+                Log::write($data, 'shouhuan');
+                Log::write($e->getMessage(), 'shouhuan');
+                var_dump($e->getMessage());
+            }
+        }
+    }
+
+    public function onClose($connection)
+    {
+
+    }
+}