Files
tougao/application/api/controller/Journal.php

461 lines
18 KiB
PHP

<?php
namespace app\api\controller;
use app\api\controller\Base;
use think\Validate;
use app\api\controller\User as usercontroller;
use think\Db;
/**
* @title 期刊相关
* @description 期刊相关
*/
class Journal extends Base {
protected $sJournalUrl = 'http://journalapi.tmrjournals.com/public/index.php/';//'http://zmzm.journal.dev.com/';
public function __construct(\think\Request $request = null) {
parent::__construct($request);
}
/**
* @title 获取期刊列表除去审稿人已存在审稿关系
* @description 获取期刊列表除去审稿人已存在审稿关系
* @author wangjinlei
* @url /api/Journal/getJournalOutReviewer
* @method POST
*
* @param name:username type:string require:1 desc:用户名
*
* @return journals:期刊列表#
*/
public function getJournalOutReviewer(){
$data = $this->request->post();
$user_info = $this->user_obj->where("account",$data['username'])->find();
$journalIds = $this->reviewer_to_journal_obj->where('reviewer_id',$user_info['user_id'])->where('state',0)->column('journal_id');
$list = $this->journal_obj->where('journal_id',"not in",$journalIds)->where('state',0)->select();
$re['journals'] = $list;
return jsonSuccess($re);
}
/**
* @title 获取审稿人所属期刊列表
* @description 获取审稿人所属期刊列表
* @author wangjinlei
* @url /api/Journal/getJournalInReviewer
* @method POST
*
* @param name:username type:string require:1 desc:用户名
*
* @return journals:期刊列表#
*/
public function getJournalInReviewer(){
$data = $this->request->post();
$user_info = $this->user_obj->where('account',$data['username'])->where('state',0)->find();
$list = $this->reviewer_to_journal_obj
->field("t_journal.*")
->join('t_journal',"t_journal.journal_id = t_reviewer_to_journal.journal_id","left")
->where('t_reviewer_to_journal.reviewer_id',$user_info['user_id'])
->where('t_reviewer_to_journal.state',0)
->select();
$re['journals'] = $list;
return jsonSuccess($re);
}
public function getAllJournal(){
$list = $this->journal_obj->where('state',0)->select();
//接口请求获取journal_topic 和 abstract_chinese chengxiaoling 20250514 start
if(!empty($list)){
$list = $this->_getJournalForApi($list);
}
//接口请求获取journal_topic 和 abstract_chinese chengxiaoling 20250514 end
$re['journals'] = $list;
return jsonSuccess($re);
}
/**获取连续出刊的当年分期信息
* @return void
*/
public function getJournalStageLX(){
$data = $this->request->post();
$rule = new Validate([
"journal_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$journal_info = $this->journal_obj->where("journal_id",$data['journal_id'])->find();
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Journal/getJournalStageLXForSubmission";
$program['issn'] = $journal_info['issn'];
$res = object_to_array(json_decode(myPost($url,$program)));
$list = $res['data']['detail'];
$re['detail'] = $list;
return jsonSuccess($re);
}
public function creatJournalStage(){
$data = $this->request->post();
$rule = new Validate([
"issn"=>"require",
"stage_year"=>"require",
"stage_vol"=>"require",
"stage_no"=>"require",
"stage_page"=>"require",
"issue_date"=>"require",
"stage_icon"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Journal/addStageForTG";
$program['issn'] = $data['issn'];
$program['stage_year'] = $data['stage_year'];
$program['stage_vol'] = $data['stage_vol'];
$program['stage_no'] = $data['stage_no'];
$program['stage_pagename'] = "No.";
$program['stage_page'] = $data['stage_page'];
$program['issue_date'] = $data['issue_date'];
$program['stage_icon'] = $data['stage_icon'];
object_to_array(json_decode(myPost($url,$program)));
return jsonSuccess($program);
}
public function delJournalStage(){
$data = $this->request->post();
$rule = new Validate([
"journal_stage_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Journal/delStage";
$program['journal_stage_id'] = $data['journal_stage_id'];
$res = object_to_array(json_decode(myPost($url,$program)));
if($res['code']==0){
return jsonSuccess($res);
}else{
return jsonError($res['msg']);
}
}
public function getJournalStageArticles(){
$data = $this->request->post();
$rule = new Validate([
"journal_id" => "require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$journal_info = $this->journal_obj->where("journal_id",$data['journal_id'])->find();
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Journal/getJournalStageArticlesForSubmission";
$program['issn'] = $journal_info['issn'];
$res = object_to_array(json_decode(myPost($url,$program)));
$list = empty($res['data']['list']) ? [] : $res['data']['list'];
//获取微信公众号文章状态 chengxiaoling 20250522 start
if(!empty($list)){
$aArticleId = array_column($list, 'article_id');
$aWechatArticle = $this->getWechatInfo($aArticleId);
$aAiArticle = empty($aWechatArticle['ai_article']) ? [] : $aWechatArticle['ai_article'];
$aAiWechatArticle = empty($aWechatArticle['ai_wechat_article']) ? [] : $aWechatArticle['ai_wechat_article'];
foreach ($list as $key => $val) {
//获取微信公众号文章状态 chengxiaoling 20250522 start
$list[$key]['ai_wechat_status'] = 2; //1 Ai内容已生成 2ai内容未生成
if(in_array($val['article_id'],$aAiArticle)){
$list[$key]['ai_wechat_status'] = 1;
//是否推送到微信
$aDraft = empty($aAiWechatArticle[$val['article_id']]) ? [] : $aAiWechatArticle[$val['article_id']];
$list[$key]['ai_wechat_status'] = empty($aDraft) ? 3 : 4; //3 未生成草稿 4 已生成草稿未发布 10 发布成功 11 发布中 >11发布失败
if(!empty($aDraft)){
foreach ($aDraft as $kk => $value) {
if($kk == '-1'){
$list[$key]['ai_wechat_status'] = 4;
}else{
$list[$key]['ai_wechat_status'] = '1'.$kk;
}
}
}
}
//获取微信公众号文章状态 chengxiaoling 20250522 end
}
}
//获取微信公众号文章状态 chengxiaoling 20250522 end
$re['list'] = $list;
return jsonSuccess($re);
}
public function pushArticleToPublic(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
//推送数据到数据库
$uu = "http://journalapi.tmrjournals.com/public/index.php/master/Datebase/dataPushForLx";
$program['article_id'] = $data['article_id'];
$res = object_to_array(json_decode(myPost($uu,$program)));
//更改文章状态
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Journal/publishArticleForSubmission";
$program['article_id'] = $data['article_id'];
$res = object_to_array(json_decode(myPost($url,$program)));
return jsonSuccess([]);
}
public function editJournalLeftZc(){
$data = $this->request->post();
$rule = new Validate([
"journal_id"=>"require",
"ethics"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->journal_obj->where("journal_id",$data['journal_id'])->update(["ethics"=>$data['ethics']]);
return jsonSuccess([]);
}
/**
* 获取期刊列表
*/
public function getJournalByeditor()
{
$user_id = $this->request->post('user_id');
$list = $this->journal_obj->where('editor_id',$user_id)->where("state",0)->select();
//接口请求获取journal_topic 和 abstract_chinese chengxiaoling 20250514 start
if(!empty($list)){
$list = $this->_getJournalForApi($list);
}
//接口请求获取journal_topic 和 abstract_chinese chengxiaoling 20250514 end
$re['journals'] = $list;
return jsonSuccess($re);
}
/**
* 获取可申请审稿人的期刊
*/
public function getJournalsForReviewerInEditor(){
$data = $this->request->post();
$rule = new Validate([
'editor_id' => 'require',
'reviewer_id' => 'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$editor_info = $this->user_obj->where('user_id',$data['editor_id'])->find();
$journalIds = [];
if($editor_info['type']==2){//责任编辑
$journalIds = $this->journal_obj->where('editor_id',$editor_info['user_id'])->column('journal_id');
}else{//客座编辑
$guests = $this->user_to_special_obj->where('user_id',$data['reviewer_id'])->where('uts_state',0)->select();
$usercontroller = new usercontroller();
foreach($guests as $v){
$c_res = $usercontroller->getSpecialDetailById($v['special_id']);
$journalIds[] = $this->journal_obj->where('issn',$c_res['journal_issn'])->value('journal_id');
}
}
$njournalIds = $this->reviewer_to_journal_obj->where('reviewer_id',$data['reviewer_id'])->where('state',0)->column('journal_id');
$list = $this->journal_obj->where('journal_id',"not in",$njournalIds)->where('journal_id',"in",$journalIds)->where('state',0)->select();
$re['journals'] = $list;
return jsonSuccess($re);
}
public function editJournal(){
$data = $this->request->post();
$rule = new Validate([
'journal_id'=>'require',
'level'=>'require',
'email'=>'require',
'epassword'=>'require',
"kfen"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$journal_info = $this->journal_obj->where("journal_id",$data['journal_id'])->find();
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Journal/editJournalEmailPasswordForSubmission";
$program['issn'] = $journal_info['issn'];
$program['epassword'] = $data['epassword'];
$res = object_to_array(json_decode(myPost($url,$program)));
$update['level'] = $data['level'];
$update['email'] = $data['email'];
$update['epassword'] = $data['epassword'];
$update['kfen'] = $data['kfen'];
//新增字段期刊涵盖主题多个逗号分隔\中文简介\发布作者\编辑二维码 chengxiaoling 20250507 start
if(isset($data['journal_topic'])){
if(is_array($data['journal_topic'])){
$update['journal_topic'] = implode(',', $data['journal_topic']);
}else{
$update['journal_topic'] = $data['journal_topic'];
}
$aJournalUpdate['journal_topic'] = $update['journal_topic'];
}
if(isset($data['abstract_chinese'])){
$update['abstract_chinese'] = $data['abstract_chinese'];
$aJournalUpdate['abstract_chinese'] = $update['abstract_chinese'];
}
if(isset($data['publish_author'])){
$update['publish_author'] = $data['publish_author'];
$aJournalUpdate['publish_author'] = $update['publish_author'];
}
if(isset($data['editor_qrcode'])){
$update['editor_qrcode'] = $data['editor_qrcode'];
$aJournalUpdate['editor_qrcode'] = $update['editor_qrcode'];
}
if(isset($data['wechat_name'])){
$update['wechat_name'] = $data['wechat_name'];
$aJournalUpdate['wechat_name'] = $update['wechat_name'];
}
if(isset($data['wechat_app_id'])){
$update['wechat_app_id'] = $data['wechat_app_id'];
$aJournalUpdate['wechat_app_id'] = $update['wechat_app_id'];
}
if(isset($data['wechat_app_secret'])){
$update['wechat_app_secret'] = $data['wechat_app_secret'];
$aJournalUpdate['wechat_app_secret'] = $update['wechat_app_secret'];
}
if(!empty($aJournalUpdate)){
$aJournalUpdate['issn'] = $journal_info['issn'];
$sUrl = $this->sJournalUrl."wechat/Article/updateJournal";
$program['issn'] = $journal_info['issn'];
$res = object_to_array(json_decode(myPost($sUrl,$aJournalUpdate)));
}
//新增字段期刊涵盖主题多个逗号分隔 chengxiaoling 20250507 end
if(isset($data['fee'])&&$data['fee']!=0){
$update['fee'] = $data['fee'];
}
$update['scope'] = isset($data['scope'])?trim($data['scope']):"";
$this->journal_obj->where('journal_id',$data['journal_id'])->update($update);
return jsonSuccess([]);
}
/**
* 获取期刊详情
*/
public function getJournalDetail(){
$data = $this->request->post();
$rule = new Validate([
'journal_id'=>'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$info = $this->journal_obj->where('journal_id',$data['journal_id'])->find();
$re['journal'] = $info;
return jsonSuccess($re);
}
/**
* 获取期刊详情通过文章id
*/
public function getJournalDetailByArticleId(){
$data = $this->request->post();
$rule = new Validate([
'article_id'=>'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$article_info = $this->article_obj->where('article_id',$data['article_id'])->find();
$info = $this->journal_obj->where('journal_id',$article_info['journal_id'])->find();
$re['journal'] = $info;
return jsonSuccess($re);
}
/**
* 接口请求获取Journal数据库里的期刊话题及中文简介
*/
private function _getJournalForApi($list = []){
if(empty($list)){
return [];
}
$aIssn = array_column($list, 'issn');
$sUrl = $this->sJournalUrl."master/Journal/getJournals";
$aParam['issn'] = $aIssn;
$aResult = object_to_array(json_decode(myPost1($sUrl,$aParam)));
$aData = empty($aResult['data']) ? [] : $aResult['data'];
$aJournal = empty($aData['journals']) ? [] : array_column($aData['journals'],null,'issn');
foreach ($list as $key => $value) {
$aJournalInfo = empty($aJournal[$value['issn']]) ? [] : $aJournal[$value['issn']];
$list[$key]['journal_topic'] = empty($aJournalInfo['journal_topic']) ? '' : $aJournalInfo['journal_topic'];
$list[$key]['abstract_chinese'] = empty($aJournalInfo['abstract_chinese']) ? '' : $aJournalInfo['abstract_chinese'];
$list[$key]['publish_author'] = empty($aJournalInfo['publish_author']) ? '' : $aJournalInfo['publish_author'];
$list[$key]['editor_qrcode'] = empty($aJournalInfo['editor_qrcode']) ? '' : $aJournalInfo['editor_qrcode'];
$list[$key]['wechat_name'] = empty($aJournalInfo['wechat_name']) ? '' : $aJournalInfo['wechat_name'];
$list[$key]['wechat_app_id'] = empty($aJournalInfo['wechat_app_id']) ? '' : $aJournalInfo['wechat_app_id'];
$list[$key]['wechat_app_secret'] = empty($aJournalInfo['wechat_app_secret']) ? '' : $aJournalInfo['wechat_app_secret'];
}
return $list;
}
/**
* 上传期刊编辑的二维码
*/
public function uploadEditorQrcode()
{
$file = request()->file('qrcode_url');
if ($file) {
$info = $file->move(ROOT_PATH . 'public' . DS . 'journaleditorqrcode');
if ($info) {
return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
} else {
return json(['code' => 1, 'msg' => $file->getError()]);
}
}
}
/**
* 获取微信公众号相关数量
*/
public function getWechatInfo($aArticleId){
if(empty($aArticleId)){
return [];
}
//获取文章生成记录
$aWhere = ['article_id' => ['in',$aArticleId],'is_delete' => 2];
$aAiArticle = Db::name('ai_article')->where($aWhere)->column('article_id');
if(!empty($aAiArticle)){
//获取推送到草稿箱否
$aWhere['article_id'] = ['in',$aAiArticle];
$ai_wechat_article = Db::name('ai_wechat_article')->field('article_id,template_id,wechat_id,is_publish,publish_status')->where($aWhere)->select();
if(!empty($ai_wechat_article)){
foreach ($ai_wechat_article as $key => $value) {
$aWechatArticle[$value['article_id']][$value['publish_status']][] = $value['template_id'];
}
}
}
unset($ai_wechat_article);
//返回数据
return ['ai_article' => $aAiArticle,'ai_wechat_article' => empty($aWechatArticle) ? [] : $aWechatArticle];
}
}