StoreBrandDao.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\common\dao\store;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\store\StoreBrand as model;
  5. use ln\traits\CategoresDao;
  6. class StoreBrandDao extends BaseDao
  7. {
  8. use CategoresDao;
  9. protected function getModel(): string
  10. {
  11. return model::class;
  12. }
  13. public function getAll()
  14. {
  15. $query = $this->getModel()::hasWhere('brandCategory',function($query){
  16. $query->where('is_show',1);
  17. });
  18. $query->where('StoreBrand.is_show',1);
  19. return $query->order('StoreBrand.sort DESC')->select();
  20. }
  21. public function merFieldExists($field, $value, $except = null)
  22. {
  23. return ($this->getModel())::getDB()
  24. ->when($except, function ($query, $except) use ($field) {
  25. $query->where($field, '<>', $except);
  26. })
  27. ->where($field, $value)->count() > 0;
  28. }
  29. public function search(array $where)
  30. {
  31. $query = $this->getModel()::getDB()->order('sort DESC');
  32. if(isset($where['brand_category_id']) && $where['brand_category_id'])
  33. $query->where('brand_category_id',$where['brand_category_id']);
  34. if(isset($where['brand_name']) && $where['brand_name'])
  35. $query->where('brand_name','like','%'.$where['brand_name'].'%');
  36. if((isset($where['ids']) && $where['ids']))
  37. $query->where($this->getPk(),'in',$where['ids']);
  38. return $query->order('create_time desc');
  39. }
  40. }