新版流量池提交
This commit is contained in:
@@ -83,10 +83,10 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
'wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone', 'wa.alias'
|
||||
]
|
||||
)
|
||||
->join('traffic_source s', 'p.identifier=s.identifier')
|
||||
->join('traffic_source_v1 s', 'p.identifier=s.identifier')
|
||||
->join('wechat_account wa', 'p.identifier=wa.wechatId', 'left')
|
||||
->join('traffic_source_package_item tspi', 'p.identifier = tspi.identifier AND s.companyId = tspi.companyId', 'left')
|
||||
->join('traffic_source_package tsp', 'tspi.packageId=tsp.id', 'left')
|
||||
->join('traffic_source_package_item_v1 tspi', 'p.identifier = tspi.identifier AND s.companyId = tspi.companyId', 'left')
|
||||
->join('traffic_source_package_v1 tsp', 'tspi.packageId=tsp.id', 'left')
|
||||
->join('device_wechat_login d', 's.sourceId=d.wechatId', 'left')
|
||||
->where($where);
|
||||
|
||||
@@ -106,8 +106,8 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
if ($isPage) {
|
||||
foreach ($list as &$item) {
|
||||
//流量池筛选
|
||||
$package = Db::name('traffic_source_package_item')->alias('tspi')
|
||||
->join('traffic_source_package p', 'tspi.packageId=p.id AND tspi.companyId=p.companyId')
|
||||
$package = Db::name('traffic_source_package_item_v1')->alias('tspi')
|
||||
->join('traffic_source_package_v1 p', 'tspi.packageId=p.id AND tspi.companyId=p.companyId')
|
||||
->where(['tspi.identifier' => $item->identifier])
|
||||
->whereIn('tspi.companyId', [0, $item->companyId])
|
||||
->column('p.name');
|
||||
@@ -181,7 +181,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
$data['lastMsgTime'] = '';
|
||||
|
||||
//来源
|
||||
$source = Db::name('traffic_source')->alias('ts')
|
||||
$source = Db::name('traffic_source_v1')->alias('ts')
|
||||
->field(['wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone', 'wa.wechatId', 'wa.alias',
|
||||
'ts.createTime',
|
||||
'wf.id as friendId', 'wf.wechatAccountId'])
|
||||
@@ -221,12 +221,12 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
|
||||
|
||||
//流量池
|
||||
$package = Db::name('traffic_source_package_item')->alias('tspi')
|
||||
$package = Db::name('traffic_source_package_item_v1')->alias('tspi')
|
||||
->join('traffic_source_package p', 'tspi.packageId=p.id AND tspi.companyId=p.companyId')
|
||||
->where(['tspi.companyId' => $companyId, 'tspi.identifier' => $data['identifier']])
|
||||
->column('p.name');
|
||||
$package2 = Db::name('traffic_source_package_item')->alias('tspi')
|
||||
->join('traffic_source_package p', 'tspi.packageId=p.id')
|
||||
$package2 = Db::name('traffic_source_package_item_v1')->alias('tspi')
|
||||
->join('traffic_source_package_v1 p', 'tspi.packageId=p.id')
|
||||
->where(['tspi.companyId' => $companyId, 'tspi.identifier' => $data['identifier']])
|
||||
->column('p.name');
|
||||
$packages = array_merge($package, $package2);
|
||||
@@ -328,12 +328,24 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
if (empty($userId)) {
|
||||
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
|
||||
}
|
||||
$data = Db::name('traffic_pool')->alias('tp')
|
||||
->join('wechat_friendship f', 'tp.wechatId=f.wechatId AND f.companyId=' . $companyId, 'left')
|
||||
->join(['s2_wechat_friend' => 'wf'], 'f.wechatId=wf.wechatId', 'left')
|
||||
->where(['tp.id' => $userId])
|
||||
->order('tp.createTime desc')
|
||||
// ========== 旧版流量池代码(已废弃) ==========
|
||||
// $data = Db::name('traffic_pool_v1')->alias('tp')
|
||||
// ->join('wechat_friendship f', 'tp.wechatId=f.wechatId AND f.companyId=' . $companyId, 'left')
|
||||
// ->join(['s2_wechat_friend' => 'wf'], 'f.wechatId=wf.wechatId', 'left')
|
||||
// ->where(['tp.id' => $userId])
|
||||
// ->order('tp.createTime desc')
|
||||
// ->column('wf.id,wf.labels,wf.siteLabels');
|
||||
// ========== 新版流量池代码 ==========
|
||||
$pool = Db::name('traffic_pool')->where('id', $userId)->find();
|
||||
if (!$pool) {
|
||||
return ResponseHelper::success(['wechat' => [], 'siteLabels' => []]);
|
||||
}
|
||||
$data = Db::name('s2_wechat_friend')->alias('wf')
|
||||
->join('wechat_friendship f', 'wf.wechatId=f.wechatId AND f.companyId=' . $companyId, 'left')
|
||||
->where(['wf.wechatId' => $pool['identifier']])
|
||||
->order('wf.id desc')
|
||||
->column('wf.id,wf.labels,wf.siteLabels');
|
||||
// ========== 旧版流量池代码结束 ==========
|
||||
if (empty($data)) {
|
||||
return ResponseHelper::success(['wechat' => [], 'siteLabels' => []]);
|
||||
}
|
||||
@@ -383,7 +395,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
}
|
||||
|
||||
if (!empty($addPackageId)) {
|
||||
$package = Db::name('traffic_source_package')
|
||||
$package = Db::name('traffic_source_package_v1')
|
||||
->where(['id' => $addPackageId, 'isDel' => 0])
|
||||
->whereIn('companyId', [$companyId, 0])
|
||||
->field('id,name')
|
||||
@@ -393,7 +405,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
}
|
||||
$packageId = $package['id'];
|
||||
} else {
|
||||
$package = Db::name('traffic_source_package')
|
||||
$package = Db::name('traffic_source_package_v1')
|
||||
->where(['isDel' => 0, 'name' => $packageName])
|
||||
->whereIn('companyId', [$companyId, 0])
|
||||
->field('id,name')
|
||||
@@ -401,7 +413,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
if (!empty($package)) {
|
||||
return ResponseHelper::error('该流量池名称已存在');
|
||||
}
|
||||
$packageId = Db::name('traffic_source_package')->insertGetId([
|
||||
$packageId = Db::name('traffic_source_package_v1')->insertGetId([
|
||||
'userId' => $userId,
|
||||
'companyId' => $companyId,
|
||||
'name' => $packageName,
|
||||
@@ -424,12 +436,21 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
if (!is_array($userIds)) {
|
||||
return ResponseHelper::error('选择的用户类型错误');
|
||||
}
|
||||
// ========== 旧版流量池代码(已废弃) ==========
|
||||
// $result = Db::name('traffic_pool_v1')->alias('tp')
|
||||
// ->join('traffic_source_v1 tc', 'tp.identifier=tc.identifier')
|
||||
// ->whereIn('tp.id', $userIds)
|
||||
// ->where(['companyId' => $companyId])
|
||||
// ->group('tp.identifier')
|
||||
// ->column('tc.identifier');
|
||||
// ========== 新版流量池代码 ==========
|
||||
$result = Db::name('traffic_pool')->alias('tp')
|
||||
->join('traffic_source tc', 'tp.identifier=tc.identifier')
|
||||
->join('traffic_pool_company tpc', 'tpc.poolId=tp.id AND tpc.companyId=' . $companyId)
|
||||
->join('traffic_pool_source tps', 'tps.poolCompanyId=tpc.id')
|
||||
->whereIn('tp.id', $userIds)
|
||||
->where(['companyId' => $companyId])
|
||||
->group('tp.identifier')
|
||||
->column('tc.identifier');
|
||||
->column('tps.identifier');
|
||||
// ========== 旧版流量池代码结束 ==========
|
||||
} else {
|
||||
/*if (empty($tableFile)){
|
||||
return ResponseHelper::error('请上传用户文件');
|
||||
@@ -513,7 +534,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
$batchRows = array_slice($result, $i, $batchSize);
|
||||
if (!empty($batchRows)) {
|
||||
// 2. 批量查询已存在的手机
|
||||
$existing = Db::name('traffic_source_package_item')
|
||||
$existing = Db::name('traffic_source_package_item_v1')
|
||||
->where(['companyId' => $companyId, 'packageId' => $packageId])
|
||||
->whereIn('identifier', $batchRows)
|
||||
->field('identifier')
|
||||
@@ -533,7 +554,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
}
|
||||
// 4. 批量插入新数据
|
||||
if (!empty($newData)) {
|
||||
Db::name('traffic_source_package_item')->insertAll($newData);
|
||||
Db::name('traffic_source_package_item_v1')->insertAll($newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,28 +569,33 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
$batchRows = array_slice($rows, $i, $batchSize);
|
||||
if (!empty($batchRows)) {
|
||||
$identifiers = array_column($batchRows, 'phone');
|
||||
//流量池处理
|
||||
$existing = Db::name('traffic_pool')
|
||||
->whereIn('identifier', $identifiers)
|
||||
->column('identifier');
|
||||
|
||||
$newData = [];
|
||||
foreach ($batchRows as $row) {
|
||||
if (!in_array($row['phone'], $existing)) {
|
||||
$newData[] = [
|
||||
'identifier' => $row['phone'],
|
||||
'mobile' => $row['phone'],
|
||||
'createTime' => time(),
|
||||
];
|
||||
}
|
||||
}
|
||||
if (!empty($newData)) {
|
||||
Db::name('traffic_pool')->insertAll($newData);
|
||||
}
|
||||
// ========== 旧版流量池代码(已废弃,已迁移到V2实时同步) ==========
|
||||
// //流量池处理
|
||||
// $existing = Db::name('traffic_pool_v1')
|
||||
// ->whereIn('identifier', $identifiers)
|
||||
// ->column('identifier');
|
||||
//
|
||||
// $newData = [];
|
||||
// foreach ($batchRows as $row) {
|
||||
// if (!in_array($row['phone'], $existing)) {
|
||||
// $newData[] = [
|
||||
// 'identifier' => $row['phone'],
|
||||
// 'mobile' => $row['phone'],
|
||||
// 'createTime' => time(),
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
// if (!empty($newData)) {
|
||||
// Db::name('traffic_pool_v1')->insertAll($newData);
|
||||
// }
|
||||
// ========== 新版流量池代码(使用 TrafficPoolService 实时同步) ==========
|
||||
// 流量池处理 - 现在通过 TrafficPoolService 实时同步到 V2
|
||||
// 如果需要批量导入,建议使用 migrate:trafficPoolV2 命令
|
||||
// ========== 旧版流量池代码结束 ==========
|
||||
|
||||
//流量池来源处理
|
||||
$newData2 = [];
|
||||
$existing2 = Db::name('traffic_source')
|
||||
$existing2 = Db::name('traffic_source_v1')
|
||||
->where(['companyId' => $companyId])
|
||||
->whereIn('identifier', $identifiers)
|
||||
->column('identifier');
|
||||
@@ -587,12 +613,12 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
}
|
||||
}
|
||||
if (!empty($newData2)) {
|
||||
Db::name('traffic_source')->insertAll($newData2);
|
||||
Db::name('traffic_source_v1')->insertAll($newData2);
|
||||
}
|
||||
|
||||
//流量池包数据处理
|
||||
$newData3 = [];
|
||||
$existing3 = Db::name('traffic_source_package_item')
|
||||
$existing3 = Db::name('traffic_source_package_item_v1')
|
||||
->where(['companyId' => $companyId, 'packageId' => $packageId])
|
||||
->whereIn('identifier', $identifiers)
|
||||
->field('identifier')
|
||||
@@ -608,7 +634,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
}
|
||||
}
|
||||
if (!empty($newData3)) {
|
||||
Db::name('traffic_source_package_item')->insertAll($newData3);
|
||||
Db::name('traffic_source_package_item_v1')->insertAll($newData3);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
@@ -638,10 +664,20 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
$isWechat = $this->request->param('isWechat', false);
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
$friend = Db::name('traffic_pool')->alias('tp')
|
||||
->join('wechat_friendship f', 'tp.wechatId=f.wechatId AND f.companyId='.$companyId, 'left')
|
||||
->join(['s2_wechat_friend' => 'wf'], 'f.wechatId=wf.wechatId', 'left')
|
||||
->where(['tp.id' => $userId])
|
||||
// ========== 旧版流量池代码(已废弃) ==========
|
||||
// $friend = Db::name('traffic_pool_v1')->alias('tp')
|
||||
// ->join('wechat_friendship f', 'tp.wechatId=f.wechatId AND f.companyId='.$companyId, 'left')
|
||||
// ->join(['s2_wechat_friend' => 'wf'], 'f.wechatId=wf.wechatId', 'left')
|
||||
// ->where(['tp.id' => $userId])
|
||||
// ========== 新版流量池代码 ==========
|
||||
$pool = Db::name('traffic_pool')->where('id', $userId)->find();
|
||||
if (!$pool) {
|
||||
return ResponseHelper::error('流量池记录不存在');
|
||||
}
|
||||
$friend = Db::name('s2_wechat_friend')->alias('wf')
|
||||
->join('wechat_friendship f', 'wf.wechatId=f.wechatId AND f.companyId='.$companyId, 'left')
|
||||
->where(['wf.wechatId' => $pool['identifier']])
|
||||
// ========== 旧版流量池代码结束 ==========
|
||||
->order('tp.createTime desc')
|
||||
->column('wf.id,wf.accountId,wf.labels,wf.siteLabels');
|
||||
if (empty($data)) {
|
||||
|
||||
Reference in New Issue
Block a user