Relation.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 关系
  7. */
  8. class Relation extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. //关系列表
  13. public function lists(){
  14. $uid = input('uid',$this->auth->id);
  15. //所有
  16. $list = Db::name('relation')->where('is_show',1)->order('weigh desc')->select();
  17. //已有关系
  18. $user_relation = Db::name('user_relation')->alias('ur')
  19. ->field('ur.*,u.avatar,u.nickname,to.avatar as to_avatar,to.nickname as to_nickname')
  20. ->join('user u','ur.uid = u.id','LEFT')
  21. ->join('user to','ur.to_uid = to.id','LEFT')
  22. ->where('ur.uid|ur.to_uid',$uid)->where('ur.status',1)->select();
  23. $user_relation = list_domain_image($user_relation,['avatar','to_avatar']);
  24. $new_user_relation = array_column($user_relation,null,'relation_id');
  25. //处理,留对方的头像和昵称
  26. foreach($list as $key => &$val){
  27. $val['info'] = [];
  28. if(isset($new_user_relation[$val['id']])){
  29. $info = $new_user_relation[$val['id']];
  30. if($info['uid'] == $uid){
  31. $info['avatar'] = $info['to_avatar'];
  32. $info['nickname'] = $info['to_nickname'];
  33. unset($info['to_avatar']);
  34. unset($info['to_nickname']);
  35. }else{
  36. unset($info['to_avatar']);
  37. unset($info['to_nickname']);
  38. }
  39. $val['info'] = $info;
  40. }
  41. }
  42. $this->success('success',$list);
  43. }
  44. //新增举报
  45. public function addone(){
  46. $to_uid = input('to_uid',0);
  47. if($to_uid == $this->auth->id){
  48. $this->error('不能跟自己建立关系');
  49. }
  50. $relation_id = input('relation_id','');
  51. $relation = Db::name('relation')->where('id',$relation_id)->find();
  52. if(empty($relation)){
  53. $this->error('不存在的关系');
  54. }
  55. $where = '(uid = '.$this->auth->id.' and to_uid = '.$to_uid.') or (uid = '.$to_uid.' and to_uid = '.$this->auth->id.')';
  56. $check = Db::name('user_relation')->where('relation_id',$relation_id)->where($where)->find();
  57. if($check){
  58. if($check['status'] == 1){
  59. $this->error('该用户已经与您建立此关系');
  60. }
  61. //各种状态的判断,拒绝,过期等
  62. }
  63. echo db()->getLastSql();exit;
  64. /*
  65. $data = [
  66. 'user_id' => $this->auth->id,
  67. 'type' => $type,
  68. 'content' => $content,
  69. 'images' => $images,
  70. 'mobile' => $mobile,
  71. 'createtime' => time(),
  72. 'updatetime' => time(),
  73. ];
  74. $id = Db::name('report')->insertGetId($data);
  75. $this->success();*/
  76. }
  77. }