...
|
...
|
@@ -15,6 +15,8 @@ use cmf\controller\HomeBaseController; |
|
|
use app\portal\model\CityCategoryModel;
|
|
|
use app\portal\validate\CommentValidate;
|
|
|
use app\portal\model\PortalPostModel;
|
|
|
use app\portal\model\CollectionModel;
|
|
|
use app\portal\model\LikeModel;
|
|
|
use think\Db;
|
|
|
//星球奇境
|
|
|
class StarController extends HomeBaseController
|
...
|
...
|
@@ -360,4 +362,90 @@ class StarController extends HomeBaseController |
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//收藏
|
|
|
public function collection(){
|
|
|
//判断是否登录
|
|
|
$login = cmf_is_user_login();
|
|
|
$article_id = $this->request->param('article_id');//文章id
|
|
|
if($login){
|
|
|
$data['uid'] = cmf_get_current_user_id();
|
|
|
$data['post_id'] = $article_id;
|
|
|
$data['create_time'] = time();
|
|
|
$data['update_time'] = time();
|
|
|
$collectionModel = new CollectionModel();
|
|
|
$res = $collectionModel->allowField(true)->save($data);
|
|
|
$contentModel = new PortalPostModel();
|
|
|
$contentModel->where('id',$article_id)->setInc('post_favorites',1);
|
|
|
if($res){
|
|
|
$this->apiResponse(1,'收藏成功!');
|
|
|
}else{
|
|
|
$this->apiResponse(0,'收藏失败!');
|
|
|
}
|
|
|
}else{
|
|
|
$this->apiResponse(0,'请登录后操作!');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//取消收藏
|
|
|
public function cancelCollection(){
|
|
|
//判断是否登录
|
|
|
$login = cmf_is_user_login();
|
|
|
$article_id = $this->request->param('article_id');//文章id
|
|
|
if($login){
|
|
|
$uid = cmf_get_current_user_id();
|
|
|
$collectionModel = new CollectionModel();
|
|
|
$res = $collectionModel->where(['uid'=>$uid,'post_id'=>$article_id])->delete();
|
|
|
$contentModel = new PortalPostModel();
|
|
|
$contentModel->where('id',$article_id)->setDec('post_favorites',1);
|
|
|
if($res){
|
|
|
$this->apiResponse(1,'已取消!');
|
|
|
}else{
|
|
|
$this->apiResponse(0,'取消失败!');
|
|
|
}
|
|
|
}else{
|
|
|
$this->apiResponse(0,'请登录后操作!');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//点赞
|
|
|
public function like(){
|
|
|
//判断是否登录
|
|
|
$login = cmf_is_user_login();
|
|
|
$article_id = $this->request->param('article_id');//文章id
|
|
|
if($login){
|
|
|
$data['uid'] = cmf_get_current_user_id();
|
|
|
$data['post_id'] = $article_id;
|
|
|
$data['create_time'] = time();
|
|
|
$data['update_time'] = time();
|
|
|
$likeModel = new LikeModel();
|
|
|
$res = $likeModel->allowField(true)->save($data);
|
|
|
if($res){
|
|
|
$this->apiResponse(1,'点赞成功!');
|
|
|
}else{
|
|
|
$this->apiResponse(0,'点赞失败!');
|
|
|
}
|
|
|
}else{
|
|
|
$this->apiResponse(0,'请登录后操作!');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//取消点赞
|
|
|
public function cancelLike(){
|
|
|
//判断是否登录
|
|
|
$login = cmf_is_user_login();
|
|
|
$article_id = $this->request->param('article_id');//文章id
|
|
|
if($login){
|
|
|
$uid = cmf_get_current_user_id();
|
|
|
$likeModel = new LikeModel();
|
|
|
$res = $likeModel->where(['uid'=>$uid,'post_id'=>$article_id])->delete();
|
|
|
if($res){
|
|
|
$this->apiResponse(1,'已取消!');
|
|
|
}else{
|
|
|
$this->apiResponse(0,'取消失败!');
|
|
|
}
|
|
|
}else{
|
|
|
$this->apiResponse(0,'请登录后操作!');
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|