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.

79 lines
3.7KB

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