12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\Base;
- use app\hander\HelpHander;
- use think\Db;
- class NewsLike extends Base
- {
- public function like(){
- $newsId=input('id');
- $type=input('type');//1点赞0取消点赞
- if($type==1){
- $data=[
- 'news_id'=>$newsId,
- 'user_id'=>$this->userId
- ];
- $ret=Db::name('news_like')
- ->insert($data);
- if($ret){
- HelpHander::success('点赞成功');
- }else{
- HelpHander::error('点赞失败');
- }
- }
- if($type==0){
- $ret=Db::name('news_like')
- ->where([
- 'news_id'=>$newsId,
- 'user_id'=>$this->userId
- ])
- ->delete();
- if($ret){
- HelpHander::success('取消点赞成功');
- }else{
- HelpHander::error('取消点赞失败');
- }
- }
- }
- }
|