likang 3 rokov pred
rodič
commit
48a80c5c06

+ 319 - 300
app/common.php

@@ -3,327 +3,346 @@
 use think\facade\Env;
 use think\facade\Db;
 use Aliyun\OTS\OTSClient;
-    /**
-     * 增量解析含wifi信号Gps
-     */
-    function queryTableStoreGpsRoute($options){
-        
-        if(!isset($options['device_number']) &&  $options['device_number'] !=''){
-            return array('success'=>false,'message'=>'缺少设备号');
-        }
-        $device_number=$options['device_number'];
-        if(!isset($options['start_time']) &&  $options['start_time']>0){
-            return array('success'=>false,'message'=>'缺少起始时间');
-        }
-        $start_time=$options['start_time'];
-        if(!isset($options['end_time']) &&  $options['end_time']>0){
-            $end_time=time();
-        }else{
-            $end_time=$options['end_time'];
-        }
-        
-        if(!isset($options['table_name']) &&  $options['table_name']>0){
-            return array('success'=>false,'message'=>'缺少表名参数');
-        }
-        $table_name=$options['table_name'];
-
-
-        // $otsClient = new OTSClient (array (
-        //     'EndPoint' => 'https://rlfd.cn-hangzhou.ots.aliyuncs.com',
-        //     'AccessKeyID' => 'LTAI4FecTAyMPdhAdkUwhAGA',
-        //     'AccessKeySecret' => 'Ih0knSSfcje3OUi1YrdjeXQZYIfmTK',
-        //     'InstanceName' => 'rlfd',
-        // ));
-        $table_config=Db::table('sys_config')->where('type','table_store')->column('fieldValue','field');
-        if(!isset($table_config['EndPoint']) || !isset($table_config['AccessKeyID']) || !isset($table_config['AccessKeySecret']) || !isset($table_config['InstanceName'])){
-            return array('success'=>false,'message'=>'未配置表格存储');
-        }
-        $otsClient = new OTSClient (array (
-            'EndPoint' => $table_config['EndPoint'],
-            'AccessKeyID' => $table_config['AccessKeyID'],
-            'AccessKeySecret' => $table_config['AccessKeySecret'],
-            'InstanceName' =>  $table_config['InstanceName'],
-        ));
-        $otsClient->getClientConfig()->debugLogHandler = null;
-        $otsClient->getClientConfig()->errorLogHandler = null;
-        // var_dump($otsClient);
-        ini_set('memory_limit', '512M');
-
-        $startPK = array (
-            array('DeviceNumber',$device_number),
-            array('Timestamp', $start_time)
-            // array('Timestamp', 1620885120)
-        );
-        $endPK = array (
-            array('DeviceNumber', $device_number),
-            array('Timestamp', $end_time)
-            // array('Timestamp', 1620885441)
+
+/**
+ * 增量解析含wifi信号Gps
+ */
+function queryTableStoreGpsRoute($options)
+{
+
+    if (!isset($options['device_number']) &&  $options['device_number'] != '') {
+        return array('success' => false, 'message' => '缺少设备号');
+    }
+    $device_number = $options['device_number'];
+    if (!isset($options['start_time']) &&  $options['start_time'] > 0) {
+        return array('success' => false, 'message' => '缺少起始时间');
+    }
+    $start_time = $options['start_time'];
+    if (!isset($options['end_time']) &&  $options['end_time'] > 0) {
+        $end_time = time();
+    } else {
+        $end_time = $options['end_time'];
+    }
+
+    if (!isset($options['table_name']) &&  $options['table_name'] > 0) {
+        return array('success' => false, 'message' => '缺少表名参数');
+    }
+    $table_name = $options['table_name'];
+
+
+    // $otsClient = new OTSClient (array (
+    //     'EndPoint' => 'https://rlfd.cn-hangzhou.ots.aliyuncs.com',
+    //     'AccessKeyID' => 'LTAI4FecTAyMPdhAdkUwhAGA',
+    //     'AccessKeySecret' => 'Ih0knSSfcje3OUi1YrdjeXQZYIfmTK',
+    //     'InstanceName' => 'rlfd',
+    // ));
+    $table_config = Db::table('sys_config')->where('type', 'table_store')->column('fieldValue', 'field');
+    if (!isset($table_config['EndPoint']) || !isset($table_config['AccessKeyID']) || !isset($table_config['AccessKeySecret']) || !isset($table_config['InstanceName'])) {
+        return array('success' => false, 'message' => '未配置表格存储');
+    }
+    $otsClient = new OTSClient(array(
+        'EndPoint' => $table_config['EndPoint'],
+        'AccessKeyID' => $table_config['AccessKeyID'],
+        'AccessKeySecret' => $table_config['AccessKeySecret'],
+        'InstanceName' =>  $table_config['InstanceName'],
+    ));
+    $otsClient->getClientConfig()->debugLogHandler = null;
+    $otsClient->getClientConfig()->errorLogHandler = null;
+    // var_dump($otsClient);
+    ini_set('memory_limit', '512M');
+
+    $startPK = array(
+        array('DeviceNumber', $device_number),
+        array('Timestamp', $start_time)
+        // array('Timestamp', 1620885120)
+    );
+    $endPK = array(
+        array('DeviceNumber', $device_number),
+        array('Timestamp', $end_time)
+        // array('Timestamp', 1620885441)
+    );
+    if (isset($options['limit']) &&  $options['limit'] > 0) {
+        $limit = $options['limit'];
+    } else {
+        $limit = 5500;
+    }
+
+
+
+    $rows = [];
+    while (!empty($startPK) && $limit > 0) {
+
+        $request = array(
+            'table_name' => $table_name,
+            'max_versions' => 1,
+            'direction' => 'BACKWARD', // 方向可以为 FORWARD 或者 BACKWARD
+            'inclusive_start_primary_key' => $endPK, // 开始主键
+            'exclusive_end_primary_key' => $startPK, // 结束主键
+            'limit' => $limit
         );
-        if(isset($options['limit']) &&  $options['limit']>0){
-            $limit = $options['limit']; 
-        }else{
-            $limit = 5500; 
-        }
-        
-
-       
-        $rows=[];
-        while (! empty ($startPK) && $limit > 0) {
-
-            $request = array (
-                'table_name' => $table_name,
-                'max_versions' => 1,
-                'direction' => 'BACKWARD', // 方向可以为 FORWARD 或者 BACKWARD
-                'inclusive_start_primary_key' => $endPK, // 开始主键
-                'exclusive_end_primary_key' => $startPK, // 结束主键
-                'limit' => $limit
-            );
-            
-            
-            $response = [];
-            try {
-                $response = $otsClient->getRange($request);
-            } catch (\Exception $e) {
-               var_dump($e->getMessage());
-            }
-            
-            if (!isset($response['rows'])){
-                return CatchResponse::success([]);
-            }
-            
-            foreach ($response['rows'] as $rowData) {
-                    // $str=($limit-4000)/2000;
-                    $item=[];
-                    foreach($rowData['primary_key'] as $keyItem){
-                        $item[$keyItem[0]]=$keyItem[1];
-                    }
-                    foreach($rowData['attribute_columns'] as $colItem){
-                        $item[$colItem[0]]=$colItem[1];
-                    }
-                    $item['PassTime']=date('Y-m-d H:i:s',$item['Timestamp']);
-                    $rows[]=$item;
-                    $limit --;
-
-              // 处理每一行数据
-            }
-          
-              $startPK = $response['next_start_primary_key'];
-              // 如果 next_start_primary_key 不为空并且 limit > 0 则循环继续
-        }
-        if(!$rows){
-            return array('success'=>true,'message'=>'查询成功','data'=>[]);
+
+
+        $response = [];
+        try {
+            $response = $otsClient->getRange($request);
+        } catch (\Exception $e) {
+            var_dump($e->getMessage());
         }
 
-        $arr= [];
-        
-        foreach($rows  as $k=> $v){
-            if( !isset($v['Latitude']) ||  !isset($v['Longitude']) || $v['Latitude']<0.065 || $v['Longitude']<0.065){
-                continue;
-            }
-            array_push($arr, $rows[$k]);
+        if (!isset($response['rows'])) {
+            return CatchResponse::success([]);
         }
-        return array('success'=>true,'message'=>'查询成功','data'=>$arr);
-    }
-     
-    
-    
-     /**
-     * debug日志 
-     */
-    function debug_log($filename,$data){
-        if(Env::get('APP_DEBUG')){
-            $file = runtime_path() . '/log/'.date("Y-m-d", time()) ."/".$filename.".log";
-            $folder=dirname($file);
-            if (!is_dir($folder)){
-                mkdir($folder,0777,true);
+
+        foreach ($response['rows'] as $rowData) {
+            // $str=($limit-4000)/2000;
+            $item = [];
+            foreach ($rowData['primary_key'] as $keyItem) {
+                $item[$keyItem[0]] = $keyItem[1];
             }
-            if(is_array($data)){
-                $data = json_encode($data);
+            foreach ($rowData['attribute_columns'] as $colItem) {
+                $item[$colItem[0]] = $colItem[1];
             }
-            file_put_contents($file, '[' . date('Y-m-d H:i:s') . ']' . $data . PHP_EOL,FILE_APPEND);
+            $item['PassTime'] = date('Y-m-d H:i:s', $item['Timestamp']);
+            $rows[] = $item;
+            $limit--;
+
+            // 处理每一行数据
         }
+
+        $startPK = $response['next_start_primary_key'];
+        // 如果 next_start_primary_key 不为空并且 limit > 0 则循环继续
+    }
+    if (!$rows) {
+        return array('success' => true, 'message' => '查询成功', 'data' => []);
     }
 
-    /**
-     * api日志 
-     */
-    function api_log($filename,$data){
-    
-            $file = runtime_path() . '/log/'.date("Ymd", time()) ."/".$filename.".log";
-            $folder=dirname($file);
-            if (!is_dir($folder)){
-                mkdir($folder,0777,true);
-            }
-            if(is_array($data)){
-                $data = json_encode($data);
-            }
-            file_put_contents($file, '[' . date('Y-m-d H:i:s') . ']' . $data . PHP_EOL,FILE_APPEND);
-        
+    $arr = [];
+
+    foreach ($rows  as $k => $v) {
+        if (!isset($v['Latitude']) ||  !isset($v['Longitude']) || $v['Latitude'] < 0.065 || $v['Longitude'] < 0.065) {
+            continue;
+        }
+        array_push($arr, $rows[$k]);
     }
-    /**
-      *postt请求
-    */
-    function curl_http_post($data,$url,$ssl){
-        $curl = curl_init();
-        curl_setopt($curl,CURLOPT_URL,$url);
-        if($ssl){
-            curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
-            curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,1);
-            curl_setopt($curl,CURLOPT_SSLVERSION,3);
+    return array('success' => true, 'message' => '查询成功', 'data' => $arr);
+}
+
+
+
+/**
+ * debug日志 
+ */
+function debug_log($filename, $data)
+{
+    if (Env::get('APP_DEBUG')) {
+        $file = runtime_path() . '/log/' . date("Y-m-d", time()) . "/" . $filename . ".log";
+        $folder = dirname($file);
+        if (!is_dir($folder)) {
+            mkdir($folder, 0777, true);
         }
-        // curl_setopt($curl,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
-        curl_setopt($curl,CURLOPT_AUTOREFERER,1);
-        curl_setopt($curl,CURLOPT_POST,1);
-        curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
-        curl_setopt($curl,CURLOPT_TIMEOUT,30);
-        curl_setopt($curl,CURLOPT_HEADER,0);
-        curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
-        $tmpInfo = curl_exec($curl);
-        if(curl_errno($curl)){
-            dump(curl_error($curl));
-            return false;
+        if (is_array($data)) {
+            $data = json_encode($data);
         }
-        curl_close($curl);
-        return $tmpInfo;
+        file_put_contents($file, '[' . date('Y-m-d H:i:s') . ']' . $data . PHP_EOL, FILE_APPEND);
     }
+}
+
+/**
+ * api日志 
+ */
+function api_log($filename, $data)
+{
 
-     /**
-     * api日志 
-     */
-    function updateDeviceStatus($imei){
-        $res=Db::table('devices')->where('imei',$imei)->update(['sync_status'=>1]);
-        //var_dump(Db::table('devices')->getLastSql());
-    
+    $file = runtime_path() . '/log/' . date("Ymd", time()) . "/" . $filename . ".log";
+    $folder = dirname($file);
+    if (!is_dir($folder)) {
+        mkdir($folder, 0777, true);
     }
-    //短信管理
-    function send_sms_with_config( $mobile, $content, $sms_config, $info ){
-            
-            
-            
-        $config = array();
-        /*url示例
+    if (is_array($data)) {
+        $data = json_encode($data);
+    }
+    file_put_contents($file, '[' . date('Y-m-d H:i:s') . ']' . $data . PHP_EOL, FILE_APPEND);
+}
+/**
+      *postt请求
+ */
+function curl_http_post($data, $url, $ssl)
+{
+    $curl = curl_init();
+    curl_setopt($curl, CURLOPT_URL, $url);
+    if ($ssl) {
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
+        curl_setopt($curl, CURLOPT_SSLVERSION, 3);
+    }
+    // curl_setopt($curl,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
+    curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
+    curl_setopt($curl, CURLOPT_POST, 1);
+    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
+    curl_setopt($curl, CURLOPT_HEADER, 0);
+    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+    $tmpInfo = curl_exec($curl);
+    if (curl_errno($curl)) {
+        dump(curl_error($curl));
+        return false;
+    }
+    curl_close($curl);
+    return $tmpInfo;
+}
+
+/**
+ * api日志 
+ */
+function updateDeviceStatus($imei)
+{
+    $res = Db::table('devices')->where('imei', $imei)->update(['sync_status' => 1]);
+    //var_dump(Db::table('devices')->getLastSql());
+
+}
+//短信管理
+function send_sms_with_config($mobile, $content, $sms_config, $info)
+{
+
+
+
+    $config = array();
+    /*url示例
         $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/SMS/TemplateSMS?sig=$sig";
         */
-        //沙盒环境(应用开发调试):sandboxapp.cloopen.com
-        //生产环境(应用上线使用):app.cloopen.com
-        $serverIP = 'app.cloopen.com';
-        
-        //sdk版本号
-        $softVersion = '2013-12-26';
-        //请求端口,一般为8883
-        $serverPort='8883';
-        //主账号,对应开官网发者主账号下的 ACCOUNT SID
-        $accountSid= $sms_config['accountSid'];
-        //$accountSid="8aaf0708754a3ef201755a063f070592";
-        $config['accountSid']= $accountSid;
-        //密钥
-        $config['accountToken'] = $sms_config['accountToken'];
-        //$config['accountToken'] = "324fb91d40cf472580dc8dc4d9a3e0d5";
-        //应用Id,在官网应用列表中点击应用,对应应用详情中的APP ID
-        $config['appId'] = $sms_config['appId'];
-        //$config['appId'] = "8aaf070875774c6d0175910e26fc0bf9";
-        //时间戳
-        $batch = date("YmdHis");
-        //验证信息编码
-        $config['authen'] = base64_encode($accountSid . ":" . $batch);
-        //加密REST API验证参数
-        $sig = strtoupper(md5($accountSid . $config['accountToken'] . $batch));
-        //拼接url
-        $config['api_send_url'] = "https://$serverIP:$serverPort/$softVersion/Accounts/$accountSid/SMS/TemplateSMS?sig=".$sig;
-        
-        $postArr = array (
-            'to'=>$mobile,
-            'templateId' => $content['tplno'],
-            'appId'=>$config['appId'],
-            'datas'=>$content['tpldata'],
-        );
-        $postArr = json_encode($postArr);
-        $authen = $config['authen'];
-        $header = array("Accept:application/json","Content-Type:application/json;charset=utf-8","Authorization:$authen");
-        $url = $config['api_send_url'];
-        //$result = $this->curlPost( $url , $postArr, $header);
-        //初始化curl
-        $ch = curl_init();
-        //参数设置  
-        $res= curl_setopt ($ch, CURLOPT_URL,$url);  
-        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
-        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
-        curl_setopt ($ch, CURLOPT_HEADER, 0);
-        curl_setopt($ch, CURLOPT_POST, 1);
-        curl_setopt($ch, CURLOPT_POSTFIELDS, $postArr);
-        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
-        curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
-        $result = curl_exec ($ch);
-        curl_close($ch);
-        
-        $result = json_decode($result,true);
-        //var_dump($result);
-        $data=array(
-                    'recipient'=>$mobile,
-                    'content'=>$content['info'],
-                    // 'type'=>'sms',
-                    'created_at'=>time(),
-                    'creator_id'=>0,
-                    // 'sent_time'=>time(),
-        );
-        if($result['statusCode']==='000000'){
-            $data['sent_result']='发送成功';
-            $res = Db::name('sms_send_log')->insert($data);
-            return array('success'=>true,'message'=>'发送成功');
-        }else{
-            $data['sent_result']=json_encode($result,JSON_UNESCAPED_UNICODE);
-            $res = Db::name('sms_send_log')->insert($data);
-            return array('success'=>false,'errorCode'=>$result['statusCode'],'message'=>$result['statusMsg'],'data'=>$data);
-        }
-        
+    //沙盒环境(应用开发调试):sandboxapp.cloopen.com
+    //生产环境(应用上线使用):app.cloopen.com
+    $serverIP = 'app.cloopen.com';
+
+    //sdk版本号
+    $softVersion = '2013-12-26';
+    //请求端口,一般为8883
+    $serverPort = '8883';
+    //主账号,对应开官网发者主账号下的 ACCOUNT SID
+    $accountSid = $sms_config['accountSid'];
+    //$accountSid="8aaf0708754a3ef201755a063f070592";
+    $config['accountSid'] = $accountSid;
+    //密钥
+    $config['accountToken'] = $sms_config['accountToken'];
+    //$config['accountToken'] = "324fb91d40cf472580dc8dc4d9a3e0d5";
+    //应用Id,在官网应用列表中点击应用,对应应用详情中的APP ID
+    $config['appId'] = $sms_config['appId'];
+    //$config['appId'] = "8aaf070875774c6d0175910e26fc0bf9";
+    //时间戳
+    $batch = date("YmdHis");
+    //验证信息编码
+    $config['authen'] = base64_encode($accountSid . ":" . $batch);
+    //加密REST API验证参数
+    $sig = strtoupper(md5($accountSid . $config['accountToken'] . $batch));
+    //拼接url
+    $config['api_send_url'] = "https://$serverIP:$serverPort/$softVersion/Accounts/$accountSid/SMS/TemplateSMS?sig=" . $sig;
+
+    $postArr = array(
+        'to' => $mobile,
+        'templateId' => $content['tplno'],
+        'appId' => $config['appId'],
+        'datas' => $content['tpldata'],
+    );
+    $postArr = json_encode($postArr);
+    $authen = $config['authen'];
+    $header = array("Accept:application/json", "Content-Type:application/json;charset=utf-8", "Authorization:$authen");
+    $url = $config['api_send_url'];
+    //$result = $this->curlPost( $url , $postArr, $header);
+    //初始化curl
+    $ch = curl_init();
+    //参数设置  
+    $res = curl_setopt($ch, CURLOPT_URL, $url);
+    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+    curl_setopt($ch, CURLOPT_HEADER, 0);
+    curl_setopt($ch, CURLOPT_POST, 1);
+    curl_setopt($ch, CURLOPT_POSTFIELDS, $postArr);
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
+    $result = curl_exec($ch);
+    curl_close($ch);
+
+    $result = json_decode($result, true);
+    //var_dump($result);
+    $data = array(
+        'recipient' => $mobile,
+        'content' => $content['info'],
+        // 'type'=>'sms',
+        'created_at' => time(),
+        'creator_id' => 0,
+        // 'sent_time'=>time(),
+    );
+    if ($result['statusCode'] === '000000') {
+        $data['sent_result'] = '发送成功';
+        $res = Db::name('sms_send_log')->insert($data);
+        return array('success' => true, 'message' => '发送成功');
+    } else {
+        $data['sent_result'] = json_encode($result, JSON_UNESCAPED_UNICODE);
+        $res = Db::name('sms_send_log')->insert($data);
+        return array('success' => false, 'errorCode' => $result['statusCode'], 'message' => $result['statusMsg'], 'data' => $data);
     }
+}
 
 
-    function get_sms_config( $type ){
-        $key="wxt_sms_send_config_".$type;
-        $sms_cache_config =S($key);
-        
-        $sms_config=array();
-        
-        if(!$sms_cache_config){
-            $config_id=Db::name('sms_config')->where(array('name'=>$type,'pid'=>'0'))->getField('id');
-            if(!$config_id){
-                return array('result'=>'fail','message'=>'未配置'.$type);
-            }
-            $config_list=Db::name('sms_config')->where(array('pid'=>$config_id))->select();
-            if(!$config_list){
-                return array('result'=>'fail','message'=>'未配置参数'.$type);
-            }
-            foreach($config_list as $val){
-                $sms_config[$val['key']]=$val['value'];
-            }
+function get_sms_config($type)
+{
+    $key = "wxt_sms_send_config_" . $type;
+    $sms_cache_config = S($key);
+
+    $sms_config = array();
 
-            S($key,json_encode($sms_config),60);
-        }else{
-            $sms_config=json_decode($sms_cache_config,true);
+    if (!$sms_cache_config) {
+        $config_id = Db::name('sms_config')->where(array('name' => $type, 'pid' => '0'))->getField('id');
+        if (!$config_id) {
+            return array('result' => 'fail', 'message' => '未配置' . $type);
+        }
+        $config_list = Db::name('sms_config')->where(array('pid' => $config_id))->select();
+        if (!$config_list) {
+            return array('result' => 'fail', 'message' => '未配置参数' . $type);
+        }
+        foreach ($config_list as $val) {
+            $sms_config[$val['key']] = $val['value'];
         }
-        
-        return $sms_config;
-    }
 
-    /**
-     * 返回JSON成功信息
-     * message: 消息文本
-	 * data: 额外数据
-     * @time 2022年06月09日 14:22
-     */
-    function json_success($message,$data=''){
-        echo json_encode(array('success' => true, 'message' => $message, 'data' => $data),JSON_UNESCAPED_UNICODE);
-	    exit;
+        S($key, json_encode($sms_config), 60);
+    } else {
+        $sms_config = json_decode($sms_cache_config, true);
     }
-    
-    /**
-     * 失败JSON成功信息
-     * message: 消息文本
-	 * data: 额外数据
-     * @time 2022年06月09日 14:22
-     */
-    function json_fail($message,$data = ''){
-        echo json_encode(array('success' => false, 'message' => $message, 'data' => $data),JSON_UNESCAPED_UNICODE);
-        exit;
-    }
+
+    return $sms_config;
+}
+
+/**
+ * 返回JSON成功信息
+ * message: 消息文本
+ * data: 额外数据
+ * @time 2022年06月09日 14:22
+ */
+function json_success($message, $data = '')
+{
+    echo json_encode(array('success' => true, 'message' => $message, 'data' => $data), JSON_UNESCAPED_UNICODE);
+    exit;
+}
+
+/**
+ * 失败JSON成功信息
+ * message: 消息文本
+ * data: 额外数据
+ * @time 2022年06月09日 14:22
+ */
+function json_fail($message, $data = '')
+{
+    echo json_encode(array('success' => false, 'message' => $message, 'data' => $data), JSON_UNESCAPED_UNICODE);
+    exit;
+}
+/**
+ * @Descripttion: 获取当前毫秒级时间戳
+ * @name: likang
+ * @return {*}
+ */
+function msectime()
+{
+    list($msec, $sec) = explode(' ', microtime());
+    $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
+    return $msectime;
+}

+ 102 - 0
catch/api/Listen.php

@@ -0,0 +1,102 @@
+<?php
+
+
+namespace catchAdmin\api;
+
+use catchAdmin\api\model\Publish as ModelPublish;
+use Exception;
+use think\facade\Db;
+
+trait Listen
+{
+    public $imei;
+    public static function onAfterInsert($obj)
+    {
+        $data = null;
+        if (method_exists($obj, 'addContent')) {
+            $data = $obj->addContent($obj);
+        } else {
+            throw new Exception('addContent函数不存在');
+        }
+        //是否要过滤
+        if (array_key_exists('is_filter', $data)) {
+            if ($data['is_filter']) {
+                return;
+            }
+        }
+        $time = msectime();
+        $content = [
+            'Type' => 'add',
+            'ContentType' => $data['type'],
+            'Imei' => $obj->imei ? '' : $obj->imei,
+            'ContentId' => $data['data']['id'],
+            'AddTime' => $time,
+            'Version' => $time,
+            'Status' => 1,
+            'Content' => json_encode($data['data'])
+        ];
+        Db::name('publish')->save($content);
+    }
+
+    public static function onAfterUpdate($obj)
+    {
+        $data = [];
+        $where = [];
+        $time = null;
+        $content = null;
+        if (method_exists($obj, 'addContent')) {
+            $data = $obj->addContent($obj);
+        } else {
+            throw new Exception('addContent函数不存在');
+        }
+        //是否要过滤
+        if (array_key_exists('is_filter', $data)) {
+            if ($data['is_filter']) {
+                return;
+            }
+        }
+        $time = msectime();
+        $where = [];
+        $where[] = ['ContentType', '=', $data['type']];
+        $where[] = ['ContentId', '=', $data['data']['id']];
+        $content = [
+            'Type' => 'update',
+            'Imei' => $obj->imei ? '' : $obj->imei,
+            'Version' => $time,
+            'Status' => 1,
+            'Content' => json_encode($data['data'])
+        ];
+        Db::name('publish')->where($where)->update($content);
+    }
+    public static function onAfterDelete($obj)
+    {
+        $data = [];
+        $where = [];
+        $time = null;
+        $content = null;
+        if (method_exists($obj, 'addContent')) {
+            $data = $obj->addContent($obj);
+        } else {
+            throw new Exception('addContent函数不存在');
+        }
+
+        //是否要过滤
+        if (array_key_exists('is_filter', $data)) {
+            if ($data['is_filter']) {
+                return;
+            }
+        }
+        $time = msectime();
+        $where = [];
+        $where[] = ['ContentType', '=', $data['type']];
+        $where[] = ['ContentId', '=', $data['data']['id']];
+        $content = [
+            'Type' => 'delete',
+            'Imei' => $obj->imei ? '' : $obj->imei,
+            'Version' => $time,
+            'Status' => 1,
+            'Content' => json_encode($data['data'])
+        ];
+        Db::name('publish')->where($where)->update($content);
+    }
+}

+ 51 - 0
catch/api/database/migrations/20220706114453_publish.php

@@ -0,0 +1,51 @@
+<?php
+/*
+ * @Descripttion: 
+ * @version: 1.0.0
+ * @Author: likang
+ * @Date: 2022-07-06 11:44:53
+ * @LastEditors: likang
+ * @LastEditTime: 2022-07-07 15:30:20
+ */
+
+use think\migration\Migrator;
+use think\migration\db\Column;
+use Phinx\Db\Adapter\MysqlAdapter;
+
+class Publish extends Migrator
+{
+    /**
+     * Change Method.
+     *
+     * Write your reversible migrations using this method.
+     *
+     * More information on writing migrations is available here:
+     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
+     *
+     * The following commands can be used in this method and Phinx will
+     * automatically reverse them when rolling back:
+     *
+     *    createTable
+     *    renameTable
+     *    addColumn
+     *    renameColumn
+     *    addIndex
+     *    addForeignKey
+     *
+     * Remember to call "create()" or "update()" and NOT "save()" when working
+     * with the Table class.
+     */
+    public function change()
+    {
+        $table = $this->table('publish', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '下发表', 'id' => 'id', 'signed' => true, 'primary_key' => ['id']]);
+        $table->addColumn('Type', 'string', ['limit' => 50, 'null' => true, 'signed' => true, 'comment' => '类型 add|update|delete',])
+            ->addColumn('ContentType', 'string', ['limit' => 50, 'null' => true, 'signed' => true, 'comment' => '数据类型',])
+            ->addColumn('Content', 'text', ['limit' => MysqlAdapter::TEXT_LONG, 'null' => true, 'signed' => true, 'comment' => '内容 json',])
+            ->addColumn('Imei', 'string', ['limit' => 255, 'null' => true, 'signed' => true, 'comment' => '网关imei',])
+            ->addColumn('ContentId', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => true, 'signed' => true, 'comment' => '内容id',])
+            ->addColumn('AddTime', 'string', ['limit' => 50, 'null' => true, 'signed' => true, 'comment' => '添加时间',])
+            ->addColumn('Version', 'string', ['limit' => 50, 'null' => true, 'signed' => true, 'comment' => '毫秒时间戳',])
+            ->addColumn('Status', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => true, 'signed' => true, 'comment' => '1 更新 2 只读',])
+            ->create();
+    }
+}

+ 42 - 0
catch/api/database/migrations/20220706135109_publish_ack.php

@@ -0,0 +1,42 @@
+<?php
+
+use think\migration\Migrator;
+use think\migration\db\Column;
+use Phinx\Db\Adapter\MysqlAdapter;
+
+class PublishAck extends Migrator
+{
+    /**
+     * Change Method.
+     *
+     * Write your reversible migrations using this method.
+     *
+     * More information on writing migrations is available here:
+     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
+     *
+     * The following commands can be used in this method and Phinx will
+     * automatically reverse them when rolling back:
+     *
+     *    createTable
+     *    renameTable
+     *    addColumn
+     *    renameColumn
+     *    addIndex
+     *    addForeignKey
+     *
+     * Remember to call "create()" or "update()" and NOT "save()" when working
+     * with the Table class.
+     */
+    public function change()
+    {
+        $table = $this->table('publish_ack', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '已发记录表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
+        $table->addColumn('PublishVersion', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '下发表版本号',])
+			->addColumn('PublishContent', 'text', ['limit' => MysqlAdapter::TEXT_LONG,'null' => true,'signed' => true,'comment' => '内容',])
+			->addColumn('AddTime', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '添加时间',])
+			->addColumn('Succ', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '1 成功  -1 失败',])
+			->addColumn('ErrStr', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '失败原因',])
+			->addColumn('AckTime', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '回复时间',])
+			->addColumn('Imei', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '网关',])
+            ->create();
+    }
+}

+ 42 - 0
catch/api/model/Publish.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace catchAdmin\api\model;
+
+use catcher\base\CatchModel as Model;
+use catcher\traits\db\BaseOptionsTrait;
+use catcher\traits\db\ScopeTrait;
+
+class Publish extends Model
+{
+    use BaseOptionsTrait, ScopeTrait;
+    // 表名
+    public $name = 'publish';
+    // 数据库字段映射
+    public $field = array(
+        'id',
+        // 类型 add|update|delete
+        'Type',
+        // 数据类型
+        'ContentType',
+        // 内容 json
+        'Content',
+        // 网关imei
+        'Imei',
+        // 内容id
+        'ContentId',
+        // 添加时间
+        'AddTime',
+        // 毫秒时间戳
+        'Version',
+        // 1 更新 2 只读
+        'Status',
+    );
+    /**
+     * @Descripttion: 添加记录
+     * @name: likang
+     * @return {*}
+     */
+    public function add($type)
+    {
+    }
+}

+ 32 - 0
catch/api/model/Publishack.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace catchAdmin\api\model;
+
+use catcher\base\CatchModel as Model;
+use catcher\traits\db\BaseOptionsTrait;
+use catcher\traits\db\ScopeTrait;
+
+class Publishack extends Model
+{
+    use BaseOptionsTrait, ScopeTrait;
+    // 表名
+    public $name = 'publish_ack';
+    // 数据库字段映射
+    public $field = array(
+        'id',
+        // 下发表版本号
+        'PublishVersion',
+        // 内容
+        'PublishContent',
+        // 添加时间
+        'AddTime',
+        // 1 成功  -1 失败
+        'Succ',
+        // 失败原因
+        'ErrStr',
+        // 回复时间
+        'AckTime',
+        // 网关
+        'Imei',
+    );
+}

+ 2 - 1
catch/hydraulic/controller/Maintenance.php

@@ -66,6 +66,7 @@ class Maintenance extends CatchController
     public function update(Request $request, $id): \think\Response
     {
         $data =  $request->post();
+        $data['id'] = $id;
         $where[] = ["device_type", '=', $data['device_type']];
         $where[] = ['value', '=', $data["value"]];
         $where[] = ['id', '<>', $id];
@@ -74,7 +75,7 @@ class Maintenance extends CatchController
             return CatchResponse::fail('唯一标识重复');
         };
 
-        return CatchResponse::success($this->maintenanceModel->updateBy($id, $request->post()));
+        return CatchResponse::success($this->maintenanceModel->updateBy($id, $data));
     }
 
     /**

+ 29 - 0
catch/hydraulic/model/MaintenanceMapper.php

@@ -2,6 +2,7 @@
 
 namespace catchAdmin\hydraulic\model;
 
+use catchAdmin\api\Listen;
 use catcher\base\CatchModel as Model;
 use catchAdmin\system\model\SysDictData;
 use catchAdmin\permissions\model\DataRangScopeTrait;
@@ -9,6 +10,7 @@ use \think\facade\Db;
 
 class maintenancemapper extends Model
 {
+    use Listen;
     use DataRangScopeTrait;
     // 表名
     public $name = 'maintenance_mapper';
@@ -87,4 +89,31 @@ class maintenancemapper extends Model
         $name = Db::name('device_mold')->where($where)->value('name');
         return $name;
     }
+    //下发数据 工作部件/工作位置
+    public function addContent(&$obj)
+    {
+        //var_dump($obj);
+        $data = null;
+        $content = null;
+        if ($obj->device_type == 1) {
+            $data = [
+                'id' => $obj->id,
+                'name' => $obj['name'],
+            ];
+            $content['data'] = $data;
+            $content['type'] = 'WorkingParts';
+        } else if ($obj->device_type == 2) {
+            $data = [
+                'id' => $obj->id,
+                'fan_model' => Db::name('device_mold')->where('id', $obj->fan_model)->value('name'),
+                'name' => $obj['name'],
+                'parts' => $this->where('device_type', 1)->where('value', $obj->parts)->value('name')
+            ];
+            $content['data'] = $data;
+            $content['type'] = 'WorkingPosition';
+        } else {
+            $content['is_filter'] = true;
+        }
+        return  $content;
+    }
 }

+ 50 - 48
catch/wind/controller/Fan.php

@@ -12,24 +12,24 @@ use think\facade\Db;
 class Fan extends CatchController
 {
     protected $fanModel;
-    
+
     public function __construct(FanModel $fanModel)
     {
-        
+
         $this->fanModel = $fanModel;
     }
-    
+
     /**
      * 列表
      * @time 2022年04月28日 19:53
      * @param Request $request 
      */
-    public function index(Request $request) : \think\Response
+    public function index(Request $request): \think\Response
     {
 
         return CatchResponse::paginate($this->fanModel->getList());
     }
-   
+
     /**
      *根据风场的id获取风机的列表
      *
@@ -38,92 +38,94 @@ class Fan extends CatchController
      */
     public function getList(Request $request)
     {
-       
+
         return CatchResponse::success($this->fanModel->getFanList());
     }
-    
+
     /**
      * 保存信息
      * @time 2022年04月28日 19:53
      * @param Request $request 
      */
-    public function save(Request $request) : \think\Response
+    public function save(Request $request): \think\Response
     {
         $data = $request->post();
-        
-        $save_data=array(
-            'wind_id'=>$data['wind_id'],
-            'fan_model'=>$data['fan_model'],
-            'supplier'=>$data['supplier'],
-            'out_date'=>date('Y-m-d',$data['out_date']),
-            'address'=>$data['address'],
-            'info'=>$data['info'],
+
+        $save_data = array(
+            'wind_id' => $data['wind_id'],
+            'fan_model' => $data['fan_model'],
+            'supplier' => $data['supplier'],
+            'out_date' => date('Y-m-d', $data['out_date']),
+            'address' => $data['address'],
+            'info' => $data['info'],
             'creator_id' => $data['creator_id'],
             'created_at' => time(),
         );
-        if(isset($data['out_date']) && is_int($data['out_date'])){
-            $save_data['out_date'] = date('Y-m-d',$data['out_date']);
+        if (isset($data['out_date']) && is_int($data['out_date'])) {
+            $save_data['out_date'] = date('Y-m-d', $data['out_date']);
         }
-        $add_fans=array();
-        if($data['mul_number']){
-            $numArr=explode(',',$data['mul_number']);
-            foreach($numArr as $value) {
-                $save_data['number']=$value;
+        $add_fans = array();
+        if ($data['mul_number']) {
+            $numArr = explode(',', $data['mul_number']);
+            foreach ($numArr as $value) {
+                $save_data['number'] = $value;
                 array_push($add_fans, $save_data);
             }
         }
-        $rule_data=$data['rule_data'];
-        if($rule_data['number_length'] && $rule_data['start_number']){
-            $start=$rule_data['start_number'];
-            $length=$rule_data['start_number']+$rule_data['number_length'];
-            for($i=$start; $i<$length;$i++){
-                if($rule_data['zero_fill']){
-                    $number=str_pad($i,$rule_data['zero_length'],'0',STR_PAD_LEFT );
-                }else{
-                    $number=$i;
+        $rule_data = $data['rule_data'];
+        if ($rule_data['number_length'] && $rule_data['start_number']) {
+            $start = $rule_data['start_number'];
+            $length = $rule_data['start_number'] + $rule_data['number_length'];
+            for ($i = $start; $i < $length; $i++) {
+                if ($rule_data['zero_fill']) {
+                    $number = str_pad($i, $rule_data['zero_length'], '0', STR_PAD_LEFT);
+                } else {
+                    $number = $i;
                 }
-                $save_data['number']=$rule_data['number_first'].$number.$rule_data['number_last'];
+                $save_data['number'] = $rule_data['number_first'] . $number . $rule_data['number_last'];
                 array_push($add_fans, $save_data);
             }
         }
-        $count1 = $this->fanModel->limit(100)->insertAll($add_fans);
-        return CatchResponse::success('添加成功,共' . $count1 . '条');
+
+        $count1 = $this->fanModel->saveAll($add_fans);
+        return CatchResponse::success('添加成功,共' . count($count1) . '条');
         // return CatchResponse::success($this->fanModel->storeBy($data));
     }
-    
+
     /**
      * 读取
      * @time 2022年04月28日 19:53
      * @param $id 
      */
-    public function read($id) : \think\Response
+    public function read($id): \think\Response
     {
         return CatchResponse::success($this->fanModel->findBy($id));
     }
-    
+
     /**
      * 更新
      * @time 2022年04月28日 19:53
      * @param Request $request 
      * @param $id
      */
-    public function update(Request $request, $id) : \think\Response
-    {   $data = $request->post();
-      
-        if(isset($data['out_date']) && is_int($data['out_date'])){
-            $data['out_date'] = date('Y-m-d',$data['out_date']);
+    public function update(Request $request, $id): \think\Response
+    {
+        $data = $request->post();
+
+        if (isset($data['out_date']) && is_int($data['out_date'])) {
+            $data['out_date'] = date('Y-m-d', $data['out_date']);
         }
+        $data['id'] = $id;
         return CatchResponse::success($this->fanModel->updateBy($id, $data));
     }
-    
+
     /**
      * 删除
      * @time 2022年04月28日 19:53
      * @param $id
      */
-    public function delete($id) : \think\Response
+    public function delete($id): \think\Response
     {
-        return CatchResponse::success($this->fanModel->deleteBy($id,true));
+        return CatchResponse::success($this->fanModel->deleteBy($id, true));
     }
-    
-}
+}

+ 37 - 36
catch/wind/controller/Wind.php

@@ -10,38 +10,38 @@ use catchAdmin\wind\model\Wind as windModel;
 class Wind extends CatchController
 {
     protected $windModel;
-    
+
     public function __construct(WindModel $windModel)
     {
         $this->windModel = $windModel;
     }
-    
+
     /**
      * 列表
      * @time 2022年04月27日 10:49
      * @param Request $request 
      */
-    public function index(Request $request) : \think\Response
+    public function index(Request $request): \think\Response
     {
         return CatchResponse::paginate($this->windModel->getList());
     }
-    
+
     /**
      * 列表
      * @time 2022年04月27日 10:49
      * @param Request $request 
      */
-    public function getWindList(Request $request) : \think\Response
+    public function getWindList(Request $request): \think\Response
     {
-        $list=$this->windModel->getWindList();
-        foreach($list as $val){
-            if($val['wind_shape']=='circle'){
-                $val['center_lng']=$val['wind_info']['center']['lng'];
-                $val['center_lat']=$val['wind_info']['center']['lat'];
+        $list = $this->windModel->getWindList();
+        foreach ($list as $val) {
+            if ($val['wind_shape'] == 'circle') {
+                $val['center_lng'] = $val['wind_info']['center']['lng'];
+                $val['center_lat'] = $val['wind_info']['center']['lat'];
             }
-            if($val['wind_shape']=='polygon'){
-                $val['center_lng']=$val['wind_info'][0]['lng'];
-                $val['center_lat']=$val['wind_info'][0]['lat'];
+            if ($val['wind_shape'] == 'polygon') {
+                $val['center_lng'] = $val['wind_info'][0]['lng'];
+                $val['center_lat'] = $val['wind_info'][0]['lat'];
             }
         }
         return CatchResponse::success($list);
@@ -51,10 +51,10 @@ class Wind extends CatchController
      * @time 2022年04月27日 10:49
      * @param Request $request 
      */
-    public function save(Request $request) : \think\Response
+    public function save(Request $request): \think\Response
     {
         $post = $request->post();
-        
+
         if (!isset($post['name']) || !$post['name']) {
             return CatchResponse::fail('风场名称不能为空');
         }
@@ -68,7 +68,7 @@ class Wind extends CatchController
             return CatchResponse::fail('获取风场所属部门失败');
         }
         // 检测名称重复
-        if($this->windModel->where('name',$post['name'])->count()){
+        if ($this->windModel->where('name', $post['name'])->count()) {
             return CatchResponse::fail('风场名称已存在');
         }
         $post['wind_info'] = json_encode($post['wind_info']);
@@ -76,58 +76,59 @@ class Wind extends CatchController
 
         return CatchResponse::success($this->windModel->storeBy($post));
     }
-    
+
     /**
      * 读取
      * @time 2022年04月27日 10:49
      * @param $id 
      */
-    public function read($id) : \think\Response
+    public function read($id): \think\Response
     {
         return CatchResponse::success($this->windModel->findBy($id));
     }
-    
+
     /**
      * 更新
      * @time 2022年04月27日 10:49
      * @param Request $request 
      * @param $id
      */
-    public function update(Request $request, $id) : \think\Response
+    public function update(Request $request, $id): \think\Response
     {
         $post = $request->post();
-        
-        if(isset($post['name'])){
+        $post['id'] = $id;
+        if (isset($post['name'])) {
             // 检测名称重复
-            $n_id = $this->windModel->where('name',$post['name'])->value('id');
-            if($n_id && ($n_id != $id)){
+            $n_id = $this->windModel->where('name', $post['name'])->value('id');
+            if ($n_id && ($n_id != $id)) {
                 return CatchResponse::fail('风场名称已存在');
             }
-       }
-       if(isset($post['department_id']) && is_array($post['department_id'])){
+        }
+        if (isset($post['department_id']) && is_array($post['department_id'])) {
             $post['department_id'] = array_pop($post['department_id']);
         }
-       $post['wind_info'] = json_encode($post['wind_info']);
+        $post['wind_info'] = json_encode($post['wind_info']);
 
-       return CatchResponse::success($this->windModel->updateBy($id, $post));
+        return CatchResponse::success($this->windModel->updateBy($id, $post));
     }
-    
+
     /**
      * 删除
      * @time 2022年04月27日 10:49
      * @param $id
      */
-    public function delete($id) : \think\Response
+    public function delete($id): \think\Response
     {
-        return CatchResponse::success($this->windModel->deleteBy($id,true));
+        return CatchResponse::success($this->windModel->deleteBy($id, true));
     }
-        /**
+    /**
      * 获取风场下拉菜单
      * @time 2022年04月28日 19:53
      */
-    public function getWindOptions(Request $request){
-       
-        $list=$this->windModel->field('id as value,name as text')->select();
+    public function getWindOptions(Request $request)
+    {
+
+        $list = $this->windModel->field('id as value,name as text')->select();
         return CatchResponse::success($list);
     }
-}
+}

+ 27 - 1
catch/wind/model/Fan.php

@@ -1,7 +1,16 @@
 <?php
+/*
+ * @Descripttion: 
+ * @version: 1.0.0
+ * @Author: likang
+ * @Date: 2022-05-27 13:34:31
+ * @LastEditors: likang
+ * @LastEditTime: 2022-07-07 11:00:49
+ */
 
 namespace catchAdmin\wind\model;
 
+use catchAdmin\api\Listen;
 use catcher\base\CatchModel as Model;
 use think\facade\Db;
 use catchAdmin\wind\model\get\FanGet;
@@ -10,7 +19,7 @@ use catchAdmin\permissions\model\DataRangScopeTrait;
 
 class Fan extends Model
 {
-
+    use Listen;
     use DataRangScopeTrait;
     use FanGet;
     use FanSearch;
@@ -65,4 +74,21 @@ class Fan extends Model
         $data = $this->where('wind_id', $wind_id)->select();
         return $data;
     }
+    /**
+     * 风机下发内容
+     */
+    public function addContent(&$obj)
+    {
+
+        $data = null;
+        $content = null;
+        $data = [
+            'id' => $obj->id,
+            'wind_number' => Wind::where('id', $obj->wind_id)->value('number'),
+            'number' => $this->number,
+        ];
+        $content['data'] = $data;
+        $content['type'] = 'Fan';
+        return  $content;
+    }
 }

+ 17 - 0
catch/wind/model/Wind.php

@@ -2,6 +2,7 @@
 
 namespace catchAdmin\wind\model;
 
+use catchAdmin\api\Listen;
 use catcher\base\CatchModel as Model;
 use catchAdmin\permissions\model\DataRangScopeTrait;
 use \think\facade\Db;
@@ -9,6 +10,7 @@ use \think\facade\Db;
 class Wind extends Model
 {
     use DataRangScopeTrait;
+    use Listen;
     // 表名
     public $name = 'wind';
     // 数据库字段映射
@@ -96,4 +98,19 @@ class Wind extends Model
     {
         return $query->where('name', 'like', '%' . $value . '%');
     }
+    //下发数据
+    public function addContent(&$obj)
+    {
+        //var_dump($obj);
+        $data = null;
+        $content = null;
+        $data = [
+            'id' => $obj->id,
+            'number' => $obj->number,
+            'name' => $obj['name'],
+        ];
+        $content['data'] = $data;
+        $content['type'] = 'Wind';
+        return  $content;
+    }
 }

+ 48 - 55
catch/worklocation/model/WorkLocation.php

@@ -2,13 +2,18 @@
 
 namespace catchAdmin\worklocation\model;
 
+use catchAdmin\api\Listen;
+use catchAdmin\hydraulic\model\DeviceMold as ModelDeviceMold;
 use catcher\base\CatchModel as Model;
 use catchAdmin\permissions\model\DataRangScopeTrait;
+use catchAdmin\wind\model\Fan;
+use catchAdmin\wind\model\Wind;
+use DeviceMold;
 use think\facade\Db;
 
 class Worklocation extends Model
 {
-
+    use Listen;
     use DataRangScopeTrait;
     // 表名
     public $name = 'work_location';
@@ -46,11 +51,11 @@ class Worklocation extends Model
         // 外径
         'external_diameter',
     );
-     public function getList()
+    public function getList()
     {
-            return $this->dataRange()
+        return $this->dataRange()
             ->catchSearch()
-            ->append(['department_name','wind_name','fan_number','work_local_name','parts_name','bolt_style_name','boit_type_name','work_name'])
+            ->append(['department_name', 'wind_name', 'fan_number', 'work_local_name', 'parts_name', 'bolt_style_name', 'boit_type_name', 'work_name'])
             ->field('*')
             ->catchOrder()
             ->creator()
@@ -59,9 +64,9 @@ class Worklocation extends Model
     //获取部门名称
     public function getDepartmentNameAttr()
     {
-       $dep_id = Db::name('wind')->where('id',$this->wind_id)->value('department_id');
-       $name = Db::name('departments')->where('id',$dep_id)->where('status',1)->value('department_name');
-       return $name;
+        $dep_id = Db::name('wind')->where('id', $this->wind_id)->value('department_id');
+        $name = Db::name('departments')->where('id', $dep_id)->where('status', 1)->value('department_name');
+        return $name;
     }
 
     /**
@@ -72,18 +77,17 @@ class Worklocation extends Model
     public function getWindNameAttr()
     {
         $wind_id = $this->wind_id;
-        $wind_name =  Db::name('wind')->where('id',$wind_id)->value('name');
+        $wind_name =  Db::name('wind')->where('id', $wind_id)->value('name');
         return $wind_name;
-
     }
     //获取操作人员
     public function getWorkNameAttr()
     {
         $user_id = $this->creator_id;
-        $name =  Db::name("users")->where('id',$user_id)->value('realname');
+        $name =  Db::name("users")->where('id', $user_id)->value('realname');
         return $name;
     }
-   
+
     /**
      * 获取风机机位号
      * @return void
@@ -91,7 +95,7 @@ class Worklocation extends Model
     public function getFanNumberAttr()
     {
         $fan_id = $this->fan_id;
-        $fan_number =  Db::name('fan')->where('id',$fan_id)->value('number');
+        $fan_number =  Db::name('fan')->where('id', $fan_id)->value('number');
         return $fan_number;
     }
     /**
@@ -102,14 +106,14 @@ class Worklocation extends Model
     public function getPartsNameAttr()
     {
         $parts = $this->parts;
-        $value = $this->get_dict_data(1,$parts);
+        $value = $this->get_dict_data(1, $parts);
         return $value;
     }
     //获取工作位置型号
     public function getWorkLocalNameAttr()
     {
         $code = $this->work_local;
-        $value = $this->get_dict_data(2,$code);
+        $value = $this->get_dict_data(2, $code);
         return $value;
     }
     /**
@@ -119,9 +123,9 @@ class Worklocation extends Model
      */
     public function  getBoltStyleNameAttr()
     {
-    
+
         $code = $this->bolt_style;
-        $value = $this->get_dict_data(3,$code);
+        $value = $this->get_dict_data(3, $code);
         return $value;
     }
     /**
@@ -132,53 +136,42 @@ class Worklocation extends Model
     public function getBoitTypeNameAttr()
     {
         $code = $this->boit_type;
-        $value = $this->get_dict_data(4,$code);
+        $value = $this->get_dict_data(4, $code);
         return $value;
     }
 
-   /**
-    * 
-    * @param [type] $type 类型
-    * @param [type] $value 唯一value
-    * @return void
-    */
-    public function get_dict_data($type,$value)
+    /**
+     * 
+     * @param [type] $type 类型
+     * @param [type] $value 唯一value
+     * @return void
+     */
+    public function get_dict_data($type, $value)
     {
-        $where[]=['device_type',"=",$type];
-        $where[] = ['value','=',$value];
+        $where[] = ['device_type', "=", $type];
+        $where[] = ['value', '=', $value];
         $name = Db::name('maintenance_mapper')->where($where)->value('name');
         return $name;
     }
-  
-   //搜索
-
-//    public function searchNumberAttr($query, $value, $data)
-//    {
-//        return $query->where('number', 'like', '%'.$value.'%');
-//    }
-  /**
-     * 统计属性
-     * 根据时间 压力和扭矩力线性图
+    /**
+     * 监听转换
      */
-    public function getTotal()
+    public function addContent(&$obj)
     {
-        
-        
+        $data = null;
+        $content = null;
+        $data = [
+            'id' => $obj->wind_id . $obj->fan_id . $obj->fan_model . $obj->parts . $obj->work_local,
+            'wind_number' => $obj->id,
+            'fan_number' => Wind::where('id', $obj->wind_id)->value('number'),
+            'fan_model'  => ModelDeviceMold::where('device_type', 4)->where('id', $this->fan_model)->value('name'),
+            'parts' => $this->get_dict_data(1, $obj->parts),
+            'fan_number' => Fan::where('id', $obj->fan_id)->value('number'),
+            'bolt_num' => $this->bolt_num,
+            'torque' => $this->torque
+        ];
+        $content['data'] = $data;
+        $content['type'] = 'WorkRecord';
+        return  $content;
     }
-
-
-
-
-
-
-
-
-
-
-
-
-    
-
-        
 }
-

+ 22 - 0
catch/worklocation/model/Workplan.php

@@ -2,6 +2,8 @@
 
 namespace catchAdmin\worklocation\model;
 
+use catchAdmin\api\Listen;
+use catchAdmin\hydraulic\model\DeviceMold;
 use catchAdmin\hydraulic\model\MaintenanceMapper as ModelMaintenancemapper;
 use catchAdmin\permissions\model\DataRangScopeTrait;
 use catchAdmin\permissions\model\Users;
@@ -9,8 +11,10 @@ use catchAdmin\wind\model\Fan;
 use catchAdmin\wind\model\Wind;
 use catcher\base\CatchModel as Model;
 
+
 class Workplan extends Model
 {
+    use Listen;
     use DataRangScopeTrait;
     // 表名
     public $name = 'work_plan';
@@ -42,6 +46,24 @@ class Workplan extends Model
         // 软删除
         'deleted_at',
     );
+    /**
+     * 监听转换
+     */
+    public function addContent(&$obj)
+    {
+        $data = null;
+        $content = null;
+        $data = [
+            'id' => $obj->id,
+            'plan_number' => $obj->id,
+            'wind_number' => Wind::where('id', $obj->wind_id)->value('number'),
+            'wind_name' => Wind::where('id', $obj->wind_id)->value('name'),
+            'fan_number' => Fan::where('id', $obj->wind_id)->value('number'),
+        ];
+        $content['data'] = $data;
+        $content['type'] = 'WorkPlan';
+        return  $content;
+    }
     public function getList()
     {
         return $this->dataRange()