public function stock(){ $curl = new Curl(); $curl->setUserAgent('Mozilla/5.0'); $curl->get('http://stock.gtimg.cn/data/get_hs_xls.php?id=ranka&type=1&metric=chr'); $file_name = date('Ymd').'.xls'; $dataSet = ''; if ($curl->error) { echo $curl->error_code; } else { file_put_contents($file_name, $curl->response); //echo $curl->response; $objPHPExcel = \PHPExcel_IOFactory::load($file_name); $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); // 取得总行数 $highestColumn = $sheet->getHighestColumn(); // 取得总列数 $objdata = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); $date = date('Y-m-d',strtotime(date('Y',time()).'-'.$objdata['1']['B'])); foreach ($objdata as $k=>$v){ if($k>2){ $dataSet[]=array( 'dm'=>$v['A'], 'name'=>$v['B'], 'zxj' =>$v['C'], 'zdf' =>str_replace('%', '', $v['D']), 'zde' =>$v['E'], 'cjl' =>$v['H'], 'cje' =>$v['I'], 'jk' =>$v['J'], 'zs' =>$v['K'], 'zg' =>$v['L'], 'zd' =>$v['M'], 'data_time'=>$date, 'ctime'=>date('Y-m-d H:i:s',time()), ); } } } if($dataSet) { db('record')->where('data_time',$date)->delete(); db('record')->insertAll($dataSet); echo 'success'; }else{ echo 'false'; } $curl->close(); }
composer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | { "require" : { "php" : ">=5.4.0" , "topthink/framework" : "^5.0" , "phpoffice/phpexcel" : "^1.0" , "curl/curl" : "^1.0" }, "repositories" : { "packagist" : { "type" : "composer" , "url" : "https://packagist.phpcomposer.com" } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | CREATE TABLE `record` ( `id` int (10) NOT NULL AUTO_INCREMENT, `dm` varchar (64) DEFAULT NULL COMMENT '代码' , ` name ` varchar (64) DEFAULT NULL COMMENT '名称' , `zxj` decimal (10,2) DEFAULT NULL COMMENT '最新价' , `zdf` decimal (10,2) DEFAULT NULL COMMENT '涨跌幅' , `zde` decimal (10,2) DEFAULT NULL COMMENT '涨跌额' , `cjl` double (20,0) DEFAULT NULL COMMENT '成交量' , `cje` decimal (20,2) DEFAULT NULL COMMENT '成交额' , `jk` decimal (10,2) DEFAULT NULL COMMENT '今开' , `zs` decimal (10,2) DEFAULT NULL COMMENT '昨收' , `zg` decimal (10,2) DEFAULT NULL COMMENT '最高' , `zd` decimal (10,2) DEFAULT NULL COMMENT '最低' , `data_time` datetime DEFAULT NULL COMMENT '交易日期' , `ctime` datetime DEFAULT NULL COMMENT '创建时间' , PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4096 DEFAULT CHARSET=utf8; |
db类https://packagist.org/packages/joshcam/mysqli-database-class
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步