20201112
This commit is contained in:
@@ -28,6 +28,7 @@ class Special extends Controller {
|
||||
protected $sys_scient_obj = '';
|
||||
protected $sys_book_obj = '';
|
||||
protected $journal_special_alert_obj = '';
|
||||
protected $article_cite_obj = '';
|
||||
|
||||
public function __construct(\think\Request $request = null) {
|
||||
parent::__construct($request);
|
||||
@@ -46,6 +47,7 @@ class Special extends Controller {
|
||||
$this->sys_scient_obj = Db::name('system_scient');
|
||||
$this->sys_book_obj = Db::name('system_books');
|
||||
$this->journal_special_alert_obj = Db::name('journal_special_alert');
|
||||
$this->article_cite_obj = Db::name('article_cite');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,5 +319,91 @@ class Special extends Controller {
|
||||
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 读取引用文件
|
||||
*/
|
||||
public function readCiteExcel(){
|
||||
$path = ROOT_PATH.'public'.DS.'system'.DS;
|
||||
$res = $this->readExcel($path.'savedrecs.xls');
|
||||
foreach ($res as $k => $v){
|
||||
if($k<6||$v['C']<1){
|
||||
continue;
|
||||
}
|
||||
$doi = explode('/', $v['B']);
|
||||
$article = '';
|
||||
if(isset($doi[1])){
|
||||
$article = $this->article_obj->where('doi','like','%'.$doi[1].'%')->find();
|
||||
}else{
|
||||
$article = $this->article_obj->where('title',$v['A'])->find();
|
||||
}
|
||||
$cache = $this->readExcel1($path.($k+1).'.xls');
|
||||
foreach ($cache as $key => $val){
|
||||
if($key == 0){
|
||||
continue;
|
||||
}
|
||||
$insert['article_id'] = $article['article_id'];
|
||||
$insert['journal_id'] = $article['journal_id'];
|
||||
$insert['journal_name'] = $val['journal'];
|
||||
$insert['article_name'] = $val['title'];
|
||||
$day = $val['day']==''?'':$val['day'].' ';
|
||||
$insert['date'] = $day.$val['year'];
|
||||
$insert['ctime'] = time();
|
||||
$this->article_cite_obj->insert($insert);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取excel数据
|
||||
*/
|
||||
private function readExcel1($path) {
|
||||
$extension = substr($path, strrpos($path, '.') + 1);
|
||||
vendor("PHPExcel.PHPExcel");
|
||||
if ($extension == 'xlsx') {
|
||||
$objReader = new \PHPExcel_Reader_Excel2007();
|
||||
$objPHPExcel = $objReader->load($path);
|
||||
} else if ($extension == 'xls') {
|
||||
$objReader = new \PHPExcel_Reader_Excel5();
|
||||
$objPHPExcel = $objReader->load($path);
|
||||
}
|
||||
$sheet = $objPHPExcel->getSheet(0);
|
||||
$highestRow = $sheet->getHighestRow();
|
||||
$frag = [];
|
||||
for ($i = 1; $i <= $highestRow; $i++) {
|
||||
$cache['title'] = $objPHPExcel->getActiveSheet()->getCell("I".$i)->getValue();
|
||||
$cache['journal'] = $objPHPExcel->getActiveSheet()->getCell("J".$i)->getValue();
|
||||
$cache['year'] = $objPHPExcel->getActiveSheet()->getCell("AS".$i)->getValue();
|
||||
$cache['day'] = $objPHPExcel->getActiveSheet()->getCell("AR".$i)->getValue();
|
||||
$frag[] = $cache;
|
||||
}
|
||||
return $frag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取excel数据
|
||||
*/
|
||||
private function readExcel($path) {
|
||||
$extension = substr($path, strrpos($path, '.') + 1);
|
||||
vendor("PHPExcel.PHPExcel");
|
||||
if ($extension == 'xlsx') {
|
||||
$objReader = new \PHPExcel_Reader_Excel2007();
|
||||
$objPHPExcel = $objReader->load($path);
|
||||
} else if ($extension == 'xls') {
|
||||
$objReader = new \PHPExcel_Reader_Excel5();
|
||||
$objPHPExcel = $objReader->load($path);
|
||||
}
|
||||
$sheet = $objPHPExcel->getSheet(0);
|
||||
$highestRow = $sheet->getHighestRow();
|
||||
$frag = [];
|
||||
for ($i = 1; $i <= $highestRow; $i++) {
|
||||
$cache['A'] = $objPHPExcel->getActiveSheet()->getCell("A".$i)->getValue();
|
||||
$cache['B'] = $objPHPExcel->getActiveSheet()->getCell("B".$i)->getValue();
|
||||
$cache['C'] = $objPHPExcel->getActiveSheet()->getCell("C".$i)->getValue();
|
||||
$frag[] = $cache;
|
||||
}
|
||||
return $frag;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user