Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

127 rindas
4.8KB

  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. $results = $query->getQuery()->getResult() ;
  45. if($results) {
  46. return $results[0] ;
  47. }
  48. return null ;
  49. }
  50. public function findAllBy($params = [])
  51. {
  52. $query = $this->findByMerchantQuery() ;
  53. if(isset($params['dateStart'])) {
  54. $query->andWhere('e.createdAt >= :dateStart')->setParameter('dateStart', $params['dateStart']) ;
  55. }
  56. if(isset($params['dateEnd'])) {
  57. $query->andWhere('e.createdAt <= :dateEnd')->setParameter('dateEnd', $params['dateEnd']) ;
  58. }
  59. if(!isset($params['isCart'])) {
  60. $this->filterOrderCart($query) ;
  61. }
  62. if(isset($params['user'])) {
  63. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  64. }
  65. $query->orderBy('e.id', 'DESC') ;
  66. return $query->getQuery()->getResult() ;
  67. }
  68. public function findAllByDateStartEnd($dateStart, $dateEnd)
  69. {
  70. $query = $this->findByMerchantQuery()
  71. ->andWhere('e.createdAt >= :dateStart')
  72. ->setParameter('dateStart', $dateStart)
  73. ->andWhere('e.createdAt <= :dateEnd')
  74. ->setParameter('dateEnd', $dateEnd);
  75. $this->filterOrderCart($query) ;
  76. $query->leftJoin('e.deliveryAvailabilityZone', 'deliveryAvailabilityZone') ;
  77. $query->leftJoin('deliveryAvailabilityZone.deliverySlot', 'deliverySlotZone') ;
  78. $query->addOrderBy('deliverySlotZone.day', 'ASC') ;
  79. $query->addOrderBy('deliverySlotZone.timeStart', 'ASC') ;
  80. $query->leftJoin('e.deliveryAvailabilityPointSale', 'deliveryAvailabilityPointSale') ;
  81. $query->leftJoin('deliveryAvailabilityPointSale.deliverySlot', 'deliverySlotPointSale') ;
  82. $query->addOrderBy('deliverySlotPointSale.day', 'ASC') ;
  83. $query->addOrderBy('deliverySlotPointSale.timeStart', 'ASC') ;
  84. return $query->getQuery()->getResult() ;
  85. }
  86. public function filterOrderCart($query, $isCart = false)
  87. {
  88. $operator = $isCart ? '=' : '!=' ;
  89. return $query->leftJoin('e.orderStatus', 'orderStatus')
  90. ->andWhere('orderStatus.alias '.$operator.' :orderStatus')
  91. ->setParameter('orderStatus', 'cart');
  92. }
  93. //getValidOrders()
  94. }