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 ...@@ -18,7 +18,6 @@ class GroupChatService
{ {
public $wxApp; public $wxApp;
public $pageSize = 100; public $pageSize = 100;
public $nextCursor = '';
public $ownerUserIds = []; public $ownerUserIds = [];
public $departmentId; // 部门id public $departmentId; // 部门id
...@@ -37,16 +36,19 @@ class GroupChatService ...@@ -37,16 +36,19 @@ class GroupChatService
* User: pengfei@yidian-inc.com * User: pengfei@yidian-inc.com
* Date: 2021/9/28 7:36 下午 * Date: 2021/9/28 7:36 下午
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/ */
public function process() public function process()
{ {
$nextCursor = ''; // 下一页游标,首次为空,请求接口会返回
while (true) { while (true) {
$result = $this->getGroupChatList($this->nextCursor); $result = $this->getGroupChatList($nextCursor);
if (empty($result['group_chat_list'])) { if (empty($result['group_chat_list'])) {
break; break;
} }
$existChatIds = $this->getWxGroupChatIds(array_column($result['group_chat_list'], 'chat_id')); $groupChatList = $result['group_chat_list'];
foreach ($result['group_chat_list'] as $group) { $existChatIds = $this->getWxGroupChatIds(array_column($groupChatList, 'chat_id'));
foreach ($groupChatList as $group) {
try { try {
$groupChat = $this->getGroupChatDetail($group['chat_id']); $groupChat = $this->getGroupChatDetail($group['chat_id']);
$chatInfo = $this->getFormatGroupChat($group, $groupChat); $chatInfo = $this->getFormatGroupChat($group, $groupChat);
...@@ -62,7 +64,7 @@ class GroupChatService ...@@ -62,7 +64,7 @@ class GroupChatService
if (empty($result['next_cursor'])) { if (empty($result['next_cursor'])) {
break; break;
} }
$this->nextCursor = $result['next_cursor']; $nextCursor = $result['next_cursor'];
} }
} }
...@@ -92,12 +94,16 @@ class GroupChatService ...@@ -92,12 +94,16 @@ class GroupChatService
private function processGroupChatUser($chatId, $memberList) private function processGroupChatUser($chatId, $memberList)
{ {
$insertMember = []; $insertMember = [];
$existUserIds = $this->getWxGroupChatUserIds(array_column($memberList, 'userid')); $existUserIds = $this->getWxGroupChatUserIds($chatId, array_column($memberList, 'userid'));
WxGroupChatUser::updateRecord(['status' => WxGroupChatUser::STATUS_LEAVE], []); // 重置将该群成员状态
WxGroupChatUser::updateRecord(
['status' => WxGroupChatUser::STATUS_LEAVE],
['chat_id' => $chatId, 'status' => WxGroupChatUser::STATUS_NORMAL]
);
foreach ($memberList as $member) { foreach ($memberList as $member) {
$member = $this->getFormatGroupChatUser($chatId, $member); $member = $this->getFormatGroupChatUser($chatId, $member);
if (isset($existUserIds[$member['user_id']])) { 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 { } else {
$insertMember[] = $member; $insertMember[] = $member;
} }
...@@ -168,12 +174,13 @@ class GroupChatService ...@@ -168,12 +174,13 @@ class GroupChatService
* Notes: 获取群成员id * Notes: 获取群成员id
* User: pengfei@yidian-inc.com * User: pengfei@yidian-inc.com
* Date: 2021/9/28 3:03 下午 * Date: 2021/9/28 3:03 下午
* @param $chatId
* @param $userIds * @param $userIds
* @return array * @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') : []; return !empty($userList) ? array_column($userList, null, 'user_id') : [];
} }
...@@ -199,10 +206,11 @@ class GroupChatService ...@@ -199,10 +206,11 @@ class GroupChatService
* @param $chatId * @param $chatId
* @return array * @return array
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/ */
private function getGroupChatDetail($chatId): array 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 ...@@ -212,6 +220,7 @@ class GroupChatService
* @param string $nextCursor * @param string $nextCursor
* @return array * @return array
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/ */
private function getGroupChatList(string $nextCursor = ''): array private function getGroupChatList(string $nextCursor = ''): array
{ {
......
...@@ -21,6 +21,11 @@ idgen.key = "5cfdb867e96374c7883b31d6928cc4cb" ...@@ -21,6 +21,11 @@ idgen.key = "5cfdb867e96374c7883b31d6928cc4cb"
wechat.appid = "wx4e0d92499185fb74"; wechat.appid = "wx4e0d92499185fb74";
wechat.secret = "731bcf2f7ebb1ebddb677618c2008b25"; wechat.secret = "731bcf2f7ebb1ebddb677618c2008b25";
wechat.appid.merchant-pub-idle = "wx4e0d92499185fb74"
wechat.secret.merchant-pub-idle = "731bcf2f7ebb1ebddb677618c2008b25"
[exception] [exception]
debug = false debug = false
......
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