request->post(); $rule = new Validate([ "article_id" => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $production_info = $this->production_article_obj->where('article_id', $data['article_id'])->find(); if ($production_info == null) { return jsonError("Object is null"); } $list = $this->production_article_refer_obj->where("p_article_id", $production_info['p_article_id'])->where('state', 0)->order("index")->select(); $re["refers"] = $list; return jsonSuccess($re); } /**清空引用文献 * @return \think\response\Json * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function discardRefers() { $data = $this->request->post(); $rule = new Validate([ "article_id" => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $production_info = $this->production_article_obj->where('article_id', $data['article_id'])->find(); $this->production_article_refer_obj->where('p_article_id', $production_info['p_article_id'])->update(['state' => 1]); return jsonSuccess([]); } /**清空引用文献byp_article_id * @return void */ public function discardRefersByParticleid(){ $data = $this->request->post(); $rule = new Validate([ "p_article_id"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $this->production_article_refer_obj->where('p_article_id',$data['p_article_id'])->update(["state"=>1]); return jsonSuccess([]); } /**添加refer * @return \think\response\Json * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function addRefer() { $data = $this->request->post(); $rule = new Validate([ "article_id" => "require", "pre_p_refer_id" => "require", "refer_type"=>"require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $p_info = $this->production_article_obj->where('article_id', $data['article_id'])->where('state', 0)->find(); $pre_refer = $this->production_article_refer_obj->where('p_refer_id', $data['pre_p_refer_id'])->find(); $insert['p_article_id'] = $p_info['p_article_id']; $insert['index'] = $pre_refer['index'] + 1; $insert['ctime'] = time(); $insert['is_change'] = 1; $insert['refer_type'] = $data['refer_type']; if($data['refer_type']=="journal"){ $insert['refer_doi'] = isset($data['doi'])?$data['doi']:''; $insert['author'] = trim($data['author']); $insert['title'] = trim($data['title']); $insert['joura'] = trim($data['joura']); $insert['dateno'] = $data['dateno']; $insert['doilink'] = $data['doilink']; $insert['cs'] = 1; $insert['is_ja'] = 1; }elseif($data['refer_type']=="book"){ $insert['author'] = trim($data['author']); $insert['title'] = trim($data['title']); $insert['dateno'] = $data['dateno']; $insert['isbn'] = $data['isbn']; $insert['cs'] = 1; $insert['is_ja'] = 1; }else{ $insert['cs'] = 0; $insert['refer_frag'] = trim($data['content']); } $adId= $this->production_article_refer_obj->insertGetId($insert); $this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->where("p_refer_id", "<>", $adId)->where("index", ">", $pre_refer['index'])->where('state', 0)->setInc('index'); return jsonSuccess([]); // $adId = $this->production_article_refer_obj->insertGetId($insert); // my_doiToFrag2($this->production_article_refer_obj->where('p_refer_id', $adId)->find()); // //判断是否合法 // $check = $this->production_article_refer_obj->where('p_refer_id', $adId)->find(); // if ($check['author']) {//合法 // $this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->where("p_refer_id", "<>", $adId)->where("index", ">", $pre_refer['index'])->where('state', 0)->setInc('index'); // return jsonSuccess([]); // } else {//非法 // $this->production_article_refer_obj->where('p_refer_id', $adId)->update(['state' => 1]); // return jsonError("Doi error"); // } } public function addReferByParticleid(){ $data = $this->request->post(); $rule = new Validate([ "p_article_id" => "require", "pre_p_refer_id" => "require", "refer_type"=>"require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $p_info = $this->production_article_obj->where('p_article_id', $data['p_article_id'])->find(); $pre_refer = $this->production_article_refer_obj->where('p_refer_id', $data['pre_p_refer_id'])->find(); $insert['p_article_id'] = $p_info['p_article_id']; $insert['index'] = $pre_refer['index'] + 1; $insert['ctime'] = time(); $insert['is_change'] = 1; $insert['refer_type'] = $data['refer_type']; if($data['refer_type']=="journal"){ $insert['refer_doi'] = isset($data['doi'])?$data['doi']:''; $insert['author'] = trim($data['author']); $insert['title'] = trim($data['title']); $insert['joura'] = trim($data['joura']); $insert['dateno'] = $data['dateno']; $insert['doilink'] = $data['doilink']; $insert['cs'] = 1; $insert['is_ja'] = 1; }elseif($data['refer_type']=="book"){ $insert['author'] = trim($data['author']); $insert['title'] = trim($data['title']); $insert['dateno'] = $data['dateno']; $insert['isbn'] = $data['isbn']; $insert['cs'] = 1; $insert['is_ja'] = 1; }else{ $insert['cs'] = 0; $insert['refer_frag'] = trim($data['content']); } $adId= $this->production_article_refer_obj->insertGetId($insert); $this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->where("p_refer_id", "<>", $adId)->where("index", ">", $pre_refer['index'])->where('state', 0)->setInc('index'); return jsonSuccess([]); } /**非doi形式添加refer节点 * @return void */ public function addReferNotdoi() { $data = $this->request->post(); $rule = new Validate([ "article_id" => "require", "pre_p_refer_id" => "require", "author" => "require", "title" => "require", "joura" => "require", "dateno" => "require", "doilink" => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $p_info = $this->production_article_obj->where('article_id', $data['article_id'])->where('state', 0)->find(); $pre_refer = $this->production_article_refer_obj->where('p_refer_id', $data['pre_p_refer_id'])->find(); $insert['p_article_id'] = $p_info['p_article_id']; $insert['index'] = $pre_refer['index'] + 1; $insert['author'] = trim($data['author']); $insert['title'] = trim($data['title']); $insert['joura'] = trim($data['joura']); $insert['dateno'] = trim($data['dateno']); $insert['doilink'] = trim($data['doilink']); $insert['refer_doi'] = trim($data['doilink']); $insert['is_web'] = 1; $insert['cs'] = 1; $adId = $this->production_article_refer_obj->insertGetId($insert); $this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->where("p_refer_id", "<>", $adId)->where("index", ">", $pre_refer['index'])->where('state', 0)->setInc('index'); return jsonSuccess([]); } public function editReferNotdoi() { $data = $this->request->post(); $rule = new Validate([ "p_refer_id" => "require", "author" => "require", "title" => "require", "joura" => "require", "dateno" => "require", "doilink" => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $update['author'] = trim($data['author']); $update['title'] = trim($data['title']); $update['joura'] = trim($data['joura']); $update['dateno'] = trim($data['dateno']); $update['doilink'] = trim($data['doilink']); $update['refer_doi'] = trim($data['doilink']); $this->production_article_refer_obj->where('p_refer_id', $data['p_refer_id'])->update($update); return jsonSuccess([]); } // public function aaa(){ // $list = $this->production_article_refer_obj->where('p_article_id',423)->where('state',0)->where('index',">",0)->setInc('index'); // dump($list); // } /**删除refer * @return \think\response\Json * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function delRefer() { $data = $this->request->post(); $rule = new Validate([ "p_refer_id" => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $this->delOneRefer($data['p_refer_id']); return jsonSuccess([]); } public function delRefers(){ $data = $this->request->post(); $rule = new Validate([ "ids" => "require|array" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } foreach ($data['ids'] as $v){ $this->delOneRefer($v); } return jsonSuccess([]); } public function positioningImage(){ $data = $this->request->post(); $rule = new Validate([ "am_id"=>"require", "ami_id"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find(); $ami_info = $this->article_main_image_obj->where("ami_id",$data['ami_id'])->find(); $check = $this->article_main_obj->where("article_id",$am_info['article_id'])->where("ami_id",$data['ami_id'])->whereIn("state",[0,2])->find(); if($check){ return jsonError("Repeat operation"); } $sort_check = $this->article_main_obj->where("article_id",$am_info['article_id'])->whereIn("state",[0,2])->where("sort",$am_info['sort']+1)->find(); if($sort_check){ $this->article_main_obj->where("article_id",$am_info['article_id'])->whereIn("state",[0,2])->where("sort",">",$am_info['sort'])->inc("sort",1)->update(); } $insert['article_id'] = $am_info['article_id']; $insert['type'] = 1; $insert['content'] = ""; $insert['ami_id'] = $data['ami_id']; $insert['sort'] = $am_info['sort']+1; $insert['ctime'] = time(); $this->article_main_obj->insert($insert); return jsonSuccess([]); } public function removeImage(){ $data = $this->request->post(); $rule = new Validate([ "am_id"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find(); if($am_info['type']!=1){ return jsonError("error"); } $this->article_main_obj->where("am_id",$data['am_id'])->update(['state'=>1]); return jsonSuccess([]); } public function removeTable(){ $data = $this->request->post(); $rule = new Validate([ "am_id"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find(); if($am_info['type']!=2){ return jsonError("error"); } $this->article_main_obj->where("am_id",$data['am_id'])->update(['state'=>1]); return jsonSuccess([]); } public function positioningTable(){ $data = $this->request->post(); $rule = new Validate([ "am_id" => "require", "amt_id" => "require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find(); $amt_info = $this->article_main_table_obj->where("amt_id",$data['amt_id'])->find(); $check = $this->article_main_obj->where("article_id",$am_info['article_id'])->where("amt_id",$data['amt_id'])->whereIn('state',[0,2])->find(); if($check){ return jsonError("Repeat operation"); } $sort_check = $this->article_main_obj->where("article_id",$amt_info['article_id'])->whereIn("state",[0,2])->where("sort",$am_info['sort']+1)->find(); if ($sort_check){ $this->article_main_obj->where("article_id",$am_info['article_id'])->whereIn("state",[0,2])->where('sort',">",$am_info['sort'])->inc("sort",1)->update(); } $insert['article_id'] = $am_info['article_id']; $insert['type'] = 2; $insert['amt_id'] = $data['amt_id']; $insert["content"] = ""; $insert['sort'] = $am_info['sort']+1; $insert['ctime'] = time(); $this->article_main_obj->insert($insert); return jsonSuccess([]); } /**编辑refer * @return \think\response\Json * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function editRefer() { $data = $this->request->post(); $rule = new Validate([ "p_refer_id" => "require", "refer_type" => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $old_refer_info = $this->production_article_refer_obj->where('p_refer_id',$data['p_refer_id'])->find(); $updata['refer_type'] = $data['refer_type']; $updata['is_change'] = 1; if($data['refer_type']=="journal"){ $updata['refer_doi'] = isset($data['doi'])?$data['doi']:''; $updata['author'] = trim($data['author']); $updata['title'] = trim($data['title']); $updata['joura'] = trim($data['joura']); $updata['dateno'] = $data['dateno']; $updata['doilink'] = $data['doilink']; $updata['cs'] = 1; $updata['is_ja'] = 1; }elseif($data['refer_type']=="book"){ $updata['author'] = trim($data['author']); $updata['title'] = trim($data['title']); $updata['dateno'] = $data['dateno']; $updata['isbn'] = $data['isbn']; $updata['cs'] = 1; $updata['is_ja'] = 1; }else{ $updata['cs'] = 0; $updata['refer_frag'] = trim($data['content']); } $this->production_article_refer_obj->where('p_refer_id',$data['p_refer_id'])->update($updata); // $doi = trim($data['doi']); // $url = "https://citation.crosscite.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US"; // $res = myGet($url); // $frag = trim(substr($res, strpos($res, '.') + 1)); // if ($frag == "") { // return jsonError("doi error"); // } // $this->production_article_refer_obj->where('p_refer_id', $data['p_refer_id'])->update(['refer_doi' => $data['doi']]); // my_doiToFrag2($this->production_article_refer_obj->where('p_refer_id', $data['p_refer_id'])->find()); return jsonSuccess([]); } public function addMainsRemark(){ $data = $this->request->post(); $rule = new Validate([ "am_id"=>"require", "remark"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $update['remark'] = trim($data['remark']); $update['state'] = 2; $this->article_main_obj->where("am_id",$data['am_id'])->update($update); return jsonSuccess([]); } public function searchDoi() { $data = $this->request->post(); $rule = new Validate([ "doi" => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $doi = str_replace('/', '%2F', $data['doi']); $url = "https://citation.crosscite.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US"; $res = myGet($url); $frag = trim(substr($res, strpos($res, '.') + 1)); if ($frag == "") { return jsonError("not find"); } if (mb_substr_count($frag, '.') != 3) { return jsonError("formate fail"); } $res = explode('.', $frag); $f['author'] = prgeAuthor($res[0]); $f['title'] = trim($res[1]); $bj = bekjournal($res[2]); $joura = formateJournal(trim($bj[0])); $f['joura'] = $joura; $f['dateno'] = str_replace(' ', '', str_replace('-', '–', trim($bj[1]))); $f['doilink'] = strpos($data['doi'], "http") === false ? "http://doi.org/" . $data['doi'] : $data['doi']; $re['formate'] = $f; return jsonSuccess($re); } public function mytt(){ $ss[] = "this id test this id 3test 55this id test this id test this id test this id test"; $ss[] = "this id test this id 3test 55this id test this id test this id test this id test"; $ss[] = ""; $ss[] = "this id test this id 3test 55this id test this id test this id test this id test"; $ss[] = "this id test this id 3test 55this id test this id test this id test this id test"; $re['detail'] = json_encode($ss); return jsonSuccess($re); } public function getArticleMains(){ $data = $this->request->post(); $rule = new Validate([ "article_id"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $mains = $this->article_main_obj->where("article_id",$data['article_id'])->whereIn("state",[0,2])->order("sort asc")->select(); if(!$mains){ $this->addArticleMainEx($data['article_id']); } $mains = $this->article_main_obj->where("article_id",$data['article_id'])->whereIn("state",[0,2])->order("sort asc")->select(); if(!$mains){ return jsonError("error"); } foreach ($mains as $k=>$main) { if($main['type']==0){ continue; }elseif($main['type']==1){ $c_d = $this->article_main_image_obj->where("ami_id",$main['ami_id'])->find(); $mains[$k]['image'] = $c_d; }else{ $c_d_t = $this->article_main_table_obj->where("amt_id",$main['amt_id'])->find(); $mains[$k]['table'] = $c_d_t; } } $re['list'] = $mains; return jsonSuccess($re); } public function getMainImages(){ $data = $this->request->post(); $rule = new Validate([ "article_id"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $list = $this->article_main_image_obj ->field("*,if((select am_id from t_article_main where ami_id = t_article_main_image.ami_id and state <>1)>0 ,1,0) as has_selected") ->where("t_article_main_image.article_id",$data['article_id']) ->where("t_article_main_image.state",0) ->select(); $re['list'] = $list; return jsonSuccess($re); } public function getNotes(){ $data = $this->request->post(); $rule = new Validate([ "article_id"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $list = $this->article_main_obj->where("article_id",$data['article_id'])->where("state",2)->select(); $re['list'] = $list; return jsonSuccess($re); } public function getMainTables(){ $data = $this->request->post(); $rule = new Validate([ "article_id"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $list = $this->article_main_table_obj ->field("*,if((select am_id from t_article_main where amt_id = t_article_main_table.amt_id and state <>1)>0 ,1,0) as has_selected") ->where("t_article_main_table.article_id",$data['article_id']) ->where("t_article_main_table.state",0) ->select(); $re['list'] = $list; return jsonSuccess($re); } public function delArticleMains(){ $data = $this->request->post(); $rule = new Validate([ "am_id"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $this->article_main_obj->where("am_id",$data['am_id'])->update(['state'=>1]); return jsonSuccess([]); } public function editArticleMainsForAuthor(){ $data = $this->request->post(); $rule = new Validate([ "am_id"=>"require", "content"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $update['content'] = $this->replaceChinesePunctuation($this->removeExtraSpaces(trim($data['content']))); $update['state'] = 0; $this->article_main_obj->where("am_id",$data['am_id'])->update($update); return jsonSuccess([]); } public function getArticleMainsRecycle(){ $data = $this->request->post(); $rule = new Validate([ "article_id"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $list = $this->article_main_obj->where("article_id",$data['article_id'])->where("type",0)->where("state",1)->select(); $re['list'] = $list; return jsonSuccess($re); } public function addMainImage(){ $data = $this->request->post(); $rule = new Validate([ "article_id"=>"require", "url"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $insert['article_id'] = $data['article_id']; $insert['url'] = $data['url']; if(isset($data['note'])){ $insert['note'] = $data['note']; } $insert['ctime'] = time(); $this->article_main_image_obj->insert($insert); $re['url'] = $data['url']; return jsonSuccess($re); } public function editMainImage(){ $data = $this->request->post(); $rule = new Validate([ "ami_id"=>"require", "url"=>"require", "note"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $update['url'] = $data['url']; $update['note'] = $data['note']; $this->article_main_image_obj->where("ami_id",$data['ami_id'])->update($update); return jsonSuccess([]); } public function addMainTable(){ $data = $this->request->post(); $rule = new Validate([ "article_id"=>"require", "table_data"=>"require", "title"=>"require", ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $insert['article_id'] = $data['article_id']; $insert['type'] = 0; $insert['table_data'] = $data['table_data']; if(isset($data['html_data'])){ $insert['html_data'] = $data['html_data']; } $insert['title']=$data['title']; if(isset($data['note'])){ $insert['note'] = $data['note']; } $insert['ctime'] = time(); $this->article_main_table_obj->insert($insert); return jsonSuccess([]); } public function editMainTable(){ $data = $this->request->post(); $rule = new Validate([ "amt_id"=>"require", "table_data"=>"require", "html_data"=>"require", "title"=>"require", "note"=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $update['table_data'] = $data['table_data']; $update['html_data'] = $data['html_data']; $update['title'] = $data['title']; $update['note'] = $data['note']; $this->article_main_table_obj->where("amt_id",$data['amt_id'])->update($update); return jsonSuccess([]); } public function up_img_mainImage(){ $article_id = input('post.article_id'); $file = request()->file('mainImage'); // 检查文件是否有效 if (!$file) { return jsonError("error"); } // 定义上传目录 $uploadDir = ROOT_PATH . 'public' . DS . "articleImage".DS.$article_id; $extension = pathinfo($file->getInfo("name"),PATHINFO_EXTENSION); // 生成自定义文件名,使用 uniqid 生成唯一的文件名 $fileName = uniqid('file_') . '.' .$extension; // 移动文件到指定目录,并重命名 $info = $file->move($uploadDir, $fileName); // 检查文件是否上传成功 if ($info) { $ff = ''; if($extension=="tif"||$extension=="tiff"){ $ff = $this->crossTifToPng($article_id."/".$fileName); }else{ $ff = $article_id."/".$fileName; } $re['upurl'] = $ff; return jsonSuccess($re); } else { return jsonError("error"); } } public function replyArticleRecycle(){ $data = $this->request->post(); $rule = new Validate([ 'am_id'=>"require" ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $info = $this->article_main_obj->where("am_id",$data['am_id'])->find(); $check = $this->article_main_obj->where("article_id",$info['article_id'])->where("sort",$info['sort'])->whereIn("state",[0,2])->find(); if($check){ $this->article_main_obj->where("article_id",$info['article_id'])->where("sort",">=",$info['sort'])->inc('sort',1)->update(); } $this->article_main_obj->where("am_id",$data['am_id'])->update(['state'=>0]); return jsonSuccess([]); } /**调整refer排序 * @return \think\response\Json * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function sortRefer() { $data = $this->request->post(); $rule = new Validate([ "p_refer_id" => "require", "act" => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $refer_info = $this->production_article_refer_obj->where('p_refer_id', $data['p_refer_id'])->find(); if ($data['act'] == "up") { $up_info = $this->production_article_refer_obj->where('p_article_id', $refer_info['p_article_id'])->where('index', $refer_info['index'] - 1)->where('state', 0)->find(); if (!$up_info) { return jsonError("system error"); } $this->production_article_refer_obj->where('p_refer_id', $up_info['p_refer_id'])->setInc("index"); $this->production_article_refer_obj->where('p_refer_id', $refer_info['p_refer_id'])->setDec("index"); } else { $down_info = $this->production_article_refer_obj->where('p_article_id', $refer_info['p_article_id'])->where('index', $refer_info['index'] + 1)->where('state', 0)->find(); if (!$down_info) { return jsonError("system error"); } $this->production_article_refer_obj->where('p_refer_id', $refer_info['p_refer_id'])->setInc("index"); $this->production_article_refer_obj->where('p_refer_id', $down_info['p_refer_id'])->setDec("index"); } return jsonSuccess([]); } // public function getArticleMains(){ // $data = $this->request->post(); // $rule = new Validate([ // "article_id"=>"require" // ]); // if(!$rule->check($data)){ // return jsonError($rule->getError()); // } // $article_info = $this->article_obj->where("article_id",$data['article_id'])->find(); // $product_info = $this->production_article_obj->where("article_id".$data['article_id'])->find(); // // // // } public function addRefersByExcel() { $data = $this->request->post(); $rule = new Validate([ "article_id" => "require", "referFile" => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $production_info = $this->production_article_obj->where('article_id', $data['article_id'])->where("state", 0)->find(); if (!$production_info) { return jsonError("Object is null"); } $file = ROOT_PATH . 'public' . DS . "referFile" . DS . $data['referFile']; $list = $this->readRefersExcel($file); foreach ($list as $k => $v) { $ca['p_article_id'] = $production_info['p_article_id']; $ca['refer_content'] = $v['content']; $ca['refer_doi'] = $v['doi']; $ca['index'] = $k; $ca['ctime'] = time(); $adId = $this->production_article_refer_obj->insertGetId($ca); my_doiToFrag2($this->production_article_refer_obj->where('p_refer_id', $adId)->find()); } return jsonSuccess([]); } /**读取excel文件获取refer列表 * @param $afile * @return array * @throws \PHPExcel_Exception * @throws \PHPExcel_Reader_Exception */ public function readRefersExcel($afile) { $extension = substr($afile, strrpos($afile, '.') + 1); vendor("PHPExcel.PHPExcel"); if ($extension == 'xlsx') { $objReader = new \PHPExcel_Reader_Excel2007(); $objPHPExcel = $objReader->load($afile); } else if ($extension == 'xls') { $objReader = new \PHPExcel_Reader_Excel5(); $objPHPExcel = $objReader->load($afile); } $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $frag = []; for ($i = 2; $i <= $highestRow; $i++) { if ($objPHPExcel->getActiveSheet()->getCell("A" . $i)->getValue() == '') { continue; } $aa['content'] = $objPHPExcel->getActiveSheet()->getCell("A" . $i)->getValue(); $aa['doi'] = $objPHPExcel->getActiveSheet()->getCell("B" . $i)->getValue(); $frag[] = $aa; } return $frag; } /**上传引用文献文件,并返回读取到的内容 * @return \think\response\Json|void */ public function up_refer_file() { $file = request()->file("referFile"); if ($file) { $info = $file->move(ROOT_PATH . 'public' . DS . "referFile"); if ($info) { $file = ROOT_PATH . 'public' . DS . "referFile" . DS . str_replace("\\", "/", $info->getSaveName()); $re["refers"] = $this->readRefersExcel($file); $re["upurl"] = str_replace("\\", "/", $info->getSaveName()); $re['code'] = 0; return json($re); } else { return json(['code' => 1, 'msg' => $file->getError()]); } } } }