wang jun 1 year ago
parent
commit
4a5b3db40d

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

@@ -1,84 +0,0 @@
-<?php
-namespace app\common\model;
-
-use think\Model;
-
-/**
- * 手环类型 1 接受信息 实时数据
- *
- * @author wj
- * @date 2023-08-14
- */
-class ShoneReceiveInfoModel extends Model
-{
-    protected $table = "t_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;
-    }
-}

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

@@ -1,84 +0,0 @@
-<?php
-namespace app\common\model;
-
-use think\Model;
-
-/**
- * 手环类型 1 接受信息 历史数据
- *
- * @author wj
- * @date 2023-08-14
- */
-class ShoneReceiveInfoRecode extends Model
-{
-    protected $table = "t_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;
-    }
-}

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

@@ -1,84 +0,0 @@
-<?php
-namespace app\common\model;
-
-use think\Model;
-
-/**
- * 接收信息队列
- *
- * @author wj
- * @date 2023-08-14
- */
-class ShoneReceiveQueueModel extends Model
-{
-    protected $table = "t_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;
-    }
-}

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

@@ -1,85 +0,0 @@
-<?php
-namespace app\common\model;
-
-use think\Model;
-
-/**
- * 手环一发送列表
- *
- * @author wj
- * @date 2023-08-14
- */
-class ShoneSendListModel extends Model
-{
-    protected $table = "t_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;
-    }
-
-}

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

@@ -1,84 +0,0 @@
-<?php
-namespace app\common\model;
-
-use think\Model;
-
-/**
- * 发送信息队列
- *
- * @author wj
- * @date 2023-08-14
- */
-class ShoneSendQueueModel extends Model
-{
-    protected $table = "t_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;
-    }
-}

+ 0 - 792
application/common/server/ShOneanalysis.php

@@ -1,792 +0,0 @@
-<?php
-
-namespace app\common\server;
-
-use app\common\model\FacilityModel;
-use app\common\model\ShoneReceiveInfoModel;
-use app\common\model\ShoneReceiveInfoRecode;
-use app\common\model\ShoneReceiveQueueModel;
-use app\common\model\ShoneSendListModel;
-use app\common\model\ShoneSendQueueModel;
-use think\facade\Log;
-
-/**
- * 手环字符串解析
- *
- * @author wj
- * @date 2023-08-11
- */
-class ShOneanalysis
-{
-    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 = [
-            'WT' => [
-                '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,
-            ],
-            'WG' => [
-                '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 ShoneSendListModel();
-            $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 ShoneSendQueueModel();
-            $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 ShoneReceiveQueueModel();
-        $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 ShoneReceiveInfoModel();
-        $m_srir = new ShoneReceiveInfoRecode();
-        $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 ShoneReceiveQueueModel();
-        $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 ShoneSendQueueModel();
-        $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 ShoneSendQueueModel();
-        $m_ssl = new ShoneSendListModel();
-        $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 ShoneReceiveQueueModel();
-        $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 ShoneReceiveQueueModel();
-        $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'];
-        if (in_array($command, $showcommands)) {
-            var_dump($data);
-        }
-    }
-}

+ 39 - 24
application/common/server/SouhuanAnalysis.php

@@ -694,19 +694,21 @@ class SouhuanAnalysis
         $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);
+        $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:心率异常报警
+        $first_num = $mid - $first_num + ($mid - 1);
         $alarm_type = $first_num;
         $status = substr($terminal_status_str, $mid);
-        $first_num = strpos($status, 1);
-        $end_num = strrpos($status, 1);
+        $first_num = strpos($status, '1');
+        $end_num = strrpos($status, '1');
         if ($first_num != $end_num) {
             Log::write("状态解析错误:状态:" . $terminal_status . " " . $terminal_status_str, 'shouhuan');
         }
+        $first_num = $mid - 1 - $first_num;
         //1:低电状态;2:出围栏状态;3:进围栏状态;4:手环戴上取下状态;5:手表运行静止状态
         $status_type = $first_num + 1;
         $data = [
@@ -992,8 +994,8 @@ class SouhuanAnalysis
     {
         $infoarr = $this->getsendcommandinfo($command);
         if (!$infoarr) {
-            Log::write("无对应命令数据1:" . $command, 'shouhuan');
-            Log::write($data, 'shouhuan');
+            // Log::write("无对应命令数据1:" . $command, 'shouhuan');
+            // Log::write($data, 'shouhuan');
             return false;
         }
         $command = $data['command'];
@@ -1078,7 +1080,7 @@ class SouhuanAnalysis
      */
     public function getSOSCommandinfo($param)
     {
-        if (count($param) <= 3) {
+        if (count($param) <= 0) {
             throw new \Exception("未设置电话");
 
         }
@@ -1117,7 +1119,7 @@ class SouhuanAnalysis
     /**
      * 设置电话本
      * 最多10条
-     *{telno=>'',name=>''}
+     *[{telno=>'',name=>''}]
      * @param  [type] $param
      * @return void
      * @author wj
@@ -1125,7 +1127,7 @@ class SouhuanAnalysis
      */
     public function getPHLCommaninfo($param)
     {
-        if (50 > count($param)) {
+        if (50 < count($param)) {
             throw new \Exception("PHL参数错误");
         }
         if (0 != count($param) % 2) {
@@ -1135,8 +1137,9 @@ class SouhuanAnalysis
         foreach ($param as $key => $value) {
             $telno = $value['telno'];
             $name = $value['name'];
+            var_dump($name);
             //电话号码
-            if (20 > mb_strlen($telno)) {
+            if (20 < mb_strlen($telno)) {
                 throw new \Exception("PHL电话号码错误:" . $telno);
             }
             $name = $this->srtingToUnicode($name);
@@ -1170,15 +1173,17 @@ class SouhuanAnalysis
             throw new \Exception("PHL参数错误");
         }
         $usedata = [];
-        $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
         foreach ($param as $key => $value) {
-            $time = date('H:i', $value['time']);
+            $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
+            $time = $this->formattime($value['time'], 'H:i');
             $isopen = $value['isopen'];
             $type = $value['type'];
-            $weeks = $param['weeks'];
+            $weeks = $value['weeks'];
             if (3 == $type) {
                 foreach ($weeks as $wkey => $wvalue) {
-                    $useweeks[$wvalue - 1] = 1;
+                    if ($wvalue >= 1 && $wvalue <= 7) {
+                        $useweeks[$wvalue - 1] = '1';
+                    }
                 }
                 $useweeks = implode("", $useweeks);
                 $type = $useweeks;
@@ -1211,20 +1216,21 @@ class SouhuanAnalysis
      */
     public function getSILENCETIME2Commandinfo($param)
     {
-        if (3 > count($param)) {
+        if (3 <= count($param)) {
             throw new \Exception("SILENCETIME2参数错误");
         }
         $usedata = [];
-        $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
         foreach ($param as $key => $value) {
+            $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
             //未比较时间大小
-            $starttime = date('H:i', $value['starttime']);
-            $endtime = date('H:i', $value['endtime']);
-
+            $starttime = $this->formattime($value['starttime'], 'H:i');
+            $endtime = $this->formattime($value['endtime'], 'H:i');
             $isopen = $value['isopen'];
-            $weeks = $param['weeks'];
+            $weeks = $value['weeks'];
             foreach ($weeks as $wkey => $wvalue) {
-                $useweeks[$wvalue - 1] = 1;
+                if ($wvalue >= 1 && $wvalue <= 7) {
+                    $useweeks[$wvalue - 1] = '1';
+                }
             }
             $useweeks = implode("", $useweeks);
             $usedata[] = $starttime . "-" . $endtime . "-" . $isopen . "-" . $useweeks;
@@ -1245,11 +1251,12 @@ class SouhuanAnalysis
         if (2 > count($param)) {
             throw new \Exception("SLEEPTIME参数错误");
         }
-        $starttime = date('H:i', $param['starttime']);
-        $endtime = date('H:i', $param['endtime']);
+        $starttime = $this->formattime($param['starttime'], 'H:i');
+        $endtime = $this->formattime($param['endtime'], 'H:i');
         $usedata = $starttime . "-" . $endtime;
         return $usedata;
     }
+    //发送完处理
     /**
      * 发送成功 删除发送数据
      *
@@ -1379,8 +1386,9 @@ class SouhuanAnalysis
     public function srtingToUnicode($str)
     {
         $unicode = '';
-        $arr = str_split($str);
+        $arr = mb_str_split($str); //适配中文
         foreach ($arr as $key => $value) {
+            var_dump($value);
             $char = bin2hex(iconv('UTF-8', 'UCS-2BE', $value));
             $char = str_pad($char, 4, '0', STR_PAD_LEFT);
             $arr[$key] = $char;
@@ -1439,4 +1447,11 @@ class SouhuanAnalysis
         return $arr;
     }
 
+    public function formattime($time, $format)
+    {
+        $time = strtotime($time);
+        $time = date($format, $time);
+        return $time;
+    }
+
 }