12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?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();*/
- }
- }
|