From ccd2f4d3b665f90091f7d180ec2feaaa1facfbc2 Mon Sep 17 00:00:00 2001 From: huangguancheng <huangguancheng@bestfulfill> Date: Wed, 15 Jan 2025 21:30:42 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=88Accounts=E3=80=81Campaigns=E3=80=81Ad?= =?UTF-8?q?=20Sets=20=E3=80=81Ads=E3=80=81Creatives=EF=BC=89=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=88=B0=20Excel=20=E6=9B=B4=E6=96=B03?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/AdsInsightService.php | 63 ++++++++++++++++++------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/app/service/AdsInsightService.php b/app/service/AdsInsightService.php index 74e885f..ca1d670 100644 --- a/app/service/AdsInsightService.php +++ b/app/service/AdsInsightService.php @@ -20,6 +20,7 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use think\db\exception\DbException; use think\facade\Db as ThinkDb; use support\Redis; +use support\Response; class AdsInsightService { @@ -336,11 +337,12 @@ class AdsInsightService $campaignList = self::getCampaignList($platformType, $customerIds, $page, $pageSize, $keyword, $startDate, $endDate, $status, false); if (empty($campaignList['data'])) { - return Json([ + $data = [ 'code' => 901, 'msg' => 'No data available for export.', 'data' => [] - ]); + ]; + return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE)); } // 创建 Spreadsheet 对象 @@ -440,11 +442,12 @@ class AdsInsightService return response()->download($filePath, $fileName); } catch (\Exception $e) { // return ['success' => false, 'message' => $e->getMessage()]; - return Json([ + $data = [ 'code' => 901, - 'msg' => 'error', + 'msg' => 'No data available for export.', 'data' => [] - ]); + ]; + return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE)); } } @@ -466,11 +469,12 @@ class AdsInsightService $adsetList = self::getAdsetList($platformType, $customerIds, $page, $pageSize, $keyword, $startDate, $endDate, $status, false); if (empty($adsetList['data'])) { - return Json([ + $data = [ 'code' => 901, 'msg' => 'No data available for export.', 'data' => [] - ]); + ]; + return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE)); } // 创建 Spreadsheet 对象 @@ -570,11 +574,12 @@ class AdsInsightService return response()->download($filePath, $fileName); } catch (\Exception $e) { // return ['success' => false, 'message' => $e->getMessage()]; - return Json([ + $data = [ 'code' => 901, - 'msg' => 'error', + 'msg' => 'No data available for export.', 'data' => [] - ]); + ]; + return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE)); } } @@ -596,11 +601,12 @@ class AdsInsightService $adList = self::getAdList($platformType, $customerIds, $page, $pageSize, $keyword, $startDate, $endDate, $status, false); if (empty($adList['data'])) { - return Json([ + $data = [ 'code' => 901, 'msg' => 'No data available for export.', 'data' => [] - ]); + ]; + return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE)); } // 创建 Spreadsheet 对象 @@ -700,11 +706,12 @@ class AdsInsightService return response()->download($filePath, $fileName); } catch (\Exception $e) { // return ['success' => false, 'message' => $e->getMessage()]; - return Json([ + $data = [ 'code' => 901, - 'msg' => 'error', + 'msg' => 'No data available for export.', 'data' => [] - ]); + ]; + return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE)); } } @@ -714,11 +721,12 @@ class AdsInsightService $creativeList = self::getCreativeInsightData($platformType, $customerIds, $page, $pageSize, $keyword, $startDate, $endDate, false); if (empty($creativeList['data'])) { - return Json([ + $data = [ 'code' => 901, 'msg' => 'No data available for export.', 'data' => [] - ]); + ]; + return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE)); } // 创建 Spreadsheet 对象 @@ -830,11 +838,12 @@ class AdsInsightService $writer->save($filePath); return response()->download($filePath, $fileName); } catch (\Exception $e) { - return Json([ + $data = [ 'code' => 901, - 'msg' => 'error', + 'msg' => 'No data available for export.', 'data' => [] - ]); + ]; + return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE)); } } @@ -1026,14 +1035,15 @@ class AdsInsightService // 调用 getCampaignList 获取广告系列数据 $accountList = self::getAccountList($platformType, $customerIds, $page, $pageSize, $keyword, $startDate, $endDate, false); -// dump($accountList); + $accountList['data'] = []; if (empty($accountList['data'])) { - return Json([ + $data = [ 'code' => 901, 'msg' => 'No data available for export.', 'data' => [] - ]); + ]; + return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE)); } // 创建 Spreadsheet 对象 @@ -1131,11 +1141,12 @@ class AdsInsightService return response()->download($filePath, $fileName); } catch (\Exception $e) { // return ['success' => false, 'message' => $e->getMessage()]; - return Json([ + $data = [ 'code' => 901, - 'msg' => 'error', + 'msg' => 'No data available for export.', 'data' => [] - ]); + ]; + return new Response(400, ['Content-Type' => 'application/json'], json_encode($data, JSON_UNESCAPED_UNICODE)); } }