Test.php 3.4 KB

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