1、新增一个所有好友的流量池
2、旧版场景获客数据迁移 3、场景获客功能兼容旧版数据
This commit is contained in:
@@ -162,11 +162,31 @@ class WorkbenchGroupCreateJob
|
||||
// 获取流量池用户(如果配置了流量池)
|
||||
$poolItem = [];
|
||||
if (!empty($config['poolGroups'])) {
|
||||
$poolItem = Db::name('traffic_source_package_item')
|
||||
->whereIn('packageId', $config['poolGroups'])
|
||||
->where('isDel', 0)
|
||||
->group('identifier')
|
||||
->column('identifier');
|
||||
// 检查是否包含"所有好友"(packageId=0)
|
||||
$hasAllFriends = in_array(0, $config['poolGroups']) || in_array('0', $config['poolGroups']);
|
||||
$normalPools = array_filter($config['poolGroups'], function($id) {
|
||||
return $id !== 0 && $id !== '0';
|
||||
});
|
||||
|
||||
// 处理"所有好友"特殊流量池
|
||||
if ($hasAllFriends) {
|
||||
$companyId = $workbench->companyId ?? 0;
|
||||
$allFriendsIdentifiers = $this->getAllFriendsIdentifiersByCompany($companyId);
|
||||
$poolItem = array_merge($poolItem, $allFriendsIdentifiers);
|
||||
}
|
||||
|
||||
// 处理普通流量池
|
||||
if (!empty($normalPools)) {
|
||||
$normalIdentifiers = Db::name('traffic_source_package_item')
|
||||
->whereIn('packageId', $normalPools)
|
||||
->where('isDel', 0)
|
||||
->group('identifier')
|
||||
->column('identifier');
|
||||
$poolItem = array_merge($poolItem, $normalIdentifiers);
|
||||
}
|
||||
|
||||
// 去重
|
||||
$poolItem = array_unique($poolItem);
|
||||
}
|
||||
|
||||
// 如果既没有流量池也没有指定群组,跳过
|
||||
@@ -802,6 +822,34 @@ class WorkbenchGroupCreateJob
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取公司下所有好友的identifier列表(特殊流量池 packageId=0)
|
||||
* @param int $companyId
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllFriendsIdentifiersByCompany($companyId)
|
||||
{
|
||||
// 获取公司下所有设备的微信ID
|
||||
$wechatIds = Db::name('device')->alias('d')
|
||||
->join('(SELECT MAX(id) AS id, deviceId FROM ck_device_wechat_login WHERE companyId='.$companyId.' GROUP BY deviceId) dwl_max', 'dwl_max.deviceId = d.id')
|
||||
->join('device_wechat_login dwl', 'dwl.id = dwl_max.id')
|
||||
->where(['d.companyId' => $companyId, 'd.deleteTime' => 0])
|
||||
->column('dwl.wechatId');
|
||||
|
||||
if (empty($wechatIds)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 获取所有好友的wechatId作为identifier
|
||||
$identifiers = Db::table('s2_wechat_friend')
|
||||
->where('ownerWechatId', 'in', $wechatIds)
|
||||
->where('isDeleted', 0)
|
||||
->group('wechatId')
|
||||
->column('wechatId');
|
||||
|
||||
return $identifiers ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录任务开始
|
||||
* @param string $jobId
|
||||
|
||||
Reference in New Issue
Block a user