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.

OrderShopRepository.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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->createQueryBuilder('e') ;
  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. $query->leftJoin('e.orderStatusHistories', 'orderStatusHistories')
  27. ->andWhere('SIZE(e.orderStatusHistories) = 0') ;
  28. return $query->getQuery()->getOneOrNullResult() ;
  29. }
  30. public function findAllBy($params = [])
  31. {
  32. $query = $this->findByMerchantQuery() ;
  33. if(isset($params['dateStart'])) {
  34. $query->andWhere('e.createdAt >= :dateStart')->setParameter('dateStart', $params['dateStart']) ;
  35. }
  36. if(isset($params['dateEnd'])) {
  37. $query->andWhere('e.createdAt <= :dateEnd')->setParameter('dateEnd', $params['dateEnd']) ;
  38. }
  39. if(!isset($params['isCart'])) {
  40. $query = $this->filterOrderCart($query) ;
  41. }
  42. if(isset($params['user'])) {
  43. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  44. }
  45. $query->orderBy('e.createdAt', 'DESC') ;
  46. return $query->getQuery()->getResult() ;
  47. }
  48. public function findAllByDateStartEnd($dateStart, $dateEnd)
  49. {
  50. $query = $this->findByMerchantQuery()
  51. ->andWhere('e.createdAt >= :dateStart')
  52. ->setParameter('dateStart', $dateStart)
  53. ->andWhere('e.createdAt <= :dateEnd')
  54. ->setParameter('dateEnd', $dateEnd);
  55. $this->filterOrderCart($query) ;
  56. return $query->getQuery()->getResult() ;
  57. }
  58. public function filterOrderCart($query, $isCart = false)
  59. {
  60. $operator = $isCart ? '=' : '>' ;
  61. return $query->leftJoin('e.orderStatusHistories', 'orderStatusHistories')
  62. ->andWhere('SIZE(e.orderStatusHistories) '.$operator.' 0') ;
  63. }
  64. }