diff --git a/app/console/controller/VehicleNewController.php b/app/console/controller/VehicleNewController.php index 4a09ab5..bcaecd5 100644 --- a/app/console/controller/VehicleNewController.php +++ b/app/console/controller/VehicleNewController.php @@ -44,12 +44,12 @@ class VehicleNewController extends BaseController $result = [ 'id' => $item['id'], 'vin' => $item['vin'], - 'brand' => $item['brand'], 'price' => $item['price'], 'cover' => $item['cover'], - 'energy' => $item['energy'], - 'type' => $item['type'], - 'model' => $item['model'], + 'brand' => is_array($item['brand']) ? $item['brand']['translation']['brand_id'] : $item['brand'], + 'energy' => is_array($item['energy']) ? $item['energy']['translation']['energy_id'] : $item['energy'], + 'type' => isset($item['types']) ? $item['types']['translation']['type_id'] : $item['type'], + 'model' => isset($item['models']) ? $item['models']['translation']['model_id'] : $item['model'], 'video' => $item['video'], 'name' => isset($item['translation']) ? $item['translation']['name'] : '', 'condition_desc' => isset($item['translation']) ? $item['translation']['condition_desc'] : '', diff --git a/app/console/service/VehicleNewService.php b/app/console/service/VehicleNewService.php index e1a1787..489f551 100644 --- a/app/console/service/VehicleNewService.php +++ b/app/console/service/VehicleNewService.php @@ -49,11 +49,11 @@ class VehicleNewService extends BaseService 'album.translation' => ['id', 'album_id', 'locale', 'alt'], 'content' => ['id', 'vehicle_id', 'status', 'sort'], 'content.translation' => ['id', 'content_id', 'locale', 'content'], + 'brand.translation' => ['brand_id', 'name'], + 'types.translation' => ['type_id', 'name'], + 'energy.translation' => ['energy_id', 'name'], + 'models.translation' => ['model_id', 'name'], ], - 'brand.translation' => ['brand_id', 'name'], - 'types.translation' => ['type_id', 'name'], - 'energy.translation' => ['energy_id', 'name'], - 'models.translation' => ['model_id', 'name'], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] ], @@ -266,22 +266,22 @@ class VehicleNewService extends BaseService $sourceFields ); + $askedsId = []; foreach ($askeds as $asked) { $askedsourceFields = $VehicleNewAskedService->extractSourceFields($asked); $asked['vehicle_id'] = $id; - $askedsId = []; if(!empty($asked['id'])){ $askedId = $asked['id']; $askedsId[] = $askedId; $asked_res = $VehicleNewAskedService->update($askedId, $asked); if (!$asked_res) { - throw new BusinessException('提交失败:常见问题'); + throw new BusinessException('提交失败:常见问题2'); } } else { unset($asked['id']); $asked_res = $VehicleNewAskedService->create($asked); if (!$asked_res) { - throw new BusinessException('提交失败:常见问题'); + throw new BusinessException('提交失败:常见问题1'); } $askedId = $asked_res->id; $askedsId[] = $askedId; @@ -295,10 +295,10 @@ class VehicleNewService extends BaseService } VehicleNewAskedModel::whereNotIn('id', $askedsId)->where('vehicle_id',$id)->delete(); + $traitsId = []; foreach ($traits as $trait) { $traitsourceFields = $VehicleNewTraitService->extractSourceFields($trait); $trait['vehicle_id'] = $id; - $traitsId = []; if(!empty($trait['id'])){ $traitId = $trait['id']; $traitsId[] = $traitId; @@ -324,6 +324,7 @@ class VehicleNewService extends BaseService } VehicleNewTraitModel::whereNotIn('id', $traitsId)->where('vehicle_id',$id)->delete(); + $albumsId = []; foreach ($albums as $album) { $albumsourceFields = $VehicleNewAlbumService->extractSourceFields($album); $album['vehicle_id'] = $id; @@ -333,7 +334,6 @@ class VehicleNewService extends BaseService // throw new BusinessException('提交失败'); // } - $albumsId = []; if(!empty($album['id'])){ $albumId =$album['id']; $albumsId[] =$albumId; @@ -358,7 +358,9 @@ class VehicleNewService extends BaseService $albumsourceFields ); } + VehicleNewAlbumModel::whereNotIn('id', $traitsId)->where('vehicle_id',$id)->delete(); + $contentsId = []; foreach ($contents as $content) { $contentsourceFields = $VehicleNewContentService->extractSourceFields($content); $content['vehicle_id'] = $id; @@ -368,7 +370,6 @@ class VehicleNewService extends BaseService // throw new BusinessException('提交失败'); // } - $contentsId = []; if(!empty($content['id'])){ $contentId =$content['id']; $contentsId[] =$contentId;