|
@@ -56,39 +56,105 @@ class Relation extends Api
|
|
$this->error('不能跟自己建立关系');
|
|
$this->error('不能跟自己建立关系');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //关系检测
|
|
$relation_id = input('relation_id','');
|
|
$relation_id = input('relation_id','');
|
|
$relation = Db::name('relation')->where('id',$relation_id)->find();
|
|
$relation = Db::name('relation')->where('id',$relation_id)->find();
|
|
if(empty($relation)){
|
|
if(empty($relation)){
|
|
$this->error('不存在的关系');
|
|
$this->error('不存在的关系');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //检查已有关系
|
|
$where = '(uid = '.$this->auth->id.' and to_uid = '.$to_uid.') or (uid = '.$to_uid.' and to_uid = '.$this->auth->id.')';
|
|
$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($where)->find();
|
|
|
|
|
|
- $check = Db::name('user_relation')->where('relation_id',$relation_id)->where($where)->find();
|
|
|
|
if($check){
|
|
if($check){
|
|
|
|
+ $now_relation = Db::name('relation')->where('id',$check['relation_id'])->value('name');
|
|
|
|
+
|
|
if($check['status'] == 1){
|
|
if($check['status'] == 1){
|
|
- $this->error('该用户已经与您建立此关系');
|
|
|
|
|
|
+ if($check['uid'] = $this->auth->id){
|
|
|
|
+ $this->error('您已经与该用户建立'.$now_relation.'关系');
|
|
|
|
+ }else{
|
|
|
|
+ $this->error('该用户已经与您建立'.$now_relation.'关系');
|
|
|
|
+ }
|
|
|
|
+ }elseif($check['status'] == 0){
|
|
|
|
+ if($check['uid'] = $this->auth->id){
|
|
|
|
+ $this->error('您已经申请建立'.$now_relation.'关系,待对方同意');
|
|
|
|
+ }else{
|
|
|
|
+ $this->error('对方已经申请建立'.$now_relation.'关系,待您同意');
|
|
|
|
+ }
|
|
|
|
+ }elseif($check['status'] == 2){
|
|
|
|
+ $this->error($now_relation.'关系的申请已被拒绝,七日内不能申请');
|
|
|
|
+ }else{
|
|
|
|
+ //可以申请
|
|
}
|
|
}
|
|
- //各种状态的判断,拒绝,过期等
|
|
|
|
-
|
|
|
|
|
|
+ }else{
|
|
|
|
+ //可以申请
|
|
}
|
|
}
|
|
|
|
|
|
- echo db()->getLastSql();exit;
|
|
|
|
|
|
+ //新增
|
|
|
|
+ $data = [
|
|
|
|
+ 'uid' => $this->auth->id,
|
|
|
|
+ 'relation_id' => $relation_id,
|
|
|
|
+ 'to_uid' => $to_uid,
|
|
|
|
+ 'status' => 0,
|
|
|
|
+ 'createtime' => time(),
|
|
|
|
+ 'updatetime' => time(),
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $id = Db::name('user_relation')->insertGetId($data);
|
|
|
|
+ $this->success('申请成功,等待对方同意',$id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //待审核关系
|
|
|
|
+ public function audit_lists(){
|
|
|
|
+ $list = Db::name('user_relation')->alias('ur')
|
|
|
|
+ ->field('ur.*,relation.name as relation_name,user.nickname,user.avatar,user.gender,user.birthday,user.attribute,uw.vip_endtime')
|
|
|
|
+ ->join('relation','ur.relation_id = relation.id','LEFT')
|
|
|
|
+ ->join('user','ur.uid = user.id','LEFT')
|
|
|
|
+ ->join('user_wallet uw','ur.uid = uw.user_id','LEFT')
|
|
|
|
+ ->where('ur.to_uid',$this->auth->id)
|
|
|
|
+ ->where('ur.status',0)
|
|
|
|
+ ->order('ur.id desc')->autopage()->select();
|
|
|
|
+ $list = list_domain_image($list,['avatar']);
|
|
|
|
+
|
|
|
|
+ if(!empty($list)){
|
|
|
|
+ foreach($list as $key => &$val){
|
|
|
|
+
|
|
|
|
+ //用户年龄
|
|
|
|
+ $val['age'] = birthtime_to_age($val['birthday']);
|
|
|
|
+ unset($val['birthday']);
|
|
|
|
+
|
|
|
|
+ //用户vip
|
|
|
|
+ $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
|
|
|
|
+ unset($val['vip_endtime']);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- /*
|
|
|
|
|
|
+ $this->success('success',$list);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ //审核
|
|
|
|
+ public function audit(){
|
|
|
|
+ $id = input('id',0);
|
|
|
|
+ $status = input('status',1);
|
|
|
|
+
|
|
|
|
+ $info = Db::name('user_relation')->alias('ur')
|
|
|
|
+ ->where('ur.id',$id)
|
|
|
|
+ ->where('ur.to_uid',$this->auth->id)
|
|
|
|
+ ->where('ur.status',0)
|
|
|
|
+ ->find();
|
|
|
|
+ if(!$info){
|
|
|
|
+ $this->error('请刷新重试');
|
|
|
|
+ }
|
|
|
|
|
|
$data = [
|
|
$data = [
|
|
- 'user_id' => $this->auth->id,
|
|
|
|
- 'type' => $type,
|
|
|
|
- 'content' => $content,
|
|
|
|
- 'images' => $images,
|
|
|
|
- 'mobile' => $mobile,
|
|
|
|
- 'createtime' => time(),
|
|
|
|
|
|
+ 'status' => $status,
|
|
'updatetime' => time(),
|
|
'updatetime' => time(),
|
|
];
|
|
];
|
|
|
|
|
|
- $id = Db::name('report')->insertGetId($data);
|
|
|
|
- $this->success();*/
|
|
|
|
|
|
+ Db::name('user_relation')->where('id',$id)->update($data);
|
|
|
|
+
|
|
|
|
+ $this->success();
|
|
}
|
|
}
|
|
}
|
|
}
|