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.2KB

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