CheckUserFundValidator.php 960 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Module\Fund\Validators;
  3. use App\Module\Fund\Enums\FUND_TYPE;
  4. use App\Module\Fund\Services\FundService;
  5. use UCore\Validator;
  6. class CheckUserFundValidator extends Validator
  7. {
  8. /**
  9. * @param mixed $value
  10. * @param array $data
  11. * @return bool
  12. * 验证用户余额是否充足
  13. */
  14. public function validate(mixed $value, array $data): bool
  15. {
  16. $map = [
  17. 1 => FUND_TYPE::FUND1->value,
  18. 2 => FUND_TYPE::USD->value,
  19. 3 => FUND_TYPE::BNB->value
  20. ];
  21. $fundId = $map[$data['coinType']];
  22. // 操作资金
  23. $amount = $data['amount'] * 10000000;
  24. // 矿工费
  25. $miner = \App\Module\AppGame\Service\FundService::getMiner($data['coinType'], $amount);
  26. $service = new FundService($data['userId'], $fundId);
  27. if ($service->balance() < ($amount + $miner)) {
  28. return false;
  29. }
  30. return true;
  31. }
  32. }