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)); } }