Userfollow.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 关注
  7. */
  8. class Userfollow extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //我的关注列表
  13. public function my_follow_list(){
  14. $list = Db::name('user_follow')
  15. ->alias('follow')
  16. ->join('user','follow.follow_uid = user.id','LEFT')
  17. ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender')
  18. ->where('follow.uid',$this->auth->id)->order('follow.id desc')->autopage()->select();
  19. $list = list_domain_image($list,['avatar']);
  20. $list = list_birthday_age($list);
  21. $this->success('success',$list);
  22. }
  23. //我的粉丝列表
  24. public function my_fans_list(){
  25. $list = Db::name('user_follow')
  26. ->alias('follow')
  27. ->join('user','follow.uid = user.id','LEFT')
  28. ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender')
  29. ->where('follow.follow_uid',$this->auth->id)->order('follow.id desc')->autopage()->select();
  30. $list = list_domain_image($list,['avatar']);
  31. $list = list_birthday_age($list);
  32. $this->success('success',$list);
  33. }
  34. //关注某人
  35. public function follow_one(){
  36. $follow_uid = input('follow_uid',0);
  37. if(!$follow_uid){
  38. $this->error(__('Invalid parameters'));
  39. }
  40. $checkuser = Db::name('user')->find($follow_uid);
  41. if(empty($checkuser)){
  42. $this->error('此用户不存在');
  43. }
  44. $map = [
  45. 'uid' => $this->auth->id,
  46. 'follow_uid' => $follow_uid,
  47. ];
  48. $check = Db::name('user_follow')->where($map)->find();
  49. if($check){
  50. $this->success('success');
  51. }
  52. $id = Db::name('user_follow')->insertGetId($map);
  53. $this->success('success',$id);
  54. }
  55. //取关某人
  56. public function un_follow_one(){
  57. $follow_uid = input('follow_uid',0);
  58. if(!$follow_uid){
  59. $this->error(__('Invalid parameters'));
  60. }
  61. $checkuser = Db::name('user')->find($follow_uid);
  62. if(empty($checkuser)){
  63. $this->error('此用户不存在');
  64. }
  65. $map = [
  66. 'uid' => $this->auth->id,
  67. 'follow_uid' => $follow_uid,
  68. ];
  69. //不检查,全删
  70. $rs = Db::name('user_follow')->where($map)->delete();
  71. $this->success('success');
  72. }
  73. }