diff --git a/application/api/controller/Article.php b/application/api/controller/Article.php index 7b4207a..b14a9c7 100644 --- a/application/api/controller/Article.php +++ b/application/api/controller/Article.php @@ -794,12 +794,34 @@ class Article extends Base $authors = $this->article_obj->field("t_article_author.*")->join("t_article_author", "t_article_author.article_id = t_article.article_id", "left") ->where("t_article.user_id", $data['user_id'])->where("t_article_author.state", 0) ->order("t_article_author.email,t_article_author.art_aut_id")->select(); + //查询作者机构 20251031 start $cache_author = []; - foreach ($authors as $k => $v) { - if (!isset($v['email']) || $v['email'] == "") { - continue; + if(!empty($authors)){ + //查询作者机构 + $aAutId = array_column($authors, 'art_aut_id'); + $aWhere = ['art_aut_id' => ['in',$aAutId],'state' => 0]; + $aAuthorOrganId = Db::name('article_author_organ')->field('art_aut_id,organ_id')->where($aWhere)->select(); + if(!empty($aAuthorOrganId)){ + //查询机构名称 + $aOragnId = array_unique(array_column($aAuthorOrganId, 'organ_id')); + $aWhere = ['state' => 0,'organ_id' => ['in',$aOragnId]]; + $aOragn = Db::name('article_organ')->where($aWhere)->column('organ_id,organ_name'); + $aAuthorOrgan = []; + foreach ($aAuthorOrganId as $key => $value) { + if(empty($aOragn[$value['organ_id']])){ + continue; + } + $aAuthorOrgan[$value['art_aut_id']][] = ['organ_id' => $value['organ_id'],'organ_name' => $aOragn[$value['organ_id']]]; + } + } + foreach ($authors as $key => $value) { + if (empty($value['email'])) { + continue; + } + $value['organ_id'] = empty($aAuthorOrgan[$value['art_aut_id']]) ? [] : array_column($aAuthorOrgan[$value['art_aut_id']], 'organ_id'); + $value['organ_name'] = empty($aAuthorOrgan[$value['art_aut_id']]) ? [] : array_column($aAuthorOrgan[$value['art_aut_id']], 'organ_name'); + $cache_author[$value['email']][] = $value; } - $cache_author[$v['email']][] = $v; } $authors = []; foreach ($cache_author as $k => $v) { @@ -828,6 +850,8 @@ class Article extends Base $c['address'] = $value['address']; } } + $c['organ_id'] = empty($value['organ_id']) ? [] : $value['organ_id']; + $c['organ_name'] = empty($value['organ_name']) ? [] : $value['organ_name']; $authors[] = $c; } $re['authors'] = $authors; @@ -2960,7 +2984,8 @@ class Article extends Base "email" => "require", "country" => "require", "isSuper" => "require", - "isReport" => "require" + "isReport" => "require", + 'organ' => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); @@ -2978,7 +3003,68 @@ class Article extends Base $insert['company'] = isset($data['company']) ? trim($data['company']) : ""; $insert['department'] = isset($data['department']) ? trim($data['department']) : ""; $insert['address'] = isset($data['address']) ? trim($data['address']) : ""; - $this->article_author_obj->insert($insert); + //新增修改orcid chengxiaoling 20251029 start + $insert['orcid'] = isset($data['orcid']) ? trim($data['orcid']) : ""; + //新增修改orcid chengxiaoling 20251029 end + + //处理作者绑定机构 chengxiaoling 251031 start + $aOrgrnId = empty($data['organ']) ? '' : $data['organ']; + if(!empty($aOrgrnId) && is_string($aOrgrnId)){ + $aOrgrnId = explode(',', $aOrgrnId); + } + Db::startTrans(); + $iId = $this->article_author_obj->insertGetId($insert); + if(empty($iId)){ + return jsonError('Adding author failed'); + } + if(!empty($aOrgrnId)){ + //查询机构 + $aWhere = ['organ_id' => ['in',$aOrgrnId],'state' => 0]; + $aOrgan = Db::name('article_organ')->field('organ_id,article_id,organ_name')->where($aWhere)->select(); + if(!empty($aOrgan)){ + //获取最大sort值 + $aMaxSort = Db::name('article_organ')->field('max(sort) as sort')->where(['article_id' => $data['article_id']])->find(); + $iSort = empty($aMaxSort['sort']) ? 0 : $aMaxSort['sort']; + + //处理数据 + $aOrgrnIdData = $aCompanyName = []; + foreach ($aOrgan as $key => $value) { + if($value['article_id'] == $data['article_id']){ + $aOrgrnIdData[] = $value['organ_id']; + $aCompanyName[] = $value['organ_name']; + }else{ + $iSort ++; + $aAdd = ['article_id' => $data['article_id'],'organ_name' =>$value['organ_name'],'create_time' => time(),'sort' => $iSort]; + $iOrganId = DB::name('article_organ')->insertGetId($aAdd); + if(empty($iOrganId)){ + continue; + } + $aOrgrnIdData[] = $iOrganId; + $aCompanyName[] = $value['organ_name']; + } + + } + } + if(!empty($aOrgrnIdData)){ + foreach ($aOrgrnIdData as $key => $value) { + $aInsert[] = ['article_id' => $data['article_id'],'art_aut_id' => $iId,'organ_id' => $value,'create_time' => time()]; + } + } + + } + if(!empty($aInsert)){ + $result = Db::name('article_author_organ')->insertAll($aInsert); + if($result === false){ + return jsonError('Failed to add author institution'); + } + } + if(!empty($aCompanyName) && !empty($iId)){ + $aWhere = ['art_aut_id' => $iId]; + $sCompany = implode('/', array_unique($aCompanyName)); + $update_company_result = Db::name('article_author')->where($aWhere)->limit(1)->update(['company' => $sCompany]); + } + Db::commit(); + //处理作者绑定机构 chengxiaoling 251031 end return jsonSuccess([]); } @@ -2994,7 +3080,8 @@ class Article extends Base "country" => "require", "isSuper" => "require", "isReport" => "require", - "title" => "require" + "title" => "require", + 'organ' => "require" ]); if (!$rule->check($data)) { return jsonError($rule->getError()); @@ -3010,7 +3097,62 @@ class Article extends Base $insert['company'] = isset($data['company']) ? trim($data['company']) : ""; $insert['department'] = isset($data['department']) ? trim($data['department']) : ""; $insert['address'] = isset($data['address']) ? trim($data['address']) : ""; - $this->article_author_obj->where("art_aut_id", $data['art_aut_id'])->update($insert); + //新增修改orcid chengxiaoling 20251029 start + $insert['orcid'] = isset($data['orcid']) ? trim($data['orcid']) : ""; + //新增修改orcid chengxiaoling 20251029 end + + //处理作者绑定机构 chengxiaoling 251031 start + $aOrgrnId = empty($data['organ']) ? '' : $data['organ']; + if(!empty($aOrgrnId) && is_string($aOrgrnId)){ + $aOrgrnId = explode(',', $aOrgrnId); + //查询作者机构 + $aWhere = ['art_aut_id' => $data['art_aut_id'],'state' => 0]; + $aAuthorOrganId = Db::name('article_author_organ')->where($aWhere)->column('organ_id'); + //新增 + $aInsert = array_diff($aOrgrnId, $aAuthorOrganId); + //删除 + $aDelete = array_diff($aAuthorOrganId, $aOrgrnId); + } + Db::startTrans(); + if(!empty($aInsert)){ + foreach ($aInsert as $key => $value) { + $aInsertData[] = ['article_id' => $data['article_id'],'art_aut_id' => $data['art_aut_id'],'organ_id' => $value,'create_time' => time()]; + } + if(!empty($aInsertData)){ + $result = Db::name('article_author_organ')->insertAll($aInsertData); + if($result === false){ + return jsonError('Failed to add author institution'); + } + } + } + if(!empty($aDelete)){ + $aWhere = ['organ_id' => ['in',$aDelete],'state' => 0]; + $aUpdate = ['state' => 1,'update_time' => time()]; + $author_organ_result = Db::name('article_author_organ')->where($aWhere)->limit(count($aDelete))->update($aUpdate); + if($author_organ_result === false){ + return json_encode(['status' => 3,'msg' => 'Failed to unbind the relationship between the institution and the author']); + } + } + + //获取机构名称 + $aWhere = ['art_aut_id' => $data['art_aut_id'],'state' => 0]; + if(!empty($aDelete)){ + $aWhere['organ_id'] =['not in',$aDelete]; + } + $aOrganIdList = Db::name('article_author_organ')->where($aWhere)->column('organ_id'); + $insert['company'] = ''; + if(!empty($aOrganIdList)){ + $aWhere = ['organ_id' => ['in',$aOrganIdList],'state' => 0]; + $aOrganName = Db::name('article_organ')->where($aWhere)->column('organ_name'); + if(!empty($aOrganName) && !empty($data['art_aut_id'])){ + $sCompany = implode('/', array_unique($aOrganName)); + $insert['company'] = $sCompany; + } + } + + $update_company_result = $this->article_author_obj->where("art_aut_id", $data['art_aut_id'])->limit(1)->update($insert); + Db::commit(); + //处理作者绑定机构 chengxiaoling 251031 end return jsonSuccess([]); } @@ -3027,6 +3169,34 @@ class Article extends Base return jsonError($rule->getError()); } $authors = $this->article_author_obj->where("article_id", $data["article_id"])->where("state", 0)->order("sort")->select(); + //查询作者机构 20251031 start + if(!empty($authors)){ + //查询作者机构 + $aAutId = array_column($authors, 'art_aut_id'); + $aWhere = ['art_aut_id' => ['in',$aAutId],'state' => 0]; + if($aAuthorOrganId = Db::name('article_author_organ')->field('art_aut_id,organ_id')->where($aWhere)->select()){ + //查询机构名称 + $aOragnId = array_unique(array_column($aAuthorOrganId, 'organ_id')); + $aWhere = ['article_id' => $data['article_id'],'state' => 0,'organ_id' => ['in',$aOragnId]]; + $aOragn = Db::name('article_organ')->where($aWhere)->column('organ_id,organ_name'); + } + + if(!empty($aAuthorOrganId)){ + $aAuthorOrgan = []; + foreach ($aAuthorOrganId as $key => $value) { + if(empty($aOragn[$value['organ_id']])){ + continue; + } + $aAuthorOrgan[$value['art_aut_id']][] = ['organ_id' => $value['organ_id'],'organ_name' => empty($aOragn[$value['organ_id']]) ? '' : $aOragn[$value['organ_id']]]; + + } + } + foreach ($authors as $key => $value) { + $authors[$key]['organ_id'] = empty($aAuthorOrgan[$value['art_aut_id']]) ? [] : array_unique(array_column($aAuthorOrgan[$value['art_aut_id']], 'organ_id')); + $authors[$key]['organ_name'] = empty($aAuthorOrgan[$value['art_aut_id']]) ? [] : array_column($aAuthorOrgan[$value['art_aut_id']], 'organ_name'); + } + } + //查询作者机构 20251031 end $re['authors'] = $authors; return jsonSuccess($re); } @@ -3147,15 +3317,42 @@ class Article extends Base } $authors = $this->article_author_obj->where('article_id', $data['article_id'])->where('state', 0)->select(); $files = $this->article_file_obj->where('article_id', $data['article_id'])->where('state', 0)->select(); + + //推荐记录 + $aWhere = ['urr_state' => 0,'article_id' => $data['article_id']]; + $aUserRecommend = Db::name('user_reviewer_recommend')->where($aWhere)->column('reviewer_id,urr_id'); + if(!empty($aUserRecommend)){ + //获取基本信息 + $aUserId = array_keys($aUserRecommend); + $aWhere = ['user_id' => ['in',$aUserId],'state' => 0]; + $aUser = Db::name('user')->field('user_id,account,email,realname')->where($aWhere)->select(); + if(!empty($aUser)){ + $aWhere = ['reviewer_id' => ['in',$aUserId],'state' => 0]; + $aReviewer = Db::name('user_reviewer_info')->field('reviewer_id,country,major,company,department')->where($aWhere)->select(); + $aReviewer = array_column($aReviewer, null,'reviewer_id'); + foreach ($aUser as $key => $value) { + $value['country'] = empty($aReviewer[$value['user_id']]['country']) ? '' : $aReviewer[$value['user_id']]['country']; + $value['major'] = empty($aReviewer[$value['user_id']]['major']) ? '' : $aReviewer[$value['user_id']]['major']; + $value['p_major'] = ''; + if(!empty($value['major'])){ + $value['p_major'] = empty($this->getMajorShuList($value['major'])) ? '' : trim($this->getMajorShuList($value['major']),','); + } + $value['urr_id'] = empty($aUserRecommend[$value['user_id']]) ? 0 : $aUserRecommend[$value['user_id']]; + $value['company'] = empty($aReviewer[$value['user_id']]['company']) ? '' : $aReviewer[$value['user_id']]['company']; + $value['department'] = empty($aReviewer[$value['user_id']]['department']) ? '' : $aReviewer[$value['user_id']]['department']; + $aUser[$key] = $value; + } + } + } $re['base'] = $base; $re['authors'] = $authors; $re['files'] = $files; $re['major'] = $major; $re['majors'] = $majors; + $re['reviewer'] = empty($aUser) ? [] : $aUser; return jsonSuccess($re); } - public function changeJournal() { $data = $this->request->post(); @@ -3200,6 +3397,14 @@ class Article extends Base } //判断简介字符串长度是否不低于200 chengxiaoling 20250327 end + //判断伦理 + if(!empty($data['approval']) && $data['approval'] == 1 && empty($data['approval_file'])){ + return jsonError("Ethics documents not uploaded"); + } + if(isset($aArticle['approval']) && $aArticle['approval'] == 0 && empty($aArticle['approval_content'])){ + return jsonError("Please explain the lack of ethical recognition"); + } + $user_info = $this->user_obj->where('user_id', $data['user_id'])->find(); $journal_info = $this->journal_obj->where('journal_id', $data['journal'])->find(); @@ -3232,19 +3437,16 @@ class Article extends Base if (isset($data['approval']) && $data['approval'] == 1) { $inset_data['approval'] = 1; $inset_data['approval_file'] = isset($data["approval_file"]) ? $data["approval_file"] : ''; + $inset_data['approval_content'] = ''; } else { $inset_data["approval"] = 0; $inset_data['approval_content'] = isset($data["approval_content"]) ? $data["approval_content"] : ''; + $inset_data['approval_file'] = ''; } $inset_data['ctime'] = time(); $inset_data['state'] = -1; - //新增字段是否使用AI及使用说明 chengxiaoling 20250725 start - $inset_data['is_use_ai'] = empty($data['is_use_ai']) ? 2 : $data['is_use_ai']; //是否使用AI1是2否 - $inset_data['use_ai_explain'] = isset($data['use_ai_explain']) ? $data['use_ai_explain'] : ''; - //新增字段是否使用AI及使用说明 chengxiaoling 20250725 end - $article_id = $this->article_obj->insertGetId($inset_data); } else { @@ -3254,6 +3456,14 @@ class Article extends Base // return json(['code' => 1, 'msg' => 'Warning: you are re-submitting the article!']); // } // } + //查询manuscirpt文件是否上传 + $aWhere = ['article_id' => $data['article_id'],'state' => 0,'type_name' => 'manuscirpt']; + $aFile = Db::name('article_file')->where($aWhere)->order('ctime desc')->find(); + if(empty($aFile)){ + $iFirstStatus = 2; + $sFirstMsg = 'Step 1: The manuscirpt file has not been uploaded'; + } + $up['user_id'] = $user_info['user_id']; $up['journal_id'] = $data['journal']; $up['editor_id'] = $journal_info['editor_id']; @@ -3268,16 +3478,13 @@ class Article extends Base if (isset($data['approval']) && $data['approval'] == 1) { $up['approval'] = 1; $up['approval_file'] = isset($data["approval_file"]) ? $data["approval_file"] : ''; + $up['approval_content'] = ''; } else { $up["approval"] = 0; $up['approval_content'] = isset($data["approval_content"]) ? $data["approval_content"] : '';//trim($data['approval_content']); + $up['approval_file'] = ''; } - //新增字段是否使用AI及使用说明 chengxiaoling 20250725 start - $up['is_use_ai'] = empty($data['is_use_ai']) ? 2 : $data['is_use_ai']; //是否使用AI1是2否 - $up['use_ai_explain'] = isset($data['use_ai_explain']) ? $data['use_ai_explain'] : '';//使用AI说明 - //新增字段是否使用AI及使用说明 chengxiaoling 20250725 end - $this->article_obj->where('article_id', $article_id)->update($up); } //注释文章筛选领域添加修改为AI推荐领域,在第四步可以查看修改 chengxiaoling 20250722 @@ -3451,8 +3658,8 @@ class Article extends Base /** * 添加文章最终 */ - public function addArticlePart4() - { + public function addArticlePart4(){ + $data = $this->request->post(); $rule = new Validate([ 'article_id' => 'require', @@ -3461,6 +3668,20 @@ class Article extends Base if (!$rule->check($data)) { return jsonError($rule->getError()); } + + //验证文章领域 + $sMajorData = empty($data['major']) ? '' : $data['major'];//文章领域 + if(empty($sMajorData)){ + return jsonError('Please select the field of the article'); + } + //判断是否转投 + if (!isset($data['istransfer'])) { + return jsonError('Please choose to transfer to a journal'); + } + if(isset($data['istransfer']) && $data['istransfer'] == 'true' && empty($data['checkedjours'])){ + return jsonError('Please choose whether to transfer or not'); + } + $article_info = $this->article_obj->where('article_id', $data['article_id'])->find(); $journal_info = $this->journal_obj->where('journal_id', $article_info['journal_id'])->find(); $user_res = $this->user_obj->where('user_id', $article_info['user_id'])->find(); @@ -3595,11 +3816,26 @@ class Article extends Base if (isset($data['code']) && $data['code'] != '') { $update_l['code'] = trim($data['code']); } + + //新增保存字段 chengxiaoling 20251031 start + if (isset($data['istransfer']) && $data['istransfer'] == true) { + $update_l['is_transfer'] = 1; + } + if (isset($data['istransfer']) && $data['istransfer'] == false) { + $update_l['is_transfer'] = 0; + } + if (isset($data['is_become_reviewer'])) { + $update_l['is_become_reviewer'] = $data['is_become_reviewer']; + } + if (isset($data['is_agree'])) { + $update_l['is_agree'] = $data['is_agree']; + } + //新增保存字段 chengxiaoling 20251031 end + $this->article_obj->where('article_id', $data['article_id'])->update($update_l); $this->ai_scor($data['article_id']); //判断是否有文章领域 进行更新操作 chengxiaoling 20250722 start - $sMajorData = empty($data['article_field']) ? '' : $data['article_field'];//文章领域 $iArticleId = empty($data['article_id']) ? 0 : $data['article_id'];//文章ID if(!empty($sMajorData) && !empty($iArticleId)){ $this->updateArticleField(['article_id' => $iArticleId,'article_field' => $sMajorData]); @@ -3614,10 +3850,10 @@ class Article extends Base return json(['code' => 0]); } - // public function ffff(){ - // $data = $this->request->post(); - // $this->ai_scor($data['article_id']); - // } + public function ffff(){ + $data = $this->request->post(); + $this->ai_scor($data['article_id']); + } /** @@ -4087,9 +4323,11 @@ class Article extends Base $uri = $this->user_reviewer_info_obj->where('reviewer_id', $reviewer_info['user_id'])->where('state', 0)->find(); if ($uri == null) { //添加审稿人信息 $insert_reviewer_info['reviewer_id'] = $reviewer_info['user_id']; - $insert_reviewer_info['major'] = $reivewe['major']; + $insert_reviewer_info['major'] = empty($reivewe['major']) ? '' : $reivewe['major']; // $insert_reviewer_info['cmajor'] = $reivewe['cmajor']; - $insert_reviewer_info['country'] = $reivewe['country']; + $insert_reviewer_info['country'] = empty($reivewe['country']) ? '' : $reivewe['country']; + $insert_reviewer_info['company'] = empty($reivewe['company']) ? '' : $reivewe['company']; + $insert_reviewer_info['department'] = empty($reivewe['department']) ? '' : $reivewe['department']; $insert_reviewer_info['test_from'] = "addRecommentReviewer"; $res2 = $this->user_reviewer_info_obj->insert($insert_reviewer_info); } @@ -4102,12 +4340,16 @@ class Article extends Base } //添加推荐审稿人信息 - $insert_recommend['reviewer_id'] = $reviewer_info['user_id']; - $insert_recommend['article_id'] = $article_id; - $insert_recommend['recommend_user_id'] = $user_id; - $insert_recommend['urr_ctime'] = time(); - $res_recommend = $this->user_reviewer_recommend_obj->insert($insert_recommend); - + $aWhere = ['urr_state' => 0,'article_id' => $article_id,'reviewer_id' => $reviewer_info['user_id']]; + $aUserRecommend = Db::name('user_reviewer_recommend')->where($aWhere)->count(); + $res_recommend = true; + if(empty($aUserRecommend)){ + $insert_recommend['reviewer_id'] = $reviewer_info['user_id']; + $insert_recommend['article_id'] = $article_id; + $insert_recommend['recommend_user_id'] = $user_id; + $insert_recommend['urr_ctime'] = time(); + $res_recommend = $this->user_reviewer_recommend_obj->insert($insert_recommend); + } if ($res2 && $res3 && $res_recommend) { return true; } else { @@ -4298,6 +4540,19 @@ class Article extends Base } $where['state'] = 0; $list = $this->journal_obj->where($where)->select(); + + //获取期刊封面 chengxiaoling 20251027 start + if(!empty($list)){ + $aParam = ['issn' => array_column($list, 'issn')]; + $sUrl = 'http://journalapi.tmrjournals.com/public/index.php/'; + $sUrl = $sUrl."api/Supplementary/getJournal"; + $aResult = object_to_array(json_decode(myPost1($sUrl,$aParam),true)); + $aResult = empty($aResult['data']) ? [] : array_column($aResult['data'], 'icon','issn'); + foreach ($list as $key => $value) { + $list[$key]['journal_icon'] = empty($aResult[$value['issn']]) ? '' : $aResult[$value['issn']]; + } + } + //获取期刊封面 chengxiaoling 20251027 end return json($list); } @@ -4982,4 +5237,734 @@ class Article extends Base return ['status' => $iIsSuccess,'msg' => $sMsg]; } + + /** + * 添加文章文件信息 + * @param article_id + * @param + */ + public function addArticlePart3($aParam = []){ + //获取参数 + $aParam = empty($aParam) ? $this->request->post() : $aParam; + + //必填值验证 + $iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id']; + if(empty($iArticleId)){ + return json_encode(['status' => 2,'msg' => 'Please select an article']); + } + //用户ID + $iUserId = empty($aParam['user_id']) ? '' : $aParam['user_id']; + if(empty($iUserId)){ + return json_encode(['status' => 2,'msg' => 'Please select author']); + } + //获取文章信息 + $aArticle = $this->getArticleInfo($aParam); + $iStatus = empty($aArticle['status']) ? 0 : $aArticle['status']; + if($iStatus != 1){ + return json_encode($aArticle); + } + $aArticle = empty($aArticle['data']) ? [] : $aArticle['data']; + + //是否使用AI + $iIsUserAi = empty($aParam['is_use_ai']) ? 3 : $aParam['is_use_ai']; //是否使用AI1是2否 + if($iIsUserAi == 3){ + return json_encode(['status' => 5,'msg' => 'Please check whether to use AI technology']); + } + $sUseAiExplain = empty($aParam['use_ai_explain']) ? '' : $aParam['use_ai_explain']; + if($iIsUserAi == 1 && empty($sUseAiExplain)){ + return json_encode(['status' => 6,'msg' => 'Please enter supplementary instructions']); + } + //是否上传图片版权声明1是2否 + $iIsFigureCopyright = empty($aParam['is_figure_copyright']) ? 3 : $aParam['is_figure_copyright']; + if($iIsFigureCopyright == 3){ + return json_encode(['status' => 7,'msg' => 'Please check whether to upload the figure copyright statement']); + } + $aWhere = ['article_id' => $iArticleId,'state' => 0,'type_name' => 'figurecopyright']; + $aFileId = Db::name('article_file')->where($aWhere)->column('file_id'); + if($iIsFigureCopyright == 1){//是 + if(empty($aFileId)){ + return json_encode(['status' => 8,'msg' =>'Please upload the figure copyright declaration file']); + } + } + + Db::startTrans(); + if($iIsFigureCopyright == 2 && !empty($aFileId)){ + $aWhere = ['article_id' => $iArticleId,'file_id' => ['in',$aFileId],'state' => 0,'type_name' => 'figurecopyright']; + $file_result = Db::name('article_file')->where($aWhere)->limit(count($aFileId))->update(['state' => 1]); + if($file_result === false){ + return json_encode(['status' => 9,'msg' =>'figure copyright declaration File deletion failed']); + } + } + $aUpdate = ['is_use_ai' => $iIsUserAi,'use_ai_explain' => $sUseAiExplain,'is_figure_copyright' => $iIsFigureCopyright]; + //更新文章内容 + $aWhere = ['article_id' => $iArticleId,'state' => ['in',[-1,3]]]; + $result = Db::name('article')->where($aWhere)->limit(1)->update($aUpdate); + if($result === false){ + return json_encode(['status' => 10,'msg' =>'Failed to save article content']); + } + Db::commit(); + + return json_encode(['status' => 1,'msg' =>'The content of the article has been successfully saved']); + } + + /** + * 按步骤获取文章的状态 + */ + public function getArticleState(){ + + //获取参数 + $aParam = empty($aParam) ? $this->request->post() : $aParam; + + //获取文章ID + $iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id']; + if(empty($iArticleId)){ + return json_encode(['status' => 2,'msg' => 'Please select the article']); + } + //用户ID + $iUserId = empty($aParam['user_id']) ? '' : $aParam['user_id']; + if(empty($iUserId)){ + return json_encode(['status' => 2,'msg' => 'Please select author']); + } + //获取文章信息 + $aArticle = $this->getArticleInfo($aParam); + $iStatus = empty($aArticle['status']) ? 0 : $aArticle['status']; + if($iStatus != 1){ + return json_encode($aArticle); + } + $aArticle = empty($aArticle['data']) ? [] : $aArticle['data']; + + //定义返回内容 + $aData = ['first' => 2,'second' => 2,'three' => 2,'four' => 2]; + //第一步验证 + $aFirst = ['title','type','abstrart','journal_id']; + $iFirstStatus = 1; + $sFirstMsg = $sSecondMsg = $sThreeMsg = $sFourMsg = ''; + foreach ($aFirst as $key => $value) { + if(empty($aArticle[$value])){ + $iFirstStatus = 2; + $sFirstMsg = 'Step 1: Required fields incomplete'; + break; + } + } + + //判断伦理 + if(!empty($aArticle['approval']) && $aArticle['approval'] == 1 && empty($aArticle['approval_file'])){ + $iFirstStatus = 2; + $sFirstMsg = 'Step 1: Ethics documents not uploaded'; + } + if(isset($aArticle['approval']) && $aArticle['approval'] == 0 && empty($aArticle['approval_content'])){ + $iFirstStatus = 2; + $sFirstMsg = 'Step 1: Please explain the lack of ethical recognition'; + } + + //查询manuscirpt文件是否上传 + if($iFirstStatus == 1){ + $aWhere = ['article_id' => $iArticleId,'state' => 0,'type_name' => 'manuscirpt']; + $aFile = Db::name('article_file')->where($aWhere)->order('ctime desc')->find(); + if(empty($aFile)){ + $iFirstStatus = 2; + $sFirstMsg = 'Step 1: The manuscirpt file has not been uploaded'; + } + } + + //第二步 查询作者 + $iSecondStatus = 1; + $is_super = $is_report = 2; + // if($iFirstStatus == 1){ + $aWhere = ['article_id' => $iArticleId,'state' => 0]; + $aAuthorData = DB::name('article_author')->where($aWhere)->select(); + if(empty($aAuthorData)){ + $iSecondStatus = 2; + } + if(!empty($aAuthorData)){ + foreach ($aAuthorData as $key => $value) { + if(empty($value['email']) || empty($value['author_title']) || empty($value['company']) || empty($value['firstname'])){ + $iSecondStatus = 2; + break; + } + if($value['is_report'] == 1){ + if(empty($value['address'])){ + $is_report = 2; + break; + }else{ + $is_report = 1; + } + } + if($value['is_super'] == 1){ + $is_super = 1; + } + } + + } + // } + if($iSecondStatus == 2){ + $sSecondMsg = 'Step 2: The author\'s required information is incomplete'; + } + if($iSecondStatus == 1){ + if($is_super == 2){ + $sSecondMsg = 'Step 2: Please select the first author'; + $iSecondStatus = 2; + } + if($is_report == 2){ + $sSecondMsg = empty($sSecondMsg) ? 'Step 2: Please select the first author' : 'Step 2: Please select the corresponding/first author'; + $iSecondStatus = 2; + } + } + + //第三步 + $iThreeStatus = 1; + $sThreeMsg = ''; + // if($iSecondStatus == 1){ + if($aArticle['is_use_ai'] == 3){//验证是否使用AI + $sThreeMsg = 'Step 3: Please check whether to use AI technology'; + $iThreeStatus = 2; + } + if($aArticle['is_use_ai'] == 1 && empty($aArticle['use_ai_explain'])){//验证是否填写AI说明 + $sThreeMsg = 'Step 3: Please enter supplementary instructions'; + $iThreeStatus = 2; + } + if($aArticle['is_figure_copyright'] == 3){//验证是否上传版权声明 + $sThreeMsg = 'Step 3: Please check whether to upload the figure copyright statement'; + $iThreeStatus = 2; + } + if($aArticle['is_figure_copyright'] == 1){//验证是否上传版权声明 + $aWhere = ['article_id' => $iArticleId,'state' => 0,'type_name' => 'figurecopyright']; + $aFile = Db::name('article_file')->where($aWhere)->order('ctime desc')->find(); + if(empty($aFile)){ + $sThreeMsg = 'Step 3: Please upload the figure copyright declaration file'; + $iThreeStatus = 2; + + } + } + // } + //第四步 + $iFourStatus = 1; + $sFourMsg = ''; + // if($iThreeStatus == 1){ + if($aArticle['is_transfer'] == 3){//是否转投 + $sFourMsg = 'Step 4: Please choose whether to transfer or not'; + $iFourStatus = 2; + } + + if($iFourStatus == 1 && $aArticle['is_transfer'] == 1){//查询转投期刊 + $aWhere = ['state' => 0, 'article_id' => $iArticleId]; + $iCount = Db::name('article_transfer')->where($aWhere)->count(); + if(empty($iCount)){ + $sFourMsg = 'Step 4: Please choose to transfer to a journal'; + $iFourStatus = 2; + } + } + //查询文章领域 + if($iFourStatus == 1){ + $aWhere = ['article_id' => $iArticleId,'state' => 0]; + $aMajor = DB::name('major_to_article')->where($aWhere)->select(); + if(empty($aMajor)){ + $sFourMsg = 'Step 4: Please select the field of the article'; + $iFourStatus = 2; + } + } + if($iFourStatus == 1){//查询是否推荐审稿人 + $aWhere = ['urr_state' => 0,'article_id' => $iArticleId]; + $aUserRecommend = Db::name('user_reviewer_recommend')->where($aWhere)->column('reviewer_id'); + if(empty($aMajor)){ + $sFourMsg = 'Step 4: Please recommend reviewers'; + $iFourStatus = 2; + } + } + + // } + + //数据处理 + $aData['first'] = $iFirstStatus; + $aData['second'] = $iSecondStatus; + $aData['three'] = $iThreeStatus; + $aData['four'] = $iFourStatus; + $aData['first_msg'] = $sFirstMsg; + $aData['second_msg'] = $sSecondMsg; + $aData['three_msg'] = $sThreeMsg; + $aData['four_msg'] = $sFourMsg; + + //判断当前未完成的步骤 + foreach ($aData as $key => $value) { + if($value == 2){ + $current = $key; + break; + } + } + $aData['current_step'] = empty($current) ? '' : $current; + return json_encode(['status' => 1,'msg' => 'success','data' => $aData]); + } + + /** + * 文章暂存 + */ + public function addArticleStaging() + { + //获取参数 + $aParam = empty($aParam) ? $this->request->post() : $aParam; + //用户ID + $iUserId = empty($aParam['user_id']) ? '' : $aParam['user_id']; + if(empty($iUserId)){ + return json_encode(['status' => 2,'msg' => 'Please select author']); + } + //获取文章ID + $iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id']; + if(empty($iArticleId)){ + $sTitle = empty($aParam['title']) ? '' : $aParam['title']; + $iJournalId = empty($aParam['journal_id']) ? 0 : $aParam['journal_id']; + if(empty($iJournalId)){ + return json_encode(['status' => 2,'msg' => 'Please select a journal']); + } + $aArticleInsert = ['journal_id' => $iJournalId,'title' => $sTitle,'state' => -1,'user_id' => $iUserId]; + $aArticleInsert['is_use_ai'] = 3; + $aArticleInsert['is_figure_copyright'] = 3; + $aArticleInsert['is_transfer'] = 3; + $aArticleInsert['is_become_reviewer'] = 3; + $iArticleId = Db::name('article')->insertGetId($aArticleInsert); + $aParam['article_id'] = $iArticleId; + } + if(empty($iArticleId)){ + return json_encode(['status' => 2,'msg' => 'Please select a article']); + } + //获取文章信息 + $aArticle = $this->getArticleInfo($aParam); + $iStatus = empty($aArticle['status']) ? 0 : $aArticle['status']; + if($iStatus != 1){ + return json_encode($aArticle); + } + $aArticle = empty($aArticle['data']) ? [] : $aArticle['data']; + + //定义更新数组 + $aUpdate = []; + // //摘要 + // $abstrart = empty($aParam['abstrart']) ? '' : $aParam['abstrart']; + // if(!empty($abstrart)){//判断简介字符串长度是否不低于200 + // if(!$this->checkMinChars($abstrart, 200)){ + // return json_encode(['status' => 3,'msg' => 'The abstract should not be less than 200 Chinese characters or English words!']); + // } + // $aUpdate['abstrart'] = $abstrart; + // } + //是否转投 + $istransfer = isset($aParam['istransfer']) ? $aParam['istransfer'] : '' ; + if($istransfer == true){ + $aParam['is_transfer'] = 1; + } + if($istransfer == false){ + $aParam['is_transfer'] = 2; + } + //是否成为审稿人 + $becomeRev = isset($aParam['becomeRev']) ? $aParam['becomeRev'] : ''; + if($becomeRev == true){ + $aParam['is_become_reviewer'] = 1; + } + if($becomeRev == false){ + $aParam['is_become_reviewer'] = 2; + } + $aField = ['is_use_ai','use_ai_explain','is_figure_copyright','is_transfer','is_become_reviewer','approval','approval_file','approval_content','code','is_transfer','is_become_reviewer','is_agree','title','abstrart','keywords','topics','fund','type','journal_id'];//,'title','abstrart','keywords','topics','fund','type' + $sMsg = ''; + $iIsUpdate = 1; + foreach ($aField as $key => $value) { + $sValue = isset($aParam[$value]) ? $aParam[$value] : -2 ; + if($sValue == -2){ + continue; + } + if($value == 'is_use_ai' && $sValue == 0){ + $aUpdate['is_use_ai'] = 3; + continue; + } + if($value == 'is_figure_copyright' && $sValue == 0){ + $aUpdate['is_figure_copyright'] = 3; + continue; + } + // if($value == 'is_use_ai'){ + // if(!in_array($sValue, [1,2])){ + // $sMsg = 'Please check whether to use AI technology'; + // $iIsUpdate = 2; + // break; + // } + // // if($sValue == 1 && empty($aParam['use_ai_explain'])){ + // // $sMsg = 'Please enter supplementary instructions'; + // // $iIsUpdate = 3; + // // break; + // // } + // } + // if($value == 'is_figure_copyright'){ + // if(!in_array($sValue, [1,2])){ + // $sMsg = 'Please check whether to upload the figure copyright statement'; + // break; + // } + // // if($sValue == 1){ + // // $sMsg = 'Please enter supplementary instructions'; + // // $iIsUpdate = 4; + // // break; + // // } + // } + // $iIsUpdate = 1; + $aUpdate[$value] = trim($aParam[$value]); + } + //获取期刊编辑 + //期刊ID + $iJournalId = empty($aParam['journal_id']) ? 0 : $aParam['journal_id']; + if(!empty($iJournalId)){ + //查询期刊信息 + $aJournalWhere = ['journal_id' => $iJournalId,'state' => 0]; + $aJournal = DB::name('journal')->field('editor_id')->where($aJournalWhere)->find(); + $aUpdate['editor_id'] = empty($aJournal['editor_id']) ? 0 : $aJournal['editor_id']; + } + //数据处理 + // if($iIsUpdate == 4){ + // $aWhere = ['article_id' => $iArticleId,'state' => 0,'type_name' => 'figurecopyright']; + // $aFile = Db::name('article_file')->where($aWhere)->order('ctime desc')->find(); + // if(empty($aFile)){ + // $sSecondMsg = 'Step 3: Please upload the figure copyright declaration file'; + // $iThreeStatus = 2; + // return json_encode(['status' => 4,'msg' => 'Please upload the figure copyright declaration file']); + // } + // } + if($iIsUpdate != 1){ + return json_encode(['status' => 5,'msg' => $sMsg]); + } + + //参数判空 + $sMajorData = empty($aParam['major']) ? '' : $aParam['major'];//文章领域 + // if(empty($sMajorData) && empty($aUpdate)){ + // return json_encode(['status' => 6,'msg' => 'Update data to empty']); + // } + + //文章领域处理 + $aMajorInsert = $aMajorDelete = []; + if(!empty($sMajorData)){ + $aField = explode(',', $sMajorData); + $aWhere = ['state' => 0, 'article_id' => $iArticleId]; + $aArticleMajor = Db::name('major_to_article')->where($aWhere)->order('major_id asc')->column('major_id'); + //新增 + $aInsert = array_diff($aField, $aArticleMajor); + //删除 + $aMajorDelete = array_diff($aArticleMajor, $aField); + //数据处理 + if (!empty($aInsert)) {//新增 + foreach ($aInsert as $key => $value) { + $aMajorInsert[] = ['major_id' => $value, 'article_id' => $iArticleId, 'ctime' => time(), 'state' => 0]; + } + } + } + + //转投信息 + $aTransferJournalId = empty($aParam['checkedjours']) ? [] : $aParam['checkedjours']; + if(!empty($aTransferJournalId) && is_string($aTransferJournalId)){ + $aTransferJournalId = explode(',', $aTransferJournalId); + } + $aJournalInsert = $aJournalDelete = []; + if(!empty($aTransferJournalId)){ + //查询转投期刊ID + $aWhere = ['state' => 0, 'article_id' => $iArticleId]; + $aTransferJournal = Db::name('article_transfer')->where($aWhere)->order('journal_id asc')->column('journal_id'); + //新增 + $aInsert = array_diff($aTransferJournalId, $aTransferJournal); + //删除 + $aJournalDelete = array_diff($aTransferJournal, $aTransferJournalId); + if (!empty($aInsert)) {//新增 + foreach ($aInsert as $key => $value) { + $aJournalInsert[] = ['journal_id' => $value, 'article_id' => $iArticleId, 'ctime' => time(), 'state' => 0]; + } + } + } + + //推荐审稿人 + $aReviewer = isset($aParam['reviewers']) ? $aParam['reviewers'] : []; +// $json = '{ +// "article_id": "5997", +// "user_id": "54", +// "major": "52,55,56", +// "checkedjours": [], +// "istransfer": false, +// "becomeRev": false, +// "reviewers": [ + +// { +// "realname": "77777", +// "email": "752204719@qq.com", +// "country": "Afghanistan", +// "company": "11111", +// "department": "33333333", +// "major_all": [ +// 167, +// 171, +// 173 +// ], +// "major": 173 +// }, +// { +// "realname": "8888", +// "email": "752204716@qq.com", +// "country": "Albania", +// "major_all": [ +// 167, +// 171, +// 173 +// ], +// "major": 173 +// } +// ], +// "code": "777777777898" +// }'; +// $aReviewer = json_decode($json,true); +// $aReviewer = $aReviewer['reviewers']; + if(!empty($aReviewer)){ + + //根据用户邮箱查询是否注册 + $aEmail = array_unique(array_column($aReviewer, 'email')); + $aWhere = ['email' => ['in',$aEmail],'state' => 0]; + $aUserDataResult = Db::name('user')->field('user_id,account,email,realname')->where($aWhere)->select(); + if(empty($aUserDataResult)){ + $aUserDataResult = []; + } + $aUserData = empty($aUserDataResult) ? [] : array_column($aUserDataResult, null,'email'); + + //数据处理 + $aUserInsert = $aUserRecommendDelete = []; + foreach ($aReviewer as $key => $value) { + $sEmail = empty($value['email']) ? '' : $value['email']; + if(empty($sEmail)){ + continue; + } + if(!empty($aUserData[$sEmail])){ + continue; + } + $aUserInsert = ['account' => $value['email'],'password' => md5('123456qwe'),'email' => $sEmail,'realname' => empty($value['realname']) ? '' : $value['realname'],'ctime' => time()]; + $iId = Db::name('user')->insertGetId($aUserInsert); + if(empty($iId)){ + continue; + } + $aUserInsert['user_id'] = $iId; + $aUserDataResult[] = $aUserInsert; + } + if(!empty($aUserDataResult)){ + + //查询期刊标题 + $iJournalId = empty($aArticle['journal_id']) ? 0 : $aArticle['journal_id']; + $aWhere = ['journal_id' => $iJournalId,'state' => 0]; + $aJournal = Db::name('journal')->field('title')->where($aWhere)->find(); + + //用户信息 + $aUserDataResult = array_column($aUserDataResult, null,'user_id'); + $aUserData = empty($aUserDataResult) ? [] : array_column($aUserDataResult, 'user_id','email'); + //获取期刊审稿人 + $aReviewerId = array_column($aUserDataResult, 'user_id'); + $aWhere = ['reviewer_id' => ['in',$aReviewerId],'state' => 0]; + $aReviewerToJournal = Db::name('reviewer_to_journal')->where($aWhere)->select(); + $aReviewerToJournal = empty($aReviewerToJournal) ? [] : array_column($aReviewerToJournal, null,'reviewer_id'); + + //获取审稿人资料 + $aReviewerInfo = Db::name('user_reviewer_info')->field('reviewer_info_id,reviewer_id')->where($aWhere)->select(); + $aReviewerInfo = empty($aReviewerInfo) ? [] : array_column($aReviewerInfo, 'reviewer_info_id','reviewer_id'); + + //推荐记录 + $aWhere = ['reviewer_id' => ['in',$aReviewerId],'urr_state' => 0,'article_id' => $iArticleId]; + $aUserRecommend = Db::name('user_reviewer_recommend')->where($aWhere)->column('reviewer_id'); + + $aReviewerInfoAll = $aReviewerToJournalAll = $aInsertRecommend = []; + foreach ($aReviewer as $key => $value) { + $sEmail = empty($value['email']) ? '' : $value['email']; + if(empty($sEmail)){ + continue; + } + $iReviewerUserId = empty($aUserData[$sEmail]) ? 0 : $aUserData[$sEmail]; + if(empty($iReviewerUserId)){ + continue; + } + //审稿人的详细信息 + $insert_reviewer_info = ['reviewer_id' => $iReviewerUserId,'major' => empty($value['major']) ? '' : $value['major'], 'country' => empty($value['country']) ? '' : $value['country'],'test_from' => 'addRecommentReviewer','company' => empty($value['company']) ? '' : $value['company'],'department' => empty($value['department']) ? '' : $value['department']]; + if(!empty($aReviewerInfo[$iReviewerUserId])){ + $insert_reviewer_info['reviewer_info_id'] = $aReviewerInfo[$iReviewerUserId]; + } + $aReviewerInfoAll[] = $insert_reviewer_info; + //期刊审稿人 + $reviewer_to_journal = ['reviewer_id' => $iReviewerUserId,'journal_id' => $iJournalId, 'account' => empty($aUserDataResult[$iReviewerUserId]['account']) ? '' : $aUserDataResult[$iReviewerUserId]['account'],'journal_title' => empty($aJournal['title']) ? '' : $aJournal['title'],'ctime' => time()]; + if(!empty($aReviewerToJournal[$iReviewerUserId])){ + $reviewer_to_journal['rtj_id'] = $aReviewerToJournal[$iReviewerUserId]['rtj_id']; + } + $aReviewerToJournalAll[] = $reviewer_to_journal; + + if(in_array($iReviewerUserId, $aUserRecommend)){ + continue; + } + //添加推荐审稿人信息 + $aInsertRecommend[] = ['reviewer_id' => $iReviewerUserId,'article_id' => $iArticleId,'recommend_user_id' => $iUserId,'urr_ctime' => time()]; + } + + //判读是否有删除 + $aUserRecommendId = array_column($aUserDataResult, 'user_id'); + //删除 + $aWhere = ['urr_state' => 0,'article_id' => $iArticleId]; + $aUserRecommend = Db::name('user_reviewer_recommend')->where($aWhere)->column('reviewer_id'); + $aUserRecommendDelete = array_diff($aUserRecommend,$aUserRecommendId); + } + } + Db::startTrans(); + if(!empty($aMajorInsert)){//新增领域 + $add_result = Db::name('major_to_article')->insertAll($aMajorInsert); + } + if(!empty($aMajorDelete)){//删除领域 + $aWhere = ['article_id' => $iArticleId, 'state' => 0, 'major_id' => ['in', $aMajorDelete]]; + $delete_result = Db::name('major_to_article')->where($aWhere)->limit(count($aMajorDelete))->update(['state' => 1, 'ctime' => time()]); + } + if(!empty($aJournalInsert)){//新增转投期刊 + $add_journal_result = Db::name('article_transfer')->insertAll($aJournalInsert); + } + if(!empty($aJournalDelete)){//删除转投期刊 + $aWhere = ['article_id' => $iArticleId, 'state' => 0, 'journal_id' => ['in', $aJournalDelete]]; + $delete_journal_result = Db::name('article_transfer')->where($aWhere)->limit(count($aJournalDelete))->delete(); + } + //更新数据 + if(!empty($aUpdate)){//更新文章主表数据 + //数据更新 + $aWhere = ['article_id' => $iArticleId,'state' => ['in',[-1,3]]]; + $result = Db::name('article')->where($aWhere)->limit(1)->update($aUpdate); + if($result === false){ + return json_encode(['status' => 7,'msg' =>'Failed to save article content']); + } + } + //更新审稿人数据 + if(!empty($aReviewerInfoAll)){ + $oUserReviewerInfo = new \app\common\UserReviewerInfo(); + $sReviewerInfoAll = $oUserReviewerInfo->saveAll($aReviewerInfoAll); + } + if(!empty($aReviewerToJournalAll)){ + $oReviewerTojournal = new \app\common\ReviewerToJournal(); + $sReviewerTojournal = $oReviewerTojournal->saveAll($aReviewerToJournalAll); + } + if(!empty($aInsertRecommend)){ + $sInsertRecommend = Db::name('user_reviewer_recommend')->insertAll($aInsertRecommend); + } + if(!empty($aUserRecommendDelete)){ + $aWhere = ['urr_state' => 0,'article_id' => $iArticleId,'reviewer_id' => ['in',$aUserRecommendDelete]]; + $sDelete = Db::name('user_reviewer_recommend')->where($aWhere)->limit(count($aUserRecommendDelete))->delete(); + } + Db::commit(); + + return json_encode(['status' => 1,'msg' =>'The content of the article has been successfully saved','data' => ['article_id' => $iArticleId]]); + } + /** + * 文章信息获取 + */ + private function getArticleInfo($aParam = []){ + //获取参数 + $aParam = empty($aParam) ? [] : $aParam; + //获取文章ID + $iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id']; + if(empty($iArticleId)){ + return ['status' => 2,'msg' => 'Please select the article']; + } + //用户ID + $iUserId = empty($aParam['user_id']) ? '' : $aParam['user_id']; + if(empty($iUserId)){ + return ['status' => 2,'msg' => 'Please select author']; + } + //查询文章 + $aWhere = ['article_id' => $iArticleId]; + $aArticle = Db::name('article')->field('article_id,title,type,abstrart,journal_id,state,user_id,is_use_ai,use_ai_explain,is_figure_copyright,is_transfer,approval,approval_content,approval_file')->where($aWhere)->find(); + if(empty($aArticle)){ + return ['status' => 7,'msg' => 'The article does not exist']; + } + if($aArticle['state'] != -1 && $aArticle['state'] != 3){ + return ['status' => 8,'msg' => 'Article cannot be edited']; + } + if($aArticle['user_id'] != $iUserId){ + return ['status' => 9,'msg' => 'The article does not belong to the current author']; + } + return ['status' => 1,'msg' => 'success','data' => $aArticle]; + } + + /** + * 添加图片版权声明文件 + */ + public function addFigureCopyright($aParam = []){ + //获取参数 + $aParam = empty($aParam) ? $this->request->post() : $aParam; + + //获取文章ID + $iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id']; + if(empty($iArticleId)){ + return json_encode(['status' => 2,'msg' => 'Please select the article']); + } + //用户ID + $iUserId = empty($aParam['user_id']) ? '' : $aParam['user_id']; + if(empty($iUserId)){ + return json_encode(['status' => 2,'msg' => 'Please select author']); + } + //文件地址 + $sUrl = empty($aParam['url']) ? '' : $aParam['url']; + if(empty($sUrl)){ + return json_encode(['status' => 2,'msg' => 'Please choose to upload the file']); + } + //文件地址 + $sTypeName = empty($aParam['type']) ? '' : $aParam['type']; + if(empty($sTypeName)){ + return json_encode(['status' => 2,'msg' => 'Please select the type of file to upload']); + } + + //文件地址 + $aArticleUpdate = []; + if($sTypeName == 'figurecopyright'){ + $is_figure_copyright = empty($aParam['is_figure_copyright']) ? 3 : $aParam['is_figure_copyright']; + if($is_figure_copyright != 1){ + return json_encode(['status' => 2,'msg' => 'Please check whether to upload the figure copyright statement']); + } + $aArticleUpdate['is_figure_copyright'] = 1; + } + + + //获取文章信息 + $aArticle = $this->getArticleInfo($aParam); + $iStatus = empty($aArticle['status']) ? 0 : $aArticle['status']; + if($iStatus != 1){ + return json_encode($aArticle); + } + + //验证文件是否上传 + $aWhere = ['file_url' => $sUrl,'state' => 0]; + $result = Db::name('article_file')->where($aWhere)->find(); + if(!empty($result)){ + return json_encode(['status' => 1,'msg' => 'Duplicate upload','data' => $result]); + } + //获取作者信息 + $aWhere = ['user_id' => $iUserId,'state' => 0]; + $aUser = Db::name('user')->field('account')->where($aWhere)->find(); + + Db::startTrans(); + $aInsert['article_id'] = $iArticleId; + $aInsert['user_id'] = $iUserId; + $aInsert['username'] = empty($aUser['account']) ? '' : $aUser['account']; + $aInsert['file_url'] = $sUrl; + $aInsert['type_name'] = $sTypeName; + $aInsert['ctime'] = time(); + $result = Db::name('article_file')->insertGetId($aInsert); + //更新文章内容 + if(!empty($aArticleUpdate)){ + $aWhere = ['article_id' => $iArticleId,'state' => ['in',[-1,3]]]; + $update_result = Db::name('article')->where($aWhere)->limit(1)->update($aArticleUpdate); + } + Db::commit(); + + return json_encode(['status' => 1,'msg' => 'success','data' => ['file_id' => $result]]); + } + + /** + * 获取领域树 + */ + private function getMajorShuList($major) + { + $major_obj = Db::name('major'); + if ($major == 0) { + return; + } + $res = $major_obj->where('major_id', $major)->find(); + if ($res['pid'] == 0) { + return $res['major_id']; + } + + $p = self::getMajorShuList($res['pid']); + return $p . ',' . $res['major_id']; + } }