更新
This commit is contained in:
@@ -9,6 +9,7 @@ use app\adminapi\logic\qywx\CustomerLogic;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\QywxExternalContact;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 企业微信客户列表
|
||||
@@ -26,6 +27,32 @@ class CustomerLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[] 入参 tag_ids 规范化后的非空字符串数组(实际为 string[])
|
||||
*/
|
||||
private function normalizeTagIds(): array
|
||||
{
|
||||
$raw = $this->params['tag_ids'] ?? null;
|
||||
if ($raw === null || $raw === '') {
|
||||
return [];
|
||||
}
|
||||
if (is_string($raw)) {
|
||||
$raw = explode(',', $raw);
|
||||
}
|
||||
if (!is_array($raw)) {
|
||||
return [];
|
||||
}
|
||||
$ids = [];
|
||||
foreach ($raw as $v) {
|
||||
$s = trim((string) $v);
|
||||
if ($s !== '') {
|
||||
$ids[] = $s;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($ids));
|
||||
}
|
||||
|
||||
private function baseQuery()
|
||||
{
|
||||
$query = QywxExternalContact::where($this->searchWhere);
|
||||
@@ -34,6 +61,22 @@ class CustomerLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$query->whereLike('follow_users', '%' . $kw . '%');
|
||||
}
|
||||
|
||||
// 标签筛选:JOIN 关系表按 tag_id 过滤;多个标签为 OR(命中任一即返回)。
|
||||
// 走 zyt_qywx_external_contact_tag.idx_tag 索引,比 LIKE follow_users 快得多
|
||||
$tagIds = $this->normalizeTagIds();
|
||||
if ($tagIds !== []) {
|
||||
$matchedExtIds = Db::name('qywx_external_contact_tag')
|
||||
->whereIn('tag_id', $tagIds)
|
||||
->group('external_userid')
|
||||
->column('external_userid');
|
||||
if ($matchedExtIds === []) {
|
||||
// 没人命中:直接给一个不可能成立的条件,避免下面命中所有客户
|
||||
$query->whereRaw('1=0');
|
||||
} else {
|
||||
$query->whereIn('external_userid', $matchedExtIds);
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
@@ -91,6 +134,10 @@ class CustomerLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$followAdminIds = json_decode($item['follow_admin_ids'] ?? '[]', true);
|
||||
$item['follow_admin_ids'] = is_array($followAdminIds) ? $followAdminIds : [];
|
||||
|
||||
// 解析标签 JSON 数组(值由 CustomerLogic::extractFollowUserTags 写入;按 tag_id 去重)
|
||||
$tags = json_decode((string) ($item['tags'] ?? '[]'), true);
|
||||
$item['tags'] = is_array($tags) ? $tags : [];
|
||||
|
||||
$fromDb = (int) ($item['external_first_add_time'] ?? 0);
|
||||
$fromJson = CustomerLogic::minFollowCreatetime($followUsers);
|
||||
$item['external_first_add_time'] = $fromDb > 0 ? $fromDb : $fromJson;
|
||||
|
||||
Reference in New Issue
Block a user