load->model('User_model'); $this->response = $this->config->config['response_en']; $version = 1; $this->session->set_userdata('version', $version); $this->version = $version; } public function crazycat(){ $this->db->query('update lampinfo set netstatus = 0'); var_dump('ok'); } // 批量导入 public function haha(){ $info = '91 0100 00 a800010001 0c 11 3e80 3c8c 3908 3138 2f44 3390283c2ee0245403e8007800781e05a3412cec27101e010fc3'; $info = '91010000a8000100010c113e803c8c390831382f443390283c2ee0245403e8007800781e05a3412cec27101e010fc3'; var_dump(substr($info, 34,4)); var_dump(round(base_convert(substr($info, 34,4), 16, 10)/1000,1));die; $indexArr = ['B'=>'b','C'=>'c']; // 文件上传成功 // $data = $this->upload->data(); $filePath = '../upload/test.xlsx'; $this->load->library('phpExcel/PHPExcel'); $extension = strtolower( pathinfo($filePath, PATHINFO_EXTENSION) ); if($extension =='xls' ){ $reader = PHPExcel_IOFactory::createReader('Excel5'); }elseif($extension =='xlsx'){ $reader = PHPExcel_IOFactory::createReader('Excel2007'); }else if ($extension=='csv' || strtolower($extension)=='hcl') { $reader = new PHPExcel_Reader_CSV(); } // $reader = PHPExcel_IOFactory::createReader('Excel5'); //设置以Excel5格式(Excel97-2003工作簿) $PHPExcel = $reader->load($filePath); // 载入excel文件 $sheet = $PHPExcel->getSheet(0); // 读取第一個工作表 $highestRow = $sheet->getHighestRow(); // 取得总行数 // $highestColumm = $sheet->getHighestColumn(); // 取得总列数 /** 循环读取每个单元格的数据 */ $k = 0; $data = array(); for ($row = 1; $row <= $highestRow; $row++) //行号从1开始 { if ($row < 4) continue; // 跳过标题行 foreach ($indexArr as $key => $value) { $res = $sheet->getCell($key.$row)->getValue(); if (is_object($res)) { $res= $res->__toString(); } $data[$k][$value] = $res; } $k ++; } $supId = 0; foreach ($data as $key => $value) { if (isset($value['b']) && !empty($value['b'])) { $res = $this->db->query('select * from company where name = "'.$value['b'].'"')->row_array(); // if (empty($res)) var_dump($value['b']); $supId = $res['id']; // var_dump($res); } if (!empty($value['c'])) $this->db->query('insert into model_info (supId,name) values('.$supId.',"'.$value['c'].'")'); } var_dump($data);die; // 批量写入数据 return $data; } public function update_project_count(){ $list = $this->db->query('select id from project')->result_array(); foreach ($list as $key => $value) { $res = $this->db->query('select count(*) as total from lampinfo where projectid = '.$value['id'])->row_array(); $this->db->query('update project set lampcount = '.$res['total'].' where id = '.$value['id']); } var_dump('ok'); } }