广告接口支持多店铺 初始化
This commit is contained in:
parent
9a60e35749
commit
965d4cc2b2
@ -137,7 +137,11 @@ class BpsAdController
|
||||
// 获取请求参数
|
||||
// $startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||||
// $endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id']]);
|
||||
$store_id = $options['conditions']['store_id'] ?? null; // 新引入店铺id
|
||||
if ($store_id === null) {
|
||||
return $this->successResponse(['data' => []], $request);
|
||||
}
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'store_id' => $store_id]);
|
||||
if (empty($accounts)) {
|
||||
return $this->successResponse(['data' => []], $request);
|
||||
}
|
||||
@ -146,7 +150,7 @@ class BpsAdController
|
||||
$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);
|
||||
$ad_data_count = $this->adsInsightService::getAdCountData($options['jwtClaims']['merchant_id'], $store_id, $accountIds, $startDateLastWeek, $endDateLastWeek);
|
||||
// } else {
|
||||
// $ad_data_count = [];
|
||||
// }
|
||||
@ -158,13 +162,7 @@ class BpsAdController
|
||||
{
|
||||
$options = $request->all();
|
||||
$options['jwtClaims'] = $request->jwtClaims;
|
||||
$options['rpc'] = (bool)true;
|
||||
if ($options['rpc']) {
|
||||
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
}
|
||||
$options['rpc'] = $request->rpc ?? false;
|
||||
|
||||
|
||||
// 获取请求参数
|
||||
@ -172,16 +170,25 @@ class BpsAdController
|
||||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
// $status = $options['conditions']['status'] ?? 0; // 平台类型
|
||||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||||
// $dateRange = 'Last Week'; // 默认日期范围
|
||||
if ($options['rpc']) {
|
||||
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
$store_id = $options['jwtClaims']['store_id'] ?? null;
|
||||
}
|
||||
|
||||
// 根据 platformType 获取广告账户
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts)) {
|
||||
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
if ($options['rpc']) {
|
||||
return [];
|
||||
}
|
||||
@ -196,6 +203,7 @@ class BpsAdController
|
||||
$result = $this->adsInsightService::getAccountList(
|
||||
$platformType, // 平台类型
|
||||
$options['jwtClaims']['merchant_id'], // 店铺
|
||||
$store_id,
|
||||
$accountIds, // 客户 ID 数组
|
||||
$page, // 页码
|
||||
$pageSize, // 每页数量
|
||||
@ -219,28 +227,32 @@ class BpsAdController
|
||||
$options = $request->all();
|
||||
$options['jwtClaims'] = $request->jwtClaims;
|
||||
$options['rpc'] = $request->rpc ?? false;
|
||||
if ($options['rpc']) {
|
||||
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
}
|
||||
|
||||
|
||||
// 获取请求参数
|
||||
$page = $options['pageNo'] ?? 1; // 页码
|
||||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
$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 ($options['rpc']) {
|
||||
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
$store_id = $options['jwtClaims']['store_id'] ?? null;
|
||||
}
|
||||
|
||||
if (empty($accounts)) {
|
||||
// 根据 platformType 获取广告账户
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
if ($options['rpc']) {
|
||||
return [];
|
||||
}
|
||||
@ -275,28 +287,31 @@ class BpsAdController
|
||||
{
|
||||
$options = $request->all();
|
||||
$options['jwtClaims'] = $request->jwtClaims;
|
||||
$options['rpc'] = (bool)true;
|
||||
if ($options['rpc']) {
|
||||
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
}
|
||||
$options['rpc'] = $request->rpc ?? false;
|
||||
|
||||
// 获取请求参数
|
||||
$page = $options['pageNo'] ?? 1; // 页码
|
||||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
$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)) {
|
||||
if ($options['rpc']) {
|
||||
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
$store_id = $options['jwtClaims']['store_id'] ?? null;
|
||||
}
|
||||
// 根据 platformType 获取广告账户
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
if ($options['rpc']) {
|
||||
return [];
|
||||
}
|
||||
@ -336,15 +351,16 @@ class BpsAdController
|
||||
$pageSize = 10000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
$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]);
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts)) {
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
$data = [
|
||||
'code' => 901,
|
||||
'msg' => 'No data available for export.',
|
||||
@ -379,15 +395,16 @@ class BpsAdController
|
||||
$pageSize = 10000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
// $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]);
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts)) {
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
$data = [
|
||||
'code' => 901,
|
||||
'msg' => 'No data available for export.',
|
||||
@ -402,6 +419,8 @@ class BpsAdController
|
||||
// 调用 Service 层查询
|
||||
return $this->adsInsightService::exportAccountsToExcel(
|
||||
$platformType,
|
||||
$options['jwtClaims']['merchant_id'], // 店铺
|
||||
$store_id,
|
||||
$accountIds, // 客户 ID 数组
|
||||
$page, // 页码
|
||||
$pageSize, // 每页数量
|
||||
@ -422,15 +441,16 @@ class BpsAdController
|
||||
$pageSize = 10000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
// $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]);
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts)) {
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
$data = [
|
||||
'code' => 901,
|
||||
'msg' => 'No data available for export.',
|
||||
@ -465,15 +485,16 @@ class BpsAdController
|
||||
$pageSize = 10000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
$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]);
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts)) {
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
$data = [
|
||||
'code' => 901,
|
||||
'msg' => 'No data available for export.',
|
||||
@ -509,15 +530,16 @@ class BpsAdController
|
||||
$pageSize = 10000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 关键字搜索
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
$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]);
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts)) {
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
$data = [
|
||||
'code' => 901,
|
||||
'msg' => 'No data available for export.',
|
||||
@ -548,28 +570,32 @@ class BpsAdController
|
||||
$options = $request->all();
|
||||
$options['jwtClaims'] = $request->jwtClaims;
|
||||
$options['rpc'] = $request->rpc ?? false;
|
||||
if ($options['rpc']) {
|
||||
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
}
|
||||
|
||||
|
||||
// 获取请求参数
|
||||
$page = $options['pageNo'] ?? 1; // 页码
|
||||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
$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 ($options['rpc']) {
|
||||
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
$store_id = $options['jwtClaims']['store_id'] ?? null;
|
||||
}
|
||||
|
||||
if (empty($accounts)) {
|
||||
// 根据 platformType 获取广告账户
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
if ($options['rpc']) {
|
||||
return [];
|
||||
}
|
||||
@ -604,28 +630,31 @@ class BpsAdController
|
||||
{
|
||||
$options = $request->all();
|
||||
$options['jwtClaims'] = $request->jwtClaims;
|
||||
if ($options['rpc']) {
|
||||
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
}
|
||||
|
||||
|
||||
// 获取请求参数
|
||||
$page = $options['pageNo'] ?? 1; // 页码
|
||||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
$startDate = $options['conditions']['startDate'] ?? null; // 开始日期
|
||||
$endDate = $options['conditions']['endDate'] ?? null; // 结束日期
|
||||
$requireSpend = (bool)($options['conditions']['requireSpend'] ?? false);
|
||||
|
||||
// $dateRange = 'Last Week'; // 默认日期范围
|
||||
if ($options['rpc']) {
|
||||
//$options['conditions']['startDate']由2025-02-14处理成纯整数
|
||||
$options['conditions']['startDate'] = (int)str_replace('-', '', $options['conditions']['startDate']);
|
||||
$options['conditions']['endDate'] = (int)str_replace('-', '', $options['conditions']['endDate']);
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
$store_id = $options['jwtClaims']['store_id'] ?? null;
|
||||
}
|
||||
|
||||
// 根据 platformType 获取广告账户
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType]);
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts)) {
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
if ($options['rpc']) {
|
||||
return [];
|
||||
}
|
||||
@ -664,14 +693,15 @@ class BpsAdController
|
||||
$pageSize = $options['pageSize'] ?? 1000; // 每页数量
|
||||
$keyword = $options['conditions']['keyword'] ?? ''; // 关键字搜索
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
$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]);
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts)) {
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
return $this->successResponse(['data' => []], $request);
|
||||
}
|
||||
|
||||
@ -701,14 +731,15 @@ class BpsAdController
|
||||
// 获取请求参数
|
||||
$cycle = $options['conditions']['cycle'] ?? 3; // 页码
|
||||
$platformType = $options['conditions']['platformType'] ?? 0; // 平台类型
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
$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]);
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'platform' => $platformType, 'store_id' => $store_id]);
|
||||
|
||||
if (empty($accounts)) {
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
return $this->successResponse(['data' => []], $request);
|
||||
}
|
||||
|
||||
@ -733,21 +764,23 @@ class BpsAdController
|
||||
$options = $request->all();
|
||||
$options['jwtClaims'] = $request->jwtClaims;
|
||||
$options['rpc'] = $request->rpc ?? false;
|
||||
if ($options['rpc']) {
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
}
|
||||
|
||||
|
||||
// 获取请求参数
|
||||
$cycle = $options['conditions']['dateType'] ?? 'today'; //默认today || today yesterday、month、year 、custom
|
||||
$cycle = $options['conditions']['dateType'] ?? 'today'; //默认today || today yesterday、month、year 、custom
|
||||
$store_id = $options['conditions']['store_id'] ?? null;
|
||||
// $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 ($options['rpc']) {
|
||||
$options['jwtClaims'] = $options['conditions']['user'];
|
||||
$store_id = $options['jwtClaims']['store_id'] ?? null;
|
||||
}
|
||||
$accounts = $this->bpsAdAccountService->getAllAdAccounts(['merchant_id' => $options['jwtClaims']['merchant_id'], 'store_id' => $store_id]);
|
||||
|
||||
|
||||
if (empty($accounts)) {
|
||||
if (empty($accounts) || $store_id === null) {
|
||||
return $this->successResponse(['data' => new \stdClass()], $request);
|
||||
}
|
||||
|
||||
|
36
app/model/BpsAdsMerchantStoreRelation.php
Normal file
36
app/model/BpsAdsMerchantStoreRelation.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class BpsAdsMerchantStoreRelation extends Model
|
||||
{
|
||||
// 设置当前模型对应的完整数据表名称
|
||||
protected $table = 'bps.bps_ads_merchant_store_relation';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
// 复合唯一键验证
|
||||
protected $unique = [
|
||||
['platform', 'merchant_id', 'account_id', 'store_id']
|
||||
];
|
||||
|
||||
// 设置自动时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
// 定义时间戳字段
|
||||
protected $createTime = 'created_at'; // 创建时间字段
|
||||
protected $updateTime = 'updated_at'; // 更新时间字段
|
||||
|
||||
// 字段类型映射
|
||||
// 字段类型映射(移除了不存在的字段)
|
||||
protected $casts = [
|
||||
'platform' => 'int',
|
||||
];
|
||||
|
||||
// 默认值设置
|
||||
protected $defaults = [
|
||||
// 根据实际需要设置存在的字段默认值
|
||||
];
|
||||
|
||||
}
|
@ -5,7 +5,9 @@ namespace app\service;
|
||||
use app\model\Ad;
|
||||
use app\model\BpsAdCreativeInsight;
|
||||
use app\model\BpsAdInsight;
|
||||
use app\model\BpsAdsMerchantRelation;
|
||||
|
||||
//use app\model\BpsAdsMerchantRelation;
|
||||
use app\model\BpsAdsMerchantStoreRelation;
|
||||
use app\model\DayData;
|
||||
use app\model\Campaign;
|
||||
use app\model\BpsAdCampaign;
|
||||
@ -56,7 +58,7 @@ class AdsInsightService
|
||||
* @param array $customerIds 客户 ID 数组
|
||||
* @return array 各项 count 统计数据
|
||||
*/
|
||||
public static function getAdCountData($merchantId, $customerIds, $startDate, $endDate)
|
||||
public static function getAdCountData($merchantId, $storeId, $customerIds, $startDate, $endDate)
|
||||
{
|
||||
if (empty($customerIds)) {
|
||||
return [];
|
||||
@ -71,7 +73,7 @@ class AdsInsightService
|
||||
return json_decode($cachedData, true);
|
||||
}
|
||||
// 没有缓存时重新计算
|
||||
$countData = self::calculateCountData($merchantId, $customerIds, $startDate, $endDate);
|
||||
$countData = self::calculateCountData($merchantId, $storeId, $customerIds, $startDate, $endDate);
|
||||
|
||||
// 缓存到 Redis,有效期 10 分钟
|
||||
Redis::setex($redisKey, 600, json_encode($countData));
|
||||
@ -83,13 +85,13 @@ class AdsInsightService
|
||||
/**
|
||||
* 计算广告数据的 count
|
||||
*/
|
||||
protected static function calculateCountData($merchantId, $customerIds, $startDate, $endDate)
|
||||
protected static function calculateCountData($merchantId, $storeId, $customerIds, $startDate, $endDate)
|
||||
{
|
||||
if (!$startDate || !$endDate) {
|
||||
[$startDate, $endDate] = self::getLastWeekDateRange();
|
||||
}
|
||||
return [
|
||||
'account_list_count' => self::getAccountListCount($merchantId, $customerIds, $startDate, $endDate),
|
||||
'account_list_count' => self::getAccountListCount($merchantId, $storeId, $customerIds, $startDate, $endDate),
|
||||
'campaign_list_count' => self::getCampaignListCount($customerIds, $startDate, $endDate),
|
||||
'adset_list_count' => self::getAdsetListCount($customerIds, $startDate, $endDate),
|
||||
'ad_list_count' => self::getAdListCount($customerIds, $startDate, $endDate),
|
||||
@ -133,9 +135,9 @@ class AdsInsightService
|
||||
/**
|
||||
* 获取账户列表的 count
|
||||
*/
|
||||
protected static function getAccountListCount($merchantId, $customerIds, $startDate, $endDate)
|
||||
protected static function getAccountListCount($merchantId, $storeId, $customerIds, $startDate, $endDate)
|
||||
{
|
||||
return self::getAccountList(0, $merchantId, $customerIds, 1, 1, '', $startDate, $endDate, false, true);
|
||||
return self::getAccountList(0, $merchantId, $storeId, $customerIds, 1, 1, '', $startDate, $endDate, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1044,10 +1046,10 @@ class AdsInsightService
|
||||
* @param string|null $endDate 结束日期
|
||||
* @param int $status 广告系列状态
|
||||
*/
|
||||
public static function exportAccountsToExcel($platformType, $customerIds, $page, $pageSize, $keyword, $startDate = null, $endDate = null, $requireSpend = false)
|
||||
public static function exportAccountsToExcel($platformType, $merchantId, $storeId, $customerIds, $page, $pageSize, $keyword, $startDate = null, $endDate = null, $requireSpend = false)
|
||||
{
|
||||
// 调用 getCampaignList 获取广告系列数据
|
||||
$accountList = self::getAccountList($platformType, $customerIds, $page, $pageSize, $keyword, $startDate, $endDate, $requireSpend);
|
||||
$accountList = self::getAccountList($platformType, $merchantId, $storeId, $customerIds, $page, $pageSize, $keyword, $startDate, $endDate, $requireSpend);
|
||||
|
||||
if (empty($accountList['data'])) {
|
||||
$data = [
|
||||
@ -1162,7 +1164,7 @@ class AdsInsightService
|
||||
}
|
||||
}
|
||||
|
||||
public static function getAccountList($platformType, $merchantId, $customerIds, $page, $pageSize, $keyword, $startDate = null, $endDate = null, $requireSpend = false, $countOnly = false)
|
||||
public static function getAccountList($platformType, $merchantId, $storeId, $customerIds, $page, $pageSize, $keyword, $startDate = null, $endDate = null, $requireSpend = false, $countOnly = false)
|
||||
{
|
||||
// 检查 customerIds 是否为空,直接返回计数为 0
|
||||
if (empty($customerIds)) {
|
||||
@ -1183,9 +1185,10 @@ class AdsInsightService
|
||||
// $query = ThirdUserAdvertiser::alias('a')
|
||||
// ->cache(false)
|
||||
// ->where('a.advertiser_id', 'in', $customerIds);
|
||||
$query = BpsAdsMerchantRelation::alias('bamr')
|
||||
$query = BpsAdsMerchantStoreRelation::alias('bamr')
|
||||
->cache(false)
|
||||
->where('bamr.merchant_id', '=', $merchantId)
|
||||
->where('bamr.store_id', '=', $storeId)
|
||||
->where('bamr.account_id', 'in', $customerIds);
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\service;
|
||||
|
||||
use app\model\BpsAdsMerchantStoreRelation;
|
||||
use think\facade\Db as ThinkDb;
|
||||
use app\model\ThirdUserAdvertiser;
|
||||
|
||||
@ -258,10 +259,11 @@ class BpsAdAccountService
|
||||
// }
|
||||
|
||||
/**
|
||||
* 作废2025-03-17
|
||||
* 批量获取全部广告账号数据
|
||||
* TODO 增加fields入参
|
||||
*/
|
||||
public function getAllAdAccounts($options = [])
|
||||
public function getAllAdAccountsOld($options = [])
|
||||
{
|
||||
$merchant_id = $options['merchant_id'];
|
||||
$platform = $options['platform'] ?? 0;
|
||||
@ -293,6 +295,41 @@ class BpsAdAccountService
|
||||
return $customers->toArray();
|
||||
|
||||
}
|
||||
/**
|
||||
* 批量获取全部广告账号数据(通过store_id)
|
||||
* TODO 增加fields入参
|
||||
*/
|
||||
public function getAllAdAccounts($options = [])
|
||||
{
|
||||
$store_id = $options['store_id'];
|
||||
$merchant_id = $options['merchant_id'];
|
||||
$platform = $options['platform'] ?? 0;
|
||||
if ($platform > 0) {
|
||||
// 获取某广告平台符合条件的客户ID数组
|
||||
$customers = BpsAdsMerchantStoreRelation::alias('bamsr')
|
||||
->where('bamsr.platform', $platform)
|
||||
->where('bamsr.merchant_id', $merchant_id)
|
||||
->where('bamsr.store_id', $store_id)
|
||||
->field('bamsr.account_id')
|
||||
->select(); // 执行查询
|
||||
} else {
|
||||
// 获取全部广告平台符合条件的客户ID数组
|
||||
$customers = BpsAdsMerchantStoreRelation::alias('bamsr')
|
||||
->where('bamsr.merchant_id', $merchant_id)
|
||||
->where('bamsr.store_id', $store_id)
|
||||
->field('bamsr.account_id')
|
||||
->select(); // 执行查询
|
||||
}
|
||||
// 如果没有找到符合条件的广告主,抛出异常
|
||||
if ($customers->isEmpty()) {
|
||||
return [];
|
||||
// throw new ApiException('No customers found for google third type');
|
||||
}
|
||||
|
||||
// 转换为简单的数组(提取 advertiser_id)
|
||||
return $customers->toArray();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 获取所有平台的第三方用户数据
|
||||
|
Loading…
Reference in New Issue
Block a user