hyperf-chat/app/Repository/Contact/ContactRepository.php

53 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2022-01-22 16:04:54 +08:00
<?php
declare(strict_types=1);
namespace App\Repository\Contact;
use App\Model\Contact\Contact;
use App\Repository\BaseRepository;
class ContactRepository extends BaseRepository
{
public function __construct(Contact $model)
{
parent::__construct($model);
}
/**
* 获取所有朋友ID
*
* @param int $user_id 用户ID
*
* @return array
*/
public function findAllFriendIds(int $user_id)
{
return $this->pluck(["user_id" => $user_id, "status" => 1], 'friend_id')->toArray();
}
/**
* 获取联系人列表
*
* @param int $user_id 用户ID
*
* @return array
*/
public function friends(int $user_id): array
{
return $this->get([
'contact.user_id' => $user_id,
'contact.status' => 1,
'join table' => [
2022-01-22 16:51:55 +08:00
['users', 'users.id', '=', 'contact.friend_id', 'inner'],
2022-01-22 16:04:54 +08:00
]
], [
'users.id',
'users.nickname',
'users.avatar',
'users.motto',
'users.gender',
'contact.remark as friend_remark',
]);
}
}