730 lines
30 KiB
PHP
730 lines
30 KiB
PHP
<?php
|
||
|
||
namespace app\controller;
|
||
|
||
use app\service\GoogleAdsAdService;
|
||
use app\service\GoogleAdsCampaignService;
|
||
use app\service\GoogleAdsGroupService;
|
||
|
||
//use app\service\GoogleAdsReportService;
|
||
use app\service\AdsInsightService;
|
||
use app\service\AdsDashboardService;
|
||
use app\service\LandingUrlInsightService;
|
||
use app\service\GoogleOAuthService;
|
||
use app\service\BpsAdAccountService;
|
||
use DI\Annotation\Inject;
|
||
use support\Request;
|
||
use support\Response;
|
||
|
||
|
||
class BpsAdController
|
||
{
|
||
|
||
/**
|
||
* @Inject
|
||
* @var AdsInsightService
|
||
*/
|
||
private $adsInsightService;
|
||
|
||
/**
|
||
* /**
|
||
* @Inject
|
||
* @var AdsDashboardService
|
||
*/
|
||
private $adsDashboardService;
|
||
|
||
/**
|
||
* @Inject
|
||
* @var LandingUrlInsightService
|
||
*/
|
||
private $landingUrlInsightService;
|
||
|
||
/**
|
||
* @Inject
|
||
* @var GoogleAdsGroupService
|
||
*/
|
||
private $googleAdsGroupService;
|
||
|
||
/**
|
||
* @Inject
|
||
* @var GoogleAdsAdService
|
||
*/
|
||
private $googleAdsAdService;
|
||
|
||
/**
|
||
* @Inject
|
||
* @var GoogleAdsCampaignService
|
||
*/
|
||
private $googleAdsCampaignService;
|
||
|
||
/**
|
||
* @Inject
|
||
* @var GoogleOAuthService
|
||
*/
|
||
private $googleOAuthService;
|
||
/**
|
||
* @Inject
|
||
* @var BpsAdAccountService
|
||
*/
|
||
private $bpsAdAccountService;
|
||
|
||
/*
|
||
* 返回标签页角标数字接口
|
||
*
|
||
*/
|
||
public function listAdBadges(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
// $startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
// $endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id']]);
|
||
if (empty($accounts)) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
$accountIds = array_unique(array_column($accounts, 'account_id'));
|
||
$endDateLastWeek = (int)date('Ymd');
|
||
$startDateLastWeek = (int)date('Ymd', strtotime('-6 days'));
|
||
// dump($startDateLastWeek, $endDateLastWeek);
|
||
// if ($startDateLastWeek === $startDate && $endDateLastWeek === $endDate) {
|
||
$ad_data_count = $this->adsInsightService::getAdCountData($options['jwtClaims']['merchant_id'], $accountIds, $startDateLastWeek, $endDateLastWeek);
|
||
// } else {
|
||
// $ad_data_count = [];
|
||
// }
|
||
// 返回结果
|
||
return $this->successResponse($ad_data_count, $request);
|
||
}
|
||
|
||
public function listThirdUsers(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||
// $status = $options['conditions']['status'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
|
||
// 根据 platformType 获取广告账户
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||
|
||
if (empty($accounts)) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
// dump($accounts);
|
||
// 获取客户ID数组
|
||
$accountIds = array_unique(array_column($accounts, 'account_id'));
|
||
|
||
|
||
// 调用 Service 层查询广告列表
|
||
$result = $this->adsInsightService::getAccountList(
|
||
$platformType, // 平台类型
|
||
$options['jwtClaims']['merchant_id'], // 店铺
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate, // 结束日期
|
||
$requireSpend
|
||
);
|
||
|
||
|
||
// 返回结果
|
||
return $this->successResponse($result, $request);
|
||
}
|
||
|
||
public function listAds(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||
$status = $options['conditions']['status'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$requireSpend = (bool)($options['conditions']['requireSpend']?? false);
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
|
||
// 根据 platformType 获取广告账户
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||
|
||
if (empty($accounts)) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_unique(array_column($accounts, 'account_id'));
|
||
|
||
// 调用 Service 层查询广告列表
|
||
$result = $this->adsInsightService::getAdList(
|
||
$platformType, // 平台类型
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate, // 结束日期
|
||
$status,
|
||
$requireSpend
|
||
);
|
||
|
||
// 返回结果
|
||
return $this->successResponse($result, $request);
|
||
}
|
||
|
||
public function listCampaigns(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||
$status = $options['conditions']['status'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
// 根据 platformType 获取广告账户
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||
|
||
if (empty($accounts)) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_column($accounts, 'account_id');
|
||
// 调用 Service 层查询
|
||
$result = $this->adsInsightService::getCampaignList(
|
||
$platformType,
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate, // 结束日期
|
||
$status,
|
||
$requireSpend
|
||
);
|
||
return $this->successResponse($result, $request);
|
||
// return $this->errorResponse(300,'授权失败');
|
||
}
|
||
|
||
public function exportCampaignsToExcel(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = 10000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||
$status = $options['conditions']['status'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
// 根据 platformType 获取广告账户
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||
|
||
if (empty($accounts)) {
|
||
$data = [
|
||
'code' => 901,
|
||
'msg' => 'No data available for export.',
|
||
'data' => []
|
||
];
|
||
// return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_column($accounts, 'account_id');
|
||
// 调用 Service 层查询
|
||
return $this->adsInsightService::exportCampaignsToExcel(
|
||
$platformType,
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate, // 结束日期
|
||
$status,
|
||
$requireSpend
|
||
);
|
||
}
|
||
|
||
public function exportAccountsToExcel(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = 10000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||
// $status = $options['conditions']['status'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
// 根据 platformType 获取广告账户
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||
|
||
if (empty($accounts)) {
|
||
$data = [
|
||
'code' => 901,
|
||
'msg' => 'No data available for export.',
|
||
'data' => []
|
||
];
|
||
return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE));
|
||
// return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_column($accounts, 'account_id');
|
||
// 调用 Service 层查询
|
||
return $this->adsInsightService::exportAccountsToExcel(
|
||
$platformType,
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate, // 结束日期
|
||
$requireSpend
|
||
);
|
||
}
|
||
|
||
public function exportCreativesToExcel(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = 10000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||
// $status = $options['conditions']['status'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
// 根据 platformType 获取广告账户
|
||
if ($platformType === 1) {
|
||
if (!$request->refresh_token_facebook) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
$accounts = $this->bpsAdAccountService->getMetaAdAccounts(['refresh_token' => $request->refresh_token_facebook]);
|
||
} elseif ($platformType === 2) {
|
||
if (!$request->refresh_token_google) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
$accounts = $this->bpsAdAccountService->getGoogleAdAccounts(['refresh_token' => $request->refresh_token_google]);
|
||
} elseif ($platformType === 3) {
|
||
if (!$request->refresh_token_tiktok) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
$accounts = $this->bpsAdAccountService->getTiktokAdAccounts(['refresh_token' => $request->refresh_token_tiktok]);
|
||
} else {
|
||
// TODO: 匹配jwt的商户id还是登录用户id
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id']]);
|
||
}
|
||
|
||
if (empty($accounts)) {
|
||
$data = [
|
||
'code' => 901,
|
||
'msg' => 'No data available for export.',
|
||
'data' => []
|
||
];
|
||
return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE));
|
||
// return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_column($accounts, 'account_id');
|
||
// 调用 Service 层查询
|
||
return $this->adsInsightService::exportCreativesToExcel(
|
||
$platformType,
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate, // 结束日期
|
||
$requireSpend
|
||
);
|
||
}
|
||
|
||
public function exportAdsetsToExcel(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = 10000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||
$status = $options['conditions']['status'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
// 根据 platformType 获取广告账户
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||
|
||
if (empty($accounts)) {
|
||
$data = [
|
||
'code' => 901,
|
||
'msg' => 'No data available for export.',
|
||
'data' => []
|
||
];
|
||
return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE));
|
||
// return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_column($accounts, 'account_id');
|
||
// 调用 Service 层查询
|
||
return $this->adsInsightService::exportAdsetsToExcel(
|
||
$platformType,
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate, // 结束日期
|
||
$status,
|
||
$requireSpend
|
||
);
|
||
}
|
||
|
||
public function exportAdsToExcel(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = 10000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||
$status = $options['conditions']['status'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
// 根据 platformType 获取广告账户
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||
|
||
if (empty($accounts)) {
|
||
$data = [
|
||
'code' => 901,
|
||
'msg' => 'No data available for export.',
|
||
'data' => []
|
||
];
|
||
return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE));
|
||
// return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_column($accounts, 'account_id');
|
||
// 调用 Service 层查询
|
||
return $this->adsInsightService::exportAdsToExcel(
|
||
$platformType,
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate, // 结束日期
|
||
$status,
|
||
$requireSpend
|
||
);
|
||
}
|
||
|
||
public function listAdsets(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||
$status = $options['conditions']['status'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
|
||
// 根据 platformType 获取广告账户
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||
|
||
if (empty($accounts)) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_unique(array_column($accounts, 'account_id'));
|
||
// dump($accountIds);
|
||
// 调用 Service 层查询广告组列表
|
||
$result = $this->adsInsightService::getAdsetList(
|
||
$platformType,
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate, // 结束日期
|
||
$status,
|
||
$requireSpend
|
||
);
|
||
|
||
// 返回结果
|
||
return $this->successResponse($result, $request);
|
||
}
|
||
|
||
public function listCreatives(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
|
||
// 根据 platformType 获取广告账户
|
||
if ($platformType === 1) {
|
||
if (!$request->refresh_token_facebook) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
$accounts = $this->bpsAdAccountService->getMetaAdAccounts(['refresh_token' => $request->refresh_token_facebook]);
|
||
} elseif ($platformType === 2) {
|
||
if (!$request->refresh_token_google) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
$accounts = $this->bpsAdAccountService->getGoogleAdAccounts(['refresh_token' => $request->refresh_token_google]);
|
||
} elseif ($platformType === 3) {
|
||
if (!$request->refresh_token_tiktok) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
$accounts = $this->bpsAdAccountService->getTiktokAdAccounts(['refresh_token' => $request->refresh_token_tiktok]);
|
||
} else {
|
||
// TODO: 匹配jwt的商户id还是登录用户id
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id']]);
|
||
}
|
||
|
||
if (empty($accounts)) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_unique(array_column($accounts, 'account_id'));
|
||
// dump($accountIds);
|
||
// 调用 Service 层查询广告组列表
|
||
$result = $this->adsInsightService::getCreativeInsightData(
|
||
$platformType,
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate, // 结束日期
|
||
$requireSpend
|
||
);
|
||
|
||
// 返回结果
|
||
return $this->successResponse($result, $request);
|
||
}
|
||
|
||
public function listLandingUrls(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$page = $options['pageNo'] ?? 1; // 页码
|
||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
|
||
// 根据 platformType 获取广告账户
|
||
if ($platformType === 1) {
|
||
if (!$request->refresh_token_facebook) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
$accounts = $this->bpsAdAccountService->getMetaAdAccounts(['refresh_token' => $request->refresh_token_facebook]);
|
||
} elseif ($platformType === 2) {
|
||
if (!$request->refresh_token_google) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
$accounts = $this->bpsAdAccountService->getGoogleAdAccounts(['refresh_token' => $request->refresh_token_google]);
|
||
} elseif ($platformType === 3) {
|
||
if (!$request->refresh_token_tiktok) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
$accounts = $this->bpsAdAccountService->getTiktokAdAccounts(['refresh_token' => $request->refresh_token_tiktok]);
|
||
} else {
|
||
// TODO: 匹配jwt的商户id还是登录用户id
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id']]);
|
||
}
|
||
|
||
if (empty($accounts)) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_unique(array_column($accounts, 'account_id'));
|
||
// dump($accountIds);
|
||
// 调用 Service 层查询广告组列表
|
||
$result = $this->landingUrlInsightService::getLandingUrlInsightData(
|
||
$platformType,
|
||
$accountIds, // 客户 ID 数组
|
||
$page, // 页码
|
||
$pageSize, // 每页数量
|
||
$keyword, // 关键字
|
||
$startDate, // 开始日期
|
||
$endDate // 结束日期
|
||
);
|
||
|
||
// 返回结果
|
||
return $this->successResponse($result, $request);
|
||
}
|
||
|
||
public function listCharts(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$cycle = $options['conditions']['cycle'] ?? 3; // 页码
|
||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
|
||
// 根据 platformType 获取广告账户
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||
|
||
if (empty($accounts)) {
|
||
return $this->successResponse(['data' => []], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_unique(array_column($accounts, 'account_id'));
|
||
// dump($accountIds);
|
||
// 调用 Service 层查询广告组列表
|
||
$result = $this->adsInsightService->getAdCycleInsight(
|
||
$platformType,
|
||
$accountIds, // 客户 ID 数组
|
||
$cycle, // 页码
|
||
$startDate, // 开始日期
|
||
$endDate // 结束日期
|
||
);
|
||
|
||
// 返回结果
|
||
return $this->successResponse($result, $request);
|
||
}
|
||
|
||
public function listCards(Request $request)
|
||
{
|
||
$options = $request->all();
|
||
$options['jwtClaims'] = $request->jwtClaims;
|
||
|
||
// 获取请求参数
|
||
$cycle = $options['conditions']['dateType'] ?? 'today'; //默认today || today yesterday、month、year 、custom
|
||
// $platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||
// $dateRange = 'Last Week'; // 默认日期范围
|
||
|
||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id']]);
|
||
|
||
|
||
if (empty($accounts)) {
|
||
return $this->successResponse(['data' => new \stdClass()], $request);
|
||
}
|
||
|
||
// 获取客户ID数组
|
||
$accountIds = array_unique(array_column($accounts, 'account_id'));
|
||
// dump($accountIds);
|
||
// 调用 Service 层查询广告组列表
|
||
$result = $this->adsDashboardService->getAdCycleCard(
|
||
$accountIds, // 客户 ID 数组
|
||
$cycle, // 页码
|
||
$startDate, // 开始日期
|
||
$endDate // 结束日期
|
||
);
|
||
|
||
// 返回结果
|
||
return $this->successResponse($result, $request);
|
||
}
|
||
|
||
|
||
// 可以加入一些公共方法
|
||
protected function successResponse($data, Request $request): Response
|
||
{
|
||
$responseData = [
|
||
'code' => 0,
|
||
'msg' => 'ok',
|
||
'data' => $data,
|
||
];
|
||
|
||
|
||
if (is_array($data) && empty($data)) {
|
||
$responseData['data'] = new \stdClass();
|
||
}
|
||
|
||
// 如果有新 token,添加到 header
|
||
if ($request->jwtNewToken) {
|
||
return new Response(200, [
|
||
'Content-Type' => 'application/json',
|
||
'X-New-Token' => $request->jwtNewToken,
|
||
], json_encode($responseData, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
|
||
return Json($responseData);
|
||
}
|
||
|
||
|
||
protected
|
||
function errorResponse($code, $message, $data = []): Response
|
||
{
|
||
return Json([
|
||
'code' => $code,
|
||
'msg' => $message ?: 'error',
|
||
'data' => $data
|
||
]);
|
||
}
|
||
|
||
}
|