選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

58 行
1.5KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\User;
  3. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  4. use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
  5. use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
  6. use Lc\SovBundle\Model\User\UserInterface;
  7. use Lc\SovBundle\Repository\AbstractStore;
  8. class UserMerchantStore extends AbstractStore
  9. {
  10. use MerchantStoreTrait;
  11. protected UserMerchantRepositoryQuery $query;
  12. public function __construct(UserMerchantRepositoryQuery $query)
  13. {
  14. $this->query = $query;
  15. }
  16. // getUserMerchant
  17. public function getOneByUser(UserInterface $user)
  18. {
  19. $query = $this->query->create();
  20. $query
  21. ->filterByMerchant($this->merchant)
  22. ->filterByUser($user);
  23. return $query->findOne();
  24. }
  25. public function isCreditActive(UserMerchantInterface $userMerchant = null)
  26. {
  27. if (!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) {
  28. return false;
  29. }
  30. return true;
  31. }
  32. public function isCreditActiveByUser(UserInterface $user)
  33. {
  34. $userMerchant = $this->getOneByUser($user);
  35. return $this->isCreditActive($userMerchant);
  36. }
  37. public function isCreditSufficientToPay(UserMerchantInterface $userMerchant, float $amount)
  38. {
  39. if ($this->isCreditActive($userMerchant) && $userMerchant->getCredit() >= $amount) {
  40. return true;
  41. }
  42. return false;
  43. }
  44. }