1、新增一个所有好友的流量池
2、旧版场景获客数据迁移 3、场景获客功能兼容旧版数据
This commit is contained in:
@@ -777,15 +777,55 @@ class WorkbenchController extends Controller
|
||||
|
||||
// 获取流量池(当targetType=2时)
|
||||
if (!empty($workbench->config->trafficPools) && isset($workbench->config->targetType) && $workbench->config->targetType == 2) {
|
||||
$poolList = Db::name('traffic_source_package')->alias('tsp')
|
||||
$poolList = [];
|
||||
$companyId = $this->request->userInfo['companyId'];
|
||||
|
||||
// 检查是否包含"所有好友"(packageId=0)
|
||||
$hasAllFriends = in_array(0, $workbench->config->trafficPools) || in_array('0', $workbench->config->trafficPools);
|
||||
$normalPools = array_filter($workbench->config->trafficPools, function($id) {
|
||||
return $id !== 0 && $id !== '0';
|
||||
});
|
||||
|
||||
// 处理"所有好友"特殊流量池
|
||||
if ($hasAllFriends) {
|
||||
// 计算所有好友数量
|
||||
$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');
|
||||
|
||||
$allFriendsCount = 0;
|
||||
if (!empty($wechatIds)) {
|
||||
$allFriendsCount = Db::table('s2_wechat_friend')
|
||||
->where('ownerWechatId', 'in', $wechatIds)
|
||||
->where('isDeleted', 0)
|
||||
->count();
|
||||
}
|
||||
|
||||
$poolList[] = [
|
||||
'id' => 0,
|
||||
'name' => '所有好友',
|
||||
'description' => '展示公司下所有设备的好友',
|
||||
'pic' => '',
|
||||
'itemCount' => $allFriendsCount,
|
||||
];
|
||||
}
|
||||
|
||||
// 处理普通流量池
|
||||
if (!empty($normalPools)) {
|
||||
$normalPoolList = Db::name('traffic_source_package')->alias('tsp')
|
||||
->leftJoin('traffic_source_package_item tspi', 'tspi.packageId = tsp.id and tspi.isDel = 0')
|
||||
->whereIn('tsp.id', $workbench->config->trafficPools)
|
||||
->whereIn('tsp.id', $normalPools)
|
||||
->where('tsp.isDel', 0)
|
||||
->whereIn('tsp.companyId', [$this->request->userInfo['companyId'], 0])
|
||||
->whereIn('tsp.companyId', [$companyId, 0])
|
||||
->field('tsp.id,tsp.name,tsp.description,tsp.pic,COUNT(tspi.id) as itemCount')
|
||||
->group('tsp.id')
|
||||
->order('tsp.id', 'desc')
|
||||
->select();
|
||||
$poolList = array_merge($poolList, $normalPoolList ?: []);
|
||||
}
|
||||
|
||||
$workbench->config->trafficPoolsOptions = $poolList;
|
||||
} else {
|
||||
$workbench->config->trafficPoolsOptions = [];
|
||||
|
||||
Reference in New Issue
Block a user