diff --git a/app/common/dao/store/CityAreaDao.php b/app/common/dao/store/CityAreaDao.php index 7300b9fe..f6bce21c 100644 --- a/app/common/dao/store/CityAreaDao.php +++ b/app/common/dao/store/CityAreaDao.php @@ -16,6 +16,12 @@ namespace app\common\dao\store; use app\common\dao\BaseDao; use app\common\model\BaseModel; use app\common\model\store\CityArea; +use app\common\model\store\GeoProvince; +use app\common\model\store\GeoCity; +use app\common\model\store\GeoArea; +use app\common\model\store\GeoStreet; +use app\common\model\store\GeoVillage; +use app\common\model\store\GeoBrigade; class CityAreaDao extends BaseDao { @@ -53,10 +59,36 @@ class CityAreaDao extends BaseDao } } } - $query->whereLike('path', $path . '%')->where('name', $street); + $query->getVillage('path', $path . '%')->where('name', $street); }); } + public function searchGeo(array $where) + { + if (!empty($where['street_code'])) { + return GeoVillage::getDB()->where('street_code', $where['street_code']); + } + if (!empty($where['area_code'])) { + return GeoStreet::getDB()->where('area_code', $where['area_code']); + } + if (!empty($where['city_code'])) { + return GeoArea::getDB()->where('city_code', $where['city_code']); + } + if (!empty($where['province_code'])) { + return GeoCity::getDB()->where('province_code', $where['province_code']); + } + if (empty($where['province_code'])) { + return GeoProvince::getDB(); + } + return false; + } + + public function searchBrigade(array $where) + { + return GeoBrigade::getDB(); + } + + public function getCityList(CityArea $city) { if (!$city->parent_id) return [$city]; diff --git a/app/common/model/store/GeoBrigade.php b/app/common/model/store/GeoBrigade.php new file mode 100644 index 00000000..6a9c2d80 --- /dev/null +++ b/app/common/model/store/GeoBrigade.php @@ -0,0 +1,30 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\model\store; + + +use app\common\model\BaseModel; + +class GeoBrigade extends BaseModel +{ + + public static function tablePk(): ?string + { + return 'id'; + } + + public static function tableName(): string + { + return 'geo_brigade'; + } +} diff --git a/app/common/model/store/GeoCity.php b/app/common/model/store/GeoCity.php new file mode 100644 index 00000000..45e0fc5b --- /dev/null +++ b/app/common/model/store/GeoCity.php @@ -0,0 +1,31 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\model\store; + + +use app\common\model\BaseModel; + +class GeoCity extends BaseModel +{ + + public static function tablePk(): ?string + { + return 'id'; + } + + public static function tableName(): string + { + return 'geo_city'; + } + +} diff --git a/app/common/model/store/GeoProvince.php b/app/common/model/store/GeoProvince.php new file mode 100644 index 00000000..4e91f8f5 --- /dev/null +++ b/app/common/model/store/GeoProvince.php @@ -0,0 +1,30 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\model\store; + + +use app\common\model\BaseModel; + +class GeoProvince extends BaseModel +{ + + public static function tablePk(): ?string + { + return 'id'; + } + + public static function tableName(): string + { + return 'geo_province'; + } +} diff --git a/app/common/model/store/GeoStreet.php b/app/common/model/store/GeoStreet.php new file mode 100644 index 00000000..1923eb94 --- /dev/null +++ b/app/common/model/store/GeoStreet.php @@ -0,0 +1,30 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\model\store; + + +use app\common\model\BaseModel; + +class GeoStreet extends BaseModel +{ + + public static function tablePk(): ?string + { + return 'id'; + } + + public static function tableName(): string + { + return 'geo_street'; + } +} diff --git a/app/common/model/store/GeoVillage.php b/app/common/model/store/GeoVillage.php new file mode 100644 index 00000000..a1eaca3b --- /dev/null +++ b/app/common/model/store/GeoVillage.php @@ -0,0 +1,30 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\model\store; + + +use app\common\model\BaseModel; + +class GeoVillage extends BaseModel +{ + + public static function tablePk(): ?string + { + return 'id'; + } + + public static function tableName(): string + { + return 'geo_village'; + } +} diff --git a/app/common/repositories/store/CityAreaRepository.php b/app/common/repositories/store/CityAreaRepository.php index 3cab1f24..f9a16ef6 100644 --- a/app/common/repositories/store/CityAreaRepository.php +++ b/app/common/repositories/store/CityAreaRepository.php @@ -34,6 +34,16 @@ class CityAreaRepository extends BaseRepository return $this->search(['pid' => $pid])->select(); } + public function getGeoChildren($where) + { + return $this->searchGeo($where)->select(); + } + + public function getBrigade($where) + { + return $this->searchBrigade($where)->select(); + } + public function getList($where) { return $this->dao->getSearch($where)->with(['parent'])->order('id ASC')->select()->append(['children','hasChildren']); diff --git a/app/controller/merchant/store/shipping/City.php b/app/controller/merchant/store/shipping/City.php index 8247d8b7..2fea961c 100644 --- a/app/controller/merchant/store/shipping/City.php +++ b/app/controller/merchant/store/shipping/City.php @@ -49,6 +49,70 @@ class City extends BaseController return app('json')->success(app()->make(CityAreaRepository::class)->getChildren(intval($pid))); } + public function lstV3() + { + $provinceCode = $this->request->param('province_code') ?? ''; + $cityCode = $this->request->param('city_code') ?? ''; + $areaCode = $this->request->param('area_code') ?? ''; + $streetCode = $this->request->param('street_code') ?? ''; + $list = app()->make(CityAreaRepository::class)->getGeoChildren(['province_code' => $provinceCode, 'city_code' => $cityCode, 'area_code' => $areaCode, 'street_code' => $streetCode]); + $geoList = []; + foreach ($list->toArray() as $v) { + if (!empty($v['village_id'])) { + $temp = [ + 'type' => 'village', + 'level' => 5, + 'name' => $v['village_name'] ?? '', + 'code' => $v['village_code'] ?? '' + ]; + $geoList[] = $temp; + } + if (!empty($v['street_id'])) { + $temp = [ + 'type' => 'street', + 'level' => 4, + 'name' => $v['street_name'] ?? '', + 'code' => $v['street_code'] ?? '' + ]; + $geoList[] = $temp; + } + if (!empty($v['area_id'])) { + $temp = [ + 'type' => 'area', + 'level' => 3, + 'name' => $v['area_name'] ?? '', + 'code' => $v['area_code'] ?? '' + ]; + $geoList[] = $temp; + } + if (!empty($v['city_id'])) { + $temp = [ + 'type' => 'city', + 'level' => 2, + 'name' => $v['city_name'] ?? '', + 'code' => $v['city_code'] ?? '' + ]; + $geoList[] = $temp; + } + if (!empty($v['province_id'])) { + $temp = [ + 'type' => 'province', + 'level' => 1, + 'name' => $v['province_name'] ?? '', + 'code' => $v['province_code'] ?? '' + ]; + $geoList[] = $temp; + } + } + return app('json')->success($geoList); + } + + public function brigade() + { + return app('json')->success(app()->make(CityAreaRepository::class)->getBrigade([])); + } + + public function cityList() { $address = $this->request->param('address'); diff --git a/route/api.php b/route/api.php index 00c04742..021576e1 100644 --- a/route/api.php +++ b/route/api.php @@ -562,6 +562,10 @@ Route::group('api/', function () { Route::get('system/city/lst', 'merchant.store.shipping.City/getlist'); Route::get('v2/system/city/lst/:pid', 'merchant.store.shipping.City/lstV2'); Route::get('v2/system/city', 'merchant.store.shipping.City/cityList'); + //更换城市源列表 + Route::get('v2/system/geo/lst', 'merchant.store.shipping.City/lstV3'); + //小队列表 + Route::get('v2/system/brigade', 'merchant.store.shipping.City/brigade'); //热门搜索 Route::get('common/hot_keyword', 'api.Common/hotKeyword')->append(['type' => 0]);