0
0

NewsLike.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\Db;
  6. class NewsLike extends Base
  7. {
  8. public function like(){
  9. $newsId=input('id');
  10. $type=input('type');//1点赞0取消点赞
  11. if($type==1){
  12. $data=[
  13. 'news_id'=>$newsId,
  14. 'user_id'=>$this->userId
  15. ];
  16. $ret=Db::name('news_like')
  17. ->insert($data);
  18. if($ret){
  19. HelpHander::success('点赞成功');
  20. }else{
  21. HelpHander::error('点赞失败');
  22. }
  23. }
  24. if($type==0){
  25. $ret=Db::name('news_like')
  26. ->where([
  27. 'news_id'=>$newsId,
  28. 'user_id'=>$this->userId
  29. ])
  30. ->delete();
  31. if($ret){
  32. HelpHander::success('取消点赞成功');
  33. }else{
  34. HelpHander::error('取消点赞失败');
  35. }
  36. }
  37. }
  38. }