MS-PDRLKVHCADMG\Administrator 5 år sedan
förälder
incheckning
53e733e1f3
1 ändrade filer med 17 tillägg och 317 borttagningar
  1. 17 317
      api/application/controllers/Lampcontrol.php

+ 17 - 317
api/application/controllers/Lampcontrol.php

@@ -1719,12 +1719,14 @@ class Lampcontrol extends Base_Controller {
         // $idArr = $this->get_section_by_user();
 
         $role = $this->get_user_info('role');
-        $companyid = $this->get_user_info('companyid');
+        $company = $this->get_user_info('company');
 
         $type = intval($this->input->post('type',true));
+        $projectid = intval($this->input->post('projectid',true));
+        if (empty($projectid)) exit(json_result('0007',$this->response['0007']));
 
         if ($type == 1) {  // 验证
-            $indexArr = ['A'=>'number','B'=>'address','C'=>'company_name','D'=>'projectid','E'=>'devicetype','F'=>'networkid','G'=>'protocoltype','H'=>'lampprotocoltype','I'=>'section','J'=>'longitude','K'=>'latitude','L'=>'poleheight','M'=>'polediameter','N'=>'polematerial','O'=>'lighttype','P'=>'lamptype','Q'=>'boardtype','R'=>'batterytype','S'=>'boardpower','T'=>'batteryah','U'=>'loadpower','V'=>'loadtype'];
+            $indexArr = ['A'=>'number','B'=>'address','C'=>'section'];
             $data = $this->batch_import($indexArr);
         }else{  // 创建
             $data = $this->input->post('lampData',true);
@@ -1732,12 +1734,9 @@ class Lampcontrol extends Base_Controller {
             if (empty($data)) exit(json_result('0007',$this->response['0007']));
             $data = json_decode($data,true);
         }
-        foreach ($data as &$v) {
-            if ($type == 1 && is_float($v['address'])) $v['address'] = strval(intval(ceil($v['address'])));
-        }
+
         $res = 0;
 
-        $typeArr = ['tcp'=>0,'nb'=>1,'gprs'=>2,'lorawan'=>3,'MQTT'=>4,'WeLoraWan'=>6,'onenet'=>7];
         $this->db->trans_begin();
         $msg = [];
         $patrol_arr = array();
@@ -1761,333 +1760,38 @@ class Lampcontrol extends Base_Controller {
                     }
                 }
             }
-            // if ($type == 1 && is_float($value['address'])) {
-            //     $value['address'] = strval(intval(ceil($value['address'])));
-            // }
+
             $value['address'] = trim($value['address']);
             if (empty($value['address'])) {
                 $res = 1;
                 
-                if (empty($this->version)) {
-                    $msg[] = '表格第'.$num.'行,无线模块地址不能为空';
-                }else{
-                    $msg[] = 'Table '.$num.' row.Address of the wireless module can not be empty';
-                }
+                $msg[] = 'Table '.$num.' row.Address of the wireless module can not be empty';
             }else{
                 $status = preg_match('/^[A-Fa-f0-9]+$/', $value['address']);
                 if (empty($status)) {
                     $res = 1;
-                    if (empty($this->version)) {
-                        $msg[] = '表格第'.$num.'行,无线模块地址为16进制数';
-                    }else{
-                        $msg[] = 'Table '.$num.' row.Wireless module address is 16 hexadecimal';
-                    }
+                    $msg[] = 'Table '.$num.' row.Wireless module address is 16 hexadecimal';
                 }else{
                     if ($this->Lamp_model->getDataCount(['address'=>$value['address']])) {
                         $res = 1;
-                        if (empty($this->version)) {
-                            $msg[] = '表格第'.$num.'行,无线模块地址已经存在';
-                        }else{
-                            $msg[] = 'Table '.$num.' row.Wireless module address already exists';
-                        }
-                    }
-                }
-            }
-            $value['company_name'] = trim($value['company_name']);
-            if (empty($value['company_name'])) {
-                $res = 1;
-                if (empty($this->version)) {
-                    $msg[] = '表格第'.$num.'行,公司名称不能为空';
-                }else{
-                    $msg[] = 'Table '.$num.' row.Company name cannot be empty';
-                }
-            }
-            $value['projectid'] = trim($value['projectid']);
-            if (empty($value['projectid'])) {
-                $res = 1;
-                if (empty($this->version)) {
-                    $msg[] = '表格第'.$num.'行,项目名称不能为空';
-                }else{
-                    $msg[] = 'Table '.$num.' row.Project name cannot be empty';
-                }
-            }else{
-                $projectid = $this->Project_model->project_exist_by_name($role,$userid,$companyid,$value['projectid'],$value['company_name']);
-                if (empty($projectid)) {
-                    $res = 1;
-                    if (empty($this->version)) {
-                        $msg[] = '表格第'.$num.'行,项目不存在,请先创建项目';
-                    }else{
-                        $msg[] = 'Table '.$num.' row.The project does not exist. Please create a project first.';
-                    }
-                    $value['projectid'] = 0;
-                }else{
-                    $value['projectid'] = $projectid;
-                    $this->Project_model->add_lamp_count(array('faultcount'=>0,'projectid'=>$projectid));
-                    if ($this->Lamp_model->getDataCount(['projectid'=>$value['projectid'],'number'=>$value['number']])) {
-                        $res = 1;
-                        if (empty($this->version)) {
-                            $msg[] = '表格第'.$num.'行,路灯编号已经存在';
-                        }else{
-                            $msg[] = 'Table '.$num.' row lamp number already exists';
-                        }
-                    }
-                }
-            }
-
-            if($type != 1 && isset($typeArr[$value['protocoltype']]) && $typeArr[$value['protocoltype']] == 6){
-                $this->add_device($value['address']);
-            }
-
-            $value['devicetype'] = intval(trim($value['devicetype']));
-
-            if ($value['devicetype'] == 0) { // 非直连设备
-                unset($value['protocoltype']);
-                $value['networkid'] = trim($value['networkid']);
-                if (empty($value['networkid'])) {
-                    $res = 1;
-                    if (empty($this->version)) {
-                        $msg[] = '表格第'.$num.'行,非直连设备网络编号不能为空';
-                    }else{
-                        $msg[] = 'Table '.$num.' row.Indirect device network number cannot be empty';
-                    }
-                }else{
-                    $networkid = $this->Network_model->project_exist_by_name($value['projectid'],$value['networkid']);
-                    // var_dump($this->db->last_query());die;
-                    if (empty($networkid)) {
-                        $res = 1;
-                        if (empty($this->version)) {
-                            $msg[] = '表格第'.$num.'行,网络不存在,请先添加网络';
-                        }else{
-                            $msg[] = 'Table '.$num.' row.The network does not exist. Please add the network first';
-                        }
-                    }else{
-                        $this->Network_model->add_lamp_count(array('faultcount'=>0,'networkid'=>$networkid));
-                        $value['networkid'] = $networkid;
-                    }
-                }
-            }elseif ($value['devicetype'] == 1) { // 直连设备
-                $value['protocoltype'] = trim($value['protocoltype']);
-                if (empty($value['protocoltype'])) {
-                    $res = 1;
-                    if (empty($this->version)) {
-                        $msg[] = '表格第'.$num.'行,协议类型不能为空';
-                    }else{
-                        $msg[] = 'Table '.$num.' row.Protocol type cannot be empty';
+                        $msg[] = 'Table '.$num.' row.Wireless module address already exists';
                     }
-                }else{
-                    if (!isset($typeArr[$value['protocoltype']])) {
-                        $res = 1;
-                        if (empty($this->version)) {
-                            $msg[] = '表格第'.$num.'行,协议类型不存在';
-                        }else{
-                            $msg[] = 'Table '.$num.' row.Protocol type not exists';
+                    if ($role != SYSTEM_ADMIN) {
+                        if ($role == 2) {
+                            $value["manu"] = $company;
+                        }elseif ($role == 4) {
+                            $value["po"] = $company;
                         }
                     }
-                }
-
-                // 创建直连网络
-                $number = mb_strlen($value['address']) == 13 ? base_convert($value['address'], 16, 10) : $value['address'];
-                if ($this->Network_model->getDataCount(array('devicesn'=>$number))) {
-                    $res = 1;
-                    if (empty($this->version)) {
-                        $msg[] = '表格第'.$num.'行,无线模块地址已被使用';
-                    }else{
-                        $msg[] = 'Table '.$num.' row.Wireless module address has been used';
-                    }
-                }
-                // 创建网络
-                // $networkData['id']  = $this->Zone_model->insert(array(
-                //     'name'   => $number,
-                //     'parent' => $value['projectid'] ,
-                //     'level'  => 4
-                // )); 
-                // 控制器协议类型
-                $value['lampprotocoltype'] = trim($value['lampprotocoltype']);
-                if (empty($value['lampprotocoltype'])) {
-                    $networkData['devicetype'] = 0;
-                }else{
-                    if ($value['lampprotocoltype'] == 'ModBus') {
-                        $networkData['devicetype'] = 3;
-                    }elseif ($value['lampprotocoltype'] == 'LightBus') {
-                        $networkData['devicetype'] = 0;
-                    }else{
-                        $networkData['devicetype'] = 0;
-                    }
-                }
-                $networkData['networkid'] = $number;
-                $networkData['gatewaytype'] = 'direct';
-                $networkData['protocoltype'] = empty($typeArr[$value['protocoltype']]) ? 'tcp' : $typeArr[$value['protocoltype']];
-                $networkData['projectid'] = $value['projectid'];
-                $networkData['devicesn'] = $number;
-                $networkData['networkname'] = $number;
-                $networkData['type'] = 1;
-                $networkData['lampcount'] = 1;
-                $networkData['createtime'] = date('Y-m-d H:i:s',time());
-
-                if ($type == 1) {
-                    $this->db->insert('network',$networkData);
-                    $value['networkid'] = $this->db->insert_id();
-                }else{
-                    $value['networkid'] = $this->Network_model->insert($networkData);
-                }
-            }else{
-                $res = 1;
-                if (empty($this->version)) {
-                    $msg[] = '表格第'.$num.'行,设备类型选择错误';
-                }else{
-                    $msg[] = 'Table '.$num.' row.Device type selection error';
-                }
-            }
-            unset($value['protocoltype']);
-
-            // 控制器协议类型
-            $value['lampprotocoltype'] = trim($value['lampprotocoltype']);
-            if (empty($value['lampprotocoltype'])) {
-                $res = 1;
-                
-                if (empty($this->version)) {
-                    $msg[] = '表格第'.$num.'行,协议类型不能为空';
-                }else{
-                    $msg[] = 'Table '.$num.' row.Protocol type can not be empty';
-                }
-            }else{
-                if ($value['lampprotocoltype'] == 'ModBus') {
-                    $value['protocoltype'] = 1;
-                }elseif ($value['lampprotocoltype'] == 'LightBus') {
-                    $value['protocoltype'] = 0;
-                }else{
-                    $res = 1;
-                    if (empty($this->version)) {
-                        $msg[] = '表格第'.$num.'行,协议类型选择错误';
-                    }else{
-                        $msg[] = 'Table '.$num.' row.Protocol type selection error';
-                    }
-                }
-            }
-            unset($value['lampprotocoltype']);
-
-            $value['longitude'] = trim($value['longitude']);
-            if (empty($value['longitude'])) {
-                $value['longitude'] = 0;
-            }else{
-                if (!is_numeric($value['longitude']) || $value['longitude'] > 180 || $value['longitude'] < -180) {
-                    $res = 1;
-                    if (empty($this->version)) {
-                        $msg[] = '表格第'.$num.'行,经度输入错误';
-                    }else{
-                        $msg[] = 'Table '.$num.' row longitude input error';
-                    }
-                }
-            }
-
-            $value['latitude'] = trim($value['latitude']);
-            if (empty($value['latitude'])) {
-                $value['latitude'] = 0;
-            }else{
-                if (!is_numeric($value['latitude']) || $value['latitude'] > 90 || $value['latitude'] < -90) {
-                    $res = 1;
-                    if (empty($this->version)) {
-                        $msg[] = '表格第'.$num.'行,纬度输入错误';
-                    }else{
-                        $msg[] = 'Table '.$num.' row latitude input error';
-                    }
-                }
-            }
-            if (empty($value['latitude']) && empty($value['longitude']) && !empty($value['projectid'])) {
-                $projectData = $this->Project_model->getOne($value['projectid'],'cityid');
-                if (!empty($projectData['cityid'])){
-                    $globalData = $this->Global_location_model->getOne($projectData['cityid'],'longitude,latitude');
-                    $value['longitude'] = $globalData['longitude'];
-                    $value['latitude'] = $globalData['latitude'];
-                }
-            }
-            
-            $value['loadtype'] = trim($value['loadtype']);
-            if (empty($value['loadtype']) || $value['loadtype'] == '0' || $value['loadtype'] == '1') {
-                if ($value['loadtype'] == '1') {
-                    $value['loadtype'] = 1;
-                }else{
-                    $value['loadtype'] = 0;
-                }
-            }else{
-                $res = 1;
-                if (empty($this->version)) {
-                    $msg[] = '表格第'.$num.'行,负载类型错误';
-                }else{
-                    $msg[] = 'Table '.$num.' row load type error';
-                }
-            }
 
-            if (trim($value['poleheight']) == '') {
-                unset($value['poleheight']);
-            }else{
-                $value['poleheight'] = trim($value['poleheight']);
-            }
-            if (trim($value['polediameter']) == '') {
-                unset($value['polediameter']);
-            }else{
-                $value['polediameter'] = trim($value['polediameter']);
-            }
-            if (trim($value['section']) == '') {
-                $value['section'] = '';
-                $res = 1;
-                if (empty($this->version)) {
-                    $msg[] = '表格第'.$num.'行,路段不能为空';
-                }else{
-                    $msg[] = 'Table '.$num.' row. Section cannot be empty';
+                    if (!isset($value["manu"])) $value["manu"] = $this->get_manu_by_address($value["address"]);
                 }
-            }else{
-                $value['section'] = trim($value['section']);
-            }
-            if (trim($value['polematerial']) == '') {
-                unset($value['polematerial']);
-            }else{
-                $value['polematerial'] = trim($value['polematerial']);
-            }
-            if (trim($value['lighttype']) == '') {
-                unset($value['lighttype']);
-            }else{
-                $value['lighttype'] = trim($value['lighttype']);
-            }
-            if (trim($value['lamptype']) == '') {
-                unset($value['lamptype']);
-            }else{
-                $value['lamptype'] = trim($value['lamptype']);
-            }
-            if (trim($value['boardtype']) == '') {
-                unset($value['boardtype']);
-            }else{
-                $value['boardtype'] = trim($value['boardtype']);
-            }
-            if (trim($value['batterytype']) == '') {
-                unset($value['batterytype']);
-            }else{
-                $value['batterytype'] = trim($value['batterytype']);
-            }
-            if (trim($value['boardpower']) == '') {
-                unset($value['boardpower']);
-            }else{
-                $value['boardpower'] = trim($value['boardpower']);
-            }
-            if (trim($value['batteryah']) == '') {
-                unset($value['batteryah']);
-            }else{
-                $value['batteryah'] = trim($value['batteryah']);
-            }
-            if (trim($value['loadpower']) == '') {
-                unset($value['loadpower']);
-            }else{
-                $value['loadpower'] = trim($value['loadpower']);
             }
+            $value['section'] = trim($value['section']);
 
             $value['createtime'] = date('Y-m-d H:i:s',time());
-            $value['updatetime'] = date('Y-m-d H:i:s',time());
-            unset($value['company_name']);
-            if (is_null($value['networkid'])) {
-                unset($value['networkid']);
-            }
+            $value['projectid'] = $projectid;
             $lamp_id = $this->Lamp_model->insert($value);
-            $patrol_arr[] = array('lampid'=>$lamp_id,'projectid'=>$value['projectid']);
         }
 
         if ($res || $type == 1) {
@@ -2095,10 +1799,6 @@ class Lampcontrol extends Base_Controller {
             exit(json_result('0000',$this->response['0000'],['lampData'=>$data,'msg'=>$msg]));
         }else{
             $this->db->trans_commit();
-            // foreach ($patrol_arr as $patrol) {
-            //     $projectData = $this->Project_model->getOne($patrol['projectid'],'patrolinterval');
-            //     $this->patrol_set($patrol['lampid'],$projectData['patrolinterval']);
-            // }
             exit(json_result('0000',$this->response['0000']));
         }
     }