StoreCategoryDao.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\common\dao\store;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\store\StoreCategory as model;
  5. use ln\traits\CategoresDao;
  6. class StoreCategoryDao extends BaseDao
  7. {
  8. use CategoresDao;
  9. protected function getModel(): string
  10. {
  11. return model::class;
  12. }
  13. public function findChildrenId($id)
  14. {
  15. return model::getDB()->whereLike('path', '%/'. $id . '/%')->column('store_category_id');
  16. }
  17. public function fieldExistsList(?int $merId,$field,$value,$except = null)
  18. {
  19. return ($this->getModel()::getDB())->when($except ,function($query)use($field,$except){
  20. $query->where($field,'<>',$except);
  21. })->when(($merId !== null) ,function($query)use($merId){
  22. $query->where('mer_id',$merId);
  23. })->where($field,$value);
  24. }
  25. public function getTwoLevel($merId = 0)
  26. {
  27. $pid = model::getDB()->where('pid', 0)->where('is_show',1)->where('mer_id', $merId)->column('store_category_id');
  28. return model::getDB()->whereIn('pid', $pid)->where('is_show', 1)->where('mer_id', $merId)->order('sort DESC')->column('store_category_id,cate_name,pid');
  29. }
  30. public function children($pid, $merId = 0)
  31. {
  32. return model::getDB()->where('pid', $pid)->where('mer_id', $merId)->where('is_show', 1)->order('sort DESC')->column('store_category_id,cate_name,pic');
  33. }
  34. public function allChildren($id)
  35. {
  36. $path = model::getDB()->where('store_category_id', $id)->where('mer_id', 0)->value('path');
  37. return model::getDB()->whereLike('path', "$path%")->where('mer_id', 0)->order('sort DESC')->column('store_category_id');
  38. }
  39. public function getMaxLevel($merId = null)
  40. {
  41. if($merId) return 2;
  42. return 3;
  43. }
  44. }