No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

ReductionCreditRepository.php 3.1KB

hace 4 años
hace 4 años
hace 4 años
hace 4 años
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Doctrine\ORM\EntityManager;
  4. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  5. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  6. use Lc\ShopBundle\Context\ReductionCreditInterface;
  7. use Lc\ShopBundle\Model\ReductionCredit;
  8. /**
  9. * @method ReductionCreditInterface|null find($id, $lockMode = null, $lockVersion = null)
  10. * @method ReductionCreditInterface|null findOneBy(array $criteria, array $orderBy = null)
  11. * @method ReductionCreditInterface[] findAll()
  12. * @method ReductionCreditInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13. */
  14. class ReductionCreditRepository extends BaseRepository implements DefaultRepositoryInterface
  15. {
  16. public function getInterfaceClass()
  17. {
  18. return ReductionCreditInterface::class;
  19. }
  20. public function findReductionCreditsByUser($user)
  21. {
  22. $query = $this->findByMerchantQuery() ;
  23. $query->andWhere('e.status = 1');
  24. $query->andWhere('e.type = :type');
  25. $query->andWhere(':user MEMBER OF e.users');
  26. $query->setParameter('user', $user);
  27. $query->setParameter('type', ReductionCredit::TYPE_CREDIT);
  28. return $query->getQuery()->getResult() ;
  29. }
  30. public function findReductionGiftToUseByUser($user){
  31. $query = $this->findByMerchantQuery() ;
  32. $query->andWhere('e.status = 1');
  33. $query->andWhere('e.type = :type');
  34. $query->andWhere(':user MEMBER OF e.users');
  35. $query->andWhere(':now > e.activationDate');
  36. $query->setParameter('now', new \DateTime()) ;
  37. $query->setParameter('user', $user);
  38. $query->setParameter('type', ReductionCredit::TYPE_GIFT);
  39. return $query->getQuery()->getResult() ;
  40. }
  41. public function findReductionGiftOwnedByUser($user){
  42. $query = $this->findByMerchantQuery() ;
  43. $query->leftJoin('e.users', 'u');
  44. $query->having('COUNT(u.id) =0');
  45. $query->andWhere('e.status = 1');
  46. $query->andWhere('e.type = :type');
  47. $query->andWhere('e.owner = :user');
  48. $query->setParameter('user', $user);
  49. $query->setParameter('type', ReductionCredit::TYPE_GIFT);
  50. $query->groupBy('e.id');
  51. return $query->getQuery()->getResult() ;
  52. }
  53. public function findReductionGiftOwnedActiveByUser($user){
  54. $query = $this->findByMerchantQuery() ;
  55. $query->leftJoin('e.users', 'u');
  56. $query->having('COUNT(u.id) >0');
  57. $query->andWhere('e.status = 1');
  58. $query->andWhere('e.type = :type');
  59. $query->andWhere('e.owner = :user');
  60. $query->setParameter('user', $user);
  61. $query->setParameter('type', ReductionCredit::TYPE_GIFT);
  62. $query->groupBy('e.id');
  63. return $query->getQuery()->getResult() ;
  64. }
  65. }