Files
huangjingfen/pro_v3.5.1/app/services/work/WorkGroupChatMemberServices.php
panchengyong 7acbf45ff7 new files
2026-03-07 22:29:07 +08:00

103 lines
3.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\services\work;
use app\dao\work\WorkGroupChatMemberDao;
use app\services\BaseServices;
use app\services\user\UserServices;
use think\annotation\Inject;
/**
* 企业微信群成员
* Class WorkGroupChatMemberServices
* @package app\services\work
* @mixin WorkGroupChatMemberDao
*/
class WorkGroupChatMemberServices extends BaseServices
{
/**
* @var WorkGroupChatMemberDao
*/
#[Inject]
protected WorkGroupChatMemberDao $dao;
/**
* 获取群成员
* @param int $chatId
* @param string $name
* @return array
*/
public function getChatMemberList(int $chatId, string $name = '')
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getDataList(['group_id' => $chatId, 'name_like' => $name, 'status' => 1], ['*'], $page, $limit, 'create_time', [
'member' => function ($query) {
$query->field(['name', 'userid', 'gender', 'avatar', 'id', 'mobile']);
},
'client' => function ($query) {
$query->field(['name', 'external_userid', 'gender', 'avatar', 'id']);
}
]);
$clientId = $mobile = [];
foreach ($list as &$item) {
$item['group_chat_num'] = $this->dao->getChatSum($item['userid']);
if ($item['group_chat_num'] > 0) {
$item['group_chat_num']--;
}
if (isset($item['client']['id'])) {
$clientId[] = $item['client']['id'];
}
if (isset($item['member'])) {
$mobile[] = $item['member']['mobile'];
}
}
/** @var WorkClientFollowServices $followService */
$followService = app()->make(WorkClientFollowServices::class);
$followList = $followService->getDataList(['client_id' => $clientId], ['id', 'client_id',], 0, 0, 'create_time', ['tags']);
if ($followList) {
foreach ($list as &$item) {
$newTag = [];
if (isset($item['client']['id'])) {
foreach ($followList as $value) {
if ($item['client']['id'] == $value['client_id'] && !empty($value['tags'])) {
$newTag = array_column($value['tags'], 'tag_name');
}
}
$item['tags'] = $newTag;
}
}
}
if ($mobile) {
/** @var UserServices $userService */
$userService = app()->make(UserServices::class);
$userList = $userService->getList(['phone' => $mobile], 'phone,uid', 0, 0);
if ($userList) {
foreach ($list as &$item) {
$newTag = [];
if (isset($item['member'])) {
foreach ($userList as $value) {
if ($item['member']['mobile'] == $value['phone'] && !empty($value['label'])) {
$newTag = array_column($value['label'], 'label_name');
}
}
$item['tags'] = $newTag;
}
}
}
}
$count = $this->dao->count(['group_id' => $chatId, 'name_like' => $name, 'status' => 1]);
return compact('list', 'count');
}
}