调整用户收货地址

This commit is contained in:
luofei 2024-02-27 11:53:12 +08:00
parent dd7176a4fd
commit af431934f2
2 changed files with 87 additions and 9 deletions

View File

@ -598,42 +598,42 @@ class Common extends BaseController
/**
* 获取市级行政区
* @param $code
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCity($code)
public function getCity()
{
$code = $this->request->get('code', $this->request->get('province_code'));
$select = Db::name('geo_city')->where('province_code', $code)->field('city_id id,city_code code,city_name name')->select();
return app('json')->success($select);
}
/**
* 获取县级行政区
* @param $code
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getArea($code)
public function getArea()
{
$code = $this->request->get('code', $this->request->get('city_code'));
$select = Db::name('geo_area')->where('city_code', $code)->field('area_id id,area_code code,area_name name')->select();
return app('json')->success($select);
}
/**
* 获取街道
* @param $code
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStreet($code)
public function getStreet()
{
$code = $this->request->get('code', $this->request->get('area_code'));
$select = Db::name('geo_street')->where('area_code', $code)->field('street_id id,street_code code,street_name name')->select()->toArray();
foreach ($select as $k => &$item) {
$first_char = mb_str_split($item['name']);
@ -651,14 +651,14 @@ class Common extends BaseController
/**
* 获取社区
* @param $code
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getVillage($code)
public function getVillage()
{
$code = $this->request->get('code', $this->request->get('street_code'));
$select = Db::name('geo_village')->where('street_code', $code)->field('village_id id,village_code code,village_name name')->select();
return app('json')->success($select);
}

View File

@ -14,6 +14,7 @@
namespace app\controller\api\user;
use app\common\model\store\GeoArea;
use app\common\model\store\GeoBrigade;
use app\common\model\store\GeoCity;
use app\common\model\store\GeoProvince;
use app\common\model\store\GeoStreet;
@ -56,7 +57,84 @@ class UserAddress extends BaseController
if (!$this->repository->existsWhere(['address_id' => $id, 'uid' => $uid])) {
return app('json')->fail('地址不存在');
}
return app('json')->success($this->repository->get($id, $uid));
$addInfo = $this->repository->get($id, $uid);
$area = [];
if (!empty($addInfo['province_id'])) {
$province = GeoProvince::where('province_id', $addInfo['province_id'])->find();
if ($province) {
$area[] = [
'type' => 'province',
'id' => $province->province_id,
'level' => 1,
'name' => $province->province_name ?? '',
'code' => $province->province_code ?? ''
];
}
}
if (!empty($addInfo['city_id'])) {
$city = GeoCity::where('city_id', $addInfo['city_id'])->find();
if ($city) {
$area[] = [
'type' => 'city',
'id' => $city['city_id'],
'level' => 2,
'name' => $city['city_name'] ?? '',
'code' => $city['city_code'] ?? ''
];
}
}
if (!empty($addInfo['district_id'])) {
$district = GeoArea::where('area_id', $addInfo['district_id'])->find();
if ($district) {
$area[] = [
'type' => 'area',
'id' => $district['area_id'],
'level' => 3,
'name' => $district['area_name'] ?? '',
'code' => $district['area_code'] ?? ''
];
}
}
if (!empty($addInfo['street_id'])) {
$street = GeoStreet::where('street_id', $addInfo['street_id'])->find();
if ($street) {
$area[] = [
'type' => 'street',
'id' => $street['street_id'],
'level' => 4,
'name' => $street['street_name'] ?? '',
'code' => $street['street_code'] ?? ''
];
}
}
if (!empty($addInfo['village_id'])) {
$village = GeoVillage::where('village_id', $addInfo['village_id'])->find();
if ($village) {
$area[] = [
'type' => 'village',
'id' => $village['village_id'],
'level' => 5,
'name' => $village['village_name'] ?? '',
'code' => $village['village_code'] ?? ''
];
}
}
$addInfo->areas = $area;
$addInfo->brigade = [];
if (!empty($addInfo['brigade_id'])) {
$brigade = GeoBrigade::where('id', $addInfo['brigade_id'])->find();
if ($brigade) {
$addInfo->brigade = [
'type' => 'brigade',
'id' => $brigade['id'],
'level' => 6,
'name' => $brigade['brigade_name'] ?? '',
'code' => $brigade['brigade_name'] ?? ''
];
}
}
return app('json')->success($addInfo);
}
/**