lizhen_gitee 1 年之前
父节点
当前提交
49c37c66c4
共有 2 个文件被更改,包括 95 次插入1 次删除
  1. 94 0
      application/api/controller/Relation.php
  2. 1 1
      application/api/controller/User.php

+ 94 - 0
application/api/controller/Relation.php

@@ -0,0 +1,94 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 关系
+ */
+class Relation extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    //关系列表
+    public function lists(){
+        $uid = input('uid',$this->auth->id);
+
+        //所有
+        $list = Db::name('relation')->where('is_show',1)->order('weigh desc')->select();
+
+        //已有关系
+        $user_relation = Db::name('user_relation')->alias('ur')
+            ->field('ur.*,u.avatar,u.nickname,to.avatar as to_avatar,to.nickname as to_nickname')
+            ->join('user u','ur.uid = u.id','LEFT')
+            ->join('user to','ur.to_uid = to.id','LEFT')
+            ->where('ur.uid|ur.to_uid',$uid)->where('ur.status',1)->select();
+        $user_relation = list_domain_image($user_relation,['avatar','to_avatar']);
+        $new_user_relation = array_column($user_relation,null,'relation_id');
+
+        //处理,留对方的头像和昵称
+        foreach($list as $key => &$val){
+            $val['info'] = [];
+            if(isset($new_user_relation[$val['id']])){
+                $info = $new_user_relation[$val['id']];
+                if($info['uid'] == $uid){
+                    $info['avatar'] = $info['to_avatar'];
+                    $info['nickname'] = $info['to_nickname'];
+                    unset($info['to_avatar']);
+                    unset($info['to_nickname']);
+                }else{
+                    unset($info['to_avatar']);
+                    unset($info['to_nickname']);
+                }
+                $val['info'] = $info;
+            }
+        }
+
+        $this->success('success',$list);
+    }
+
+    //新增举报
+    public function addone(){
+        $to_uid = input('to_uid',0);
+        if($to_uid == $this->auth->id){
+            $this->error('不能跟自己建立关系');
+        }
+
+        $relation_id    = input('relation_id','');
+        $relation = Db::name('relation')->where('id',$relation_id)->find();
+        if(empty($relation)){
+            $this->error('不存在的关系');
+        }
+
+        $where = '(uid = '.$this->auth->id.' and to_uid = '.$to_uid.') or (uid = '.$to_uid.' and to_uid = '.$this->auth->id.')';
+
+        $check = Db::name('user_relation')->where('relation_id',$relation_id)->where($where)->find();
+        if($check){
+            if($check['status'] == 1){
+                $this->error('该用户已经与您建立此关系');
+            }
+            //各种状态的判断,拒绝,过期等
+            
+        }
+
+        echo db()->getLastSql();exit;
+
+        /*
+
+
+        $data = [
+            'user_id' => $this->auth->id,
+            'type' => $type,
+            'content' => $content,
+            'images' => $images,
+            'mobile' => $mobile,
+            'createtime' => time(),
+            'updatetime' => time(),
+        ];
+
+        $id = Db::name('report')->insertGetId($data);
+        $this->success();*/
+    }
+}

+ 1 - 1
application/api/controller/User.php

@@ -554,7 +554,7 @@ class User extends Api
      */
     public function profile()
     {
-        $field_array = ['nickname','introcode','gender','birthday','attribute','shoesize','height','weight','bio','audio_bio','avatar','photo_images','tag_ids','hide_is_finishinfo','wechat_account'];
+        $field_array = ['nickname','introcode','gender','birthday','attribute','shoesize','height','weight','bio','avatar','photo_images','tag_ids'/*,'hide_is_finishinfo','wechat_account'*/];
 
         $data = [];
         foreach($field_array as $key => $field){