Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

130 lines
5.0KB

  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  4. use Lc\ShopBundle\Context\OrderShopInterface;
  5. /**
  6. * @method OrderShopInterface|null find($id, $lockMode = null, $lockVersion = null)
  7. * @method OrderShopInterface|null findOneBy(array $criteria, array $orderBy = null)
  8. * @method OrderShopInterface[] findAll()
  9. * @method OrderShopInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  10. */
  11. class OrderShopRepository extends BaseRepository implements DefaultRepositoryInterface
  12. {
  13. public function getInterfaceClass()
  14. {
  15. return OrderShopInterface::class;
  16. }
  17. protected $statusAliasAsValid = array('paid-online', 'paid-by-credit', 'waiting-delivery', 'waiting-delivery-with-payment', 'delivered-without-payment', 'done');
  18. public function getValidOrderWithReductionCredit($reductionCredit, $user){
  19. $query = $this->findValidOrderQuery();
  20. $query->andWhere('e.user = :user');
  21. $query->leftJoin('e.orderReductionCredits', 'orc');
  22. $query->andWhere('orc.reductionCredit = :reductionCredit');
  23. $query->setParameter('reductionCredit', $reductionCredit);
  24. $query->setParameter('user', $user);
  25. return $query->getQuery()->getResult();
  26. }
  27. public function findValidOrderQuery(){
  28. $query = $this->findByMerchantQuery();
  29. $query->leftJoin('e.orderStatus', 'os');
  30. $query->andWhere('os.alias IN (:alias)');
  31. $query->setParameter('alias', $this->statusAliasAsValid);
  32. return $query;
  33. }
  34. public function findCartCurrent($params)
  35. {
  36. $query = $this->findByMerchantQuery() ;
  37. if(isset($params['user'])) {
  38. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  39. }
  40. if(isset($params['visitor'])) {
  41. $query->andWhere('e.visitor = :visitor')->setParameter('visitor', $params['visitor']) ;
  42. }
  43. $this->filterOrderCart($query, true) ;
  44. $query->leftJoin('e.orderReductionCarts', 'orderReductionCarts')
  45. ->addSelect('orderReductionCarts');
  46. $results = $query->getQuery()->getResult() ;
  47. if($results) {
  48. return $results[0] ;
  49. }
  50. return null ;
  51. }
  52. public function findAllBy($params = [])
  53. {
  54. $query = $this->findByMerchantQuery() ;
  55. if(isset($params['dateStart'])) {
  56. $query->andWhere('e.createdAt >= :dateStart')->setParameter('dateStart', $params['dateStart']) ;
  57. }
  58. if(isset($params['dateEnd'])) {
  59. $query->andWhere('e.createdAt <= :dateEnd')->setParameter('dateEnd', $params['dateEnd']) ;
  60. }
  61. if(!isset($params['isCart'])) {
  62. $this->filterOrderCart($query) ;
  63. }
  64. if(isset($params['user'])) {
  65. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  66. }
  67. $query->orderBy('e.id', 'DESC') ;
  68. return $query->getQuery()->getResult() ;
  69. }
  70. public function findAllByDateStartEnd($dateStart, $dateEnd)
  71. {
  72. $query = $this->findByMerchantQuery()
  73. ->andWhere('e.createdAt >= :dateStart')
  74. ->setParameter('dateStart', $dateStart)
  75. ->andWhere('e.createdAt <= :dateEnd')
  76. ->setParameter('dateEnd', $dateEnd);
  77. $this->filterOrderCart($query) ;
  78. $query->leftJoin('e.deliveryAvailabilityZone', 'deliveryAvailabilityZone') ;
  79. $query->leftJoin('deliveryAvailabilityZone.deliverySlot', 'deliverySlotZone') ;
  80. $query->addOrderBy('deliverySlotZone.day', 'ASC') ;
  81. $query->addOrderBy('deliverySlotZone.timeStart', 'ASC') ;
  82. $query->leftJoin('e.deliveryAvailabilityPointSale', 'deliveryAvailabilityPointSale') ;
  83. $query->leftJoin('deliveryAvailabilityPointSale.deliverySlot', 'deliverySlotPointSale') ;
  84. $query->addOrderBy('deliverySlotPointSale.day', 'ASC') ;
  85. $query->addOrderBy('deliverySlotPointSale.timeStart', 'ASC') ;
  86. return $query->getQuery()->getResult() ;
  87. }
  88. public function filterOrderCart($query, $isCart = false)
  89. {
  90. $operator = $isCart ? '=' : '!=' ;
  91. return $query->leftJoin('e.orderStatus', 'orderStatus')
  92. ->andWhere('orderStatus.alias '.$operator.' :orderStatus')
  93. ->setParameter('orderStatus', 'cart');
  94. }
  95. //getValidOrders()
  96. }