City.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\merchant\store\shipping;
  12. use app\common\repositories\store\CityAreaRepository;
  13. use think\App;
  14. use crmeb\basic\BaseController;
  15. use app\common\repositories\store\shipping\CityRepository as repository;
  16. use think\facade\Log;
  17. class City extends BaseController
  18. {
  19. protected $repository;
  20. /**
  21. * City constructor.
  22. * @param App $app
  23. * @param repository $repository
  24. */
  25. public function __construct(App $app, repository $repository)
  26. {
  27. parent::__construct($app);
  28. $this->repository = $repository;
  29. }
  30. /**
  31. * @Author:Qinii
  32. * @Date: 2020/5/8
  33. * @Time: 14:40
  34. * @return mixed
  35. */
  36. public function lst()
  37. {
  38. return app('json')->success($this->repository->getFormatList([['is_show', '=', 1],['level','<',2]]));
  39. }
  40. public function lstV2($pid)
  41. {
  42. return app('json')->success(app()->make(CityAreaRepository::class)->getChildren(intval($pid)));
  43. }
  44. public function cityList()
  45. {
  46. $address = $this->request->param('address');
  47. if (!$address)
  48. return app('json')->fail('地址不存在');
  49. $make = app()->make(CityAreaRepository::class);
  50. $city = $make->search(compact('address'))->order('id DESC')->find();
  51. if (!$city){
  52. Log::info('用户定位对比失败,请在城市数据中增加:'.var_export($address,true));
  53. return app('json')->fail('地址不存在');
  54. }
  55. return app('json')->success($make->getCityList($city));
  56. }
  57. /**
  58. * @return mixed
  59. * @author Qinii
  60. */
  61. public function getlist()
  62. {
  63. return app('json')->success($this->repository->getFormatList(['is_show' => 1]));
  64. }
  65. }