googleOAuthService->getGoogleAdCustomers($options); // 遍历每一天的日期 $interval = new \DateInterval('P1D'); // 1天间隔 $dateRange = new \DatePeriod($startDate, $interval, $endDate->modify('+1 day')); // 包含 endDate foreach ($dateRange as $date) { $currentDate = $date->format('Y-m-d'); // 格式化日期为 Y-m-d // 遍历每个客户 foreach ($customers as $customer) { if ($customer['login_customer_id'] > 0) { $customer['date'] = $currentDate; // 设置当前日期 Redis::send($queue, $customer, rand(1, 10)); // 发送到 Redis 队列 } } } //同步消息到同步任务表 // $queueTask = self::task; // $taskInfo = [ // 'ecommerce' => 1001, // 'ecommerce_shop_id' => $options['date'], // 'task_type' => 'InsightsMerge', // 'remain' => 1 // ]; // Client::send($queueTask, $taskInfo, 30); return self::event . ' send queue ok'; } //同步某天成效 2025-2-11作废,改用syncDateRangeDatas public function syncDateDatas($options = []) { $queue = self::queue; $customers = $this->googleOAuthService->getGoogleAdCustomers($options); foreach ($customers as $customer) { if ($customer['login_customer_id'] > 0) { $customer['date'] = $options['date']; Redis::send($queue, $customer, rand(1, 10)); } } //同步消息到同步任务表 // $queueTask = self::task; // $taskInfo = [ // 'ecommerce' => 1001, // 'ecommerce_shop_id' => $options['date'], // 'task_type' => 'InsightsMerge', // 'remain' => 1 // ]; // Client::send($queueTask, $taskInfo, 30); return self::event . ' send queue ok'; } /** * get date datas * @throws ApiException */ public function getDateDatas($customer) { if ($customer['login_customer_id'] > 0 && ((isset($customer['manager']) && $customer['manager'] === false))) { // dump($customer); $googleAdsCampaignService = new googleAdsCampaignService($customer['customer_id']); // dump($customer['customer_id'],$customer, $options['date']); $googleAdsCampaignService->runListDateDatas($customer['customer_id'], $customer, $customer['date']); } // $this->googleAdsCampaignService->runListDateDatas($options['customer_id'], $options['date']); // return $this->successResponse(['data' => $resourceName]); } /** * 通知到同步task todo * @throws ApiException */ public function noticeDateDatas($taskInfo) { } // 可以加入一些公共方法 protected function successResponse($data): Response { return Json([ 'code' => 0, 'msg' => 'ok', 'data' => $data, ]); } protected function errorResponse($code, $message, $data = []): Response { return Json([ 'code' => $code, 'msg' => $message ?: 'error', 'data' => $data ]); } }