更新详细地址信息

This commit is contained in:
yaooo 2023-08-07 14:51:46 +08:00
parent 8f7873039b
commit 702e55fa7f
3 changed files with 89 additions and 2 deletions

View File

@ -50,4 +50,5 @@ class UserAddressDao extends BaseDao
{
return (($this->getModel()::getDB())->where('uid',$uid));
}
}

View File

@ -126,6 +126,6 @@ class UserAddressRepository extends BaseRepository
*/
public function get($id,$uid)
{
return $this->dao->getWhere(['address_id' => $id,'uid' => $uid])->append(['area']);
return $this->dao->getWhere(['address_id' => $id,'uid' => $uid]);
}
}

View File

@ -16,6 +16,12 @@ namespace app\controller\api\user;
use app\common\repositories\store\CityAreaRepository;
use think\App;
use crmeb\basic\BaseController;
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;
use app\validate\api\UserAddressValidate as validate;
use app\common\repositories\user\UserAddressRepository as repository;
use think\exception\ValidateException;
@ -50,7 +56,87 @@ 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);
/*
"brigade_id": 10,
"brigade": "10队"
*/
$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'] ?? ''
];
}
}
if (!empty($addinfo['brigade_id'])) {
$brigade = GeoBrigade::where('id', $addinfo['brigade_id'])->find();
if ($brigade) {
$area[] = [
'type' => 'brigade',
'id' => $brigade['id'],
'level' => 6,
'name' => $brigade['brigade_name'] ?? '',
'code' => $brigade['brigade_name'] ?? ''
];
}
}
$addinfo->areas = $area;
return app('json')->success($addinfo);
}
/**