diff --git a/app/controller/BpsAdController.php b/app/controller/BpsAdController.php index 83ab437..fd2a387 100644 --- a/app/controller/BpsAdController.php +++ b/app/controller/BpsAdController.php @@ -89,7 +89,7 @@ class BpsAdController $startDateLastWeek = (int)date('Ymd', strtotime('-6 days')); // dump($startDateLastWeek, $endDateLastWeek); // if ($startDateLastWeek === $startDate && $endDateLastWeek === $endDate) { - $ad_data_count = $this->adsInsightService::getAdCountData($accountIds, $startDateLastWeek, $endDateLastWeek); + $ad_data_count = $this->adsInsightService::getAdCountData($options['jwtClaims']['merchant_id'], $accountIds, $startDateLastWeek, $endDateLastWeek); // } else { // $ad_data_count = []; // } diff --git a/app/service/AdsInsightService.php b/app/service/AdsInsightService.php index 406726d..03d90a6 100644 --- a/app/service/AdsInsightService.php +++ b/app/service/AdsInsightService.php @@ -56,7 +56,7 @@ class AdsInsightService * @param array $customerIds 客户 ID 数组 * @return array 各项 count 统计数据 */ - public static function getAdCountData($customerIds, $startDate, $endDate) + public static function getAdCountData($merchantId, $customerIds, $startDate, $endDate) { if (empty($customerIds)) { return []; @@ -70,9 +70,8 @@ class AdsInsightService if (!empty($cachedData)) { return json_decode($cachedData, true); } - // 没有缓存时重新计算 - $countData = self::calculateCountData($customerIds, $startDate, $endDate); + $countData = self::calculateCountData($merchantId,$customerIds, $startDate, $endDate); // 缓存到 Redis,有效期 10 分钟 Redis::setex($redisKey, 600, json_encode($countData)); @@ -84,13 +83,13 @@ class AdsInsightService /** * 计算广告数据的 count */ - protected static function calculateCountData(array $customerIds, $startDate, $endDate) + protected static function calculateCountData($merchantId, $customerIds, $startDate, $endDate) { if (!$startDate || !$endDate) { [$startDate, $endDate] = self::getLastWeekDateRange(); } return [ - 'account_list_count' => self::getAccountListCount($customerIds, $startDate, $endDate), + 'account_list_count' => self::getAccountListCount($merchantId,$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), @@ -134,9 +133,9 @@ class AdsInsightService /** * 获取账户列表的 count */ - protected static function getAccountListCount(array $customerIds, $startDate, $endDate) + protected static function getAccountListCount($merchantId,$customerIds, $startDate, $endDate) { - return self::getAccountList(0, $customerIds, 1, 1, '', $startDate, $endDate, false, true); + return self::getAccountList(0, $merchantId,$customerIds, 1, 1, '', $startDate, $endDate, false, true); } /**