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