dd/app/Models/GoodPool.php
2025-07-16 20:41:54 +08:00

71 lines
1.4 KiB
PHP
Executable File

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class GoodPool extends Model
{
protected $table = 'good_pool';
public $timestamps = false;
// public static function _find($sCode)
// {
// $oSelf = self::where("code", $sCode)->first();
//
// return $oSelf;
// }
public static function _all()
{
$oSelf = self::all();
// $oNew;
foreach ($oSelf as &$oSelfRow) {
$oSelfRow->good = json_decode($oSelfRow->good);
}
return $oSelf;
}
public static function _rand($sClass)
{
$oGood = self::where("class", $sClass)->get();
if ($oGood->isEmpty()) {
return [];
}
$aGood = $oGood->toArray();
$iGoodRandKey = array_rand($aGood);
$aGoodRand = $aGood[$iGoodRandKey];
return $aGoodRand;
}
public static function _goodToGithub($sGood, $bEnter = true)
{
$aGood = json_decode($sGood);
$str = "";
$i = 0;
foreach ($aGood as $sGoodRow) {
if ($i !== 0) {
$str .= "
";
if ($bEnter == true) {
$str .= "
";
}
}
$str .= $sGoodRow;
$i++;
}
return $str;
}
}