dd/app/Http/Controllers/Api/GithubController.php
2025-07-16 20:45:41 +08:00

311 lines
8.8 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Controllers\Api;
//use App\Models\Book as ModelBook;
//use App\Models\BookOption as ModelBookOption;
use App\Services\TomTool\Http;
use App\Services\TG\Http as TgHttp;
use App\Models\GoodPool as ModelGoodPool;
use App\Models\Blade as ModelBlade;
use App\Models\Ship as ModelShip;
use App\Models\BoxCountry as ModelCountry;
use Illuminate\Http\Request;
use App\Models\BladeJctj as ModelBladeJctj;
use App\Models\BladeJctjOption as ModelBladeJctjOption;
//use App\Services\Country as ServiceCountry;
class GithubController
{
public $aArticle = [];
private function echo($sStr, $sMod)
{
if (empty($sStr)) {
return $sStr;
}
$sBr = "
";
if ($sMod == "brTop") {
$sStr = $sBr.$sStr;
} else if ($sMod == "brBottom") {
$sStr = $sStr.$sBr;
} else if ($sMod == "brFull") {
$sStr = $sBr.$sStr.$sBr;
}
return $sStr;
}
private function date($date)
{
return date($date);
}
private function goodToStr($sGood)
{
$aGood = json_decode($sGood, true);
$sGoodStr = "";
$i = 0;
foreach ($aGood as $row) {
if ($i !== 0) {
$sGoodStr .= "
";
}
$sGoodStr .= $row;
$i++;
}
return $sGoodStr;
}
private function toDayUpd($aArticle)
{
$oHttp = new Http();
$oHttp->sMethod = "get";
$oHttp->sToUrl = "https://".$this->aArticle["fn_www"]."/api/github/todayupd";
// $oHttp->bIsJson = true;
// $oHttp->aData = $row;
$r = $oHttp->send();
return $r;
}
private function getHuodong($aShip)
{
$sDateNow = date("Y-m-d");
// $sDateNow = "2025-05-03";
$oHttp = new Http();
$oHttp->sMethod = "get";
$oHttp->sToUrl = "https://".$aShip["www"]."/api/huodong/findbydate/".$sDateNow;
// $oHttp->bIsJson = true;
// $oHttp->aData = $row;
$r = $oHttp->send();
$aHuodong = json_decode($r, true);
$sHuodongStr = "";
if (!empty($aHuodong)) {
$sStartDateStr = date("n月j日", strtotime($aHuodong['start_date']));
$sEndDateStr = date("n月j日", strtotime($aHuodong['end_date']));
$sHuodongStr = "🎁 ".$aHuodong['title']."".$sStartDateStr."".$sEndDateStr."期间,".$aHuodong['content'];
}
return $sHuodongStr;
}
private function nodeContryStr()
{
$aBoxCountryRand = ModelCountry::rand();
return $aBoxCountryRand["str"];
}
private function mod_blade()
{
$aArticle = $this->aArticle;
// 可选
// $t = $this->toDayUpd(); freenode是否更新
// $t = $this->nodeContryStr(); 地区速度
$oBlade = ModelBlade::where("code", $aArticle["mod"])->first();
$aBlade = $oBlade->toArray();
$oShip = ModelShip::where("code", $aArticle["ship_code"])->first();
$aShip = $oShip->toArray();
$aGoodRand = ModelGoodPool::_rand($aArticle["ship_code"]);
$sGoodRand = ModelGoodPool::_goodToGithub($aGoodRand["good"] ?? []);
$ex["good_rand"] = $sGoodRand;
$sGoodShip = ModelGoodPool::_goodToGithub($aShip["good"]);
$ex["good_ship"] = $sGoodShip;
$ex["url_sub_v2ray"] = "https://".$aArticle["fn_www"]."/feed/v2ray-".date("Ymd").".txt";
$ex["url_sub_clash"] = "https://".$aArticle["fn_www"]."/clash/v2ray-".date("Ymd").".yaml";
$ex["youhui"] = "购买套餐时输入【".$aArticle['sale_code']."】优惠码,可享".$aArticle['sale_rate']."折优惠,折后低至".$aArticle['sale_price']."元/月。";
$ex["huodong"] = $this->getHuodong($aShip);
$eval = $oBlade->content;
eval("\$eval = \"$eval\";");
echo $eval;
exit;
}
private function mod_jctj()
{
$aArticle = $this->aArticle;
$oBladeArtile = ModelBlade::where("code", $aArticle["mod"])->first();
if (!$oBladeArtile) {
throw new \Exception("jctj也有有对应blade没找到 \n\n".json_encode($aArticle));
}
$aBladeArtile = $oBladeArtile->toArray();
//// 生成随机文章完全独立可以拿到services里
$iLimit = ModelBladeJctjOption::_hit("limit");
$iRand100 = rand(0, 100);
$oTomShip = ModelBladeJctj::where("is_tom", 1)->where("in100", ">=", $iRand100)->get();
$iTomShipCount = count($oTomShip);
$iLajiLimit = $iLimit - $iTomShipCount;
$oLaji = ModelBladeJctj::where("is_tom", "!=", 1)->get();
$aTomShip = $oTomShip->toArray();
$aLaji = $oLaji->toArray();
shuffle($aLaji);
shuffle($aTomShip);
$aLaji = array_slice($aLaji, 0, $iLimit);
$iTopCount = 0;
$iRandCount = 0;
$aTopShip = [];
$aRandShip = [];
foreach ($aTomShip as $aTomShipRow) {
if ($aTomShipRow["position"] == "top") {
unset($aLaji[$iTopCount]);
$iTopCount++;
$aTopShip[] = $aTomShipRow;
}
if ($aTomShipRow["position"] == "rand") {
$iRandCount++;
$aRandShip[] = $aTomShipRow;
}
}
// 优先toprand补充
if ($iRandCount > count($aLaji)) {
$iRandCount = count($aLaji);
}
$aRandKey = [];
if ($iRandCount >= 1) {
$aRandKey = array_rand($aLaji, $iRandCount);
}
if ((!empty($aRandKey) && !is_array($aRandKey)) || $aRandKey === 0) {
$tmp = $aRandKey;
$aRandKey = [];
$aRandKey[] = $tmp;
}
// 开始填充
if (count($aTopShip) > 0) {
foreach ($aTopShip as $k => $aTopShipRow) {
$aLaji[$k] = $aTopShipRow;
}
}
if (count($aRandKey) > 0) {
$i = 0;
foreach ($aRandKey as $v) {
$aLaji[$v] = $aRandShip[$i];
$i++;
}
}
ksort($aLaji);
//// 生成随机文章 end
$sTitleSize = ModelBladeJctjOption::_hit("title_size");
$sJctj = "";
$i = 1;
$sEnter = "
";
$eval = $aBladeArtile["content"];
eval("\$eval = \"$eval\";");
$sJctj .= $eval;
$sJctj .= $sEnter;
$sJctj .= $sEnter;
foreach ($aLaji as $k => $aLajiRow) {
// is_tom处理
if ($aLajiRow["is_tom"] == 1) {
$oShip = ModelShip::where("code", $aLajiRow["code"])->first();
if ($oShip) {
$aShip = $oShip->toArray();
$aGoodRand = ModelGoodPool::_rand($aLajiRow["code"]);
$sGoodRand = ModelGoodPool::_goodToGithub($aGoodRand["good"]);
$ex["good_rand"] = $sGoodRand;
$sGoodShip = ModelGoodPool::_goodToGithub($aShip["good"]);
$ex["good_ship"] = $sGoodShip;
$ex["huodong"] = $this->getHuodong($aShip);
$eval = $aLajiRow["content"];
eval("\$eval = \"$eval\";");
$aLajiRow["content"] = $eval;
}
}
if ($i !== 1) {
$sJctj .= $sEnter;
$sJctj .= $sEnter;
}
$sJctj .= $sTitleSize." ".$i.".".$aLajiRow["title"];
$sJctj .= $sEnter;
$sJctj .= $sEnter;
$sJctj .= $aLajiRow["content"];
$i++;
}
echo $sJctj;
exit;
}
public function get(Request $request)
{
try {
$aArticle = $request->all();
$this->aArticle = $aArticle;
if ($aArticle["mod_type"] == "blade") {
return $this->mod_blade();
} else if ($aArticle["mod_type"] == "jctj") {
return $this->mod_jctj();
}
} catch (\Throwable $e) {
$sMessage = "错误(文件: " . $e->getFile() . ",行: " . $e->getLine() . ": " . $e->getMessage();
$oTgHttp = (new TgHttp())->send($sMessage);
Http::response(200, 'error');
}
}
}