代码优化

This commit is contained in:
wong
2026-02-02 17:02:49 +08:00
parent 208c25b2f7
commit 442be3b02c
10 changed files with 1095 additions and 69 deletions

View File

@@ -10,6 +10,8 @@ use app\common\model\TrafficPoolTag;
use app\common\model\TrafficPoolTagCategory;
use app\common\model\TrafficPoolTagDefine;
use app\common\model\TrafficPoolAllotRecord;
use app\common\model\TrafficPoolSource;
use app\common\model\TrafficPoolBehavior;
use app\common\service\ClassTableService;
use library\ResponseHelper;
@@ -461,6 +463,28 @@ class TrafficPoolV2Controller extends BaseController
}
}
/**
* 从标签引擎同步用户标签
* @return \think\response\Json
*/
public function syncTagsFromEngine()
{
$poolCompanyId = $this->request->param('poolCompanyId', 0, 'intval');
$companyId = $this->getUserInfo('companyId');
$operatorId = $this->getUserInfo('id');
if (empty($poolCompanyId)) {
return ResponseHelper::error('流量ID不能为空');
}
try {
$result = $this->poolService->syncTagsFromEngine($poolCompanyId, $companyId, $operatorId);
return ResponseHelper::success($result, "同步成功:已同步 {$result['syncedCount']} 个标签");
} catch (\Exception $e) {
return ResponseHelper::error('同步标签失败:' . $e->getMessage());
}
}
// ==================== 分配相关接口 ====================
/**
@@ -565,5 +589,74 @@ class TrafficPoolV2Controller extends BaseController
return ResponseHelper::error('获取统计数据失败:' . $e->getMessage());
}
}
/**
* 分页获取流量来源
* @return \think\response\Json
*/
public function getPoolSources()
{
$poolCompanyId = $this->request->param('poolCompanyId', 0, 'intval');
$companyId = $this->getUserInfo('companyId');
$page = $this->request->param('page', 1, 'intval');
$pageSize = $this->request->param('pageSize', 20, 'intval');
$keyword = $this->request->param('keyword', '');
if (empty($poolCompanyId)) {
return ResponseHelper::error('流量ID不能为空');
}
// 验证流量归属
$poolCompany = TrafficPoolCompany::where('id', $poolCompanyId)
->where('companyId', $companyId)
->where('isDel', 0)
->find();
if (!$poolCompany) {
return ResponseHelper::error('流量不存在');
}
try {
$result = TrafficPoolSource::getSourcesWithOwnersPaginated($poolCompanyId, $page, $pageSize, $keyword);
return ResponseHelper::success($result);
} catch (\Exception $e) {
return ResponseHelper::error('获取来源列表失败:' . $e->getMessage());
}
}
/**
* 分页获取流量行为轨迹
* @return \think\response\Json
*/
public function getPoolBehaviors()
{
$poolCompanyId = $this->request->param('poolCompanyId', 0, 'intval');
$companyId = $this->getUserInfo('companyId');
$page = $this->request->param('page', 1, 'intval');
$pageSize = $this->request->param('pageSize', 20, 'intval');
$keyword = $this->request->param('keyword', '');
$behaviorType = $this->request->param('behaviorType', 0, 'intval');
if (empty($poolCompanyId)) {
return ResponseHelper::error('流量ID不能为空');
}
// 验证流量归属
$poolCompany = TrafficPoolCompany::where('id', $poolCompanyId)
->where('companyId', $companyId)
->where('isDel', 0)
->find();
if (!$poolCompany) {
return ResponseHelper::error('流量不存在');
}
try {
$result = TrafficPoolBehavior::getUserJourneyPaginated($poolCompanyId, $page, $pageSize, $keyword, $behaviorType);
return ResponseHelper::success($result);
} catch (\Exception $e) {
return ResponseHelper::error('获取行为轨迹失败:' . $e->getMessage());
}
}
}