20201112
This commit is contained in:
@@ -14,11 +14,13 @@ class Journal extends Controller {
|
||||
//put your code here
|
||||
protected $admin_obj = '';
|
||||
protected $journal_obj = '';
|
||||
protected $journal_topic_obj = '';
|
||||
|
||||
public function __construct(\think\Request $request = null) {
|
||||
parent::__construct($request);
|
||||
$this->admin_obj = Db::name('admin');
|
||||
$this->journal_obj = Db::name('journal');
|
||||
$this->journal_topic_obj = Db::name('journal_topic');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,7 +208,146 @@ class Journal extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 增加话题
|
||||
* @description 增加话题
|
||||
* @author wangjinlei
|
||||
* @url /master/Journal/addTopic
|
||||
* @method POST
|
||||
*
|
||||
* @param name:journal_id type:int require:1 desc:期刊id
|
||||
* @param name:parent_id type:int require:1 default:0 desc:父id
|
||||
* @param name:title type:string require:1 desc:标题
|
||||
* @param name:icon type:string require:1 desc:缩略图
|
||||
* @param name:is_final type:int require:1 desc:是否终结点(0no1yes)
|
||||
* @param name:sort type:int require:1 default:0 desc:权重
|
||||
*
|
||||
*/
|
||||
public function addTopic(){
|
||||
$data = $this->request->post();
|
||||
$level = 0;
|
||||
if($data['parent_id']==0){
|
||||
$level = 1;
|
||||
}else{
|
||||
$parent_info = $this->journal_topic_obj->where('journal_topic_id',$data['parent_id'])->find();
|
||||
$level = intval($parent_info['level'])+1;
|
||||
}
|
||||
$insert['journal_id'] = $data['journal_id'];
|
||||
$insert['parent_id'] = $data['parent_id'];
|
||||
$insert['title'] = $data['title'];
|
||||
$insert['icon'] = $data['icon'];
|
||||
$insert['is_final'] = $data['is_final'];
|
||||
$insert['sort'] = $data['sort'];
|
||||
$insert['level'] = $level;
|
||||
$res = $this->journal_topic_obj->insert($insert);
|
||||
if($res){
|
||||
return json(['code'=>0,'msg'=>'success']);
|
||||
}else{
|
||||
return json(['code'=>1,'msg'=>'system error']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取话题父级列表
|
||||
* @description 获取话题父级列表
|
||||
* @author wangjinlei
|
||||
* @url /master/Journal/getParent
|
||||
* @method POST
|
||||
*
|
||||
* @param name:journal_id type:int require:1 desc:
|
||||
*
|
||||
* @return parentList:array#
|
||||
*/
|
||||
public function getParent(){
|
||||
$data = $this->request->post();
|
||||
$res = $this->journal_topic_obj
|
||||
->where('journal_id',$data['journal_id'])
|
||||
->where('state',0)
|
||||
->where('is_final',0)
|
||||
->select();
|
||||
//处理数组
|
||||
$frag = [];
|
||||
foreach ($res as $v){
|
||||
if($v['parent_id'] == 0){
|
||||
$frag[] = $v;
|
||||
}
|
||||
}
|
||||
foreach ($frag as $kk => $vv){
|
||||
$frag[$kk] = $this->getChieldarr($vv,$res);
|
||||
}
|
||||
return json(['code'=>0,'msg'=>'success','data'=>['parentList'=>$frag]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取话题列表
|
||||
* @description 获取话题列表
|
||||
* @author wangjinlei
|
||||
* @url /master/Journal/getTopicList
|
||||
* @method POST
|
||||
*
|
||||
* @param name:journal_id type:int require:1 desc:期刊id
|
||||
*
|
||||
* @return journal:array#
|
||||
* @return topicList:话题数组@
|
||||
* @topicList array:数据
|
||||
*
|
||||
*/
|
||||
public function getTopicList(){
|
||||
$data = $this->request->post();
|
||||
$res = $this->journal_topic_obj
|
||||
->where('journal_id',$data['journal_id'])
|
||||
->where('state',0)
|
||||
->select();
|
||||
$journal_info = $this->journal_obj->where('journal_id',$data['journal_id'])->find();
|
||||
//处理数组
|
||||
$frag = [];
|
||||
foreach ($res as $v){
|
||||
if($v['parent_id'] == 0){
|
||||
$frag[] = $v;
|
||||
}
|
||||
}
|
||||
foreach ($frag as $kk => $vv){
|
||||
$frag[$kk] = $this->getChieldarr($vv,$res);
|
||||
}
|
||||
return json(['code'=>0,'msg'=>'success','data'=>['journal'=>$journal_info,'topicList'=>$frag]]);
|
||||
}
|
||||
|
||||
|
||||
private function getChieldarr($vv,$res){
|
||||
if($vv['is_final']==1){
|
||||
return $vv;
|
||||
}
|
||||
foreach ($res as $v){
|
||||
$vv['child'][] = $this->getChieldarr($v, $res);
|
||||
}
|
||||
return $vv;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title topic图片上传
|
||||
* @description topic图片上传
|
||||
* @author wangjinlei
|
||||
* @url /master/Journal/up_topic_file
|
||||
* @method POST
|
||||
*
|
||||
* @param name:name type:string require:1 default:journaltopic desc:文件域名称
|
||||
*
|
||||
*
|
||||
* @return upurl:图片地址
|
||||
*
|
||||
*/
|
||||
public function up_topic_file() {
|
||||
$file = request()->file('journaltopic');
|
||||
if ($file) {
|
||||
$info = $file->move(ROOT_PATH . 'public' . DS . 'journaltopic');
|
||||
if ($info) {
|
||||
return json(['code'=>0 , 'msg'=>'success', 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
|
||||
} else {
|
||||
return json(['code' => 1, 'msg' => $file->getError()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user