info(date('H:i') . ' 开始执行'); $this->start(); $this->info(date('H:i') . ' 结束执行'); return 0; } public function start() { $curTime = time(); while (true) { if ((time() - $curTime) >= 60) break; $dataJson = RedisModel::rPop(JxStarLiveTaskList::JUXING_STAR_LIVE_TASK_INDB_LIST); if (empty($dataJson)) { sleep(2); continue; } $data = json_decode($dataJson, true); if (!isset($data['advertiser_id'], $data['data'])) { # 输出错误日志 Log::error('数据参数不合法', $data, 'Star:LiveTaskDataInDb'); continue; } $this->taskDataInDb($data); } } public function taskDataInDb($data) { $advertiserId = $data['advertiser_id']; $dataVal = $data['data']; $taskId = $dataVal['task_id'] ?? null; if (empty($taskId)) { # 输出错误日志 Log::error('taskId 为空', $data, 'Star:LiveTaskDataInDb'); return false; } $lockKey = RdsLockService::getRdsLockKey([ 'starLive', $advertiserId, $taskId ]); if (RdsLockService::addRdsLock($lockKey)) { $taskInfo = JxStarLiveTaskList::query() ->where('advertiser_id', $advertiserId) ->where('task_id', $taskId) ->where('enable', 1) ->first(); if (empty($taskInfo)) { $taskInfo = new JxStarLiveTaskList([ 'advertiser_id' => $advertiserId, 'task_id' => $taskId ]); } $taskInfo->task_name = $dataVal['task_name'] ?? null; $taskInfo->task_status = $dataVal['task_status'] ?? null; $taskInfo->task_status_desc = $dataVal['task_status_desc'] ?? null; $taskInfo->create_time = $dataVal['create_time'] ?? null; $taskInfo->tips_card_config = $dataVal['tips_card_config'] ?? null; $taskInfo->tips_card_theme_pic = $dataVal['tips_card_theme_pic'] ?? null; $taskInfo->tips_card_sub_title = $dataVal['tips_card_sub_title'] ?? null; $taskInfo->app_download_component = isset($dataVal['app_download_component']) ? json_encode($dataVal['app_download_component']) : null; $taskInfo->brand_component = isset($dataVal['brand_component']) ? json_encode($dataVal['brand_component']) : null; $taskInfo->clue_collection_component = isset($dataVal['clue_collection_component']) ? json_encode($dataVal['clue_collection_component']) : null; $taskInfo->landing_component = isset($dataVal['landing_component']) ? json_encode($dataVal['landing_component']) : null; $taskInfo->save(); RdsLockService::delRdsLock($lockKey); } // Log::info('任务数据入库成功', ['taskId' => $taskId], 'Star:LiveTaskDataInDb'); return 0; } }