StoreBrandDao.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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. $list = $query->order('StoreBrand.sort DESC,StoreBrand.create_time DESC')->select()->toArray();
  29. array_push($list,[
  30. "brand_id" => 0,
  31. "brand_category_id" => 0,
  32. "brand_name" => "其他",
  33. "sort" => 999,
  34. "pic" => "",
  35. "is_show" => 1,
  36. "create_time" => "",
  37. ]);
  38. return $list;
  39. }
  40. public function merFieldExists($field, $value, $except = null)
  41. {
  42. return ($this->getModel())::getDB()
  43. ->when($except, function ($query, $except) use ($field) {
  44. $query->where($field, '<>', $except);
  45. })
  46. ->where($field, $value)->count() > 0;
  47. }
  48. public function search(array $where)
  49. {
  50. $query = $this->getModel()::getDB();
  51. if(isset($where['brand_category_id']) && $where['brand_category_id'])
  52. $query->where('brand_category_id',$where['brand_category_id']);
  53. if(isset($where['brand_name']) && $where['brand_name'])
  54. $query->where('brand_name','like','%'.$where['brand_name'].'%');
  55. if((isset($where['ids']) && $where['ids']))
  56. $query->where($this->getPk(),'in',$where['ids']);
  57. return $query->order('sort DESC,create_time desc');
  58. }
  59. }