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.

92 lines
3.1KB

  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. public function findCartCurrent($params)
  18. {
  19. $query = $this->findByMerchantQuery() ;
  20. if(isset($params['user'])) {
  21. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  22. }
  23. if(isset($params['visitor'])) {
  24. $query->andWhere('e.visitor = :visitor')->setParameter('visitor', $params['visitor']) ;
  25. }
  26. $this->filterOrderCart($query, true) ;
  27. $results = $query->getQuery()->getResult() ;
  28. if($results) {
  29. return $results[0] ;
  30. }
  31. return null ;
  32. }
  33. public function findAllBy($params = [])
  34. {
  35. $query = $this->findByMerchantQuery() ;
  36. if(isset($params['dateStart'])) {
  37. $query->andWhere('e.createdAt >= :dateStart')->setParameter('dateStart', $params['dateStart']) ;
  38. }
  39. if(isset($params['dateEnd'])) {
  40. $query->andWhere('e.createdAt <= :dateEnd')->setParameter('dateEnd', $params['dateEnd']) ;
  41. }
  42. if(!isset($params['isCart'])) {
  43. $this->filterOrderCart($query) ;
  44. }
  45. if(isset($params['user'])) {
  46. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  47. }
  48. $query->orderBy('e.id', 'DESC') ;
  49. return $query->getQuery()->getResult() ;
  50. }
  51. public function findAllByDateStartEnd($dateStart, $dateEnd)
  52. {
  53. $query = $this->findByMerchantQuery()
  54. ->andWhere('e.createdAt >= :dateStart')
  55. ->setParameter('dateStart', $dateStart)
  56. ->andWhere('e.createdAt <= :dateEnd')
  57. ->setParameter('dateEnd', $dateEnd);
  58. $this->filterOrderCart($query) ;
  59. return $query->getQuery()->getResult() ;
  60. }
  61. public function filterOrderCart($query, $isCart = false)
  62. {
  63. $operator = $isCart ? '=' : '!=' ;
  64. return $query->leftJoin('e.orderStatus', 'orderStatus')
  65. ->andWhere('orderStatus.alias '.$operator.' :orderStatus')
  66. ->setParameter('orderStatus', 'cart');
  67. }
  68. //getValidOrders()
  69. }