On this page
互关列表api
controller层:application\api\controller\v1\User.php
php
// 互关列表
public function friends(){
(new UserValidate())->goCheck('getfriends');
$list = (new UserModel())->getFriendsList();
return self::showResCode('获取成功',['list'=>$list]);
}
route层:route\route.php
php
// 用户操作(绑定手机)
Route::group('api/:v1/',function(){
// 互关列表
Route::get('friends/:page','api/v1.User/friends');
})->middleware(['ApiUserAuth','ApiUserBindPhone','ApiUserStatus']);
validate层:application\common\validate\UserValidate.php
php
protected $scene = [
'getfriends'=>['page'],
];
model层:application\common\model\User.php
php
// 获取互关列表
public function getFriendsList(){
// 获取所有参数
$params = request()->param();
// 获取用户id
$userid = request()->userId;
$page = $params['page'];
$follows = \Db::table('user')->where('id','IN', function($query) use($userid){
$query->table('follow')
->where('user_id', 'IN', function ($query) use($userid){
$query->table('follow')->where('user_id', $userid)->field('follow_id');
})->where('follow_id',$userid)
->field('user_id');
})->field('id,username,userpic')->page($page,10)->select();
return $follows;
}