|
@@ -42,6 +42,13 @@ class Relation extends Api
|
|
|
unset($info['to_avatar']);
|
|
|
unset($info['to_nickname']);
|
|
|
}
|
|
|
+
|
|
|
+ //是否能取消
|
|
|
+ $info['can_cancel'] = 0;
|
|
|
+ if($info['uid'] == $this->auth->id || $info['to_uid'] == $this->auth->id){
|
|
|
+ $info['can_cancel'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
$val['info'] = $info;
|
|
|
}
|
|
|
}
|
|
@@ -197,4 +204,41 @@ class Relation extends Api
|
|
|
//
|
|
|
$this->success($remark);
|
|
|
}
|
|
|
+
|
|
|
+ //取消
|
|
|
+ public function cancel(){
|
|
|
+ $id = input('id',0);
|
|
|
+ $relation_id = input('relation_id',0);
|
|
|
+
|
|
|
+ $where = [
|
|
|
+ 'id' => $id,
|
|
|
+ 'relation_id' => $relation_id
|
|
|
+ ];
|
|
|
+ $where2 = 'uid = '.$this->auth->id.' or to_uid = '.$this->auth->id;
|
|
|
+ $info = Db::name('user_relation')->where($where)->where($where2)->find();
|
|
|
+
|
|
|
+ if(empty($info)){
|
|
|
+ $this->error('不存在的关系');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::name('user_relation')->where($where)->delete();
|
|
|
+
|
|
|
+ //给发起方一条消息
|
|
|
+ $relation_name = Db::name('relation')->where('id',$relation_id)->value('name');
|
|
|
+ $message = [
|
|
|
+ 'user_id' => ($info['uid'] == $this->auth->id) ? $info['to_uid'] : $info['uid'],
|
|
|
+ 'title' => '关系取消',
|
|
|
+ 'content' => $this->auth->nickname.'已取消和你的'.$relation_name.'关系',
|
|
|
+ 'createtime' => time(),
|
|
|
+ 'status' => 0,
|
|
|
+ 'infotype' => '',//建立关系
|
|
|
+ 'infotype_id' => 0,
|
|
|
+ ];
|
|
|
+ Db::name('message')->insertGetId($message);
|
|
|
+
|
|
|
+ //
|
|
|
+ $this->success('关系已取消');
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|