20201112
This commit is contained in:
@@ -158,7 +158,7 @@ class Major extends Controller {
|
||||
*/
|
||||
public function getMajorList() {
|
||||
//查询顶级
|
||||
$list = $this->major_obj->where('pid', 0)->where('major_state', 0)->order('major_sort desc')->select();
|
||||
$list = $this->major_obj->where('pid', 0)->where("major_type", 0)->where('major_state', 0)->order('major_sort desc')->select();
|
||||
foreach ($list as $k => $v) {
|
||||
$cache_child = $this->getMajorChild($v);
|
||||
if ($cache_child != null) {
|
||||
@@ -185,7 +185,7 @@ class Major extends Controller {
|
||||
$data = $this->request->post();
|
||||
//判断major父级是否存在
|
||||
$major_info = $this->major_obj->where('major_id', $data['major_id'])->where("major_state", 0)->find();
|
||||
$check_major = $this->major_to_journal_obj->where('major_id', $major_info['pid'])->where('journal_issn',trim($data['journal_issn']))->where('mtj_state', 0)->find();
|
||||
$check_major = $this->major_to_journal_obj->where('major_id', $major_info['pid'])->where('journal_issn', trim($data['journal_issn']))->where('mtj_state', 0)->find();
|
||||
if ($major_info['pid'] != 0 && $check_major == null) {
|
||||
return jsonError("父级必须存在");
|
||||
}
|
||||
@@ -209,6 +209,133 @@ class Major extends Controller {
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 增加期刊独有领域
|
||||
* @description 增加期刊独有领域
|
||||
* @author wangjinlei
|
||||
* @url /api/Major/addJounalAloneMajor
|
||||
* @method POST
|
||||
*
|
||||
* @param name:journal_issn type:string require:1 desc:期刊issn号
|
||||
* @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 addJounalAloneMajor() {
|
||||
$data = $this->request->post();
|
||||
Db::startTrans();
|
||||
$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'] = 2;
|
||||
} else {
|
||||
$p_major = $this->major_obj->where('major_id', $data['pid'])->find();
|
||||
$insert['major_level'] = $p_major['major_level'] + 1;
|
||||
}
|
||||
$insert['major_ctime'] = time();
|
||||
$insert['major_type'] = 1;
|
||||
$major_id = $this->major_obj->insertGetId($insert);
|
||||
|
||||
$ins["major_id"] = $major_id;
|
||||
$ins["journal_issn"] = trim($data['journal_issn']);
|
||||
$ins['mtj_ctime'] = time();
|
||||
|
||||
$res = $this->major_to_journal_obj->insert($ins);
|
||||
if ($major_id && $res) {
|
||||
Db::commit();
|
||||
return jsonSuccess([]);
|
||||
} else {
|
||||
Db::rollback();
|
||||
return jsonError("system error");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除期刊独有领域
|
||||
* @description 删除期刊独有领域
|
||||
* @author wangjinlei
|
||||
* @url /api/Major/delJournalAloneMajor
|
||||
* @method POST
|
||||
*
|
||||
* @param name:major_id type:int require:1 desc:领域id
|
||||
* @param name:journal_issn type:string require:1 desc:期刊issn
|
||||
*
|
||||
*/
|
||||
public function delJournalAloneMajor() {
|
||||
$data = $this->request->post();
|
||||
$this->major_obj->where("major_id", $data['major_id'])->update(['major_state' => 1]);
|
||||
$this->major_to_journal_obj->where("major_id", $data['major_id'])->where("journal_issn", trim($data['journal_issn']))->update(["mtj_state" => 1]);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 编辑期刊独有领域
|
||||
* @description 编辑期刊独有领域
|
||||
* @author wangjinlei
|
||||
* @url /api/Major/editJournalAloneMajor
|
||||
* @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 editJournalAloneMajor() {
|
||||
$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/getJournalAloneMajors
|
||||
* @method POST
|
||||
*
|
||||
* @param name:journal_issn type:string require:1 desc:期刊issn号
|
||||
*
|
||||
* @return majors:领域列表#
|
||||
*/
|
||||
public function getJournalAloneMajors() {
|
||||
$data = $this->request->post();
|
||||
if (!isset($data['journal_issn'])) {
|
||||
return jsonError("参数异常");
|
||||
}
|
||||
//获取主节点
|
||||
$list = $this->major_to_journal_obj
|
||||
->field('t_major.*')
|
||||
->join("t_major", 't_major.major_id = t_major_to_journal.major_id', 'left')
|
||||
->where("t_major_to_journal.journal_issn", trim($data['journal_issn']))
|
||||
->where("t_major.pid", 0)
|
||||
->where("t_major.major_type", 1)
|
||||
->where("t_major_to_journal.mtj_state", 0)
|
||||
->select();
|
||||
foreach ($list as $k => $v) {
|
||||
$cache_child = $this->getJournalAloneMajorChild($v, trim($data['journal_issn']));
|
||||
if ($cache_child != null) {
|
||||
$list[$k]['children'] = $cache_child;
|
||||
}
|
||||
}
|
||||
$re['majors'] = $list;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除期刊领域
|
||||
* @description 删除期刊领域
|
||||
@@ -224,16 +351,16 @@ class Major extends Controller {
|
||||
$data = $this->request->post();
|
||||
//判断是否有子集
|
||||
$check = $this->major_to_journal_obj
|
||||
->join("t_major","t_major.major_id = t_major_to_journal.major_id","left")
|
||||
->join("t_major", "t_major.major_id = t_major_to_journal.major_id", "left")
|
||||
->where("t_major_to_journal.journal_issn", trim($data['journal_issn']))
|
||||
->where("t_major_to_journal.mtj_state",0)
|
||||
->where("t_major.pid",$data['major_id'])
|
||||
->where("t_major_to_journal.mtj_state", 0)
|
||||
->where("t_major.pid", $data['major_id'])
|
||||
->select();
|
||||
if($check){
|
||||
if ($check) {
|
||||
return jsonError("存在子集不能删除");
|
||||
}
|
||||
|
||||
$this->major_to_journal_obj->where('major_id', $data['major_id'])->where('journal_issn', $data['journal_issn'])->update(['mtj_state'=> 1]);
|
||||
|
||||
$this->major_to_journal_obj->where('major_id', $data['major_id'])->where('journal_issn', $data['journal_issn'])->update(['mtj_state' => 1]);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
@@ -260,6 +387,7 @@ class Major extends Controller {
|
||||
->join("t_major", 't_major.major_id = t_major_to_journal.major_id', 'left')
|
||||
->where("t_major_to_journal.journal_issn", trim($data['journal_issn']))
|
||||
->where("t_major.pid", 0)
|
||||
->where("t_major.major_type", 0)
|
||||
->where("t_major_to_journal.mtj_state", 0)
|
||||
->select();
|
||||
foreach ($list as $k => $v) {
|
||||
@@ -287,7 +415,65 @@ class Major extends Controller {
|
||||
$re['journals'] = $list;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
|
||||
public function echoJournalMajor() {
|
||||
$list = $this->journal_obj->select();
|
||||
foreach ($list as $v) {
|
||||
echo $v['title'];
|
||||
echo "<br/>------------------------------------<br/>";
|
||||
$l = $this->major_to_journal_obj
|
||||
->field('t_major.*')
|
||||
->join("t_major", 't_major.major_id = t_major_to_journal.major_id', 'left')
|
||||
->where("t_major_to_journal.journal_issn", trim($v['issn']))
|
||||
->where("t_major.pid", 0)
|
||||
->where("t_major.major_type", 0)
|
||||
->where("t_major_to_journal.mtj_state", 0)
|
||||
->select();
|
||||
foreach ($l as $val) {
|
||||
while ($val['major_level'] > 0) {
|
||||
echo "* * ";
|
||||
$val['major_level']--;
|
||||
}
|
||||
echo $val['major_title'] . "(" . $val['nickname'] . ")<br/>";
|
||||
$this->echoJournalMajorChild($val, trim($v['issn']));
|
||||
}
|
||||
echo "<br/><br/><br/><br/>";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function echoJournalMajorChild($major, $issn) {
|
||||
$list = $this->major_to_journal_obj
|
||||
->field("t_major.*")
|
||||
->join("t_major", "t_major_to_journal.major_id=t_major.major_id", 'left')
|
||||
->where("pid", $major['major_id'])
|
||||
->where("t_major.major_type", 0)
|
||||
->where("t_major_to_journal.journal_issn", $issn)
|
||||
->where("t_major_to_journal.mtj_state", 0)
|
||||
->select();
|
||||
foreach ($list as $k => $v) {
|
||||
while ($v['major_level'] > 0) {
|
||||
echo "* * ";
|
||||
$v['major_level']--;
|
||||
}
|
||||
echo $v['major_title'] . "(" . $v['nickname'] . ")<br/>";
|
||||
$this->echoJournalMajorChild($v, $issn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 同步总方法
|
||||
* @description 同步总方法
|
||||
* @author wangjinlei
|
||||
* @url /api/Major/synchroniz
|
||||
* @method POST
|
||||
*
|
||||
*/
|
||||
public function synchroniz() {
|
||||
$this->synchronization();
|
||||
$this->synchronizationJournal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 同步大池子数据
|
||||
* @description 同步大池子数据
|
||||
@@ -296,16 +482,16 @@ class Major extends Controller {
|
||||
* @method POST
|
||||
*
|
||||
*/
|
||||
public function synchronization(){
|
||||
public function synchronization() {
|
||||
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Major/sync_all";
|
||||
$url1 = "http://api.tmrjournals.cn/public/index.php/master/Major/sync_all";
|
||||
$list = $this->major_obj->select();
|
||||
myPost($url, ['majors'=> json_encode($list)]);
|
||||
myPost($url1, ['majors'=> json_encode($list)]);
|
||||
$this->sync_obj->where('akey',1)->update(['all_major'=> time()]);
|
||||
myPost($url, ['majors' => json_encode($list)]);
|
||||
myPost($url1, ['majors' => json_encode($list)]);
|
||||
$this->sync_obj->where('akey', 1)->update(['all_major' => time()]);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title 同步小池子数据
|
||||
* @description 同步小池子数据
|
||||
@@ -314,16 +500,16 @@ class Major extends Controller {
|
||||
* @method POST
|
||||
*
|
||||
*/
|
||||
public function synchronizationJournal(){
|
||||
public function synchronizationJournal() {
|
||||
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Major/sync_journal";
|
||||
$url1 = "http://api.tmrjournals.cn/public/index.php/master/Major/sync_journal";
|
||||
$list = $this->major_to_journal_obj->select();
|
||||
myPost($url, ['majors'=> json_encode($list)]);
|
||||
myPost($url1, ['majors'=> json_encode($list)]);
|
||||
$this->sync_obj->where('akey',1)->update(['journal_major'=> time()]);
|
||||
myPost($url, ['majors' => json_encode($list)]);
|
||||
myPost($url1, ['majors' => json_encode($list)]);
|
||||
$this->sync_obj->where('akey', 1)->update(['journal_major' => time()]);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title 获取大池子最后同步时间
|
||||
* @description 获取大池子最后同步时间
|
||||
@@ -333,8 +519,8 @@ class Major extends Controller {
|
||||
*
|
||||
* @return sync:同步时间记录#
|
||||
*/
|
||||
public function getLastSyncTime(){
|
||||
$d = $this->sync_obj->where('akey',1)->find();
|
||||
public function getLastSyncTime() {
|
||||
$d = $this->sync_obj->where('akey', 1)->find();
|
||||
$re['sync'] = $d;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
@@ -343,7 +529,7 @@ class Major extends Controller {
|
||||
* 获取领域子树
|
||||
*/
|
||||
private function getMajorChild($major) {
|
||||
$list = $this->major_obj->where('pid', $major['major_id'])->where('major_state', 0)->order("major_sort desc")->select();
|
||||
$list = $this->major_obj->where('pid', $major['major_id'])->where("major_type", 0)->where('major_state', 0)->order("major_sort desc")->select();
|
||||
if ($list == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -366,6 +552,7 @@ class Major extends Controller {
|
||||
->field("t_major.*")
|
||||
->join("t_major", "t_major_to_journal.major_id=t_major.major_id", 'left')
|
||||
->where("pid", $major['major_id'])
|
||||
->where("t_major.major_type", 0)
|
||||
->where("t_major_to_journal.journal_issn", $issn)
|
||||
->where("t_major_to_journal.mtj_state", 0)
|
||||
->select();
|
||||
@@ -378,4 +565,27 @@ class Major extends Controller {
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取期刊独有领域树子集
|
||||
* @param type $major
|
||||
* @param type $issn
|
||||
*/
|
||||
private function getJournalAloneMajorChild($major, $issn) {
|
||||
$list = $this->major_to_journal_obj
|
||||
->field("t_major.*")
|
||||
->join("t_major", "t_major_to_journal.major_id=t_major.major_id", 'left')
|
||||
->where("pid", $major['major_id'])
|
||||
->where("t_major.major_type", 1)
|
||||
->where("t_major_to_journal.journal_issn", $issn)
|
||||
->where("t_major_to_journal.mtj_state", 0)
|
||||
->select();
|
||||
foreach ($list as $k => $v) {
|
||||
$cache_child = $this->getJournalAloneMajorChild($v, $issn);
|
||||
if ($cache_child != null) {
|
||||
$list[$k]['children'] = $cache_child;
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user