|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
-
- namespace Lc\ShopBundle\Repository;
-
- use Lc\ShopBundle\Context\DefaultRepositoryInterface;
- use Lc\ShopBundle\Context\OrderShopInterface;
-
- /**
- * @method OrderShopInterface|null find($id, $lockMode = null, $lockVersion = null)
- * @method OrderShopInterface|null findOneBy(array $criteria, array $orderBy = null)
- * @method OrderShopInterface[] findAll()
- * @method OrderShopInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
- */
- class OrderShopRepository extends BaseRepository implements DefaultRepositoryInterface
- {
- public function getInterfaceClass()
- {
- return OrderShopInterface::class;
- }
-
- public function findCartCurrent($params)
- {
- $query = $this->findByMerchantQuery() ;
-
- if(isset($params['user'])) {
- $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
- }
-
- if(isset($params['visitor'])) {
- $query->andWhere('e.visitor = :visitor')->setParameter('visitor', $params['visitor']) ;
- }
-
- $query->leftJoin('e.orderStatusHistories', 'orderStatusHistories')
- ->andWhere('SIZE(e.orderStatusHistories) = 0') ;
-
- $results = $query->getQuery()->getResult() ;
-
- if($results) {
- return $results[0] ;
- }
-
- return null ;
- }
-
- public function findAllBy($params = [])
- {
- $query = $this->findByMerchantQuery() ;
-
- if(isset($params['dateStart'])) {
- $query->andWhere('e.createdAt >= :dateStart')->setParameter('dateStart', $params['dateStart']) ;
- }
-
- if(isset($params['dateEnd'])) {
- $query->andWhere('e.createdAt <= :dateEnd')->setParameter('dateEnd', $params['dateEnd']) ;
- }
-
- if(!isset($params['isCart'])) {
- $query = $this->filterOrderCart($query) ;
- }
-
- if(isset($params['user'])) {
- $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
- }
-
- $query->orderBy('e.id', 'DESC') ;
-
- return $query->getQuery()->getResult() ;
- }
-
- public function findAllByDateStartEnd($dateStart, $dateEnd)
- {
- $query = $this->findByMerchantQuery()
- ->andWhere('e.createdAt >= :dateStart')
- ->setParameter('dateStart', $dateStart)
- ->andWhere('e.createdAt <= :dateEnd')
- ->setParameter('dateEnd', $dateEnd);
-
- $this->filterOrderCart($query) ;
-
- return $query->getQuery()->getResult() ;
- }
-
- public function filterOrderCart($query, $isCart = false)
- {
- $operator = $isCart ? '=' : '>' ;
- return $query->leftJoin('e.orderStatusHistories', 'orderStatusHistories')
- ->andWhere('SIZE(e.orderStatusHistories) '.$operator.' 0') ;
- }
-
- }
|