StoreCategoryDao.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\StoreCategory as model;
  14. use crmeb\traits\CategoresDao;
  15. class StoreCategoryDao extends BaseDao
  16. {
  17. use CategoresDao;
  18. protected function getModel(): string
  19. {
  20. return model::class;
  21. }
  22. public function findChildrenId($id)
  23. {
  24. return model::getDB()->whereLike('path', '%/'. $id . '/%')->column('store_category_id');
  25. }
  26. public function fieldExistsList(?int $merId,$field,$value,$except = null)
  27. {
  28. return ($this->getModel()::getDB())->when($except ,function($query)use($field,$except){
  29. $query->where($field,'<>',$except);
  30. })->when(($merId !== null) ,function($query)use($merId){
  31. $query->where('mer_id',$merId);
  32. })->where($field,$value);
  33. }
  34. public function getTwoLevel($merId = 0)
  35. {
  36. $pid = model::getDB()->where('pid', 0)->where('is_show',1)->where('mer_id', $merId)->column('store_category_id');
  37. return model::getDB()->whereIn('pid', $pid)->where('is_show', 1)->where('mer_id', $merId)->order('sort DESC')->column('store_category_id,cate_name,pid');
  38. }
  39. public function children($pid, $merId = 0)
  40. {
  41. return model::getDB()->where('pid', $pid)->where('mer_id', $merId)->where('is_show', 1)->order('sort DESC')->column('store_category_id,cate_name,pic');
  42. }
  43. public function allChildren($id)
  44. {
  45. $path = model::getDB()->where('store_category_id', $id)->where('mer_id', 0)->value('path');
  46. return model::getDB()->whereLike('path', "$path%")->where('mer_id', 0)->order('sort DESC')->column('store_category_id');
  47. }
  48. public function getMaxLevel($merId = null)
  49. {
  50. if($merId) return 2;
  51. return 3;
  52. }
  53. }