This commit is contained in:
Your Name
2026-08-10 17:29:05 +08:00
parent 2199887c07
commit 9add23e019
129 changed files with 34157 additions and 59 deletions
@@ -8,6 +8,7 @@ use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
use app\common\model\QywxExternalContact;
use app\common\model\QywxSyncSettings;
use app\common\service\qywx\MediaChannelService;
use app\common\service\wechat\WechatWorkService;
use think\facade\Cache;
use think\facade\Db;
@@ -306,6 +307,7 @@ class CustomerLogic extends BaseLogic
}
// 4. 更新同步设置
MediaChannelService::forgetCurrentTagCatalogCache();
self::updateSyncStatus('success', $syncCount);
Log::info('同步完成 - 总数: ' . $syncCount . ', 新增: ' . $newCount . ', 更新: ' . $updateCount);
@@ -650,6 +652,7 @@ class CustomerLogic extends BaseLogic
$updateCount,
$skippedCount
);
MediaChannelService::forgetCurrentTagCatalogCache();
}
/**
@@ -739,6 +742,7 @@ class CustomerLogic extends BaseLogic
Db::name('qywx_external_contact_tag')
->where('external_userid', $externalUserId)
->delete();
MediaChannelService::forgetCurrentTagCatalogCache();
}
/**
@@ -796,6 +800,7 @@ class CustomerLogic extends BaseLogic
Db::name('qywx_external_contact_tag')
->where('external_userid', $externalUserId)
->delete();
MediaChannelService::forgetCurrentTagCatalogCache();
return;
}
@@ -817,6 +822,7 @@ class CustomerLogic extends BaseLogic
// 关系表按剩余 kept follow_users 同步(自动清掉离开员工那行 + 保留其他员工的标签)
self::syncContactTagsRelation($externalUserId, $kept);
MediaChannelService::forgetCurrentTagCatalogCache();
}
private static function upsertOneExternalContactBundle(
@@ -1137,24 +1143,11 @@ class CustomerLogic extends BaseLogic
*/
public static function getTagStats(): array
{
// 关系表里 external_userid 可能指向已被软删的客户;这里 INNER JOIN 主表过滤未删除的
$rows = Db::name('qywx_external_contact_tag')
->alias('ect')
->join('qywx_external_contact ec', 'ec.external_userid = ect.external_userid', 'INNER')
->whereNull('ec.delete_time')
->field([
'ect.tag_id',
'ect.tag_name',
'ect.group_name',
'COUNT(DISTINCT ect.external_userid) AS customer_count',
])
->group('ect.tag_id, ect.tag_name, ect.group_name')
->order('customer_count', 'desc')
->select()
->toArray();
// 与一诊渠道共用同一份“当前有效标签”投影:一 tag_id 一条最新名称,
// 避免企微标签改名后在筛选器里同时出现新旧快照。
$rows = MediaChannelService::getCurrentTagCatalog();
$groupMap = [];
$customersUnion = [];
foreach ($rows as $r) {
$g = (string) ($r['group_name'] ?? '');
if (!isset($groupMap[$g])) {