catchAdmin/catch/wechat/repository/WechatUsersRepository.php

75 lines
1.7 KiB
PHP
Raw Normal View History

2020-06-21 13:23:22 +08:00
<?php
/**
2020-06-21 14:41:22 +08:00
* @filename WechatUsersRepository.php
2020-06-21 13:23:22 +08:00
* @createdAt 2020/6/21
* @project https://github.com/yanwenwu/catch-admin
* @document http://doc.catchadmin.com
* @author JaguarJack <njphper@gmail.com>
* @copyright By CatchAdmin
* @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt
*/
namespace catchAdmin\wechat\repository;
use catchAdmin\wechat\model\WechatUsers;
use catcher\base\CatchRepository;
2020-06-21 14:41:22 +08:00
use catcher\library\WeChat;
2020-06-21 13:23:22 +08:00
class WechatUsersRepository extends CatchRepository
{
2020-06-21 14:41:22 +08:00
protected $wechatUser;
2020-06-21 13:23:22 +08:00
public function __construct(WechatUsers $users)
{
2020-06-21 14:41:22 +08:00
$this->wechatUser = $users;
2020-06-21 13:23:22 +08:00
}
2020-06-21 14:41:22 +08:00
/**
* 模型
*
* @time 2020年06月21日
* @return WechatUsers
*/
2020-06-21 13:23:22 +08:00
protected function model()
{
2020-06-21 14:41:22 +08:00
return $this->wechatUser;
}
/**
* 拉黑用户
*
* @time 2020年06月21日
* @param $id
* @return mixed
*/
public function block($id)
{
$user = $this->wechatUser->findBy($id);
$blockMethod = $user->block == WechatUsers::UNBLOCK ? 'block' : 'unblock';
WeChat::throw(WeChat::officialAccount()->user->{$blockMethod}([$user->openid]));
$user->block = $user->block == WechatUsers::BlOCK ? WechatUsers::UNBLOCK : WechatUsers::BlOCK;
return $user->save();
}
/**
* 粉丝备注
*
* @time 2020年06月21日
* @param $id
* @param string $remark
* @return mixed
*/
public function remark($id, string $remark)
{
$user = $this->wechatUser->findBy($id);
WeChat::throw(WeChat::officialAccount()->user->remark($user->openid, $remark));
$user->remark = $remark;
2020-06-21 13:23:22 +08:00
2020-06-21 14:41:22 +08:00
return $user->save();
2020-06-21 13:23:22 +08:00
}
}