1
This commit is contained in:
294
application/master/controller/Board.php
Normal file
294
application/master/controller/Board.php
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
|
||||
namespace app\master\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Queue;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* @title 文章接口
|
||||
* @description 文章相关操作
|
||||
* @group 文章相关
|
||||
*/
|
||||
class Board extends Controller {
|
||||
|
||||
//put your code here
|
||||
protected $admin_obj = '';
|
||||
protected $journal_obj = '';
|
||||
protected $board_obj = '';
|
||||
protected $board_group_obj = '';
|
||||
protected $article_obj = '';
|
||||
protected $article_author_obj = '';
|
||||
protected $article_organ_obj = '';
|
||||
protected $article_ltai_obj = '';
|
||||
protected $article_cite_obj = '';
|
||||
protected $author_to_organ_obj = '';
|
||||
protected $article_to_topic_obj = '';
|
||||
protected $journal_topic_obj = '';
|
||||
protected $journal_stage_obj = '';
|
||||
protected $journal_special_obj = '';
|
||||
protected $country_obj = '';
|
||||
protected $subscribe_journal_obj = '';
|
||||
protected $subscribe_topic_obj = '';
|
||||
protected $base_topic_obj = '';
|
||||
protected $subscribe_base_topic_obj = '';
|
||||
protected $medicament_obj = '';
|
||||
protected $article_to_medicament_obj = '';
|
||||
|
||||
public function __construct(\think\Request $request = null) {
|
||||
parent::__construct($request);
|
||||
$this->admin_obj = Db::name('admin');
|
||||
$this->journal_obj = Db::name('journal');
|
||||
$this->board_obj = Db::name('board');
|
||||
$this->board_group_obj = Db::name('board_group');
|
||||
$this->article_obj = Db::name('article');
|
||||
$this->article_author_obj = Db::name('article_author');
|
||||
$this->article_organ_obj = Db::name('article_organ');
|
||||
$this->article_ltai_obj = Db::name('article_ltai');
|
||||
$this->article_cite_obj = Db::name('article_cite');
|
||||
$this->author_to_organ_obj = Db::name('article_author_to_organ');
|
||||
$this->article_to_topic_obj = Db::name('article_to_topic');
|
||||
$this->journal_topic_obj = Db::name('journal_topic');
|
||||
$this->journal_stage_obj = Db::name('journal_stage');
|
||||
$this->journal_special_obj = Db::name('journal_special');
|
||||
$this->country_obj = Db::name('country');
|
||||
$this->subscribe_journal_obj = Db::name('subscribe_journal');
|
||||
$this->subscribe_topic_obj = Db::name('subscribe_topic');
|
||||
$this->base_topic_obj = Db::name('base_topic');
|
||||
$this->subscribe_base_topic_obj = Db::name('subscribe_base_topic');
|
||||
$this->medicament_obj = Db::name('medicament');
|
||||
$this->article_to_medicament_obj = Db::name('ArticleToMedicament');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取编委列表
|
||||
*/
|
||||
public function getBoardListForSubmit(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'issn'=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
|
||||
$journal_info = $this->journal_obj->where('issn',$data['issn'])->find();
|
||||
$where['journal_id'] = $journal_info['journal_id'];
|
||||
$where['state'] = 0;
|
||||
if($data['board_group_id']!=-1){
|
||||
$where['board_group_id'] = $data['board_group_id'];
|
||||
}
|
||||
$boards = $this->board_obj->where($where)->order(['type asc','name'])->select();
|
||||
$re['boards'] = $boards;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取编委分组信息
|
||||
*/
|
||||
public function getBoardGroups(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'issn'=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$journal_info = $this->journal_obj->where('issn',$data['issn'])->find();
|
||||
$groups = $this->board_group_obj->where('journal_id',$journal_info['journal_id'])->where('state',0)->select();
|
||||
foreach($groups as $k => $v){
|
||||
$cache_num = $this->board_obj->where('journal_id',$journal_info['journal_id'])
|
||||
->where('state',0)
|
||||
->where('board_group_id',$v['board_group_id'])->count();
|
||||
$groups[$k]['person_num'] = $cache_num;
|
||||
}
|
||||
$re['groups'] = $groups;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除编委分组
|
||||
*/
|
||||
public function delBoardGroup(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'board_group_id'=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$check = $this->board_obj->where('board_group_id',$data['board_group_id'])->where('state',0)->find();
|
||||
if($check){
|
||||
return jsonError('The editor can not delete the group if there is at least one occupied member.');
|
||||
}
|
||||
$this->board_group_obj->where('board_group_id',$data['board_group_id'])->update(['state'=>1]);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加编委分组
|
||||
*/
|
||||
public function addBoardGroup(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'issn'=>'require',
|
||||
'group_name'=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$journal_info = $this->journal_obj->where('issn',$data['issn'])->find();
|
||||
$insert['journal_id'] = $journal_info['journal_id'];
|
||||
$insert['group_name'] = $data['group_name'];
|
||||
$this->board_group_obj->insert($insert);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取编委详情
|
||||
*/
|
||||
public function getBoardDetail(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'board_id'=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$board_info = $this->board_obj->where('board_id',$data['board_id'])->find();
|
||||
$re['board'] = $board_info;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加编委
|
||||
*/
|
||||
public function addBoard(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'user_id'=>'require',
|
||||
'journal_issn'=>'require',
|
||||
'type'=>'require',
|
||||
'name'=>'require',
|
||||
'website'=>'require',
|
||||
'dr'=>'require',
|
||||
'email'=>'require',
|
||||
'title'=>'require',
|
||||
'field'=>'require',
|
||||
'address'=>'require',
|
||||
'country'=>'require',
|
||||
'board_group_id'=>'require',
|
||||
'board_icon'=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
|
||||
$journal_info = $this->journal_obj->where('issn',$data['journal_issn'])->find();
|
||||
$check = $this->board_obj->where('journal_id',$journal_info['journal_id'])->where('tuser_id',$data['user_id'])->where('state',0)->find();
|
||||
if($check){
|
||||
return jsonError('Add repeatedly');
|
||||
}
|
||||
|
||||
// 处理图片
|
||||
if(!is_dir(ROOT_PATH.'public'.DS.'boardIcon'.DS.date('Ymd'))){
|
||||
mkdir(ROOT_PATH.'public'.DS.'boardIcon'.DS.date('Ymd'));
|
||||
}
|
||||
$file_name = substr($data['board_icon'],strripos($data['board_icon'],'/')+1);
|
||||
$co = @copy("http://api.tmrjournals.com/public/".$data['board_icon'],ROOT_PATH.'public'.DS.'boardIcon'.DS.date('Ymd').DS.$file_name);
|
||||
|
||||
$insert['journal_id'] = $data['journal_id'];
|
||||
$insert['type'] = $data['type'];
|
||||
$insert['email'] =$data['email'];
|
||||
$insert['name'] = trim($data['name']);
|
||||
$insert['website'] = trim($data['website']);
|
||||
$insert['dr'] = $data['dr'];
|
||||
$insert['field'] = trim($data['field']);
|
||||
$insert['title'] = $data['title'];
|
||||
$insert['address'] = trim($data['address']);
|
||||
$insert['country'] = trim($data['country']);
|
||||
$insert['board_icon'] = 'boardIcon'.DS.date('Ymd').DS.$file_name;
|
||||
$insert['board_group_id'] = $data['board_group_id'];
|
||||
$this->board_obj->insert($insert);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
|
||||
public function editBoard(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'board_id'=>'require',
|
||||
'name'=>'require',
|
||||
'board_group_id'=>'require',
|
||||
'website'=>'require',
|
||||
'type'=>'require',
|
||||
'dr'=>'require',
|
||||
'title'=>'require',
|
||||
'field'=>'require',
|
||||
'address'=>'require',
|
||||
'country'=>'require',
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
|
||||
$pra['type'] = $data['type'];
|
||||
$pra['name'] = $data['name'];
|
||||
$pra['website'] = $data['website'];
|
||||
$pra['dr'] = $data['dr'];
|
||||
$pra['title'] = $data['title'];
|
||||
$pra['field'] = $data['field'];
|
||||
$pra['address'] = $data['address'];
|
||||
$pra['country'] = $data['country'];
|
||||
$pra['board_group_id'] = $data['board_group_id'];
|
||||
|
||||
$this->board_obj->where('board_id',$data['board_id'])->update($pra);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
public function delBoard(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'board_id'=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$board_info = $this->board_obj
|
||||
->field("j_board,j_journal.issn")
|
||||
->join('j_journal','j_journal.journal_id = j_board.journal_id','left')
|
||||
->where('board_id',$data['board_id'])
|
||||
->find();
|
||||
$this->board_obj->where('board_id',$data['board_id'])->update(['state'=>1]);
|
||||
|
||||
$re['board'] = $board_info;
|
||||
return jsonSuccess($re);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function editBoardIcon(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'board_id'=>'require',
|
||||
'board_icon'=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
if(!is_dir(ROOT_PATH.'public'.DS.'boardIcon'.DS.date('Ymd'))){
|
||||
mkdir(ROOT_PATH.'public'.DS.'boardIcon'.DS.date('Ymd'));
|
||||
}
|
||||
$file_name = substr($data['board_icon'],strripos($data['board_icon'],'/')+1);
|
||||
$co = @copy("http://api.tmrjournals.com/public/".$data['board_icon'],ROOT_PATH.'public'.DS.'boardIcon'.DS.date('Ymd').DS.$file_name);
|
||||
|
||||
$this->board_obj->where('board_id',$data['board_id'])->update(['board_icon'=>'boardIcon'.DS.date('Ymd').DS.$file_name]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user