Follow.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\api\controller\service;
  3. use app\common\controller\Api;
  4. /**
  5. * 首页接口
  6. */
  7. class Follow extends Api
  8. {
  9. protected $noNeedLogin = [''];
  10. protected $noNeedRight = ['*'];
  11. /**
  12. * 更新关注状态
  13. * @return void
  14. * @throws \think\db\exception\DataNotFoundException
  15. * @throws \think\db\exception\ModelNotFoundException
  16. * @throws \think\exception\DbException
  17. */
  18. public function handleFollow()
  19. {
  20. if (!$this->request->isPost()) {
  21. $this->error('请求方式异常');
  22. }
  23. $uid = $this->auth->id;
  24. $type = input('type/d','');
  25. $state = input('state/d',0);
  26. $follow_id = input('follow_id/d','');
  27. $info = model('app\api\model\service\Follow')->where(['user_id'=>$uid,'follow_id'=>$follow_id,'type'=>$type])->field('id,state')->find();
  28. ($info && $info['state'] == $state) && $this->error('关注状态异常');
  29. $re = \app\api\model\service\Follow::updateFollow(['user_id'=>$uid,'type'=>$type,'follow_id'=>$follow_id,'state'=>$state],$info);
  30. if(!$re)
  31. {
  32. $this->error('状态更新异常');
  33. }
  34. $this->success('关注状态已更新');
  35. }
  36. public function getList()
  37. {
  38. if (!$this->request->isPost()) {
  39. $this->error('请求方式异常');
  40. }
  41. $post = input('post.','','trim,strip_tags');
  42. $post['user_id'] = $this->auth->id;
  43. $list = \app\api\model\service\Follow::getList($post);
  44. $this->success('信息返回成功',$list);
  45. }
  46. }