hyperf-chat/app/Service/Contact/ContactsService.php

76 lines
1.8 KiB
PHP
Raw Normal View History

2021-01-28 20:07:14 +08:00
<?php
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
2022-01-22 16:04:54 +08:00
namespace App\Service\Contact;
2021-01-28 20:07:14 +08:00
2022-01-22 16:04:54 +08:00
use App\Repository\Contact\ContactRepository;
use App\Service\BaseService;
2021-01-28 20:07:14 +08:00
use App\Traits\PagingTrait;
/**
* ContactsService
* 注:联系人服务层
*
* @package App\Service
*/
class ContactsService extends BaseService
{
use PagingTrait;
2022-01-22 16:04:54 +08:00
/**
* @var ContactRepository
*/
private $repository;
/**
* @param ContactRepository $repository
*/
public function __construct(ContactRepository $repository)
{
$this->repository = $repository;
}
2021-01-28 20:07:14 +08:00
/**
* 删除联系人
*
2021-04-20 16:30:57 +08:00
* @param int $user_id 用户ID
2021-01-28 20:07:14 +08:00
* @param int $friend_id 好友ID
* @return bool
*/
2021-07-07 19:43:09 +08:00
public function delete(int $user_id, int $friend_id): bool
2021-01-28 20:07:14 +08:00
{
2022-01-22 16:04:54 +08:00
$isTrue = (bool)$this->repository->update([
"user_id" => $user_id,
"friend_id" => $friend_id,
"status" => 1,
], ['status' => 0]);
2021-07-07 19:43:09 +08:00
2022-01-22 16:04:54 +08:00
if ($isTrue) redis()->del("good_friends:{$user_id}_{$friend_id}");
2021-07-08 23:44:43 +08:00
2022-01-22 16:04:54 +08:00
return $isTrue;
2021-01-28 20:07:14 +08:00
}
/**
* 编辑联系人备注
*
2021-04-20 16:30:57 +08:00
* @param int $user_id 用户ID
2021-07-06 23:44:17 +08:00
* @param int $friend_id 好友ID
* @param string $remark 好友备注名称
2021-01-28 20:07:14 +08:00
* @return bool
*/
2021-07-07 19:43:09 +08:00
public function editRemark(int $user_id, int $friend_id, string $remark): bool
2021-01-28 20:07:14 +08:00
{
2022-01-22 16:04:54 +08:00
return (bool)$this->repository->update([
"user_id" => $user_id,
"friend_id" => $friend_id,
], ['remark' => $remark]);
2021-01-28 20:07:14 +08:00
}
}