You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CreditUtils.php 2.5KB

4 yıl önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Lc\ShopBundle\Services ;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\ShopBundle\Context\MerchantInterface;
  5. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  6. use Lc\ShopBundle\Context\UserInterface;
  7. use Lc\ShopBundle\Context\UserMerchantInterface;
  8. class CreditUtils
  9. {
  10. protected $em ;
  11. protected $merchantUtils ;
  12. protected $userMerchantRepository ;
  13. public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils)
  14. {
  15. $this->em = $em ;
  16. $this->merchantUtils = $merchantUtils ;
  17. $this->userMerchantRepository = $this->em->getRepository($this->em->getClassMetadata(UserMerchantInterface::class)->getName()) ;
  18. }
  19. public function getUserMerchant(UserInterface $user, MerchantInterface $merchant = null)
  20. {
  21. $merchant = $this->getMerchant($merchant) ;
  22. $userMerchant = $this->userMerchantRepository->findOneBy([
  23. 'user' => $user,
  24. 'merchant' => $merchant
  25. ]) ;
  26. return $userMerchant ;
  27. }
  28. public function createUserMerchant(UserInterface $user, MerchantInterface $merchant = null)
  29. {
  30. $merchant = $this->getMerchant($merchant) ;
  31. $classUserMerchant = $this->em->getClassMetadata(UserMerchantInterface::class)->getName();
  32. $userMerchant = new $classUserMerchant ;
  33. $userMerchant->setUser($user) ;
  34. $userMerchant->setMerchant($merchant) ;
  35. $userMerchant->setCredit(0) ;
  36. $userMerchant->setCreditActive(true) ;
  37. return $userMerchant ;
  38. }
  39. public function createCreditHistory($user, $amount, $meanPayment, $comment = null, $merchant = null)
  40. {
  41. $merchant = $this->getMerchant($merchant) ;
  42. }
  43. public function addCredit($user, $amount, $merchant = null)
  44. {
  45. $merchant = $this->getMerchant($merchant) ;
  46. }
  47. public function removeCredit($user, $amount, $merchant = null)
  48. {
  49. $merchant = $this->getMerchant($merchant) ;
  50. }
  51. public function setCredit($user, $amount, $merchant = null)
  52. {
  53. }
  54. public function getMerchant($merchant)
  55. {
  56. if(!$merchant) {
  57. $merchant = $this->merchantUtils->getMerchantCurrent() ;
  58. }
  59. return $merchant ;
  60. }
  61. }