Ai_GirlFriend/xunifriend_RaeeC/application/api/controller/Friend.php

109 lines
2.7 KiB
PHP
Raw Normal View History

2026-01-31 19:15:41 +08:00
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\model\FriendRelation ;
class Friend extends Api
{
protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third','wxapp_login','wxapp_get_phone'];
protected $noNeedRight = '*';
/*
* 获取好友列表
*/
public function index(){
$user_id = $this->auth->id;
$list = FriendRelation::getFriendList($user_id);
$this->success('获取成功', $list);
}
/*
* 添加好友
*/
// public function add(){
// $user_id = $this->auth->id;
// $friend_id = $this->request->request('friend_id');
// $res = model('Friend')->addFriend($user_id,$friend_id);
// if($res){
// $this->success('添加成功');
// }
// $this->error('添加失败');
// }
/*
* 删除好友
*/
public function delete(){
$user_id = $this->auth->id;
$friend_id = $this->request->post('friend_id');
$res = FriendRelation::deleteFriend($user_id,$friend_id);
$this->success('删除成功');
}
/*
* 搜索用户
*/
public function search(){
$search = $this->request->post('search');
if (!$search){
$this->error('请输入搜索内容');
}
$user_id = $this->auth->id;
$list = FriendRelation::searchUser($user_id,$search);
$this->success('获取成功', $list);
}
/*
* 申请好友
*/
public function apply(){
$user_id = $this->auth->id;
$friend_id = $this->request->post('friend_id');
$message = $this->request->post('message');
if (!$friend_id) {
$this->error('请选择好友');
}
if($user_id == $friend_id){
$this->error('不能添加自己为好友');
}
$res = FriendRelation::applyFriend($user_id,$friend_id,$message);
if($res['code'] <= 0){
$this->error($res['msg']);
}else{
$this->success('申请成功');
}
}
/*
* 获取好友申请列表
*/
public function apply_list(){
$user_id = $this->auth->id;
$list = FriendRelation::getApplyList($user_id);
$this->success('获取成功', $list);
}
/*
* 处理好友申请
*/
public function handle(){
$user_id = $this->auth->id;
$friend_requests_id = $this->request->post('id');
$status = $this->request->post('status');
$res = FriendRelation::handleApply($user_id,$friend_requests_id,$status);
if($res['code'] <= 0){
$this->error($res['msg']);
}
$this->success('处理成功');
}
}