diff --git a/application/api/controller/Aiarticle.php b/application/api/controller/Aiarticle.php index bc41028..fb16e27 100644 --- a/application/api/controller/Aiarticle.php +++ b/application/api/controller/Aiarticle.php @@ -7,7 +7,7 @@ use app\common\QrCodeImage; use app\common\Wechat; use app\common\Material; use think\Cache; - +use think\Queue; /** * @title 数据库接口 * @description 数据库接口 @@ -32,19 +32,18 @@ class Aiarticle extends Base /**OPENAI相关配置----------end**/ //数据表必填字段[ai_article] - protected $aAiFileds = ['article_id','title_english','title_chinese','journal_issn','covered','digest','research_result','content','highlights','discussion','prospect','research_background','discussion_results','research_method']; + protected $aAiFileds = ['article_id','title_english','title_chinese','journal_issn','covered','digest','research_result','content','highlights','discussion','prospect','research_background','discussion_results','research_method','overview','summary']; //期刊接口地址 - protected $sJournalUrl = 'http://journalapi.tmrjournals.com/public/index.php';//'http://zmzm.journal.dev.com'; // 'http://zmzm.journal.dev.com'; // 'http://journalapi.tmrjournals.com/public/index.php';//'http://zmzm.journal.dev.com'; // + protected $sJournalUrl = 'http://journalapi.tmrjournals.com/public/index.php';//'http://zmzm.journal.dev.com'; // //期刊官网 protected $sJournalUsx = 'https://www.tmrjournals.com'; //投稿系统 protected $sSubmissionUrl = 'https://submission.tmrjournals.com/'; protected $aOpenAiAsk = [ 1 => '"将以下内容翻译为中文,仅返回翻译结果,不要解释:\n {#content#}"', - 2 => ' + 'default' => ' **核心要求** - 注意:生成内容会以微信公众号的形式推送给学术专家,针对以下九点生成的内容要提高内容的连贯性,逻辑性,科学性,避免让学术专家产生疑问 1️ 内容涵盖哪些学科及方法请罗列 2 学术规范翻译并提炼摘要,更强调逻辑性、科学术语准确性和表达的严谨性,并且不需要分点展示,字数小于200字,以便更方便读者阅读 3 研究背景提炼,大于500字 @@ -62,7 +61,23 @@ class Aiarticle extends Base **输出格式** 中文格式[英文简写忽略首字母大写] 格式内容 - ```json{"covered": "【总字数<=100】", "digest": "【总字数<=500】", "research_background": "【总字数>200】", "discussion_results": "【总字数>450】","research_method" => "【总字数>300】", "prospect": "", "highlights": "", "title_chinese": "", "content": "", }' + ```json{"covered": "【总字数<=100】", "digest": "【总字数<=500】", "research_background": "【总字数>200】", "discussion_results": "【总字数>450】","research_method" => "【总字数>300】", "prospect": "", "highlights": "", "title_chinese": "", "content": ""}', + 'Review' => ' + **核心要求** + 1️ 内容涵盖哪些学科及方法请罗列 + 2 学术规范翻译并提炼文章概述,更强调逻辑性、科学术语准确性和表达的严谨性,并且不需要分点展示,大于1000字 + 3 针对文章进行简单总结,大于300字 + 4 请将标题翻译成中文【内容需自然流畅、口语化、连贯性、学术性】 + {#title_chinese#} + 5 请将文章内容翻译成中文【内容需自然流畅、口语化、连贯性、学术性】 + {#content#} + **稿件关键信息** + - 稿件简介:{#abstract#} + - 稿件内容:{#content#} + **输出格式** + 中文格式[英文简写忽略首字母大写] + 格式内容 + ```json{"covered": "【总字数<=100】", "overview": "【总字数>=1000】", "summary": "【总字数>=3500】", "title_chinese": "", "content": ""}' ]; //文章图片icon地址 @@ -103,9 +118,22 @@ class Aiarticle extends Base $data = [ 'model' => $model, - 'messages' => $messages, - 'temperature' => 0, - 'top_p' => 1, + // 'messages' => $messages, + 'messages' => [ + // [ + // 'role' => 'system', + // 'content' => '你是一名资深医学期刊编辑,需遵循医学原则回答以下问题。回答的内容会以微信公众号的形式推送给学术专家,要提高内容的连贯性,逻辑性,科学性,避免让学术专家产生质疑' + // ], + [ + 'role' => 'user', + 'content' => $messages + ] + ], + 'temperature' => 0.3,// 降低随机性(0-1,0为最确定) + // 'top_p' => 9, // 控制生成多样性 + // 'max_tokens' => 1500, // 防止答案截断 + // 'frequency_penalty' => 0.5, // 减少重复内容 + // 'presence_penalty' => 0.2 // 鼓励提及新概念 ]; $oCurl = curl_init(); @@ -143,23 +171,22 @@ class Aiarticle extends Base * @param aSearch array 模版内容 * @param iTemplateId 模版ID */ - private function _createContentForOpenAI($aSearch = [],$iTemplateId = 0){ + private function _createContentForOpenAI($aSearch = [],$sArticleType = ''){ - if(empty($aSearch) || empty($iTemplateId)){ + if(empty($aSearch) || empty($sArticleType)){ return json_encode(array('status' => 2,'msg' => 'Please select a template or enter the content you want to consult'.$this->sError)); } - //组织参数 - $sTemplate = $this->aOpenAiAsk[$iTemplateId]; + //组织参数 + if(in_array($sArticleType, ['Mini Review','Review'])){ + $sArticleType = 'Review'; + }else{ + $sArticleType = 'default'; + } + $sTemplate = $this->aOpenAiAsk[$sArticleType]; $sTemplate = str_replace(array_keys($aSearch), array_values($aSearch), $sTemplate); - $messages = [ - [ - 'role' => 'user', //角色:platform:平台;developer:开发者;user:用户;guideline:模型规范“指南”部分:连接:https://model-spec.openai.com/2025-02-12.html#chain_of_command - 'content' => $sTemplate - ] - ]; //请求接口 $sModel = empty($aParam['api_model']) ? 'gpt-4o' : $aParam['api_model']; - $result = $this->curlOpenAI($messages,$sModel); + $result = $this->curlOpenAI($sTemplate,$sModel); if($result == FALSE){ return json_encode(array('status' => 2,'msg' => 'Interface request failed'.$this->sError)); } @@ -202,6 +229,8 @@ class Aiarticle extends Base return json_encode(array('status' => 2,'msg' => 'Please select an article' )); } + //媒体类型 + $iMediaType = empty($aParam['media_type']) ? 1 : $aParam['media_type']; //获取文章是否生成AI内容 $aResult = json_decode($this->getArticle($iArticleId),true); $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; @@ -212,13 +241,17 @@ class Aiarticle extends Base $aArticleContent = empty($aResult['data']) ? [] : $aResult['data']; //文章数据 $aArticle = empty($aArticleContent['article']) ? [] : $aArticleContent['article']; + if(empty($aArticle)){ return json_encode(['status' => 3,'msg' => 'The content of the article is empty']); } //期刊数据 $aJournal = empty($aArticleContent['journal']) ? [] : $aArticleContent['journal']; - - + if(empty($aJournal)){ + return json_encode(['status' => 3,'msg' => 'The journal to which the article belongs does not exist or has been closed']); + } + // Queue::later(10,'app\api\job\WechatMaterial@fire', ['article_id' => $iArticleId], 'uploadMaterial'); + // exit; //查询AI内容是否生成 $aAiArticle = json_decode($this->getAiArticle(['article_id' => $iArticleId]),true); $aAiArticleContent = empty($aAiArticle['data']) ? [] : $aAiArticle['data']; @@ -228,14 +261,13 @@ class Aiarticle extends Base if(empty($aAiArticle)){ //插入t_ai_article数据 $sIssn = empty($aJournal['issn']) ? '' : $aJournal['issn']; - $aInsert = ['title_english' => $aArticle['title'],'article_id' => $iArticleId,'create_time' => time(),'journal_issn' => $sIssn,'journal_id' => $aArticle['journal_id']]; + $aInsert = ['title_english' => $aArticle['title'],'article_id' => $iArticleId,'create_time' => time(),'journal_issn' => $sIssn,'journal_id' => $aArticle['journal_id'],'article_type' => $aArticle['type'],'media_type' => $iMediaType,'journal_issn' => empty($aJournal['issn']) ? '' :$aJournal['issn']]; $iId = Db::name('ai_article')->insertGetId($aInsert); if($iId === false){ return json_encode(['status' => 4,'msg' => 'Data insertion failed']); } $aAiArticle = array_merge(['ai_article_id' => $iId,'article_id' => $iArticleId,'is_generate' => 2],$aInsert); } - //判断是否生成 if(!empty($aAiArticle['is_generate']) && $aAiArticle['is_generate'] == 1){ return json_encode(['status' => 5,'msg' => 'The data has been generated, please proceed with the next steps']); @@ -283,7 +315,8 @@ class Aiarticle extends Base $aSearch['{#journal_content#}'] = trim(trim($aSearch['{#journal_content#}'],'.'),'。'); //写入Redis 标识已经开始请求OPENAI处理 - $aResult = $this->_createContentForOpenAI($aSearch,2); + $sArticleType = empty($aArticle['type']) ? 'default' : $aArticle['type']; + $aResult = $this->_createContentForOpenAI($aSearch,$sArticleType); $aResult = json_decode($aResult,true); if($aResult['status'] != 1){ return json_encode($aResult); @@ -521,6 +554,9 @@ class Aiarticle extends Base if(!isset($aParam[$val])){ continue; } + if(is_array($aParam[$val])){ + $aParam[$val] = implode(";",$aParam[$val]); + } $aUpdateParam[$val] = empty($aParam[$val]) ? '' : addslashes(strip_tags($aParam[$val])); } if(empty($aUpdateParam)){ @@ -616,8 +652,7 @@ class Aiarticle extends Base //文章ID $iArticleId = empty($aParam['article_id']) ? '' : $aParam['article_id']; - //模版ID - $iTemplateId = empty($aParam['template_id']) ? '' : $aParam['template_id']; + //模版ID $iIsSync = empty($aParam['is_sync']) ? 2 : $aParam['is_sync']; @@ -625,9 +660,6 @@ class Aiarticle extends Base if(empty($iArticleId)){ return json_encode(['status' => 2, 'msg' => 'Please select an article']); } - if(empty($iTemplateId)){ - return json_encode(['status' => 2, 'msg' => 'Please select a template']); - } //获取AI生成文章内容 $aAiContent = json_decode($this->getAiArticle(['article_id' => $iArticleId,'is_select_author' => 1]),true); @@ -637,8 +669,6 @@ class Aiarticle extends Base if(empty($aAiArticle)){ return json_encode(['status' => 3, 'msg' => 'The article content of WeChat official account has not been generated']); } - //模版ID - $iTemplateId = empty($iTemplateId) ? $aAiArticle['template_id'] : $iTemplateId; //获取文章内容 $aResult = json_decode($this->getArticle($iArticleId),true); @@ -668,7 +698,10 @@ class Aiarticle extends Base //文章图片 $sArticleIcon = trim($this->sJournalUsx,'/').$this->sArticleIcon.$aArticle['article_icon']; //期刊图片 - $sJournalIcon = trim($this->sJournalUsx,'/').$this->sJournalIcon.$aJournal['journal_icon']; + $sJournalStageIcon = empty($aJournalStage['stage_icon']) ? '' : '/public/'.$aJournalStage['stage_icon']; + $sJournalIcon = empty($aJournal['journal_icon']) ? '' : $this->sJournalIcon.$aJournal['journal_icon']; + $sJournalIcon = empty($sJournalStageIcon) ? $sJournalIcon : $sJournalStageIcon; + $sJournalIcon = trim($this->sJournalUsx,'/').$sJournalIcon; //期刊编辑二维码 $sEditorQrcode = empty($aJournal['editor_qrcode']) ? '' : $aJournal['editor_qrcode']; @@ -676,10 +709,11 @@ class Aiarticle extends Base //获取期刊二维码 $oMaterial = new Material; + $aJournal['icon'] = $sJournalIcon; + $aJournal['journal_stage_id'] = empty($aArticle['journal_stage_id']) ? 0 : $aArticle['journal_stage_id']; $aJournalQrCode = $oMaterial->createJournalQrCode($aJournal); $sJournalCode = empty($aJournalQrCode['qrcode_url']) ? '' : $this->sSubmissionUrl.'public/qrcode/'.$aJournalQrCode['qrcode_url']; $aAiArticle['journal_qrcode'] = $sJournalCode; - //文章二维码 $aArticleQrCode = $oMaterial->createArticleQrCode($aArticle); $sArticleCode = empty($aArticleQrCode['qrcode_url']) ? '' : $this->sSubmissionUrl.'public/qrcode/'.$aArticleQrCode['qrcode_url']; @@ -761,11 +795,19 @@ class Aiarticle extends Base $aAiArticle += $aJournal; - //获取模版信息 - $sTemplatePath = ROOT_PATH."public/wechatTemplate/template_".$iTemplateId; - + //获取模版信息 + $sJournalIssn = empty($aJournal['issn']) ? 'default' : $aJournal['issn'];//期刊issn + $sArticleType = empty($aArticle['type']) ? 'default' : $aArticle['type'];//文章类型 + if(in_array($sArticleType, ['review','Mini Review'])){ + $sArticleType = "Review"; + } + $sTemplatePath = ROOT_PATH."public/ArticleTemplate/".$sJournalIssn."/".$sArticleType; + if (!is_dir($sTemplatePath)) {//默认模版信息 + $sTemplatePath = ROOT_PATH."public/ArticleTemplate/default/".$sArticleType; + } //index模版目录 $sTemplateIndexPath = $sTemplatePath.'/index.html'; + // 验证文件有效性 if (!file_exists($sTemplateIndexPath)) { return json_encode(['status' => 4, 'msg' => 'Article template does not exist']); @@ -785,19 +827,19 @@ class Aiarticle extends Base } //处理通讯作者信息数据 - $aAuthorInfo = json_decode($this->dealTemplateAuthor($aAuthor,$iTemplateId),true); + $aAuthorInfo = json_decode($this->dealTemplateAuthor($aAuthor,$sTemplatePath),true); $aAuthorInfo = empty($aAuthorInfo['data']) ? [] : $aAuthorInfo['data']; $aSearch['{###author_summary###}'] = empty($aAuthorInfo['author_info']) ? '' : $aAuthorInfo['author_info']; $aSearch['{###author_string###}'] = empty($aAuthorInfo['author_string']) ? '' : ',通讯作者为'.$aAuthorInfo['author_string']; //处理往期推荐数据 - $aPreviousRecommend = json_decode($this->dealTemplatePreviousRecommend($aArticle,$iTemplateId),true); + $aPreviousRecommend = json_decode($this->dealTemplatePreviousRecommend($aArticle,$sTemplatePath),true); $aSearch['{###previous_recommend_summary###}'] = empty($aPreviousRecommend['data']) ? '' : $aPreviousRecommend['data']; //处理期刊主题数据 $sJournalTopic = empty($aJournal['journal_topic']) ? '' : $aJournal['journal_topic']; - $aTopic = json_decode($this->dealTemplateTopic($sJournalTopic,$iTemplateId),true); + $aTopic = json_decode($this->dealTemplateTopic($sJournalTopic,$sTemplatePath),true); $aSearch['{###topic_name_summary###}'] = empty($aTopic['data']) ? '' : $aTopic['data']; //公众号名字处理 @@ -832,11 +874,29 @@ class Aiarticle extends Base } $aSearch['{###jabbr###}'] = trim(trim($aSearch['{###jabbr###}'],'.'),'。'); - $aSearch['{###free_year###}'] = date('Y'); - $aSearch['{###covered###}'] = '内容涵盖'.str_replace('研究涵盖', '', $aSearch['{###covered###}']); + // $aSearch['{###free_year###}'] = date('Y'); + // $aSearch['{###covered###}'] = '内容涵盖'.str_replace('研究涵盖', '', $aSearch['{###covered###}']); + if(!empty($aSearch['{###covered###}']) && strpos($aSearch['{###covered###}'], '涵盖') === false){ + $aSearch['{###covered###}'] = '内容涵盖'.str_replace('研究涵盖', '', $aSearch['{###covered###}']); + } + + //期刊封面 + $aSearch['{###journal_icon_info###}'] = $aSearch['{###journal_icon_details###}'] = ''; + if(!empty($sJournalIcon)){ + $sTemplateJournalInfo = $sTemplatePath.'/journal_icon_info.html'; + if(file_exists($sTemplateJournalInfo) && is_readable($sTemplateJournalInfo)) { + $sTemplateJournalInfo = file_get_contents($sTemplateJournalInfo); + $aSearch['{###journal_icon_info###}'] = str_replace('{###journal_icon###}', $aAiArticle['journal_icon']??'', $sTemplateJournalInfo); + } + $sTemplateJournalInfo = $sTemplatePath.'/journal_icon_details.html'; + if(file_exists($sTemplateJournalInfo) && is_readable($sTemplateJournalInfo)) { + $sTemplateJournalInfo = file_get_contents($sTemplateJournalInfo); + $aSearch['{###journal_icon_details###}'] = str_replace('{###journal_icon###}', $aAiArticle['journal_icon']??'', $sTemplateJournalInfo); + } + } $sTemplate = str_replace(array_keys($aSearch), array_values($aSearch), $sTemplate); - file_put_contents(ROOT_PATH.'public/template_info.html', $sTemplate); + // $this->writeFile($sTemplate,ROOT_PATH.'public/template_info.html'); return json_encode(['status' => 1, 'msg' => '模版生成成功','data' => ['template' => $sTemplate]]); } @@ -844,22 +904,22 @@ class Aiarticle extends Base * 处理模版通讯作者 * @param article_id 文章ID */ - private function dealTemplateAuthor($aAuthor = [],$iTemplateId = 0){ + private function dealTemplateAuthor($aAuthor = [],$sTemplatePath = ''){ //必填字段判断 - if(empty($aAuthor) || empty($iTemplateId)){ + if(empty($aAuthor) || empty($sTemplatePath)){ return json_encode(['status' => 2,'msg' => 'Corresponding author or template does not exist']); } //获取通讯作者模版 - $sAuthorTemplatePath = ROOT_PATH."public/wechatTemplate/template_".$iTemplateId.'/author.html'; - if (!file_exists($sAuthorTemplatePath)) { + $sAuthorTemplatePathAuthor = $sTemplatePath.'/author.html'; + if (!file_exists($sAuthorTemplatePathAuthor)) { return json_encode(['status' => 3, 'msg' => 'Corresponding author template does not exist','data' => '']); } - if (!is_readable($sAuthorTemplatePath)) { + if (!is_readable($sAuthorTemplatePathAuthor)) { return json_encode(['status' => 4, 'msg' => 'The corresponding author template is unreadable','data' => '']); } - $sAuthorTemplate = file_get_contents($sAuthorTemplatePath); + $sAuthorTemplate = file_get_contents($sAuthorTemplatePathAuthor); //处理模版变量 $aAuthorSerachInfo = []; @@ -869,7 +929,7 @@ class Aiarticle extends Base //请求AI翻译 $sContent = ''; $aSearch['{#content#}'] = json_encode($aAuthor); - $aResult = json_decode($this->_createContentForOpenAI($aSearch,1),true); + // $aResult = json_decode($this->_createContentForOpenAI($aSearch,1),true); $aContent = empty($aResult['data']) ? [] : array_column($aResult['data'], null,'email'); foreach ($aAuthor as $key => $value) { @@ -916,7 +976,7 @@ class Aiarticle extends Base //通讯作者列表 //获取通讯作者汇总模版 - $sAuthorTemplatePath = ROOT_PATH."public/wechatTemplate/template_".$iTemplateId.'/author_summary.html'; + $sAuthorTemplatePath = $sTemplatePath.'/author_summary.html'; if (!file_exists($sAuthorTemplatePath)) { return json_encode(['status' => 3, 'msg' => 'Corresponding author template does not exist','data' => '']); } @@ -937,8 +997,8 @@ class Aiarticle extends Base * 处理期刊主题模版 * @param article_id 文章ID */ - private function dealTemplateTopic($sTopic = '',$iTemplateId = 0){ - if(empty($iTemplateId)){ + private function dealTemplateTopic($sTopic = '',$sTemplatePath = ''){ + if(empty($sTemplatePath)){ return json_encode(['status' => 2,'template does not exist']); } if(empty($sTopic)){ @@ -946,14 +1006,14 @@ class Aiarticle extends Base } //获取主题模版 - $sTemplatePath = ROOT_PATH."public/wechatTemplate/template_".$iTemplateId.'/topic.html'; - if (!file_exists($sTemplatePath)) { + $sTemplatePathTopic = $sTemplatePath.'/topic.html'; + if (!file_exists($sTemplatePathTopic)) { return json_encode(['status' => 4, 'msg' => 'Corresponding author template does not exist']); } - if (!is_readable($sTemplatePath)) { + if (!is_readable($sTemplatePathTopic)) { return json_encode(['status' => 5, 'msg' => 'The corresponding author template is unreadable']); } - $sTemplate = file_get_contents($sTemplatePath); + $sTemplate = file_get_contents($sTemplatePathTopic); //数据处理 $sTopic = trim($sTopic); @@ -967,7 +1027,7 @@ class Aiarticle extends Base } //获取期刊主题汇总模版 - $sTemplatePath = ROOT_PATH."public/wechatTemplate/template_".$iTemplateId.'/topic_summary.html'; + $sTemplatePath = $sTemplatePath.'/topic_summary.html'; if (!file_exists($sTemplatePath)) { return json_encode(['status' => 4, 'msg' => 'Corresponding author template does not exist']); } @@ -987,20 +1047,20 @@ class Aiarticle extends Base * 处理往期推荐 * @param article_id 文章ID */ - private function dealTemplatePreviousRecommend($aArticle=[],$iTemplateId = 0){ + private function dealTemplatePreviousRecommend($aArticle=[],$sTemplatePath = ''){ - if(empty($iTemplateId)){ + if(empty($sTemplatePath)){ return json_encode(['status' => 2,'template does not exist']); } //获取往期推荐模版 - $sTemplatePath = ROOT_PATH."public/wechatTemplate/template_".$iTemplateId.'/previous_recommend.html'; - if (!file_exists($sTemplatePath)) { + $sTemplatePathRecommend = $sTemplatePath.'/previous_recommend.html'; + if (!file_exists($sTemplatePathRecommend)) { return json_encode(['status' => 3, 'msg' => 'Corresponding author template does not exist']); } - if (!is_readable($sTemplatePath)) { + if (!is_readable($sTemplatePathRecommend)) { return json_encode(['status' => 4, 'msg' => 'The corresponding author template is unreadable']); } - $sTemplate = file_get_contents($sTemplatePath); + $sTemplate = file_get_contents($sTemplatePathRecommend); //判断是否关联文章 if(empty($aArticle['related'])){ @@ -1016,7 +1076,7 @@ class Aiarticle extends Base $aId = array_column($aRecommend, 'article_id'); //查询是否推送到微信公众号并且已发布 - $aWhere['template_id'] = $iTemplateId;//,'is_publish' => 1 + $aWhere['is_publish'] = 1; $aWechatArticle = Db::name('ai_wechat_article')->field('article_id,media_url')->where($aWhere)->select(); if(empty($aWechatArticle)){ return json_encode(['status' => 6, 'msg' => 'No article published on WeChat official account was found']); @@ -1034,7 +1094,7 @@ class Aiarticle extends Base } //获取往期推荐汇总模版 - $sTemplatePath = ROOT_PATH."public/wechatTemplate/template_".$iTemplateId.'/previous_recommend_summary.html'; + $sTemplatePath = $sTemplatePath.'/previous_recommend_summary.html'; if (!file_exists($sTemplatePath)) { return json_encode(['status' => 3, 'msg' => 'Corresponding author template does not exist']); } @@ -1062,16 +1122,12 @@ class Aiarticle extends Base //文章ID $iArticleId = empty($aParam['article_id'] ) ? '' : $aParam['article_id']; - //模版ID - $iTemplateId = empty($aParam['template_id']) ? '' : $aParam['template_id']; //必填参数验证 if(empty($iArticleId)){ return json_encode(['status' => 2, 'msg' => 'Please select an article']); } - if(empty($iTemplateId)){ - return json_encode(['status' => 2, 'msg' => 'Please select a template']); - } + //判断文章类型 $article_type = empty($aParam['article_type']) ? 'news' : $aParam['article_type']; if(!in_array($article_type, ['news','newspic'])){ @@ -1079,7 +1135,7 @@ class Aiarticle extends Base } //查询文章是否存在 $aWhere = ['article_id' => $iArticleId,'is_delete' => 2]; - $aAiArticle = Db::name('ai_article')->field('title_chinese as title,author,journal_issn,digest')->where($aWhere)->find(); + $aAiArticle = Db::name('ai_article')->field('ai_article_id,title_chinese as title,journal_issn,digest,article_type')->where($aWhere)->find(); if(empty($aAiArticle)){ return json_encode(['status' => 3, 'msg' => 'The article does not exist']); } @@ -1087,9 +1143,17 @@ class Aiarticle extends Base if(empty($sWechatId)){ return json_encode(['status' => 2, 'msg' => 'Please select the WeChat official account to push']); } + + //获取模版 + $sTemplate = empty($aAiArticle['article_type']) ? 'default' : $aAiArticle['article_type'];//文章类型 + if(in_array($sTemplate, ['review','Mini Review'])){ + $sTemplate = "Review"; + } + //查询该模版是否推送到微信公众号 - $aWhere['template_id'] = $iTemplateId; $aWhere['wechat_id'] = $sWechatId; + $aWhere['template_id'] = $sTemplate; + $aWhere['wechat_id'] = $aAiArticle['journal_issn']; $aWechatArticle = Db::name('ai_wechat_article')->where($aWhere)->find(); if(!empty($aWechatArticle)){ return json_encode(['status' => 4, 'msg' => 'Already uploaded to draft box']); @@ -1123,7 +1187,7 @@ class Aiarticle extends Base } $aParam += $aAiArticle; //获取模版生成内容 - $aTemplateParam = ['article_id' => $iArticleId,'template_id' => $iTemplateId,'is_sync' => 1,'wechat_id' => $sWechatId]; + $aTemplateParam = ['article_id' => $iArticleId,'template_id' => $sTemplate,'is_sync' => 1,'wechat_id' => $sWechatId]; $aTemplateParam += $aJournalInfo; $aResult = json_decode($this->getTemplateContent($aTemplateParam),true); $sMsg = empty($aResult['msg']) ? 'The content is empty' : $aResult['msg']; @@ -1134,7 +1198,6 @@ class Aiarticle extends Base //请求微信公众号接口推送 $aParam['content'] = $aData['template']; - $aParam['template_id'] = $iTemplateId; $aParam += $aJournalInfo; $oWechat = new Wechat; $aResult = json_decode($oWechat->addDraft($aParam),true); @@ -1143,7 +1206,7 @@ class Aiarticle extends Base return json_encode($aResult); } //插入记录表 - $aParam = ['media_id' => $aData['media_id'],'update_time' => time(),'template_id' => $iTemplateId,'template_content' => $aParam['content'],'article_id' => $iArticleId,'article_type' => $article_type,'need_open_comment' => $aParam['need_open_comment'],'only_fans_can_comment' => $aParam['only_fans_can_comment'],'template_id' => $iTemplateId,'create_time' => time(),'wechat_id' => $sWechatId]; + $aParam = ['media_id' => $aData['media_id'],'update_time' => time(),'template_id' => $sTemplate,'template_content' => $aParam['content'],'article_id' => $iArticleId,'article_type' => $article_type,'need_open_comment' => $aParam['need_open_comment'],'only_fans_can_comment' => $aParam['only_fans_can_comment'],'create_time' => time(),'wechat_id' => $sWechatId,'ai_article_id' => $aAiArticle['ai_article_id']]; $result = Db::name('ai_wechat_article')->insert($aParam); if($result === false){ return json_encode(['status' => 5,'msg' => "Article data insertion failed"]); @@ -1256,22 +1319,20 @@ class Aiarticle extends Base $aParam = empty($aParam) ? $this->request->post() : $aParam; //文章ID $iArticleId = empty($aParam['article_id'] ) ? '' : $aParam['article_id']; - //模版ID - $iTemplateId = empty($aParam['template_id']) ? '' : $aParam['template_id']; - // //推送公众号Id - // $sWechatId = empty($aParam['wechat_id']) ? '' : $aParam['wechat_id']; //必填参数验证 if(empty($iArticleId)){ return json_encode(['status' => 2, 'msg' => 'Please select an article']); } - if(empty($iTemplateId)){ - return json_encode(['status' => 2, 'msg' => 'Please select a template']); + + //查询文章是否存在 + $aWhere = ['article_id' => $iArticleId,'is_delete' => 2]; + $aAiArticle = Db::name('ai_article')->field('article_type')->where($aWhere)->find(); + if(empty($aAiArticle)){ + return json_encode(['status' => 3, 'msg' => 'The article does not exist']); } - // if(empty($sWechatId)){ - // return json_encode(['status' => 2, 'msg' => 'Please select the WeChat official account to push']); - // } + //查询是否上传到草稿箱 - $aWhere = ['article_id' => $iArticleId,'template_id' => $iTemplateId]; + $aWhere = ['article_id' => $iArticleId,'template_id' => $aAiArticle['article_type']]; $aWechatArticle = Db::name('ai_wechat_article')->field('id,is_publish,media_id,publish_status,wechat_id')->where($aWhere)->find(); $sMediaId = empty($aWechatArticle['media_id']) ? '' : $aWechatArticle['media_id']; if(empty($sMediaId)){ @@ -1293,7 +1354,6 @@ class Aiarticle extends Base $aJournalInfo = $this->aWechatConfig; } $aJournalInfo['media_id'] = $sMediaId; - //调用发布接口 $oWechat = new Wechat; $aResult = json_decode($oWechat->publishDraft($aJournalInfo),true); @@ -1428,16 +1488,11 @@ class Aiarticle extends Base //文章ID $iArticleId = empty($aParam['article_id']) ? '' : $aParam['article_id']; - //模版ID - $iTemplateId = empty($aParam['template_id']) ? '' : $aParam['template_id']; //必填参数验证 if(empty($iArticleId)){ return json_encode(['status' => 2, 'msg' => 'Please select an article']); } - if(empty($iTemplateId)){ - return json_encode(['status' => 2, 'msg' => 'Please select a template']); - } //获取AI生成文章内容 $aAiContent = json_decode($this->getAiArticle(['article_id' => $iArticleId,'is_select_author' => 1]),true); @@ -1447,8 +1502,6 @@ class Aiarticle extends Base if(empty($aAiArticle)){ return json_encode(['status' => 3, 'msg' => 'The article content of WeChat official account has not been generated']); } - //模版ID - $iTemplateId = empty($iTemplateId) ? $aAiArticle['template_id'] : $iTemplateId; //获取文章内容 $aResult = json_decode($this->getArticle($iArticleId),true); @@ -1474,8 +1527,14 @@ class Aiarticle extends Base //文章图片 $sArticleIcon = trim($this->sJournalUsx,'/').$this->sArticleIcon.$aArticle['article_icon']; + + //子期刊数据 + $aJournalStage = empty($aArticleContent['journal_stage']) ? [] : $aArticleContent['journal_stage']; //期刊图片 - $sJournalIcon = trim($this->sJournalUsx,'/').$this->sJournalIcon.$aJournal['journal_icon']; + $sJournalStageIcon = empty($aJournalStage['stage_icon']) ? '' : '/public/'.$aJournalStage['stage_icon']; + $sJournalIcon = empty($aJournal['journal_icon']) ? '' : $this->sJournalIcon.$aJournal['journal_icon']; + $sJournalIcon = empty($sJournalStageIcon) ? $sJournalIcon : $sJournalStageIcon; + $sJournalIcon = trim($this->sJournalUsx,'/').$sJournalIcon; //期刊编辑二维码 $editor_qrcode = empty($aJournal['editor_qrcode']) ? '' : $aJournal['editor_qrcode']; @@ -1483,6 +1542,7 @@ class Aiarticle extends Base //获取期刊二维码 $oMaterial = new Material; + $aJournal['journal_stage_id'] = empty($aArticle['journal_stage_id']) ? 0 : $aArticle['journal_stage_id']; $aJournalQrCode = $oMaterial->createJournalQrCode($aJournal); $sJournalCode = empty($aJournalQrCode['qrcode_url']) ? '' : $this->sSubmissionUrl.'public/qrcode/'.$aJournalQrCode['qrcode_url']; $aAiArticle['journal_qrcode'] = $sJournalCode; @@ -1500,7 +1560,7 @@ class Aiarticle extends Base $aUpload['article_info'] = ['icon' => $sArticleIcon]; //组装期刊数据 - $aUpload['journal_info'] = ['icon' => $sJournalIcon,'editor_qrcode' => $editor_qrcode]; + $aUpload['journal_info'] = ['icon' => $sJournalIcon,'editor_qrcode' => $editor_qrcode,'journal_stage_id' => $aArticle['journal_stage_id']]; //组装作者数据 if(!empty($aAuthor)){ @@ -1509,7 +1569,44 @@ class Aiarticle extends Base //上传微信公众号用到的素材 $aUpload += ['article_id' => $iArticleId,'journal_id' => $aArticle['journal_id'],'wechat_app_id' => $sWechatAppId,'wechat_app_secret' => $sWechatAppSecret]; $oMaterial = new Material; - return $oMaterial->uploadMaterial($aUpload); + $aResult = json_decode($oMaterial->uploadMaterial($aUpload),true); + $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; + if($iStatus != 1){ + return json_encode($aResult); + } + Queue::later(60,'app\api\job\WechatDraft@fire', ['article_id' => $iArticleId], 'uploadDraft'); } + /** + * 对接微信公众号日志 + */ + public function addWechatLog($aParam = []){ + //获取参数 + $aParam = empty($aParam) ? $this->request->post() : $aParam; + //必填参数验证 + if(empty($aParam['article_id']) || empty($aParam['type'])){ + return json_encode(['status' => 2, 'msg' => '非法操作']); + } + $result = Db::name('wechat_api_log')->insertGetId($aParam); + if($result === false){ + return json_encode(['status' => 3, 'msg' => '数据插入失败'.Db::getLastSql()."\n数据内容:",'data' => $aParam]); + } + return json_encode(['status' => 1, 'msg' => '日志插入成功']); + } + + /** + * 获取文章对应模版 + */ + + private function writeFile($sContent,$sPath = ''){ + + $chunkSize = 1024 * 1024; // 例如,每次写入1MB + $file = fopen($sPath, "w"); + for ($i = 0; $i < strlen($sContent); $i += $chunkSize) { + $chunk = substr($sContent, $i, $chunkSize); + fwrite($file, $chunk); + } + + fclose($file); + } } diff --git a/application/api/controller/Cronwechat.php b/application/api/controller/Cronwechat.php index e0ee6be..bedd837 100644 --- a/application/api/controller/Cronwechat.php +++ b/application/api/controller/Cronwechat.php @@ -75,9 +75,11 @@ class Cronwechat extends Controller } //插入操作日志 if(!empty($aLog)){ - $result = Db::name('wechat_crontab_log')->insertAll($aLog); - if($result === false){ - $this->showMessage('插入日志记录失败:'.json_encode($aLog)."\n",2); + $result = json_decode($oAiarticle->addWechatLog($aLog)); + $iStatus = empty($result['status']) ? 0 : $result['status']; + $sMsg = empty($result['msg']) ? '插入日志记录失败' : $result['msg']; + if($iStatus != 1){ + $this->showMessage($sMsg,2); } } $this->showMessage('AI生成的文章推送草稿箱完成:'.$sDate."\n",1); @@ -138,9 +140,11 @@ class Cronwechat extends Controller } //插入操作日志 if(!empty($aLog)){ - $result = Db::name('wechat_crontab_log')->insertAll($aLog); - if($result === false){ - $this->showMessage('插入日志记录失败:'.json_encode($aLog)."\n",2); + $result = json_decode($oAiarticle->addWechatLog($aLog)); + $iStatus = empty($result['status']) ? 0 : $result['status']; + $sMsg = empty($result['msg']) ? '插入日志记录失败' : $result['msg']; + if($iStatus != 1){ + $this->showMessage($sMsg,2); } } $this->showMessage('AI生成的文章发布草稿箱完成:'.$sDate."\n",1); @@ -197,9 +201,11 @@ class Cronwechat extends Controller } //插入操作日志 if(!empty($aLog)){ - $result = Db::name('wechat_crontab_log')->insertAll($aLog); - if($result === false){ - $this->showMessage('插入日志记录失败:'.json_encode($aLog)."\n",2); + $result = json_decode($oAiarticle->addWechatLog($aLog)); + $iStatus = empty($result['status']) ? 0 : $result['status']; + $sMsg = empty($result['msg']) ? '插入日志记录失败' : $result['msg']; + if($iStatus != 1){ + $this->showMessage($sMsg,2); } } $this->showMessage('AI生成的文章发布状态查询完成:'.$sDate."\n",1); diff --git a/application/api/controller/Reviewer.php b/application/api/controller/Reviewer.php index 08358a8..94461c9 100644 --- a/application/api/controller/Reviewer.php +++ b/application/api/controller/Reviewer.php @@ -1799,56 +1799,174 @@ class Reviewer extends Base * @param name:pageIndex type:int require:1 desc:开始页码 * @param name:pageSize type:int require:1 desc:每页是数据条数 */ + // public function getReviewerListByJournal() + // { + // $data = $this->request->post(); + // $editor_info = $this->user_obj->where('account', $data['username'])->where('state', 0)->find(); + // $limit_start = ($data['pageIndex'] - 1) * $data['pageSize']; + // $jous = []; + // $res = []; + // $count = 0; + // if ($data['journalId'] == 0) { + // $jous = $this->journal_obj->where('editor_id', $editor_info['user_id'])->where('state', 0)->column('journal_id'); + // } else { + // $jous[] = $data['journalId']; + // } + // $gradewhere = ''; + // if(isset($data['grade'])){ + // $gradewhere = 't_reviewer_to_journal.grade = "'.$data['grade'].'"'; + // } + // if (isset($data['keyword'])) { + // $res = $this->reviewer_to_journal_obj + // ->field('t_reviewer_to_journal.is_yboard,t_user.*,t_reviewer_to_journal.grade,t_user_reviewer_info.*,t_journal.journal_id,t_journal.title journal_title') + // ->join('t_journal', 't_journal.journal_id = t_reviewer_to_journal.journal_id', 'left') + // ->join('t_user', 't_user.user_id = t_reviewer_to_journal.reviewer_id', 'left') + // ->join('t_user_reviewer_info', 't_user_reviewer_info.reviewer_id = t_reviewer_to_journal.reviewer_id', 'LEFT') + // ->where('t_reviewer_to_journal.journal_id', 'in', $jous) + // ->where($gradewhere) + // ->where('t_reviewer_to_journal.state', 0) + // ->where("t_user.account|t_user.email", "like", '%' . $data['keyword'] . '%') + // ->limit($limit_start, $data['pageSize']) + // ->select(); + // $count = $this->reviewer_to_journal_obj->join('t_user', 't_user.user_id = t_reviewer_to_journal.reviewer_id', 'left')->join('t_user_reviewer_info', 't_user_reviewer_info.reviewer_id = t_reviewer_to_journal.reviewer_id', 'LEFT')->where('t_reviewer_to_journal.journal_id', 'in', $jous)->where($gradewhere)->where('t_reviewer_to_journal.state', 0)->where("t_user.account|t_user.email", "like", '%' . $data['keyword'] . '%')->count(); + // } else { + // $res = $this->reviewer_to_journal_obj + // ->field('t_reviewer_to_journal.is_yboard,t_user.*,t_reviewer_to_journal.grade,t_user_reviewer_info.*,t_journal.journal_id,t_journal.title journal_title') + // ->join('t_journal', 't_journal.journal_id = t_reviewer_to_journal.journal_id', 'left') + // ->join('t_user', 't_user.user_id = t_reviewer_to_journal.reviewer_id', 'left') + // ->join('t_user_reviewer_info', 't_user_reviewer_info.reviewer_id = t_reviewer_to_journal.reviewer_id', 'LEFT') + // ->where('t_reviewer_to_journal.journal_id', 'in', $jous) + // ->where($gradewhere) + // ->where('t_reviewer_to_journal.state', 0) + // ->limit($limit_start, $data['pageSize']) + // ->select(); + // $count = $this->reviewer_to_journal_obj->where('t_reviewer_to_journal.journal_id', 'in', $jous)->where($gradewhere)->where('t_reviewer_to_journal.state', 0)->count(); + // } + // foreach($res as $k => $v){ + // $res[$k]['major_title'] = getMajorStr($v['major']); + // $res[$k]['cvs'] = $this->getCvs($v['user_id']); + // } + // return json(['code' => 0, 'data' => $res, 'total' => $count]); + // } + public function getReviewerListByJournal() { $data = $this->request->post(); - $editor_info = $this->user_obj->where('account', $data['username'])->where('state', 0)->find(); - $limit_start = ($data['pageIndex'] - 1) * $data['pageSize']; + $sUserName = empty($data['username']) ? '' : $data['username']; + if(!empty($sUserName)){ + $editor_info = $this->user_obj->where('account', $data['username'])->where('state', 0)->find(); + } + + //每页显示数据 + $iSize = empty($data['pageSize']) ? 15 : $data['pageSize']; + //当前页 + $iPage = empty($data['pageIndex']) ? 1 : $data['pageIndex']; + $iOffset = ($iPage - 1) * $iSize; + $jous = []; - $res = []; - $count = 0; - if ($data['journalId'] == 0) { - $jous = $this->journal_obj->where('editor_id', $editor_info['user_id'])->where('state', 0)->column('journal_id'); + if(empty($data['journalId'])) { + if(!empty($editor_info['user_id'])){ + $jous = $this->journal_obj->where('editor_id', $editor_info['user_id'])->where('state', 0)->column('journal_id'); + } } else { $jous[] = $data['journalId']; } - $gradewhere = ''; - if(isset($data['grade'])){ - $gradewhere = 't_reviewer_to_journal.grade = "'.$data['grade'].'"'; - } - if (isset($data['keyword'])) { - $res = $this->reviewer_to_journal_obj - ->field('t_reviewer_to_journal.is_yboard,t_user.*,t_reviewer_to_journal.grade,t_user_reviewer_info.*,t_journal.journal_id,t_journal.title journal_title') - ->join('t_journal', 't_journal.journal_id = t_reviewer_to_journal.journal_id', 'left') - ->join('t_user', 't_user.user_id = t_reviewer_to_journal.reviewer_id', 'left') - ->join('t_user_reviewer_info', 't_user_reviewer_info.reviewer_id = t_reviewer_to_journal.reviewer_id', 'LEFT') - ->where('t_reviewer_to_journal.journal_id', 'in', $jous) - ->where($gradewhere) - ->where('t_reviewer_to_journal.state', 0) - ->where("t_user.account|t_user.email", "like", '%' . $data['keyword'] . '%') - ->limit($limit_start, $data['pageSize']) - ->select(); - $count = $this->reviewer_to_journal_obj->join('t_user', 't_user.user_id = t_reviewer_to_journal.reviewer_id', 'left')->join('t_user_reviewer_info', 't_user_reviewer_info.reviewer_id = t_reviewer_to_journal.reviewer_id', 'LEFT')->where('t_reviewer_to_journal.journal_id', 'in', $jous)->where($gradewhere)->where('t_reviewer_to_journal.state', 0)->where("t_user.account|t_user.email", "like", '%' . $data['keyword'] . '%')->count(); - } else { - $res = $this->reviewer_to_journal_obj - ->field('t_reviewer_to_journal.is_yboard,t_user.*,t_reviewer_to_journal.grade,t_user_reviewer_info.*,t_journal.journal_id,t_journal.title journal_title') - ->join('t_journal', 't_journal.journal_id = t_reviewer_to_journal.journal_id', 'left') - ->join('t_user', 't_user.user_id = t_reviewer_to_journal.reviewer_id', 'left') - ->join('t_user_reviewer_info', 't_user_reviewer_info.reviewer_id = t_reviewer_to_journal.reviewer_id', 'LEFT') - ->where('t_reviewer_to_journal.journal_id', 'in', $jous) - ->where($gradewhere) - ->where('t_reviewer_to_journal.state', 0) - ->limit($limit_start, $data['pageSize']) - ->select(); - $count = $this->reviewer_to_journal_obj->where('t_reviewer_to_journal.journal_id', 'in', $jous)->where($gradewhere)->where('t_reviewer_to_journal.state', 0)->count(); - } - foreach($res as $k => $v){ - $res[$k]['major_title'] = getMajorStr($v['major']); - $res[$k]['cvs'] = $this->getCvs($v['user_id']); - } - return json(['code' => 0, 'data' => $res, 'total' => $count]); - } + + //查询基本条件 + $aWhere = ['journal_id' => ['in',$jous],'state' => 0]; + if(!empty($data['grade'])){ + $aWhere['grade'] = trim($data['grade']); + } + + //根据邮箱查询 + if(!empty($data['keyword'])){ + $aUserId = Db::name('user')->where(['email'=>['like','%' . $data['keyword'] . '%'],'state' => 0])->column('user_id'); + if(empty($aUserId)){ + return json(['code' => 0, 'data' => [], 'total' => 0]); + } + $aWhere['reviewer_id'] = ['in',$aUserId]; + } + + //根据领域 + if(!empty($data['user_field'])){ + $aMajorWhere = ['state' => 0,'major_id' => $data['user_field']]; + if(!empty($aWhere['reviewer_id'])){ + $aMajorWhere['user_id'] = $aWhere['reviewer_id']; + } + $aUserId = Db::name('major_to_user')->where($aMajorWhere)->order('user_id asc')->column('user_id'); + if(empty($aUserId)){ + return json(['code' => 0, 'data' => [], 'total' => 0]); + } + // $aWhere['t_user.email'] = ['like','%' . $data['keyword'] . '%']; + $aWhere['reviewer_id'] = ['in',$aUserId]; + } + + //获取数量 + $count = $this->reviewer_to_journal_obj->where($aWhere)->count(); + if(empty($count)){ + return json(['code' => 0, 'data' => [], 'total' => 0]); + } + //获取数据详情 + $aResult = $this->reviewer_to_journal_obj + ->field('t_reviewer_to_journal.is_yboard,t_reviewer_to_journal.grade,t_reviewer_to_journal.journal_id,t_reviewer_to_journal.reviewer_id') + ->where($aWhere) + ->limit($iOffset, $iSize) + ->select(); + if(!empty($aResult)){ + //获取期刊信息 + $aJournalId = array_unique(array_column($aResult, 'journal_id')); + $aJournal = Db::name('journal')->where(['journal_id'=>['in',$aJournalId]])->column('journal_id,title'); + + //获取审稿人信息 + $aReviewerId = array_column($aResult, 'reviewer_id'); + $aReviewer = Db::name('user_reviewer_info')->field('reviewer_id,gender,technical,country,introduction,company,website,field,qualifications')->where(['reviewer_id'=>['in',$aReviewerId]])->select(); + $aReviewer = empty($aReviewer) ? [] : array_column($aReviewer, null,'reviewer_id'); + + //用户基本信息 + $aUser = Db::name('user')->field('user_id,account,email,phone,nickname,realname,localname,type,score,remark,wos_index,wos_time,g_author,g_website,google_index,google_time,google_editor,scopus_index,scopus_time,scopus_website,scopus_editor,code,orcid,orcid_code')->where(['user_id'=>['in',$aReviewerId]])->select(); + $aUser = empty($aUser) ? [] : array_column($aUser, null,'user_id'); + + //查询CV + $aUserCv = $this->user_cv_obj->where(['user_id'=>['in',$aReviewerId],'state' =>0])->select(); + if(!empty($aUserCv)){ + $aUserCvArray = []; + foreach ($aUserCv as $key => $value) { + $aUserCvArray[$value['user_id']][] = $value; + } + } + $aUserCv = empty($aUserCv) ? [] : array_column($aUserCv, null,'user_id'); + foreach ($aResult as $key => $value) { + + //期刊信息 + $aJournalInfo = empty($aJournal[$value['journal_id']]) ? [] : $aJournal[$value['journal_id']]; + if(!empty($aJournalInfo['title'])){ + + $aJournalInfo['journal_title'] = $aJournalInfo['title']; + unset($aJournalInfo['title']); + unset($aResult[$key]['journal_id']); + $aResult[$key] += $aJournalInfo; + } + + //审稿人信息 + $aReviewerInfo = empty($aReviewer[$value['reviewer_id']]) ? [] : $aReviewer[$value['reviewer_id']]; + if(!empty($aReviewerInfo)){ + $aResult[$key] += $aReviewerInfo; + } + + //审稿人信息 + $aUserInfo = empty($aUser[$value['reviewer_id']]) ? [] : $aUser[$value['reviewer_id']]; + if(!empty($aUserInfo)){ + $aResult[$key] += $aUserInfo; + } + //用户CVS信息 + $aUserCvInfo = empty($aUserCvArray[$value['reviewer_id']]) ? [] : $aUserCvArray[$value['reviewer_id']]; + $aResult[$key]['cvs'] = empty($aUserCvInfo) ? [] : $aUserCvInfo; + unset($aResult[$key]['reviewer_id']); + } + } + return json(['code' => 0, 'data' => $aResult, 'total' => $count]); + } /** * @title 获取国家 * @description 获取国家 @@ -2132,4 +2250,77 @@ class Reviewer extends Base // $pdf->Output($pdf_wj, 'F'); // return $pdf_wj; // } + + /** + * 获取用户所属领域 + * @param reviewer_id 审核人ID + * @param + */ + public function getUserField($aParam = []){ + + $aParam = empty($aParam) ? $this->request->post() : $this->request->post(); + + if(empty($aParam['user_id'])){ + return json_encode(['status' => 2,'msg' => 'Please select a reviewer']); + } + + //查询审稿人领域信息 + $aParam['state'] = 0; + $aReviewerMajor = Db::name('major_to_user')->field('major_id')->where($aParam)->order('major_id asc')->select(); + if(empty($aReviewerMajor)){ + return json_encode(['status' => 1,'msg' => "Reviewer's field information is empty",'data' => []]); + } + + //数据处理 + foreach ($aReviewerMajor as $key => $value) { + $aReviewerMajor[$key]['major_title'] = getMajorStr($value['major_id']); + } + return json_encode(['status' => 1,'msg' => "Reviewer's field information is empty",'data' => $aReviewerMajor]); + } + /** + * 修改用户所属领域 + * @param reviewer_id 审核人ID + * @param + */ + public function updateUserField($aParam = []){ + + $aParam = empty($aParam) ? $this->request->post() : $this->request->post(); + $iUserId = empty($aParam['user_id']) ? 0 : $aParam['user_id']; + if(empty($iUserId)){ + return json_encode(['status' => 2,'msg' => 'Please select a reviewer']); + } + $sField = empty($aParam['user_field']) ? '' : $aParam['user_field']; + if(empty($sField)){ + return json_encode(['status' => 2,'msg' => "Please select the user's field of expertise"]); + } + $aField = is_array($sField) ? $sField : explode(',', trim($sField,',')); + if(empty($aField)){ + return json_encode(['status' => 3,'msg' => "Please select the user's field of expertise"]); + } + //查询审稿人领域信息 + $aWhere = ['state' => 0,'user_id' => $iUserId]; + $aReviewerMajor = Db::name('major_to_user')->where($aWhere)->order('major_id asc')->column('major_id'); + + //新增 + $aInsert = array_diff($aField,$aReviewerMajor); + //删除 + $aDelete = array_diff($aReviewerMajor,$aField); + + //数据处理 + Db::startTrans(); + if(!empty($aInsert)){//新增 + foreach ($aInsert as $key => $value) { + $aAdd[] = ['major_id' => $value,'user_id' => $iUserId,'ctime' => time(),'state' => 0]; + } + $result = Db::name('major_to_user')->insertAll($aAdd); + echo Db::getLastSql(); + } + if(!empty($aDelete)){//修改状态为1 + $aWhere = ['user_id' => $iUserId,'state' => 0,'major_id' => ['in',$aDelete]]; + $result = Db::name('major_to_user')->where($aWhere)->limit(count($aDelete))->update(['state' => 1,'ctime' => time()]); + echo Db::getLastSql(); + } + Db::commit(); + return json_encode(['status' => 1,'msg' => "Reviewer's field has been successfully modified"]); + } } diff --git a/application/common/Material.php b/application/common/Material.php index 7309997..7a8b82f 100644 --- a/application/common/Material.php +++ b/application/common/Material.php @@ -39,11 +39,11 @@ class Material * @param aJournal 期刊信息 */ public function createJournalQrCode($aJournal = []){ - $iJournalId = empty($aJournal['journal_id']) ? 0 : $aJournal['journal_id']; + $iJournalStageId = empty($aJournal['journal_stage_id']) ? 0 : $aJournal['journal_stage_id']; //生成图片地址 - $sImagePath = 'journal/'.$iJournalId.'.jpg'; + $sImagePath = 'journal/'.$iJournalId.'_'.$iJournalStageId.'.jpg'; $sQrCodeUrl = ROOT_PATH.$this->sQrCodeUrl.$sImagePath; //地址 @@ -56,15 +56,15 @@ class Material $sImg = QrCodeImage::generate($sUrl,500,$sQrCodeUrl); }else{ $sLogo = trim($this->sJournalUsx,'/').$this->sJournalIcon.$sLogo; - $aImageInfo = json_decode($this->getImage($sLogo,$iJournalId,'journal'),true); - if(empty($aImageInfo['data'])){ + $aImageInfo = json_decode($this->getImage($sLogo,$iJournalId.'_'.$iJournalStageId,'journal'),true); + // if(empty($aImageInfo['data'])){ $sImg = QrCodeImage::generate($sUrl,500,$sQrCodeUrl); - } - $sImg = QrCodeImage::withLogo($sUrl,$aImageInfo['data'],500,100, $sQrCodeUrl); + // } + // $sImg = QrCodeImage::withLogo($sUrl,$aImageInfo['data'],500,100, $sQrCodeUrl); } //插入字段 - $aInsertParam = ['journal_id' => $iJournalId,'qrcode_url' => $sImagePath,'create_time' => time(),'update_time' => time()]; + $aInsertParam = ['journal_id' => $iJournalId,'journal_stage_id' => $iJournalStageId,'qrcode_url' => $sImagePath,'create_time' => time(),'update_time' => time()]; $sStartSql = 'INSERT INTO t_ai_journal_qrcode ('.implode(',', array_keys($aInsertParam)).') VALUES ('; $sEndSql = ') ON DUPLICATE KEY UPDATE update_time = VALUES(update_time)'; @@ -100,10 +100,10 @@ class Material }else{ $sLogo = trim($this->sJournalUsx,'/').$this->sArticleIcon.$sLogo; $aImageInfo = json_decode($this->getImage($sLogo,$iArticleId,'article'),true); - if(empty($aImageInfo['data'])){ + // if(empty($aImageInfo['data'])){ $sImg = QrCodeImage::generate($sUrl,500,$sQrCodeUrl); - } - $sImg = QrCodeImage::withLogo($sUrl,$aImageInfo['data'],500,100, $sQrCodeUrl); + // } + // $sImg = QrCodeImage::withLogo($sUrl,$aImageInfo['data'],500,100, $sQrCodeUrl); } //插入字段 @@ -230,6 +230,9 @@ class Material //期刊ID $iJournalId = empty($aParam['journal_id']) ? '' : $aParam['journal_id']; + //子期刊ID + $iJournalStageId = empty($aParam['journal_stage_id']) ? 0 : $aParam['journal_stage_id']; + //期刊图片 $sIcon = empty($aParam['icon']) ? '' : $aParam['icon']; if(empty($iJournalId) || empty($sIcon)){ @@ -239,10 +242,10 @@ class Material $aImageInfo = pathinfo($sIcon); //图片后缀名 $sExtension = empty($aImageInfo['extension']) ? 'jpg' : $aImageInfo['extension']; - $sImagePath = 'journal/imgae_'.$iJournalId.'.'.$sExtension; + $sImagePath = 'journal/imgae_'.$iJournalId.'_'.$iJournalStageId.'.'.$sExtension; $sImagePath = ROOT_PATH.$this->sQrCodeUrl.$sImagePath; if (!file_exists($sImagePath)) {//下载图片 - $aImageInfo = json_decode($this->getImage($sIcon,$iJournalId,'journal'),true); + $aImageInfo = json_decode($this->getImage($sIcon,$iJournalId.'_'.$iJournalStageId,'journal'),true); if(empty($aImageInfo['data'])){ return json_encode(['status' => 3,'msg' => 'Image download failed']); } @@ -266,7 +269,7 @@ class Material $iTime = empty($aUploadResult['created_at']) ? time() : $aUploadResult['created_at']; //入库数据组装 - $aInsert = ['type' => 'image','media_id' => $sMediaId,'create_time' => $iTime,'journal_id' => $iJournalId,'media_url' => $sMediaUrl,'update_time' => $iTime]; + $aInsert = ['type' => 'image','media_id' => $sMediaId,'create_time' => $iTime,'journal_id' => $iJournalId,'media_url' => $sMediaUrl,'update_time' => $iTime,'journal_stage_id' => $iJournalStageId]; $sStartSql = 'INSERT INTO t_ai_journal_material ('.implode(',', array_keys($aInsert)).') VALUES ('; $sEndSql = ') ON DUPLICATE KEY UPDATE update_time = VALUES(update_time),media_id = VALUES(media_id),media_url = VALUES(media_url)'; @@ -286,13 +289,18 @@ class Material //期刊ID $iJournalId = empty($aParam['journal_id']) ? '' : $aParam['journal_id']; + //子期刊ID + $iJournalStageId = empty($aParam['journal_stage_id']) ? 0 : $aParam['journal_stage_id']; if(empty($iJournalId)){ return json_encode(['status' => 2,'msg' => 'journal_id or image is empty']); } //查询是否生成二维码 $aWhere = ['journal_id' => $iJournalId,'is_delete' => 2]; - $aMaterial = Db::name('ai_journal_qrcode')->field('qrcode_url,media_id,media_url')->where($aWhere)->find(); + if(!empty($iJournalStageId)){ + $aWhere['journal_stage_id'] = $iJournalStageId; + } + $aMaterial = Db::name('ai_journal_qrcode')->field('id,qrcode_url,media_id,media_url')->where($aWhere)->find(); if(empty($aMaterial)){ return json_encode(['status' => 3,'msg' => 'data is null']); } @@ -315,7 +323,7 @@ class Material $sMediaUrl = empty($aData['url']) ? [] : $aData['url']; $iTime = empty($aUploadResult['created_at']) ? time() : $aUploadResult['created_at']; $aUpdate = ['media_id' => $sMediaId,'media_url' => $sMediaUrl,'update_time' => $iTime]; - $response = Db::name('ai_journal_qrcode')->where('journal_id',$iJournalId)->limit(1)->update($aUpdate); + $response = Db::name('ai_journal_qrcode')->where('id',$aMaterial['id'])->limit(1)->update($aUpdate); if($response === false){ return json_encode(['status' => 3,'msg' => 'fail']); } @@ -581,7 +589,7 @@ class Material //获取期刊信息 $aJournal = empty($aParam['journal_info']) ? [] : $aParam['journal_info']; //上传期刊素材相关参数组装 - $aJournalParam = ['journal_id' => $iJournalId,'icon' => empty($aJournal['icon']) ? '' : $aJournal['icon'],'editor_qrcode' => empty($aJournal['editor_qrcode']) ? '' : $aJournal['editor_qrcode']]; + $aJournalParam = ['journal_id' => $iJournalId,'icon' => empty($aJournal['icon']) ? '' : $aJournal['icon'],'editor_qrcode' => empty($aJournal['editor_qrcode']) ? '' : $aJournal['editor_qrcode'],'journal_stage_id' => empty($aJournal['journal_stage_id']) ? 0 : $aJournal['journal_stage_id']]; $aJournalParam += $aWechatParam; //上传期刊图片 if(!empty($aJournalParam['icon']) && $sStepName == 'addJournalMaterial'){ diff --git a/application/common/Wechat.php b/application/common/Wechat.php index 5c1dcd9..9b1b905 100644 --- a/application/common/Wechat.php +++ b/application/common/Wechat.php @@ -184,16 +184,7 @@ class Wechat if(empty($iArticleId)){ return json_encode(['status' => 2,'msg' => 'article_id is empty']); } - //模版ID - $iTemplateId = empty($aParam['template_id']) ? '' : $aParam['template_id']; - if(empty($iTemplateId)){ - return json_encode(['status' => 2,'msg' => 'Template ID is empty']); - } - // //发布公众号ID - // $sWechatId = empty($aParam['wechat_id']) ? 0 : $aParam['wechat_id']; - // if(empty($sWechatId)){ - // return json_encode(['status' => 2,'msg' => 'Please select the official account to be pushed']); - // } + //生成模版内容 $sContent = empty($aParam['content']) ? '' : $aParam['content']; if(empty($sContent)){