...
|
...
|
@@ -71,13 +71,20 @@ class Topic extends Api |
|
|
*/
|
|
|
public function topicAdd()
|
|
|
{
|
|
|
$post = $this->request->param();
|
|
|
empty($post['topic_category_id']) && $this->error('请选择话题分类');
|
|
|
empty($post['title']) && $this->error('请输入标题');
|
|
|
empty($post['content']) && $this->error('请填写话题内容');
|
|
|
$this->model->allowField(true)->save(array_merge([
|
|
|
'user_id' => $this->auth->id
|
|
|
],$post));
|
|
|
$topic_category_id = $this->request->param('topic_category_id');
|
|
|
$title = $this->request->param('title');
|
|
|
$cover = $this->request->param('cover');
|
|
|
$content = $this->request->param('content','','htmlspecialchars_decode');
|
|
|
empty($topic_category_id) && $this->error('请选择话题分类');
|
|
|
empty($title) && $this->error('请输入标题');
|
|
|
empty($content) && $this->error('请填写话题内容');
|
|
|
$this->model->allowField(true)->save([
|
|
|
'user_id' => $this->auth->id,
|
|
|
'topic_category_id' => $topic_category_id,
|
|
|
'title' => $title,
|
|
|
'cover' => $cover,
|
|
|
'content' => $content
|
|
|
]);
|
|
|
$this->success('发帖成功');
|
|
|
}
|
|
|
|
...
|
...
|
@@ -93,13 +100,14 @@ class Topic extends Api |
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1601349634",
|
|
|
"time": "1602300901",
|
|
|
"data": {
|
|
|
"total": 1, //数据总数
|
|
|
"list": [{
|
|
|
"id": 1, //话题ID
|
|
|
"title": "公司即将上市", //话题标题
|
|
|
"content": "这就是街舞", //话题内容
|
|
|
"cover": "http://qizhibang.brotop.cn/uploads/20201009/9bc002db9517fe79f93478550a979768.jpg", //封面图
|
|
|
"content": "他咯土佐玉木桶浴", //话题内容
|
|
|
"agree_num": 0, //赞同量
|
|
|
"download_num": 0, //下载量
|
|
|
"createtime": "2020.09.29 09:11", //发布时间
|
...
|
...
|
@@ -107,7 +115,10 @@ class Topic extends Api |
|
|
"id": 15, //用户ID
|
|
|
"nickname": "", //昵称
|
|
|
"image": "" //头像
|
|
|
}
|
|
|
},
|
|
|
"imgs": [ //发布内容图片
|
|
|
"http://qizhibang.brotop.cn/uploads/20201010/dd2b86d8186f0e89735798d6f9a8f56c.jpg"
|
|
|
]
|
|
|
}]
|
|
|
}
|
|
|
})
|
...
|
...
|
@@ -141,13 +152,19 @@ class Topic extends Api |
|
|
->order($order)
|
|
|
->paginate($page_num,false,['page'=>$page])
|
|
|
->each(function($v){
|
|
|
$v->visible(['id','title','cover','content','createtime','agree_num','download_num','user']);
|
|
|
// 发布时间格式化
|
|
|
$v->createtime = date('Y.m.d H:i',$v->createtime);
|
|
|
// 过滤标签
|
|
|
$content1 = htmlspecialchars_decode($v->content);
|
|
|
$content2 = str_replace([' ',' '],['',''],$content1);
|
|
|
$v->content = strip_tags($content2);
|
|
|
// 拼装图片
|
|
|
$imgs = strip_tags($content2, '<img>');
|
|
|
//$matches[1] 为图片路径数组
|
|
|
preg_match_all('/\<img\s+src\=\"([\w:\/\.]+)\"/', $imgs, $matches);
|
|
|
$v->imgs = $matches[1];
|
|
|
// 显示数据
|
|
|
$v->visible(['id','title','cover','content','createtime','agree_num','download_num','user'])->append(['imgs']);
|
|
|
$v->getRelation('user')->visible(['id','image','nickname']);
|
|
|
})->toArray();
|
|
|
$this->success('成功',['total'=>$data['total'],'list'=>$data['data']]);
|
...
|
...
|
@@ -210,13 +227,14 @@ class Topic extends Api |
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1601349634",
|
|
|
"time": "1602300901",
|
|
|
"data": {
|
|
|
"total": 1, //数据总数
|
|
|
"list": [{
|
|
|
"id": 1, //话题ID
|
|
|
"title": "公司即将上市", //话题标题
|
|
|
"content": "这就是街舞", //话题内容
|
|
|
"cover": "http://qizhibang.brotop.cn/uploads/20201009/9bc002db9517fe79f93478550a979768.jpg", //封面图
|
|
|
"content": "他咯土佐玉木桶浴", //话题内容
|
|
|
"agree_num": 0, //赞同量
|
|
|
"download_num": 0, //下载量
|
|
|
"createtime": "2020.09.29 09:11", //发布时间
|
...
|
...
|
@@ -224,7 +242,10 @@ class Topic extends Api |
|
|
"id": 15, //用户ID
|
|
|
"nickname": "", //昵称
|
|
|
"image": "" //头像
|
|
|
}
|
|
|
},
|
|
|
"imgs": [ //发布内容图片
|
|
|
"http://qizhibang.brotop.cn/uploads/20201010/dd2b86d8186f0e89735798d6f9a8f56c.jpg"
|
|
|
]
|
|
|
}]
|
|
|
}
|
|
|
})
|
...
|
...
|
@@ -260,13 +281,19 @@ class Topic extends Api |
|
|
->order(['hot_num'=>'desc'])
|
|
|
->paginate($page_num,false,['page'=>$page])
|
|
|
->each(function($v){
|
|
|
$v->visible(['id','title','cover','content','createtime','agree_num','download_num','user']);
|
|
|
// 发布时间格式化
|
|
|
$v->createtime = date('Y.m.d H:i',$v->createtime);
|
|
|
// 过滤标签
|
|
|
$content1 = htmlspecialchars_decode($v->content);
|
|
|
$content2 = str_replace([' ',' '],['',''],$content1);
|
|
|
$v->content = strip_tags($content2);
|
|
|
// 拼装图片
|
|
|
$imgs = strip_tags($content2, '<img>');
|
|
|
//$matches[1] 为图片路径数组
|
|
|
preg_match_all('/\<img\s+src\=\"([\w:\/\.]+)\"/', $imgs, $matches);
|
|
|
$v->imgs = $matches[1];
|
|
|
// 显示数据
|
|
|
$v->visible(['id','title','cover','content','createtime','agree_num','download_num','user'])->append(['imgs']);
|
|
|
$v->getRelation('user')->visible(['id','image','nickname']);
|
|
|
})->toArray();
|
|
|
$this->success('成功',['total'=>$data['total'],'list'=>$data['data']]);
|
...
|
...
|
|