改进 模块罗列

This commit is contained in:
iVampireSP.com 2023-02-02 19:40:05 +08:00
parent b832c47016
commit 365c36bef2
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 13 additions and 1 deletions

View File

@ -12,7 +12,7 @@ class HomeController extends Controller
{ {
public function index(): View public function index(): View
{ {
$modules = (new Module)->paginate(10); $modules = (new Module)->whereHasBalance("0.01")->paginate(10);
return view('admin.index', compact('modules')); return view('admin.index', compact('modules'));
} }

View File

@ -3,8 +3,10 @@
namespace App\Models; namespace App\Models;
use App\Exceptions\User\BalanceNotEnoughException; use App\Exceptions\User\BalanceNotEnoughException;
use GeneaLabs\LaravelModelCaching\CachedBuilder;
use GeneaLabs\LaravelModelCaching\Traits\Cachable; use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\ConnectException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Http\Client\PendingRequest; use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\Response; use Illuminate\Http\Client\Response;
@ -271,4 +273,14 @@ public function charge(string|null $amount = '0', string $payment = 'console', s
return $this->balance; return $this->balance;
} }
public function hasBalance(string $amount = '0'): bool
{
return bccomp($this->balance, $amount, 4) >= 0;
}
public function whereHasBalance(string $amount = "0"): self|Builder|CachedBuilder
{
return $this->where('balance', '>=', $amount);
}
} }