Commit 9963de73 authored by luhongguang's avatar luhongguang

Merge branch 'dev_ershou_20210927' of https://git.yidian-inc.com:8021/bp/goods...

Merge branch 'dev_ershou_20210927' of https://git.yidian-inc.com:8021/bp/goods into dev_ershou_20210927
parents 220bc787 95ece205
......@@ -18,7 +18,6 @@ class GroupChatService
{
public $wxApp;
public $pageSize = 100;
public $nextCursor = '';
public $ownerUserIds = [];
public $departmentId; // 部门id
......@@ -37,16 +36,19 @@ class GroupChatService
* User: pengfei@yidian-inc.com
* Date: 2021/9/28 7:36 下午
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function process()
{
$nextCursor = ''; // 下一页游标,首次为空,请求接口会返回
while (true) {
$result = $this->getGroupChatList($this->nextCursor);
$result = $this->getGroupChatList($nextCursor);
if (empty($result['group_chat_list'])) {
break;
}
$existChatIds = $this->getWxGroupChatIds(array_column($result['group_chat_list'], 'chat_id'));
foreach ($result['group_chat_list'] as $group) {
$groupChatList = $result['group_chat_list'];
$existChatIds = $this->getWxGroupChatIds(array_column($groupChatList, 'chat_id'));
foreach ($groupChatList as $group) {
try {
$groupChat = $this->getGroupChatDetail($group['chat_id']);
$chatInfo = $this->getFormatGroupChat($group, $groupChat);
......@@ -62,7 +64,7 @@ class GroupChatService
if (empty($result['next_cursor'])) {
break;
}
$this->nextCursor = $result['next_cursor'];
$nextCursor = $result['next_cursor'];
}
}
......@@ -92,12 +94,16 @@ class GroupChatService
private function processGroupChatUser($chatId, $memberList)
{
$insertMember = [];
$existUserIds = $this->getWxGroupChatUserIds(array_column($memberList, 'userid'));
WxGroupChatUser::updateRecord(['status' => WxGroupChatUser::STATUS_LEAVE], []);
$existUserIds = $this->getWxGroupChatUserIds($chatId, array_column($memberList, 'userid'));
// 重置将该群成员状态
WxGroupChatUser::updateRecord(
['status' => WxGroupChatUser::STATUS_LEAVE],
['chat_id' => $chatId, 'status' => WxGroupChatUser::STATUS_NORMAL]
);
foreach ($memberList as $member) {
$member = $this->getFormatGroupChatUser($chatId, $member);
if (isset($existUserIds[$member['user_id']])) {
WxGroupChatUser::save($member, ['user_id' => $member['user_id']]);
WxGroupChatUser::save($member, ['chat_id' => $member['chat_id'], 'user_id' => $member['user_id']]);
} else {
$insertMember[] = $member;
}
......@@ -168,12 +174,13 @@ class GroupChatService
* Notes: 获取群成员id
* User: pengfei@yidian-inc.com
* Date: 2021/9/28 3:03 下午
* @param $chatId
* @param $userIds
* @return array
*/
private function getWxGroupChatUserIds($userIds): array
private function getWxGroupChatUserIds($chatId, $userIds): array
{
$userList = WxGroupChatUser::getRecords(['user_id' => $userIds], ['user_id']);
$userList = WxGroupChatUser::getRecords(['chat_id' => $chatId, 'user_id' => $userIds], ['user_id']);
return !empty($userList) ? array_column($userList, null, 'user_id') : [];
}
......@@ -199,10 +206,11 @@ class GroupChatService
* @param $chatId
* @return array
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function getGroupChatDetail($chatId): array
{
return (array)$this->wxApp->external_contact->getGroupChat($chatId);
return (array)$this->wxApp->external_contact->getGroupChat($chatId, 1);
}
/**
......@@ -212,6 +220,7 @@ class GroupChatService
* @param string $nextCursor
* @return array
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function getGroupChatList(string $nextCursor = ''): array
{
......
......@@ -22,6 +22,11 @@ wechat.appid = "wx4e0d92499185fb74";
wechat.secret = "731bcf2f7ebb1ebddb677618c2008b25";
wechat.appid.merchant-pub-idle = "wx4e0d92499185fb74"
wechat.secret.merchant-pub-idle = "731bcf2f7ebb1ebddb677618c2008b25"
[exception]
debug = false
exception.user.code = -1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment