全部
常见问题
产品动态
精选推荐

【pro3.0】企业微信同步客户超时问题临时解决方案

管理 管理 编辑 删除

临时解决方案,后期版本会重新优化。

打开文件:app/services/work/WorkClientServices.php

搜索并替换authGetExternalcontact方法的代码

public function authGetExternalcontact(int $page = 1, string $cursor = '')
    {
        /** @var WorkConfig $config */
        $config = app()->make(WorkConfig::class);
        $corpId = $config->corpId;
        if (!$corpId) {
            return true;
        }
        /** @var WorkMemberServices $memberService */
        $memberService = app()->make(WorkMemberServices::class);
        $menmberList = $memberService->getDataList(['corp_id' => $corpId], ['userid'], $page, 10);
        //没有数据就返回成功
        if (!$menmberList) {
            return true;
        }
        if($page == 1 && empty($cursor)){
            \think\facade\Db::name('work_client')->where('id', "<>", 0)->delete();
            \think\facade\Db::name('work_client_follow')->where('id', "<>", 0)->delete();
            \think\facade\Db::name('work_client_follow_tags')->where('follow_id ', "<>", 0)->delete();
        }
        $tagRes = Work::getCorpTags();
        $tagMap = [];
        foreach ($tagRes["tag_group"]??[] as $tagGroupItem){
            foreach ($tagGroupItem["tag"]??[] as $tagItem){
                $tagMap[$tagItem["id"]] = $tagItem +["group_id"=>$tagGroupItem["group_id"],"group_name"=>$tagGroupItem["group_name"]];
            }
        }

        $userids = array_column($menmberList, 'userid');
        $response = Work::getBatchClientList($userids, $cursor);
        $externalContactList = $response['external_contact_list'] ?? [];
        $external = [];
        $followUser = [];//内部人员跟踪
        $externalUserids = [];//客户信息
        $this->transaction(function () use ($externalContactList, $corpId, $externalUserids, $followUser, $external, $tagMap) {
            foreach ($externalContactList as $item) {
                $externalContact = $item['external_contact'];
                $unionid = $externalContact['unionid'] ?? '';
                if (isset($externalContact['unionid'])) {
                    unset($externalContact['unionid']);
                }
                $corpName = $corpFullName = $position = '';
                if (isset($externalContact['corp_name'])) {
                    $corpName = $externalContact['corp_name'];
                    unset($externalContact['corp_name']);
                }
                if (isset($externalContact['corp_full_name'])) {
                    $corpFullName = $externalContact['corp_full_name'];
                    unset($externalContact['corp_full_name']);
                }
                if (isset($externalContact['position'])) {
                    $position = $externalContact['position'];
                    unset($externalContact['position']);
                }

                $externalContact['position'] = $position;
                unset($externalContact['external_profile']);
                $externalContact['external_profile'] = json_encode($externalContact['external_profile'] ?? [],JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

                $followUserData = [
                    'userid' => $item['follow_info']['userid'],
                    'remark' => $item['follow_info']['remark'] ?? '',
                    'description' => $item['follow_info']['description'] ?? '',
                    'createtime' => $item['follow_info']['createtime'] ?? '',
                    'remark_corp_name' => $item['follow_info']['remark_corp_name'] ?? '',
                    'remark_mobiles' => json_encode($item['follow_info']['remark_mobiles'] ?? ''),
                    'add_way' => $item['follow_info']['add_way'] ?? '',
                    'oper_userid' => $item['follow_info']['oper_userid'] ?? '',
                    'create_time' => time(),
                    'tags' => [],
                ];

                foreach ($item['follow_info']['tag_id']??[] as $tagId){
                    $tag = $tagMap[$tagId]??[];
                    $followUserData['tags'][] = [
                        'group_name' => $tag['group_name'] ?? '',
                        'tag_name' => $tag['name'] ?? '',
                        'type' => $tag['type'] ?? 1,
                        'tag_id' => $tag['id'],
                        'create_time' => time()
                    ];
                }

                $followUser[$externalContact['external_userid']] = $followUserData;
                $externalUserids[] = $externalContact['external_userid'];
                $externalUserid = $externalContact['external_userid'];
                $externalContact['corp_id'] = $corpId;
                $externalContact['unionid'] = $unionid;
                $externalContact['corp_name'] = $corpName;
                $externalContact['corp_full_name'] = $corpFullName;
                if ($this->dao->count(['external_userid' => $externalUserid, 'corp_id' => $corpId])) {
                    unset($externalContact['external_userid']);
                    $this->dao->update(['external_userid' => $externalUserid], $externalContact);
                } else {
                    $externalContact['create_time'] = time();
                    $externalContact['update_time'] = time();
                    $external[] = $externalContact;
                }
            }
            if ($external) {

                $this->dao->saveAll($external);
            }
            $clientList = $this->dao->getColumn([['external_userid', 'in', $externalUserids], ['corp_id', '=', $corpId]], 'id', 'external_userid');
            /** @var WorkClientFollowServices $followService */
            $followService = app()->make(WorkClientFollowServices::class);
            if ($followUser) {
                /** @var WorkClientFollowTagsServices $tagService */
                $tagService = app()->make(WorkClientFollowTagsServices::class);
                foreach ($followUser as $userid => $items) {
                    if(!isset($clientList[$userid])){
                        continue;
                    }
                    $items['client_id'] = $clientList[$userid];
                    if (($id = $followService->value(['client_id' => $clientList[$userid], 'userid' => $items['userid']], 'id'))) {
                        $followService->update($id, [
                            'remark' => $items['remark'],
                            'description' => $items['description'],
                            'createtime' => $items['createtime'],
                            'remark_corp_name' => $items['remark_corp_name'],
                            'remark_mobiles' => $items['remark_mobiles'],
                            'add_way' => $items['add_way'],
                            'oper_userid' => $items['oper_userid'],
                        ]);
                    } else {
                        $res = $followService->save($items);
                        $id = $res->id;
                    }
                    if (!empty($items['tags'])) {
                        $tagService->delete(['follow_id' => $id]);
                        foreach ($items['tags'] as &$tag) {
                            $tag['follow_id'] = $id;
                        }
                        $tagService->saveAll($items['tags']);
                    }
                }
            }
        });

        if (isset($response['next_cursor']) && $response['next_cursor']) {
            WorkClientJob::dispatchDo('authClient', [$page, $response['next_cursor'] ?? '']);
        } else if (empty($response['next_cursor'])) {
            WorkClientJob::dispatchDo('authClient', [$page + 1, '']);
        }

        return true;
    }


请登录后查看

''神算子 最后编辑于2024-07-15 18:36:27

快捷回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
回复从新到旧

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest==1? '取消推荐': '推荐'}}
{{item.floor}}#
{{item.user_info.title}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

作者 管理员 企业

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}   {{itemc.ip_address}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
回复
回复
443
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

''神算子 企业
暂无简介

回答

9368

发布

18

经验

28155

快速安全登录

使用微信扫码登录
{{item.label}} {{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
加精
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 开源下载 CRMEB官方论坛 帮助文档
返回顶部 返回顶部
CRMEB客服