This commit is contained in:
177
application/api/controller/Major.php
Normal file
177
application/api/controller/Major.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Queue;
|
||||
|
||||
/**
|
||||
* @title 领域接口
|
||||
* @description 领域接口
|
||||
*/
|
||||
class Major extends Controller{
|
||||
protected $article_obj = '';
|
||||
protected $user_obj = '';
|
||||
protected $user_act_obj = '';
|
||||
protected $journal_obj = '';
|
||||
protected $user_log_obj = '';
|
||||
protected $user_reviewer_info_obj = '';
|
||||
protected $reviewer_major_obj = '';
|
||||
protected $reviewer_to_journal_obj = '';
|
||||
protected $article_reviewer_question_obj = '';
|
||||
protected $article_msg_obj = '';
|
||||
protected $article_file_obj = '';
|
||||
protected $article_reviewer_obj = '';
|
||||
protected $article_author_obj = '';
|
||||
protected $article_transfer_obj = '';
|
||||
protected $chief_to_journal_obj = '';
|
||||
protected $login_auto_obj = '';
|
||||
protected $major_obj = "";
|
||||
|
||||
|
||||
public function __construct(\think\Request $request = null) {
|
||||
parent::__construct($request);
|
||||
$this->user_obj = Db::name('user');
|
||||
$this->user_act_obj = Db::name('user_act');
|
||||
$this->article_obj = Db::name('article');
|
||||
$this->journal_obj = Db::name('journal');
|
||||
$this->user_log_obj = Db::name('user_log');
|
||||
$this->user_reviewer_info_obj = Db::name("user_reviewer_info");
|
||||
$this->reviewer_major_obj = Db::name('reviewer_major');
|
||||
$this->reviewer_to_journal_obj = Db::name('reviewer_to_journal');
|
||||
$this->article_reviewer_question_obj = Db::name('article_reviewer_question');
|
||||
$this->article_msg_obj = Db::name('article_msg');
|
||||
$this->article_file_obj = Db::name('article_file');
|
||||
$this->article_reviewer_obj = Db::name('article_reviewer');
|
||||
$this->article_author_obj = Db::name('article_author');
|
||||
$this->article_transfer_obj = Db::name('article_transfer');
|
||||
$this->chief_to_journal_obj = Db::name('chief_to_journal');
|
||||
$this->login_auto_obj = Db::name('login_auto');
|
||||
$this->major_obj = Db::name("major");
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加领域
|
||||
* @description 添加领域
|
||||
* @author wangjinlei
|
||||
* @url /api/Major/addMajor
|
||||
* @method POST
|
||||
*
|
||||
* @param name:major_title type:string require:1 desc:领域名
|
||||
* @param name:nickname type:string require:0 desc:别称
|
||||
* @param name:major_sort type:int require:0 desc:权重
|
||||
* @param name:pid type:int require:1 desc:父级id(0代表顶级)
|
||||
*
|
||||
*/
|
||||
public function addMajor(){
|
||||
$data = $this->request->post();
|
||||
$insert['major_title'] = trim($data['major_title']);
|
||||
$insert['pid'] = $data['pid'];
|
||||
if(isset($data['nickname'])){
|
||||
$insert['nickname'] = trim($data['nickname']);
|
||||
}
|
||||
if(isset($data['major_sort'])){
|
||||
$insert['major_sort'] = $data['major_sort'];
|
||||
}
|
||||
if($data['pid']==0){
|
||||
$insert['major_level'] = 1;
|
||||
}else{
|
||||
$p_major = $this->major_obj->where('major_id',$data['pid'])->find();
|
||||
$insert['major_level'] = $p_major['major_level']+1;
|
||||
}
|
||||
$insert['major_ctime'] = time();
|
||||
$this->major_obj->insert($insert);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 编辑领域
|
||||
* @description 编辑领域
|
||||
* @author wangjinlei
|
||||
* @url /api/Major/editMajor
|
||||
* @method POST
|
||||
*
|
||||
* @param name:major_id type:int require:1 desc:领域id
|
||||
* @param name:major_title type:string require:1 desc:领域名
|
||||
* @param name:nickname type:string require:0 desc:别称
|
||||
* @param name:major_sort type:int require:0 desc:权重
|
||||
*
|
||||
*/
|
||||
public function editMajor(){
|
||||
$data = $this->request->post();
|
||||
$update['major_title'] = trim($data['major_title']);
|
||||
if(isset($data['nickname'])){
|
||||
$update['nickname'] = trim($data['nickname']);
|
||||
}
|
||||
if(isset($data['major_sort'])){
|
||||
$update['major_sort'] = $data['major_sort'];
|
||||
}
|
||||
$this->major_obj->where("major_id",$data['major_id'])->update($update);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取领域树
|
||||
* @description 获取领域树
|
||||
* @author wangjinlei
|
||||
* @url /api/Major/getMajorList
|
||||
* @method POST
|
||||
*
|
||||
* @return majors:领域树
|
||||
*/
|
||||
public function getMajorList(){
|
||||
//查询顶级
|
||||
$list = $this->major_obj->where('pid',0)->where('major_state',0)->order('major_sort desc')->select();
|
||||
foreach ($list as $k => $v){
|
||||
$cache_child = $this->getMajorChild($v);
|
||||
if($cache_child!=null){
|
||||
$list[$k]['children'] = $cache_child;
|
||||
}
|
||||
}
|
||||
|
||||
$re['majors'] = $list;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加期刊领域
|
||||
* @description 添加期刊领域
|
||||
* @author wangjinlei
|
||||
* @url /api/Major/addJournalMajor
|
||||
* @method POST
|
||||
*
|
||||
* @param name:major_id type:int require:1 desc:领域id
|
||||
* @param name:jou $name Description
|
||||
*
|
||||
* @return majors:领域树
|
||||
*/
|
||||
public function addJournalMajor(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取领域子树
|
||||
*/
|
||||
private function getMajorChild($major){
|
||||
$list = $this->major_obj->where('pid',$major['major_id'])->where('major_state',0)->order("major_sort desc")->select();
|
||||
if($list == null){
|
||||
return null;
|
||||
}
|
||||
foreach ($list as $k => $v){
|
||||
$cache_child = $this->getMajorChild($v);
|
||||
if($cache_child!=null){
|
||||
$list[$k]['children'] = $cache_child;
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user