CityRepository.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\repositories\store\shipping;
  12. use app\common\repositories\BaseRepository;
  13. use app\common\dao\store\shipping\CityDao as dao;
  14. class CityRepository extends BaseRepository
  15. {
  16. public function __construct(dao $dao)
  17. {
  18. $this->dao = $dao;
  19. }
  20. /**
  21. * 根据条件获取格式化后的分类列表
  22. *
  23. * 本函数通过传入的条件数组,查询所有符合条件的数据,并将这些数据
  24. * 根据城市ID和父ID的关系进行格式化处理,返回一个层次化的分类列表。
  25. * 这种格式化处理有利于后续在前端展示或进行其他需要分类层次结构的操作。
  26. *
  27. * @param array $where 查询条件数组,用于筛选数据
  28. * @return array 格式化后的分类列表,具有层次结构
  29. */
  30. public function getFormatList(array $where = [])
  31. {
  32. // 调用DAO层的方法获取所有符合条件的数据,然后转换为数组格式
  33. // 这里的formatCategory函数用于将数据根据'city_id'和'parent_id'两个字段进行格式化
  34. return formatCategory($this->dao->getAll($where)->toArray(), 'id','parent_id');
  35. }
  36. }