where("status", 1)->get(); if ($oArticleSchemaList->isEmpty()) { echo " - 没有需要同步的文章\n"; } foreach ($oArticleSchemaList as $oArticleSchema) { $aCmdList = json_decode($oArticleSchema->cmd, true); foreach ($aCmdList as $sCmdKey => $aCmd) { // 得值 $sSiteCode = $aCmd["site_code"] ?? "none"; $oSite = ModelSiteMap::where("code", $sSiteCode)->first(); if (!$oSite) { $sMsg = "siteMap里的code没有映射:{$sSiteCode}\n"; TeleSlave::warn()->send($sMsg); echo $sMsg; continue; } $sSiteGroupCode = $oSite->group_code; $sSiteUrlBase = $oSite->url; $sSiteArticleApiPath = ModelSitePathMap::where("site_group_code", $sSiteGroupCode)->where("path_group_code", "article_receive_schema")->first()?->path; if (!$sSiteArticleApiPath) { $sMsg = "sitePathMap里没找到映射:{$sSiteGroupCode}:article_receive_schema\n"; TeleSlave::warn()->send($sMsg); echo $sMsg; continue; } $sSiteArticleApiUrl = "https://".$sSiteUrlBase.$sSiteArticleApiPath; // 附加常规 $aCmd["key"] = $sCmdKey; $aCmd["article_code"] = $oArticleSchema->code; // 附加config $sArticleConfig = ModelArticleConfig::where("article_group_code", $oArticleSchema->group_code)->where("site_group_code", $sSiteGroupCode)->first()?->config; $aArticleConfig = json_decode($sArticleConfig, true); $aCmd["config"] = $aArticleConfig; // 按需要附加其他 if ($aCmd["cmd"] == "new") { $oArticleFlow = ServiceArticleSchema::start($oArticleSchema->code, $sSiteCode)->build(); if ($oArticleFlow->isFail()) { TeleSlave::warn()->send([ "msg" => "文章build失败", "result"=> $oArticleFlow->getResult() ]); continue; } $aCmd["article"] = $oArticleFlow->getDataA(); } // 发送 $sHttpResult = HttpV2::make($sSiteArticleApiUrl)->enableJsonSend()->setDataA($aCmd)->send(); $aHttpResult = json_decode($sHttpResult, true); $bHttpIsDone = $aHttpResult["isDone"] ?? false; if (!$bHttpIsDone) { TeleSlave::warn()->send([ "msg" => "slave那边同步失败?", "result" => $aHttpResult, ]); continue; } $oCmdFLow = ServiceArticleCmd::startWithO($oArticleSchema)->moveToLog($sCmdKey); if ($oCmdFLow->isFail()) { TeleSlave::warn()->send([ "msg" => "movetolog失败?", "result" => $oCmdFLow->getResult(), ]); continue; } TeleSlave::notify()->send($aHttpResult["aData"]["aNewPath"]); } } echo "ok\n"; } // 废弃,不是通知了,直接推 public static function notifySalve() { echo "\nnotifySlave::开始\n"; $oArticleSchemaList = ModelArticleSchema::where("enable_sync", 1)->where("status", 1)->get(); if ($oArticleSchemaList->isEmpty()) { echo " - 没有需要同步的文章\n"; } foreach ($oArticleSchemaList as $oArticleSchema) { $aCmdList = json_decode($oArticleSchema->cmd, true); foreach ($aCmdList as $sCmdKey => $aCmd) { $sSiteCode = $aCmd["site_code"] ?? "none"; $oSite = ModelSiteMap::where("code", $sSiteCode)->first(); if (!$oSite) { $sMsg = "siteMap里的code没有映射:{$sSiteCode}\n"; TeleSlave::warn()->send($sMsg); echo $sMsg; continue; } $sSiteGroupCode = $oSite->group_code; $sSiteUrlBase = $oSite->url; $sSiteArticleApiPath = ModelSitePathMap::where("site_group_code", $sSiteGroupCode)->where("path_group_code", "article_receive_schema")->first()?->path; if (!$sSiteArticleApiPath) { $sMsg = "sitePathMap里没找到映射:{$sSiteGroupCode}:article_receive_schema\n"; TeleSlave::warn()->send($sMsg); echo $sMsg; continue; } $aCmd["key"] = $sCmdKey; $aCmd["article_code"] = $oArticleSchema->code; $sSiteArticleApiUrl = "https://".$sSiteUrlBase.$sSiteArticleApiPath; // 附加config $sArticleConfig = ModelArticleConfig::where("article_group_code", $oArticleSchema->group_code)->where("site_group_code", $sSiteGroupCode)->first()?->config; $aArticleConfig = json_decode($sArticleConfig, true); $aCmd["config"] = $aArticleConfig; // 按需要附加其他 if ($aCmd["cmd"] == "new") { ServiceArticleSchema::start($oArticleSchema->code,); } tomd($aCmd); tomd($oArticleSchema->group_code); tomd($sSiteGroupCode); tomd($sArticleConfig, 1); // $aA $sHttpResult = HttpV2::make($sSiteArticleApiUrl)->enableJsonAs()->setDataA($aCmd)->send(); $aHttpResult = json_decode($sHttpResult, true); $bHttpIsDone = $aHttpResult["isDone"] ?? false; if (!$bHttpIsDone) { $sMsg = "slave那边同步失败?"; TeleSlave::warn()->send($sMsg); continue; } $oCmdFLow = ServiceArticleCmd::startWithO($oArticleSchema)->moveToLog($sCmdKey); if ($oCmdFLow->isFail()) { $sMsg = "movetolog失败?"; TeleSlave::warn()->send($sMsg); continue; } } } echo "ok\n"; } public static function cacheTgSave() { echo "\ncacheTgSave::开始\n"; $iCacheTimeDelay = 60; // 延迟1分钟 $oCacheTime = ModelArticleCacheTime::first(); $iCacheTime = $oCacheTime->time; if ($iCacheTime == 0) { echo " - 没有新cache的time,跳过\n"; return false; } $iTimeDiff = time() - $iCacheTime; if ($iCacheTime < $iCacheTimeDelay) { echo " - 有缓存但没到更新时间\n"; return false; } $oSaveFlow = ServiceArticleCacheTg::start()->saveToSchema(); if ($oSaveFlow->isFail()) { var_dump($oSaveFlow->getResult()); TeleSlave::warn()->send("cron的cacheTgSave处理失败:".json_encode($oSaveFlow->getResult())); return false; } $oCacheTime->time = 0; $oCacheTime->save(); echo " - ok\n"; } }