Userblack.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 黑名单
  7. */
  8. class Userblack extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //拉黑我的人列表
  13. public function black_me_list(){
  14. $list = Db::name('user_black')
  15. ->alias('black')
  16. ->join('user','black.uid = user.id','LEFT')
  17. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  18. ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime')
  19. ->where('black.black_uid',$this->auth->id)->order('black.id desc')->autopage()->select();
  20. $list = list_domain_image($list,['avatar']);
  21. if(!empty($list)){
  22. foreach($list as $key => &$val){
  23. //用户年龄
  24. $val['age'] = birthtime_to_age($val['birthday']);
  25. unset($val['birthday']);
  26. //用户vip
  27. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  28. unset($val['vip_endtime']);
  29. }
  30. }
  31. $this->success('success',$list);
  32. }
  33. //我拉黑的人列表
  34. public function my_black_list(){
  35. $list = Db::name('user_black')
  36. ->alias('black')
  37. ->join('user','black.black_uid = user.id','LEFT')
  38. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  39. ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime')
  40. ->where('black.uid',$this->auth->id)->order('black.id desc')->autopage()->select();
  41. $list = list_domain_image($list,['avatar']);
  42. if(!empty($list)){
  43. foreach($list as $key => &$val){
  44. //用户年龄
  45. $val['age'] = birthtime_to_age($val['birthday']);
  46. unset($val['birthday']);
  47. //用户vip
  48. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  49. unset($val['vip_endtime']);
  50. }
  51. }
  52. $this->success('success',$list);
  53. }
  54. //拉黑某人
  55. public function black_one(){
  56. $black_uid = input('black_uid',0);
  57. if(!$black_uid){
  58. $this->error(__('Invalid parameters'));
  59. }
  60. $checkuser = Db::name('user')->find($black_uid);
  61. if(empty($checkuser)){
  62. $this->error('此用户不存在');
  63. }
  64. if($black_uid == $this->auth->id){
  65. $this->error('不能拉黑自己');
  66. }
  67. $map = [
  68. 'uid' => $this->auth->id,
  69. 'black_uid' => $black_uid,
  70. ];
  71. $check = Db::name('user_black')->where($map)->find();
  72. if($check){
  73. $this->error('已经拉黑了此人');
  74. }
  75. $id = Db::name('user_black')->insertGetId($map);
  76. $this->success('操作成功',$id);
  77. }
  78. //取消拉黑某人
  79. public function un_black_one(){
  80. $black_uid = input('black_uid',0);
  81. if(!$black_uid){
  82. $this->error(__('Invalid parameters'));
  83. }
  84. $map = [
  85. 'uid' => $this->auth->id,
  86. 'black_uid' => $black_uid,
  87. ];
  88. //不检查,全删
  89. $rs = Db::name('user_black')->where($map)->delete();
  90. $this->success('操作成功');
  91. }
  92. }