diff --git a/application/api/controller/Article.php b/application/api/controller/Article.php index 4727073..25f6651 100644 --- a/application/api/controller/Article.php +++ b/application/api/controller/Article.php @@ -1230,6 +1230,7 @@ class Article extends Base $list = $this->article_obj->where('state',3)->page($data['pageIndex'],$data['pageSize'])->order('article_id desc')->select(); foreach ($list as $key => $val){ $list[$key]['author'] = $this->article_author_obj->where('article_id', $val['article_id'])->where('state', 0)->select(); + $list[$key]['user'] = $this->user_obj->where('user_id',$val['user_id'])->find(); } $count = $this->article_obj->where('state',3)->count(); $re['articles'] = $list; diff --git a/application/api/controller/Preaccept.php b/application/api/controller/Preaccept.php index fac5f16..dfd5dad 100644 --- a/application/api/controller/Preaccept.php +++ b/application/api/controller/Preaccept.php @@ -2,7 +2,140 @@ namespace app\api\controller; -class Preaccept +use think\Db; +use think\Queue; +use think\Validate; + +class Preaccept extends Base { + public function __construct(\think\Request $request = null) + { + parent::__construct($request); + } + + + /**获取文章参考文献列表 + * @return \think\response\Json + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function getArticleReferences(){ + $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(); + 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)->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([]); + } + + 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 $v){ + $ca['p_article_id'] = $production_info['p_article_id']; + $ca['refer_content'] = $v['content']; + $ca['refer_doi'] = $v['doi']; + $ca['ctime'] = time(); + $this->production_article_refer_obj->insert($ca); + } + 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()]); + } + } + } + + } \ No newline at end of file