StoreBrandDao.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\store;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\StoreBrand as model;
  14. use crmeb\traits\CategoresDao;
  15. class StoreBrandDao extends BaseDao
  16. {
  17. use CategoresDao;
  18. protected function getModel(): string
  19. {
  20. return model::class;
  21. }
  22. public function getAll()
  23. {
  24. $query = $this->getModel()::hasWhere('brandCategory',function($query){
  25. $query->where('is_show',1);
  26. });
  27. $query->where('StoreBrand.is_show',1);
  28. return $query->order('StoreBrand.sort DESC')->select();
  29. }
  30. public function merFieldExists($field, $value, $except = null)
  31. {
  32. return ($this->getModel())::getDB()
  33. ->when($except, function ($query, $except) use ($field) {
  34. $query->where($field, '<>', $except);
  35. })
  36. ->where($field, $value)->count() > 0;
  37. }
  38. public function search(array $where)
  39. {
  40. $query = $this->getModel()::getDB()->order('sort DESC');
  41. if(isset($where['brand_category_id']) && $where['brand_category_id'])
  42. $query->where('brand_category_id',$where['brand_category_id']);
  43. if(isset($where['brand_name']) && $where['brand_name'])
  44. $query->where('brand_name','like','%'.$where['brand_name'].'%');
  45. if((isset($where['ids']) && $where['ids']))
  46. $query->where($this->getPk(),'in',$where['ids']);
  47. return $query->order('create_time desc');
  48. }
  49. }