新版流量池服务端提交

This commit is contained in:
wong
2026-02-04 10:58:56 +08:00
parent f956fc949b
commit 7534dd79fa
19 changed files with 1101 additions and 147 deletions

View File

@@ -328,12 +328,24 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
if (empty($userId)) {
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
}
$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')
// ========== 旧版流量池代码(已废弃) ==========
// $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' => []]);
}
@@ -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')
// ========== 旧版流量池代码(已废弃) ==========
// $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_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('请上传用户文件');
@@ -548,24 +569,29 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
$batchRows = array_slice($rows, $i, $batchSize);
if (!empty($batchRows)) {
$identifiers = array_column($batchRows, 'phone');
//流量池处理
$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);
}
// ========== 旧版流量池代码已废弃已迁移到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 = [];
@@ -638,10 +664,20 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
$isWechat = $this->request->param('isWechat', false);
$companyId = $this->getUserInfo('companyId');
$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])
// ========== 旧版流量池代码(已废弃) ==========
// $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)) {