更新报告
This commit is contained in:
parent
d1c91de640
commit
828ac82f09
@ -32,24 +32,24 @@ class GoogleAdsReportService
|
|||||||
$query->whereIn('a.customer_id', $customerIds); // 添加 customer_id 的查询约束
|
$query->whereIn('a.customer_id', $customerIds); // 添加 customer_id 的查询约束
|
||||||
} else {
|
} else {
|
||||||
return [
|
return [
|
||||||
'pagination' => [
|
'pagination' => [
|
||||||
'startIndex' => 0,
|
'startIndex' => 0,
|
||||||
'maxResults' => $pageSize,
|
'maxResults' => $pageSize,
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
'pageNo' => $page,
|
'pageNo' => $page,
|
||||||
'pageSize' => $pageSize,
|
'pageSize' => $pageSize,
|
||||||
'pages' => 0,
|
'pages' => 0,
|
||||||
],
|
],
|
||||||
'statistics' => [
|
'statistics' => [
|
||||||
'results' => '-',
|
'results' => '-',
|
||||||
'reach' => '-',
|
'reach' => '-',
|
||||||
'spend' => '-',
|
'spend' => '-',
|
||||||
'revenue' => '-',
|
'revenue' => '-',
|
||||||
'roas' => '-',
|
'roas' => '-',
|
||||||
'profit' => '-',
|
'profit' => '-',
|
||||||
'be_roas' => '-',
|
'be_roas' => '-',
|
||||||
],
|
],
|
||||||
'data' => [],
|
'data' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,8 +88,9 @@ class GoogleAdsReportService
|
|||||||
COALESCE(SUM(d.conversions), 0) as results,
|
COALESCE(SUM(d.conversions), 0) as results,
|
||||||
COALESCE(SUM(d.conversions_value), 0) as conversions_value,
|
COALESCE(SUM(d.conversions_value), 0) as conversions_value,
|
||||||
COALESCE(SUM(d.impressions), 0) as reach,
|
COALESCE(SUM(d.impressions), 0) as reach,
|
||||||
-1 as roas, -1 as be_roas, -1 as revenue, -1 as profit, -1 as delivery')
|
-1 as roas, -1 as be_roas, -1 as revenue, -1 as profit, -1 as delivery,
|
||||||
->group('a.ad_id, a.ad_name, a.status, a.customer_id, a.ad_group_id, g.ad_group_name, a.campaign_id, c.campaign_name')
|
a.metadata') // Include metadata field
|
||||||
|
->group('a.ad_id, a.ad_name, a.status, a.customer_id, a.ad_group_id, g.ad_group_name, a.campaign_id, c.campaign_name')
|
||||||
->where(function ($query) use ($keyword) {
|
->where(function ($query) use ($keyword) {
|
||||||
if ($keyword) {
|
if ($keyword) {
|
||||||
$query->where('a.ad_name', 'like', '%' . $keyword . '%');
|
$query->where('a.ad_name', 'like', '%' . $keyword . '%');
|
||||||
@ -113,8 +114,40 @@ class GoogleAdsReportService
|
|||||||
|
|
||||||
// 确保转换为数值,并格式化 -1 为 "-"
|
// 确保转换为数值,并格式化 -1 为 "-"
|
||||||
$result = array_map(function ($item) {
|
$result = array_map(function ($item) {
|
||||||
|
|
||||||
|
// Extract square marketing images from metadata
|
||||||
|
// Extract square marketing images from metadata
|
||||||
|
$metadata = $item['metadata'];
|
||||||
|
|
||||||
|
// 如果是对象,转换为数组
|
||||||
|
if (is_object($metadata)) {
|
||||||
|
$metadata = (array)$metadata;
|
||||||
|
}
|
||||||
|
$imageUrls = isset($metadata['square_marketing_images']) ? $metadata['square_marketing_images'] : [];
|
||||||
|
|
||||||
|
// Extract asset_id from the image URL
|
||||||
|
$assetId = 0;
|
||||||
|
if (!empty($imageUrls)) {
|
||||||
|
// Example: "customers/8452924576/assets/191936503309"
|
||||||
|
$imagePath = $imageUrls[0]; // Get the last element
|
||||||
|
preg_match('/assets\/(\d+)/', $imagePath, $matches);
|
||||||
|
if (isset($matches[1])) {
|
||||||
|
$assetId = $matches[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Query the asset_url from the bps_google_ads_asset table
|
||||||
|
$assetUrl = '';
|
||||||
|
if ($assetId) {
|
||||||
|
$asset = Asset::find($assetId);
|
||||||
|
if ($asset) {
|
||||||
|
$assetUrl = $asset['asset_url'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $item['ad_id'],
|
'id' => $item['ad_id'],
|
||||||
|
'customer_id' => $item['customer_id'],
|
||||||
|
'ad_group_id' => $item['ad_group_id'],
|
||||||
'name' => $item['ad_name'] ?: '-', // 默认值为 '-'
|
'name' => $item['ad_name'] ?: '-', // 默认值为 '-'
|
||||||
'status' => $item['ad_status'],
|
'status' => $item['ad_status'],
|
||||||
'results' => $item['results'],
|
'results' => $item['results'],
|
||||||
@ -125,10 +158,10 @@ class GoogleAdsReportService
|
|||||||
'spend' => number_format($item['spend'], 2),
|
'spend' => number_format($item['spend'], 2),
|
||||||
'campaign_name' => $item['campaign_name'],
|
'campaign_name' => $item['campaign_name'],
|
||||||
'ad_set_name' => $item['ad_group_name'], // Assuming ad_group_name as ad_set_name
|
'ad_set_name' => $item['ad_group_name'], // Assuming ad_group_name as ad_set_name
|
||||||
'delivery' => $item['delivery'] == -1 ? '-' : $item['delivery'],
|
'delivery' => $item['ad_status'],
|
||||||
'delivery_status' => '活动', // Assuming active as '活动'
|
'delivery_status' => '-', // Assuming active as '活动'
|
||||||
'be_roas' => $item['be_roas'] == -1 ? '-' : $item['be_roas'],
|
'be_roas' => $item['be_roas'] == -1 ? '-' : $item['be_roas'],
|
||||||
'image_urls' => [], // Add logic to populate image URLs if available
|
'image_url' => $assetUrl, // Add logic to populate image URLs if available
|
||||||
];
|
];
|
||||||
}, $ads->items());
|
}, $ads->items());
|
||||||
|
|
||||||
@ -154,9 +187,9 @@ class GoogleAdsReportService
|
|||||||
];
|
];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'pagination' => $pagination,
|
'pagination' => $pagination,
|
||||||
'statistics' => $statistics,
|
'statistics' => $statistics,
|
||||||
'data' => $result,
|
'data' => $result,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,24 +333,24 @@ class GoogleAdsReportService
|
|||||||
// 检查 customerIds 是否为空,直接返回空结构
|
// 检查 customerIds 是否为空,直接返回空结构
|
||||||
if (empty($customerIds)) {
|
if (empty($customerIds)) {
|
||||||
return [
|
return [
|
||||||
'pagination' => [
|
'pagination' => [
|
||||||
'startIndex' => 0,
|
'startIndex' => 0,
|
||||||
'maxResults' => $pageSize,
|
'maxResults' => $pageSize,
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
'pageNo' => $page,
|
'pageNo' => $page,
|
||||||
'pageSize' => $pageSize,
|
'pageSize' => $pageSize,
|
||||||
'pages' => 0,
|
'pages' => 0,
|
||||||
],
|
],
|
||||||
'statistics' => [
|
'statistics' => [
|
||||||
'results' => '-',
|
'results' => '-',
|
||||||
'reach' => '-',
|
'reach' => '-',
|
||||||
'spend' => '-',
|
'spend' => '-',
|
||||||
'revenue' => '-',
|
'revenue' => '-',
|
||||||
'roas' => '-',
|
'roas' => '-',
|
||||||
'profit' => '-',
|
'profit' => '-',
|
||||||
'be_roas' => '-',
|
'be_roas' => '-',
|
||||||
],
|
],
|
||||||
'data' => [],
|
'data' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
// 动态构建日期条件
|
// 动态构建日期条件
|
||||||
@ -389,6 +422,7 @@ class GoogleAdsReportService
|
|||||||
$result = array_map(function ($item) {
|
$result = array_map(function ($item) {
|
||||||
return [
|
return [
|
||||||
'id' => $item['campaign_id'],
|
'id' => $item['campaign_id'],
|
||||||
|
'customer_id' => $item['customer_id'],
|
||||||
'name' => $item['campaign_name'] ?: '-',
|
'name' => $item['campaign_name'] ?: '-',
|
||||||
'status' => $item['campaign_status'],
|
'status' => $item['campaign_status'],
|
||||||
'results' => $item['results'],
|
'results' => $item['results'],
|
||||||
@ -397,8 +431,8 @@ class GoogleAdsReportService
|
|||||||
'roas' => $item['roas'] == -1 ? '-' : $item['roas'],
|
'roas' => $item['roas'] == -1 ? '-' : $item['roas'],
|
||||||
'profit' => $item['profit'] == -1 ? '-' : $item['profit'],
|
'profit' => $item['profit'] == -1 ? '-' : $item['profit'],
|
||||||
'spend' => number_format($item['spend'], 2),
|
'spend' => number_format($item['spend'], 2),
|
||||||
'delivery' => $item['delivery'] == -1 ? '-' : $item['delivery'],
|
'delivery' => $item['campaign_status'],
|
||||||
'delivery_status' => '活动', // 默认状态
|
'delivery_status' => '-', // 默认状态
|
||||||
'be_roas' => $item['be_roas'] == -1 ? '-' : $item['be_roas'],
|
'be_roas' => $item['be_roas'] == -1 ? '-' : $item['be_roas'],
|
||||||
];
|
];
|
||||||
}, $campaigns->items());
|
}, $campaigns->items());
|
||||||
@ -414,9 +448,9 @@ class GoogleAdsReportService
|
|||||||
];
|
];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'pagination' => $pagination,
|
'pagination' => $pagination,
|
||||||
'statistics' => $statistics,
|
'statistics' => $statistics,
|
||||||
'data' => $result,
|
'data' => $result,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,24 +649,24 @@ class GoogleAdsReportService
|
|||||||
// 检查 customerIds 是否为空,直接返回空结构
|
// 检查 customerIds 是否为空,直接返回空结构
|
||||||
if (empty($customerIds)) {
|
if (empty($customerIds)) {
|
||||||
return [
|
return [
|
||||||
'pagination' => [
|
'pagination' => [
|
||||||
'startIndex' => 0,
|
'startIndex' => 0,
|
||||||
'maxResults' => $pageSize,
|
'maxResults' => $pageSize,
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
'pageNo' => $page,
|
'pageNo' => $page,
|
||||||
'pageSize' => $pageSize,
|
'pageSize' => $pageSize,
|
||||||
'pages' => 0,
|
'pages' => 0,
|
||||||
],
|
],
|
||||||
'statistics' => [
|
'statistics' => [
|
||||||
'results' => '-',
|
'results' => '-',
|
||||||
'reach' => '-',
|
'reach' => '-',
|
||||||
'spend' => '-',
|
'spend' => '-',
|
||||||
'revenue' => '-',
|
'revenue' => '-',
|
||||||
'roas' => '-',
|
'roas' => '-',
|
||||||
'profit' => '-',
|
'profit' => '-',
|
||||||
'be_roas' => '-',
|
'be_roas' => '-',
|
||||||
],
|
],
|
||||||
'data' => [],
|
'data' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -703,6 +737,7 @@ class GoogleAdsReportService
|
|||||||
$result = array_map(function ($item) {
|
$result = array_map(function ($item) {
|
||||||
return [
|
return [
|
||||||
'id' => $item['ad_group_id'],
|
'id' => $item['ad_group_id'],
|
||||||
|
'customer_id' => $item['customer_id'],
|
||||||
'name' => $item['ad_group_name'] ?: '-',
|
'name' => $item['ad_group_name'] ?: '-',
|
||||||
'status' => $item['ad_group_status'],
|
'status' => $item['ad_group_status'],
|
||||||
'campaign_name' => $item['campaign_name'],
|
'campaign_name' => $item['campaign_name'],
|
||||||
@ -728,9 +763,9 @@ class GoogleAdsReportService
|
|||||||
|
|
||||||
// 返回结果
|
// 返回结果
|
||||||
return [
|
return [
|
||||||
'pagination' => $pagination,
|
'pagination' => $pagination,
|
||||||
'statistics' => $statistics,
|
'statistics' => $statistics,
|
||||||
'data' => $result,
|
'data' => $result,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user