按facebook入参条件修改接口入参结构

This commit is contained in:
hgc 2025-01-04 17:15:22 +08:00
parent f3cbaa3854
commit 700e96d880
2 changed files with 95 additions and 102 deletions

View File

@ -2,14 +2,14 @@
namespace app\controller;
use app\service\GoogleAdsAdService;
use app\service\GoogleAdsCampaignService;
use app\service\GoogleAdsGroupService;
use app\service\GoogleAdsAdService;
use app\service\GoogleAdsReportService;
use app\service\GoogleOAuthService;
use DI\Annotation\Inject;
use support\Request;
use support\Response;
use DI\Annotation\Inject;
class AdController
@ -47,43 +47,43 @@ class AdController
public function listAds(Request $request)
{
$options = $request->all();
// 获取请求参数
$page = $request->input('page', 1); // 页码
$pageSize = $request->input('page_size', 20); // 每页数量
$keyword = $request->input('keyword', ''); // 关键字搜索
$dateRange = $request->input('date_range', 'Last Week'); // 日期范围
$page = $options['pageNo'] ?? 1; // 页码
$pageSize = $options['pageSize'] ?? 10; // 每页数量
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
$dateRange = 'Last Week'; // 默认日期范围
// 获取自定义日期范围
$startDate = $request->input('start_date', null); // 开始日期,默认为 null
$endDate = $request->input('end_date', null); // 结束日期,默认为 null
// 你可以进一步验证日期格式(可选)
// if ($startDate && !strtotime($startDate)) {
// return response()->json(['error' => 'Invalid start date format'], 400);
// }
// if ($endDate && !strtotime($endDate)) {
// return response()->json(['error' => 'Invalid end date format'], 400);
// }
// $customerIds = [8452924576,6977154211,1401879025];
$customers = $this->googleOAuthService->getGoogleAdCustomers(['refresh_token' => $request->refresh_token]);
$customerIds = array_column($customers, 'customer_id');
// dump($customers);
// 调用 Service 层查询
$result = $this->googleAdsReportService::getAdList($customerIds, $page, $pageSize, $keyword, $dateRange, $startDate, $endDate);
$result = $this->googleAdsReportService::getAdList(
$customerIds, // 客户 ID 数组
$page, // 页码
$pageSize, // 每页数量
$keyword, // 关键字
$dateRange,
$startDate, // 开始日期
$endDate
); // 结束日期);
return $this->successResponse($result);
}
public function listAssets(Request $request)
{
// 获取请求参数
$page = $request->input('page', 1); // 页码
$pageSize = $request->input('page_size', 20); // 每页数量
$keyword = $request->input('keyword', ''); // 关键字搜索
$dateRange = $request->input('date_range', 'Last Week'); // 日期范围
$options = $request->all();
// 获取自定义日期范围
$startDate = $request->input('start_date', null); // 开始日期,默认为 null
$endDate = $request->input('end_date', null); // 结束日期,默认为 null
// 获取请求参数
$page = $options['pageNo'] ?? 1; // 页码
$pageSize = $options['pageSize'] ?? 10; // 每页数量
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
$dateRange = 'Last Week'; // 默认日期范围
// $customerId = 4060397299;
$customers = $this->googleOAuthService->getGoogleAdCustomers(['refresh_token' => $request->refresh_token]);
@ -98,54 +98,54 @@ class AdController
// }
// 调用 Service 层查询
$result = $this->googleAdsReportService->getAssetConversionData($customerIds, $page, $pageSize, $keyword, $dateRange, $startDate, $endDate);
$result = $this->googleAdsReportService->getAssetConversionData(
$customerIds, // 客户 ID 数组
$page, // 页码
$pageSize, // 每页数量
$keyword, // 关键字
$dateRange,
$startDate, // 开始日期
$endDate);
return $this->successResponse($result);
}
public function listCampaigns(Request $request)
{
$options = $request->all();
// 获取请求参数
$page = $request->input('page', 1); // 页码
$pageSize = $request->input('page_size', 20); // 每页数量
$keyword = $request->input('keyword', ''); // 关键字搜索
$dateRange = $request->input('date_range', 'Last Week'); // 日期范围
$page = $options['pageNo'] ?? 1; // 页码
$pageSize = $options['pageSize'] ?? 10; // 每页数量
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
$dateRange = 'Last Week'; // 默认日期范围
// 获取自定义日期范围
$startDate = $request->input('start_date', null); // 开始日期,默认为 null
$endDate = $request->input('end_date', null); // 结束日期,默认为 null
// 你可以进一步验证日期格式(可选)
// if ($startDate && !strtotime($startDate)) {
// return response()->json(['error' => 'Invalid start date format'], 400);
// }
// if ($endDate && !strtotime($endDate)) {
// return response()->json(['error' => 'Invalid end date format'], 400);
// }
// $customerIds = [8452924576, 6977154211, 1401879025];
$customers = $this->googleOAuthService->getGoogleAdCustomers(['refresh_token' => $request->refresh_token]);
$customerIds = array_column($customers, 'customer_id');
// 调用 Service 层查询
$result = $this->googleAdsReportService::getCampaignList($customerIds, $page, $pageSize, $keyword, $dateRange, $startDate, $endDate);
$result = $this->googleAdsReportService::getCampaignList(
$customerIds, // 客户 ID 数组
$page, // 页码
$pageSize, // 每页数量
$keyword, // 关键字
$dateRange,
$startDate, // 开始日期
$endDate // 结束日期
);
return $this->successResponse($result);
// return $this->errorResponse(300,'授权失败');
}
public function exportAdsToExcel(Request $request)
{
$keyword = $request->input('keyword', ''); // 获取关键字参数
$dateRange = $request->input('date_range', 'Last Week'); // 获取日期范围参数
$options = $request->all();
// 获取自定义日期范围
$startDate = $request->input('start_date', null); // 开始日期,默认为 null
$endDate = $request->input('end_date', null); // 结束日期,默认为 null
// 你可以进一步验证日期格式(可选)
// if ($startDate && !strtotime($startDate)) {
// return response()->json(['error' => 'Invalid start date format'], 400);
// }
// if ($endDate && !strtotime($endDate)) {
// return response()->json(['error' => 'Invalid end date format'], 400);
// }
// 获取请求参数
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
$dateRange = 'Last Week'; // 默认日期范围
$customers = $this->googleOAuthService->getGoogleAdCustomers(['refresh_token' => $request->refresh_token]);
$customerIds = array_column($customers, 'customer_id');
@ -155,35 +155,28 @@ class AdController
public function exportCampaignsToExcel(Request $request)
{
$keyword = $request->input('keyword', ''); // 获取关键字参数
$dateRange = $request->input('date_range', 'Last Week'); // 获取日期范围参数
$options = $request->all();
// 获取请求参数
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
$dateRange = 'Last Week'; // 默认日期范围
// 获取自定义日期范围
$startDate = $request->input('start_date', null); // 开始日期,默认为 null
$endDate = $request->input('end_date', null); // 结束日期,默认为 null
// 你可以进一步验证日期格式(可选)
// if ($startDate && !strtotime($startDate)) {
// return response()->json(['error' => 'Invalid start date format'], 400);
// }
// if ($endDate && !strtotime($endDate)) {
// return response()->json(['error' => 'Invalid end date format'], 400);
// }
$customers = $this->googleOAuthService->getGoogleAdCustomers(['refresh_token' => $request->refresh_token]);
$customerIds = array_column($customers, 'customer_id');
// dump($customerIds);
// 调用 service 层导出数据
return $this->googleAdsReportService->exportCampaignsToExcel($customerIds,$keyword, $dateRange, $startDate, $endDate);
return $this->googleAdsReportService->exportCampaignsToExcel($customerIds, $keyword, $dateRange, $startDate, $endDate);
}
public function exportGroupsToExcel(Request $request)
{
$keyword = $request->input('keyword', ''); // 获取关键字参数
$dateRange = $request->input('date_range', 'Last Week'); // 获取日期范围参数
// 获取自定义日期范围
$startDate = $request->input('start_date', null); // 开始日期,默认为 null
$endDate = $request->input('end_date', null); // 结束日期,默认为 null
$options = $request->all();
// 获取请求参数
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
$dateRange = 'Last Week'; // 默认日期范围
$customers = $this->googleOAuthService->getGoogleAdCustomers(['refresh_token' => $request->refresh_token]);
$customerIds = array_column($customers, 'customer_id');
@ -197,33 +190,33 @@ class AdController
// }
// 调用 service 层导出数据
return $this->googleAdsReportService->exportAdGroupsToExcel($customerIds,$keyword, $dateRange, $startDate, $endDate);
return $this->googleAdsReportService->exportAdGroupsToExcel($customerIds, $keyword, $dateRange, $startDate, $endDate);
}
public function listGroups(Request $request)
{
$options = $request->all();
// 获取请求参数
$page = $request->input('page', 1); // 页码
$pageSize = $request->input('page_size', 20); // 每页数量
$keyword = $request->input('keyword', ''); // 关键字搜索
$dateRange = $request->input('date_range', 'Last Week'); // 日期范围
$page = $options['pageNo'] ?? 1; // 页码
$pageSize = $options['pageSize'] ?? 10; // 每页数量
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
$dateRange = 'Last Week'; // 默认日期范围
// 获取自定义日期范围
$startDate = $request->input('start_date', null); // 开始日期,默认为 null
$endDate = $request->input('end_date', null); // 结束日期,默认为 null
// 你可以进一步验证日期格式(可选)
// if ($startDate && !strtotime($startDate)) {
// return response()->json(['error' => 'Invalid start date format'], 400);
// }
// if ($endDate && !strtotime($endDate)) {
// return response()->json(['error' => 'Invalid end date format'], 400);
// }
//$customerIds = [8452924576,6977154211,1401879025];
$customers = $this->googleOAuthService->getGoogleAdCustomers(['refresh_token' => $request->refresh_token]);
$customerIds = array_column($customers, 'customer_id');
// 调用 Service 层查询
$result = $this->googleAdsReportService::getAdGroupList($customerIds, $page, $pageSize, $keyword, $dateRange, $startDate, $endDate);
$result = $this->googleAdsReportService::getAdGroupList(
$customerIds, // 客户 ID 数组
$page, // 页码
$pageSize, // 每页数量
$keyword, // 关键字
$dateRange,
$startDate, // 开始日期
$endDate
);
return $this->successResponse($result);
}

View File

@ -92,9 +92,9 @@ class GoogleAdsReportService
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) {
if ($keyword) {
$query->where('a.ad_name', 'like', '%' . $keyword . '%');
}
// if ($keyword) {
// $query->where('a.ad_name', 'like', '%' . $keyword . '%');
// }
});
// 获取所有符合条件的数据(不分页)
$allAds = $query->select()->toArray(); // 使用 toArray() 将对象转化为数组
@ -249,9 +249,9 @@ class GoogleAdsReportService
->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('a.customer_id', 'in', $customerIds)
->where(function ($query) use ($keyword) {
if ($keyword) {
$query->where('a.ad_name', 'like', '%' . $keyword . '%');
}
// if ($keyword) {
// $query->where('a.ad_name', 'like', '%' . $keyword . '%');
// }
});