Test.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Test extends CI_Controller {
  3. var $response;
  4. var $userinfo;
  5. var $version;
  6. public function __construct() {
  7. parent::__construct();
  8. $this->load->model('User_model');
  9. $this->response = $this->config->config['response_en'];
  10. $version = 1;
  11. $this->session->set_userdata('version', $version);
  12. $this->version = $version;
  13. }
  14. public function crazycat(){
  15. $this->db->query('update lampinfo set netstatus = 0');
  16. var_dump('ok');
  17. }
  18. // 批量导入
  19. public function haha(){
  20. $info = '91 0100 00 a800010001 0c 11 3e80 3c8c 3908 3138 2f44 3390283c2ee0245403e8007800781e05a3412cec27101e010fc3';
  21. $info = '91010000a8000100010c113e803c8c390831382f443390283c2ee0245403e8007800781e05a3412cec27101e010fc3';
  22. var_dump(substr($info, 34,4));
  23. var_dump(round(base_convert(substr($info, 34,4), 16, 10)/1000,1));die;
  24. $indexArr = ['B'=>'b','C'=>'c'];
  25. // 文件上传成功
  26. // $data = $this->upload->data();
  27. $filePath = '../upload/test.xlsx';
  28. $this->load->library('phpExcel/PHPExcel');
  29. $extension = strtolower( pathinfo($filePath, PATHINFO_EXTENSION) );
  30. if($extension =='xls' ){
  31. $reader = PHPExcel_IOFactory::createReader('Excel5');
  32. }elseif($extension =='xlsx'){
  33. $reader = PHPExcel_IOFactory::createReader('Excel2007');
  34. }else if ($extension=='csv' || strtolower($extension)=='hcl') {
  35. $reader = new PHPExcel_Reader_CSV();
  36. }
  37. // $reader = PHPExcel_IOFactory::createReader('Excel5'); //设置以Excel5格式(Excel97-2003工作簿)
  38. $PHPExcel = $reader->load($filePath); // 载入excel文件
  39. $sheet = $PHPExcel->getSheet(0); // 读取第一個工作表
  40. $highestRow = $sheet->getHighestRow(); // 取得总行数
  41. // $highestColumm = $sheet->getHighestColumn(); // 取得总列数
  42. /** 循环读取每个单元格的数据 */
  43. $k = 0;
  44. $data = array();
  45. for ($row = 1; $row <= $highestRow; $row++) //行号从1开始
  46. {
  47. if ($row < 4) continue; // 跳过标题行
  48. foreach ($indexArr as $key => $value) {
  49. $res = $sheet->getCell($key.$row)->getValue();
  50. if (is_object($res)) {
  51. $res= $res->__toString();
  52. }
  53. $data[$k][$value] = $res;
  54. }
  55. $k ++;
  56. }
  57. $supId = 0;
  58. foreach ($data as $key => $value) {
  59. if (isset($value['b']) && !empty($value['b'])) {
  60. $res = $this->db->query('select * from company where name = "'.$value['b'].'"')->row_array();
  61. // if (empty($res)) var_dump($value['b']);
  62. $supId = $res['id'];
  63. // var_dump($res);
  64. }
  65. if (!empty($value['c'])) $this->db->query('insert into model_info (supId,name) values('.$supId.',"'.$value['c'].'")');
  66. }
  67. var_dump($data);die;
  68. // 批量写入数据
  69. return $data;
  70. }
  71. public function update_project_count(){
  72. $list = $this->db->query('select id from project')->result_array();
  73. foreach ($list as $key => $value) {
  74. $res = $this->db->query('select count(*) as total from lampinfo where projectid = '.$value['id'])->row_array();
  75. $this->db->query('update project set lampcount = '.$res['total'].' where id = '.$value['id']);
  76. }
  77. var_dump('ok');
  78. }
  79. }