|
|
@@ -241,35 +241,38 @@ class UserAddressRepository extends BaseRepository
|
|
241
|
241
|
}
|
|
242
|
242
|
$data['province_id'] = $provinceId;
|
|
243
|
243
|
|
|
244
|
|
- // 查询城市 id (level = 2),未查到返回 0
|
|
245
|
|
- if (!empty($data['city'])) {
|
|
|
244
|
+ // 查询城市 id (level = 2),带上 province_id 作为 pid,未查到返回 0
|
|
|
245
|
+ if (!empty($data['city']) && $provinceId > 0) {
|
|
246
|
246
|
$city = \think\facade\Db::name('regions')
|
|
247
|
247
|
->whereLike('name', '%' . $data['city'] . '%')
|
|
248
|
248
|
->where('level', 2)
|
|
|
249
|
+ ->where('pid', $provinceId)
|
|
249
|
250
|
->find();
|
|
250
|
251
|
$cityId = $city ? (int)$city['id'] : 0;
|
|
251
|
252
|
}
|
|
252
|
253
|
$data['city_id'] = $cityId;
|
|
253
|
254
|
|
|
254
|
|
- // 查询区/县 id (level = 3),未查到返回 0
|
|
255
|
|
- if (!empty($data['district'])) {
|
|
|
255
|
+ // 查询区/县 id (level = 3),带上 city_id 作为 pid,未查到返回 0
|
|
|
256
|
+ if (!empty($data['district']) && $cityId > 0) {
|
|
256
|
257
|
$district = \think\facade\Db::name('regions')
|
|
257
|
258
|
->whereLike('name', '%' . $data['district'] . '%')
|
|
258
|
259
|
->where('level', 3)
|
|
|
260
|
+ ->where('pid', $cityId)
|
|
259
|
261
|
->find();
|
|
260
|
262
|
$districtId = $district ? (int)$district['id'] : 0;
|
|
261
|
263
|
}
|
|
262
|
264
|
$data['district_id'] = $districtId;
|
|
263
|
265
|
|
|
264
|
|
- // 查询街道/乡镇 id (level = 4),未查到返回 0
|
|
265
|
|
- if (!empty($data['street'])) {
|
|
|
266
|
+ // 查询街道/乡镇 id (level = 4),带上 district_id 作为 pid,未查到返回 0
|
|
|
267
|
+ if (!empty($data['street']) && $districtId > 0) {
|
|
266
|
268
|
$street = \think\facade\Db::name('regions')
|
|
267
|
269
|
->whereLike('name', '%' . $data['street'] . '%')
|
|
268
|
270
|
->where('level', 4)
|
|
|
271
|
+ ->where('pid', $districtId)
|
|
269
|
272
|
->find();
|
|
270
|
273
|
$streetId = $street ? (int)$street['id'] : 0;
|
|
271
|
274
|
}
|
|
272
|
|
- $data['village'] = $data['street'];
|
|
|
275
|
+ $data['village'] = $data['street'] ?? '';
|
|
273
|
276
|
$data['village_id'] = $streetId;
|
|
274
|
277
|
|
|
275
|
278
|
// 拼接 code_list,格式:province_id,city_id,district_id,street_id
|