...
|
...
|
@@ -4,15 +4,15 @@ namespace app\mobile\controller; |
|
|
use think\Validate;
|
|
|
use think\Db;
|
|
|
use app\common\controller\Api;
|
|
|
use app\mobile\model\Forum as ForumModel;
|
|
|
use app\mobile\model\ForumCategory;
|
|
|
use app\mobile\model\Topic as TopicModel;
|
|
|
use app\mobile\model\TopicCategory;
|
|
|
use app\common\model\Attachment;
|
|
|
|
|
|
/**
|
|
|
* 论坛接口
|
|
|
* @ApiWeigh (92)
|
|
|
*/
|
|
|
class Forum extends Api
|
|
|
class Topic extends Api
|
|
|
{
|
|
|
protected $noNeedLogin = ['index','info'];
|
|
|
protected $noNeedRight = ['*'];
|
...
|
...
|
@@ -40,9 +40,9 @@ class Forum extends Api |
|
|
}]
|
|
|
})
|
|
|
*/
|
|
|
public function forumCategory()
|
|
|
public function topicCategory()
|
|
|
{
|
|
|
$list = ForumCategory::order('createtime desc')
|
|
|
$list = TopicCategory::order('createtime desc')
|
|
|
->field('id,name')
|
|
|
->select();
|
|
|
$this->success('成功',$list);
|
...
|
...
|
@@ -54,7 +54,7 @@ class Forum extends Api |
|
|
* @ApiSummary (发帖)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="forum_category_id", type="inter", required=false, description="话题分类ID")
|
|
|
* @ApiParams (name="topic_category_id", type="inter", required=false, description="话题分类ID")
|
|
|
* @ApiParams (name="title", type="string", required=false, description="标题")
|
|
|
* @ApiParams (name="content", type="string", required=false, description="话题内容")
|
|
|
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
|
...
|
...
|
@@ -74,10 +74,10 @@ class Forum extends Api |
|
|
public function topicAdd()
|
|
|
{
|
|
|
$post = $this->request->param();
|
|
|
empty($post['forum_category_id']) && $this->error('请选择话题分类');
|
|
|
empty($post['topic_category_id']) && $this->error('请选择话题分类');
|
|
|
empty($post['title']) && $this->error('请输入标题');
|
|
|
empty($post['content']) && $this->error('请填写话题内容');
|
|
|
ForumModel::create(array_merge([
|
|
|
TopicModel::create(array_merge([
|
|
|
'user_id' => $this->auth->id
|
|
|
],$post),true);
|
|
|
$this->success('发帖成功');
|
...
|
...
|
@@ -87,7 +87,7 @@ class Forum extends Api |
|
|
* @ApiTitle (论坛-首页)
|
|
|
* @ApiSummary (论坛-首页)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiParams (name="forum_category_id", type="inter", required=false, description="话题分类ID")
|
|
|
* @ApiParams (name="topic_category_id", type="inter", required=false, description="话题分类ID")
|
|
|
* @ApiParams (name="order", type="inter", required=false, description="排序方式:0=最新,1=热门,2=下载量")
|
|
|
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
|
|
|
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
|
...
|
...
|
@@ -106,12 +106,12 @@ class Forum extends Api |
|
|
*/
|
|
|
public function index()
|
|
|
{
|
|
|
$forum_category_id = $this->request->param('forum_category_id');
|
|
|
$topic_category_id = $this->request->param('topic_category_id');
|
|
|
$order = $this->request->param('order',0);
|
|
|
$page = $this->request->param('page', 1, 'intval');
|
|
|
$page_num = $this->request->param('page_num', 10, 'intval');
|
|
|
if(empty($forum_category_id)){
|
|
|
$where['forum_category_id'] = $forum_category_id;
|
|
|
if(empty($topic_category_id)){
|
|
|
$where['topic_category_id'] = $topic_category_id;
|
|
|
}else{
|
|
|
$where['is_recommend'] = '1';
|
|
|
}
|
...
|
...
|
@@ -126,7 +126,7 @@ class Forum extends Api |
|
|
$order = ['download_num' => 'desc'];
|
|
|
break;
|
|
|
}
|
|
|
$data = ForumModel::with(['user'])
|
|
|
$data = TopicModel::with(['user'])
|
|
|
->where($where)
|
|
|
->order($order)
|
|
|
->paginate($page_num,false,['page'=>$page])
|
...
|
...
|
@@ -163,11 +163,11 @@ class Forum extends Api |
|
|
*/
|
|
|
public function searchKeyword()
|
|
|
{
|
|
|
$history_list = Db::name('mobile_forum_keyword')
|
|
|
$history_list = Db::name('mobile_topic_keyword')
|
|
|
->where('user_id',$this->auth->id)
|
|
|
->limit(10)
|
|
|
->select();
|
|
|
$hot_list = Db::name('mobile_forum_keyword_hot')
|
|
|
$hot_list = Db::name('mobile_topic_keyword_hot')
|
|
|
->limit(10)
|
|
|
->select();
|
|
|
$this->success('成功',compact('history_list','hot_list'));
|
...
|
...
|
@@ -204,7 +204,7 @@ class Forum extends Api |
|
|
$page = $this->request->param('page', 1, 'intval');
|
|
|
$page_num = $this->request->param('page_num', 10, 'intval');
|
|
|
empty($keyword) && $this->error('请输入关键词');
|
|
|
$data = ForumModel::with(['user'])
|
|
|
$data = TopicModel::with(['user'])
|
|
|
->where('title','like','%'.$keyword.'%')
|
|
|
->order(['hot_num'=>'desc'])
|
|
|
->paginate($page_num,false,['page'=>$page])
|
...
|
...
|
@@ -221,7 +221,7 @@ class Forum extends Api |
|
|
* @ApiSummary (话题详情)
|
|
|
* @ApiMethod (POST)
|
|
|
*
|
|
|
* @ApiParams (name="forum_id", type="int", required=true, description="话题ID")
|
|
|
* @ApiParams (name="topic_id", type="int", required=true, description="话题ID")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
...
|
...
|
@@ -241,9 +241,9 @@ class Forum extends Api |
|
|
*/
|
|
|
public function info()
|
|
|
{
|
|
|
$forum_id = $this->request->param('forum_id');
|
|
|
empty($forum_id) && $this->error('缺少必要参数');
|
|
|
$info = ForumModel::get($forum_id,['user']);
|
|
|
$topic_id = $this->request->param('topic_id');
|
|
|
empty($topic_id) && $this->error('缺少必要参数');
|
|
|
$info = TopicModel::get($topic_id,['user']);
|
|
|
if(!empty($info)){
|
|
|
$info->visible(['id','title','content','createtime','agree_num','download_num','user']);
|
|
|
$info->createtime = date('Y.m.d H:i',$info['createtime']);
|
...
|
...
|
@@ -266,7 +266,7 @@ class Forum extends Api |
|
|
* @ApiSummary (下载)
|
|
|
* @ApiMethod (POST)
|
|
|
*
|
|
|
* @ApiParams (name="forum_id", type="int", required=true, description="话题ID")
|
|
|
* @ApiParams (name="topic_id", type="int", required=true, description="话题ID")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
...
|
...
|
@@ -286,6 +286,6 @@ class Forum extends Api |
|
|
*/
|
|
|
public function download()
|
|
|
{
|
|
|
$forum_id = $this->request->param('forum_id');
|
|
|
$topic_id = $this->request->param('topic_id');
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|