oHttp->sToUrl = "https://".env("APP_WWW")."/api/freenode/country/rand"; $this->oHttp->bIsJson = true; $this->sMethod = "get"; $r = $this->oHttp->send(); $r = json_decode($r, true); $r = $this->toJson($r); return $r; } public function country_hit($aParam) { $sName = $aParam["aArg"][1] ?? false; if (!$sName) { return "需要arg[1],name。"; } $oCountry = ModelBoxCountry::where("name", $sName)->get(); if(!$oCountry) { return "不存在".$sName; } return $this->toJson($oCountry); } public function country_list() { $oCountry = ModelBoxCountry::all()->toArray(); return $this->toJson($oCountry); } public function country_add($aParam) { $sName = $aParam["aArg"][1] ?? false; if (!$sName) { return "需要有arg[1],name。"; } $oCountry = new ModelBoxCountry(); $oCountry->name = $sName; $oCountry->save(); return $this->toJson($oCountry); } public function country_set($aParam) { $iId = $aParam["aOption"][1] ?? false; $sField = $aParam["aArg"][1] ?? false; $sValue = $aParam["aArg"][2] ?? false; if (!$iId) { return "需要option[1],id。"; } if (!$sField) { return "需要arg[1],field。"; } if (!$sValue) { return "需要arg[2],value。"; } $oCountry = ModelBoxCountry::find($iId); if (!$oCountry) { return "没找到"; } $oCountry->$sField = $sValue; $oCountry->save(); return $this->toJson($oCountry); } public function country_del($aParam) { $iId = $aParam["aArg"][1] ?? false; if (!$iId) { return "需要arg[1],id。"; } $oCountry = ModelBoxCountry::find($iId); if (!$oCountry) { return "没找到"; } $r = $oCountry->delete(); return $r; } public function github_tag_rand($aParam) { $sType = $aParam["aOption"][1] ?? false; $iLimit = $aParam["aArg"][1] ?? false; if (!$sType) { return "要有option[1],a带中文,b不带中文。"; } if (!$iLimit) { return "要有arg[1], 生成几个。"; } $aGithubTag = GithubTag::all()->toArray(); shuffle($aGithubTag); $i = 1; $sRandTag = ""; foreach ($aGithubTag as $aGithubTagRow) { if ($i == 1) { $sPre = ""; } else { $sPre = "、"; } if ($sType == "b") { if ($aGithubTagRow["type"] == "cn") { continue; } } $sRandTag .= $sPre.$aGithubTagRow["tag"]; if ($i >= $iLimit) { break; } else { $i++; } } return $sRandTag; } public function github_tag_list() { $oGithubTag = GithubTag::all()->get(); return $this->toJson($oGithubTag); } public function github_tag_add($aParam) { $sTag = $aParam["aArg"][1] ?? false; $sType = $aParam["aArg"][2] ?? false; if (!$sTag) { return "需要arg[1],tag。"; } if (!$sType) { return "需要arg[2],cn中文,en英文。"; } $oGithubTag = new GithubTag(); $oGithubTag->tag = $sTag; $oGithubTag->type = $sType; $oGithubTag->save(); return $this->toJson($oGithubTag); } public function github_tag_set($aParam) { $iId = $aParam["aOption"][1] ?? false; $sField = $aParam["aOption"][2] ?? false; $sValue = $aParam["aArg"][1] ?? false; if (!$iId) { return "需要option[1],id。"; } if (!$sField) { return "需要option[2],field。"; } if (!$sValue) { return "需要arg[1],value。"; } $oGithubTag = GithubTag::find($iId); if (!$oGithubTag) { return "没找到"; } $oGithubTag->$sField = $sValue; $oGithubTag->save(); return $this->toJson($oGithubTag); } public function github_tag_del($aParam) { $iId = $aParam["aArg"][1] ?? false; if (!$iId) { return "需要arg[1],id。"; } $oGithubTag = GithubTag::find($iId); $r = $oGithubTag->delete(); return $r; } }