UserFundCheckValidator.php 523 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Module\Fund\Validators;
  3. use App\Module\Fund\Services\FundService;
  4. use UCore\Validator;
  5. class UserFundCheckValidator extends Validator
  6. {
  7. public function validate(mixed $value, array $data): bool
  8. {
  9. if($value < 0 ) {
  10. return false;
  11. }
  12. $user_id = $this->args[0];
  13. $fund_id = $this->args[1];
  14. $fund = new FundService($user_id, $fund_id);
  15. if ($fund->balance() < $value) {
  16. return false;
  17. }
  18. return true;
  19. }
  20. }