116 lines
4.0 KiB
PHP
116 lines
4.0 KiB
PHP
<?php
|
|
namespace app\master\controller;
|
|
|
|
use think\Controller;
|
|
use think\Db;
|
|
|
|
/**
|
|
* @title 文章接口
|
|
* @description 文章相关操作
|
|
* @group 文章相关
|
|
*/
|
|
class Article extends Controller {
|
|
//put your code here
|
|
protected $admin_obj = '';
|
|
protected $journal_obj = '';
|
|
protected $article_obj = '';
|
|
protected $journal_topic_obj = '';
|
|
protected $journal_stage_obj = '';
|
|
|
|
public function __construct(\think\Request $request = null) {
|
|
parent::__construct($request);
|
|
$this->admin_obj = Db::name('admin');
|
|
$this->journal_obj = Db::name('journal');
|
|
$this->article_obj = Db::name('article');
|
|
$this->journal_topic_obj = Db::name('journal_topic');
|
|
$this->journal_stage_obj = Db::name('journal_stage');
|
|
}
|
|
|
|
/**
|
|
* @title 获取期刊和分期
|
|
* @description 获取期刊和分期
|
|
* @author wangjinleichang
|
|
* @url /master/Article/getJournalAndStage
|
|
* @method POST
|
|
*
|
|
* @param name:editor_id type:int require:1 desc:编辑id
|
|
*
|
|
* @return joutaglist:array#
|
|
*
|
|
*/
|
|
public function getJournalAndStage(){
|
|
$data = $this->request->post();
|
|
$journal_list = $this->journal_obj->where('editor_id',$data['editor_id'])->select();
|
|
$frag = [];
|
|
foreach ($journal_list as $v){
|
|
$cache_list = $this->journal_stage_obj->where('journal_id',$v['journal_id'])->select();
|
|
$v['children'] = $cache_list;
|
|
$frag[] = $v;
|
|
}
|
|
return json(['code'=>0,'msg'=>'success','data'=>['joutaglist'=>$frag]]);
|
|
}
|
|
|
|
/**
|
|
* @title 添加文章基本信息
|
|
* @description 添加文章基本信息
|
|
* @author wangjinleichang
|
|
* @url /master/Article/addArticleBase
|
|
* @method POST
|
|
*
|
|
* @param name:journal_id type:int require:1 desc:期刊id
|
|
* @param name:journal_stage_id type:int require:1 desc:分期id
|
|
* @param name:sort type:int require:1 default:0 desc:权重
|
|
* @param name:title type:string require:1 desc:标题
|
|
*/
|
|
public function addArticleBase(){
|
|
$data = $this->request->post();
|
|
$insert_data['journal_id'] = $data['journal_id'];
|
|
$insert_data['journal_stage_id'] = $data['journal_stage_id'];
|
|
$insert_data['title'] = $data['title'];
|
|
$insert_data['sort'] =
|
|
$insert_data['ctime'] = time();
|
|
$res = $this->article_obj->insert($insert_data);
|
|
if($res){
|
|
return json(['code'=>0,'msg'=>'success']);
|
|
}else{
|
|
return json(['code'=>1,'msg'=>'system error']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @title 获取文章列表
|
|
* @description 获取文章列表
|
|
* @author wangjinleichang
|
|
* @url /master/Article/getArticleList
|
|
* @method POST
|
|
*
|
|
* @param name:journal_id type:int default:0 require:1 desc:主键
|
|
* @param name:journal_stage_id type:int default:0 require:1 desc:主键
|
|
* @param name:seach type:string require:0 desc:关键词
|
|
* @param name:pageIndex type:int require:1 desc:当前页码数
|
|
* @param name:pageSize type:int require:1 desc:单页数据条数
|
|
*
|
|
* @return count:总数据数
|
|
* @return articleList:array#
|
|
*/
|
|
public function getArticleList(){
|
|
$data = $this->request->post();
|
|
$where['state'] = 0;
|
|
if($data['journal_id']!==0){
|
|
$where['journal_id'] = $data['journal_id'];
|
|
}
|
|
if($data['journal_stage_id']!==0){
|
|
$where['journal_stage_id'] = $data['journal_stage_id'];
|
|
}
|
|
if(isset($data['seach'])&&$data['seach']!=''){
|
|
$where['title'] = ['like','%'.$data['seach'].'%'];
|
|
}
|
|
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'];
|
|
$article_list = $this->article_obj->where($where)->order('sort desc')->limit($limit_start,$data['pageSize'])->select();
|
|
$count = $this->article_obj->where($where)->count();
|
|
return json(['code'=>0,'msg'=>'success','data'=>['count'=>$count,'articleList'=>$article_list]]);
|
|
}
|
|
|
|
|
|
}
|