CityService.php 1.8 KB

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