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.

ReductionCatalogRepository.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  4. use Lc\ShopBundle\Context\ReductionCatalogInterface;
  5. /**
  6. * @method ReductionCatalogInterface|null find($id, $lockMode = null, $lockVersion = null)
  7. * @method ReductionCatalogInterface|null findOneBy(array $criteria, array $orderBy = null)
  8. * @method ReductionCatalogInterface[] findAll()
  9. * @method ReductionCatalogInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  10. */
  11. class ReductionCatalogRepository extends BaseRepository implements DefaultRepositoryInterface
  12. {
  13. public function getInterfaceClass()
  14. {
  15. return ReductionCatalogInterface::class;
  16. }
  17. public function getReductionCatalogByProductFamily($productFamily, $user)
  18. {
  19. $query = $this->findByMerchantQuery();
  20. $query->andWhere('e.status = 1');
  21. $query->andWhere(':user MEMBER OF e.users OR e.users is empty');
  22. $query->andWhere(':groupUser MEMBER OF e.groupUsers OR e.groupUsers is empty');
  23. $query->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty');
  24. $query->andWhere(':productCategory MEMBER OF e.productCategories OR e.productCategories is empty');
  25. $query->andWhere(':supplier MEMBER OF e.suppliers OR e.suppliers is empty');
  26. $query->setParameter('user', $user);
  27. $query->setParameter('groupUser', $user->getGroupUsers());
  28. $query->setParameter('productFamily', $productFamily);
  29. $query->setParameter('productCategory', $productFamily->getProductCategories());
  30. $query->setParameter('supplier', $productFamily->getSupplier());
  31. return $query->getQuery()->getResult();
  32. }
  33. public function getReductionCatalogByProductFamilyConditions($productFamilyIds, $user)
  34. {
  35. $query = $this->findByMerchantQuery();
  36. $query->andWhere('e.status = 1');
  37. $query->andWhere(':user MEMBER OF e.users OR e.users is empty');
  38. $query->andWhere(':groupUser MEMBER OF e.groupUsers OR e.groupUsers is empty');
  39. $query->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty');
  40. $query->andWhere(':productCategory MEMBER OF e.productCategories OR e.productCategories is empty');
  41. $query->andWhere(':supplier MEMBER OF e.suppliers OR e.suppliers is empty');
  42. $query->setParameter('user', $user);
  43. $query->setParameter('groupUser', $user->getGroupUsers());
  44. $query->setParameter('productFamily', $productFamilyIds['ids']);
  45. $query->setParameter('productCategory', $productFamilyIds['categories']);
  46. $query->setParameter('supplier', $productFamilyIds['suppliers']);
  47. return $query->getQuery()->getResult();
  48. }
  49. }