CityService.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\CityModel;
  13. use App\Services\BaseService;
  14. /**
  15. * 城市管理-服务类
  16. * @author laravel开发员
  17. * @since 2020/11/11
  18. * Class CityService
  19. * @package App\Services\Common
  20. */
  21. class CityService extends BaseService
  22. {
  23. /**
  24. * 构造函数
  25. * @author laravel开发员
  26. * @since 2020/11/11
  27. * CityService constructor.
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new CityModel();
  32. }
  33. /**
  34. * 获取城市列表
  35. * @return array
  36. * @since 2020/11/11
  37. * @author laravel开发员
  38. */
  39. public function getList()
  40. {
  41. $param = request()->all();
  42. // 查询条件
  43. $map = [];
  44. // 上级ID
  45. $pid = intval(getter($param, 'pid', 0));
  46. if (!$pid) {
  47. $map[] = ['pid', '=', 0];
  48. } else {
  49. $map[] = ['pid', '=', $pid];
  50. }
  51. // 城市名称
  52. $name = getter($param, "name");
  53. if ($name) {
  54. $map[] = ['name', 'like', "%{$name}%"];
  55. }
  56. $list = $this->model->getList($map, [['sort', 'asc']]);
  57. if (!empty($list)) {
  58. foreach ($list as &$val) {
  59. if ($val['level'] <= 2) {
  60. $val['hasChildren'] = true;
  61. }
  62. }
  63. }
  64. return message("操作成功", true, $list);
  65. }
  66. }