新车修改
This commit is contained in:
@@ -40,7 +40,7 @@ class VehicleNewController extends BaseController
|
|||||||
protected function postProcessItem(array $item, string $scene): array
|
protected function postProcessItem(array $item, string $scene): array
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($scene === 'default') {
|
if ($scene === 'default' || $scene === 'show') {
|
||||||
$result = [
|
$result = [
|
||||||
'id' => $item['id'],
|
'id' => $item['id'],
|
||||||
'vin' => $item['vin'],
|
'vin' => $item['vin'],
|
||||||
@@ -55,32 +55,53 @@ class VehicleNewController extends BaseController
|
|||||||
'condition_desc' => isset($item['translation']) ? $item['translation']['condition_desc'] : '',
|
'condition_desc' => isset($item['translation']) ? $item['translation']['condition_desc'] : '',
|
||||||
'created_at' => date('Y-m-d H:i:s', $item['created_at']),
|
'created_at' => date('Y-m-d H:i:s', $item['created_at']),
|
||||||
'updated_at' => date('Y-m-d H:i:s', $item['updated_at']),
|
'updated_at' => date('Y-m-d H:i:s', $item['updated_at']),
|
||||||
|
|
||||||
|
'brand_name' => is_array($item['brand']) ? $item['brand']['translation']['name'] : '',
|
||||||
|
'energy_name' => is_array($item['energy']) ? $item['energy']['translation']['name'] : '',
|
||||||
|
'type_name' => isset($item['types']) ? $item['types']['translation']['name'] : '',
|
||||||
|
'model_name' => isset($item['models']) ? $item['models']['translation']['name'] : '',
|
||||||
];
|
];
|
||||||
|
if ($item['cover']) {
|
||||||
|
$result['cover_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['cover']);
|
||||||
|
}
|
||||||
|
if ($item['video']) {
|
||||||
|
$result['video_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['video']);
|
||||||
|
}
|
||||||
foreach ($item['asked'] as $asked) {
|
foreach ($item['asked'] as $asked) {
|
||||||
$result['asked']['id'] = $asked['id'];
|
$askedRes['id'] = $asked['id'];
|
||||||
$result['asked']['vehicle_id'] = $asked['vehicle_id'];
|
$askedRes['vehicle_id'] = $asked['vehicle_id'];
|
||||||
$result['asked']['status'] = $asked['status'];
|
$askedRes['status'] = $asked['status'];
|
||||||
$result['asked']['title'] = isset($asked['translation']) ? $asked['translation']['title']:'';
|
$askedRes['title'] = isset($asked['translation']) ? $asked['translation']['title']:'';
|
||||||
$result['asked']['content'] = isset($asked['translation']) ? $asked['translation']['content']:'';
|
$askedRes['content'] = isset($asked['translation']) ? $asked['translation']['content']:'';
|
||||||
|
$result['asked'][] = $askedRes;
|
||||||
}
|
}
|
||||||
foreach ($item['trait'] as $trait) {
|
foreach ($item['trait'] as $trait) {
|
||||||
$result['trait']['id'] = $trait['id'];
|
$traitRes['id'] = $trait['id'];
|
||||||
$result['trait']['vehicle_id'] = $trait['vehicle_id'];
|
$traitRes['vehicle_id'] = $trait['vehicle_id'];
|
||||||
$result['trait']['status'] = $trait['status'];
|
$traitRes['status'] = $trait['status'];
|
||||||
$result['trait']['title'] = isset($trait['translation']) ? $trait['translation']['title']:'';
|
$traitRes['title'] = isset($trait['translation']) ? $trait['translation']['title']:'';
|
||||||
$result['trait']['content'] = isset($trait['translation']) ? $trait['translation']['content']:'';
|
$traitRes['content'] = isset($trait['translation']) ? $trait['translation']['content']:'';
|
||||||
|
$result['trait'][] = $traitRes;
|
||||||
}
|
}
|
||||||
foreach ($item['album'] as $album) {
|
foreach ($item['album'] as $album) {
|
||||||
$result['album']['id'] = $album['id'];
|
$albumRes['id'] = $album['id'];
|
||||||
$result['album']['vehicle_id'] = $album['vehicle_id'];
|
$albumRes['vehicle_id'] = $album['vehicle_id'];
|
||||||
$result['album']['status'] = $album['status'];
|
$albumRes['pic'] = $album['pic'];
|
||||||
$result['album']['alt'] = isset($album['translation']) ? $album['translation']['alt']:'';
|
$albumRes['status'] = $album['status'];
|
||||||
|
$albumRes['alt'] = isset($album['translation']) ? $album['translation']['alt']:'';
|
||||||
|
|
||||||
|
if ($albumRes['pic']) {
|
||||||
|
$albumRes['pic_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($albumRes['pic']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result['album'][] = $albumRes;
|
||||||
}
|
}
|
||||||
foreach ($item['content'] as $content) {
|
foreach ($item['content'] as $content) {
|
||||||
$result['content']['id'] = $content['id'];
|
$contentRes['id'] = $content['id'];
|
||||||
$result['content']['vehicle_id'] = $content['vehicle_id'];
|
$contentRes['vehicle_id'] = $content['vehicle_id'];
|
||||||
$result['content']['status'] = $content['status'];
|
$contentRes['status'] = $content['status'];
|
||||||
$result['content']['content'] = isset($content['translation']) ? $content['translation']['content']:'';
|
$contentRes['content'] = isset($content['translation']) ? $content['translation']['content']:'';
|
||||||
|
$result['content'][] = $contentRes;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,4 +56,9 @@ class VehicleNewContentService extends BaseService
|
|||||||
// }
|
// }
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 声明需要多语言翻译
|
||||||
|
protected array $translatable = [
|
||||||
|
'content',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
@@ -50,6 +50,10 @@ class VehicleNewService extends BaseService
|
|||||||
'content' => ['id', 'vehicle_id', 'status', 'sort'],
|
'content' => ['id', 'vehicle_id', 'status', 'sort'],
|
||||||
'content.translation' => ['id', 'content_id', 'locale', 'content'],
|
'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'],
|
||||||
'sorts' => [
|
'sorts' => [
|
||||||
['field' => 'id', 'direction' => 'desc']
|
['field' => 'id', 'direction' => 'desc']
|
||||||
],
|
],
|
||||||
@@ -77,6 +81,10 @@ class VehicleNewService extends BaseService
|
|||||||
'content' => ['id', 'vehicle_id', 'status', 'sort'],
|
'content' => ['id', 'vehicle_id', 'status', 'sort'],
|
||||||
'content.translation' => ['id', 'content_id', 'locale', 'content'],
|
'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'],
|
||||||
'sorts' => [
|
'sorts' => [
|
||||||
['field' => 'id', 'direction' => 'desc']
|
['field' => 'id', 'direction' => 'desc']
|
||||||
],
|
],
|
||||||
@@ -169,7 +177,7 @@ class VehicleNewService extends BaseService
|
|||||||
$albumsourceFields = $VehicleNewAlbumService->extractSourceFields($album);
|
$albumsourceFields = $VehicleNewAlbumService->extractSourceFields($album);
|
||||||
$album['vehicle_id'] = $info->id;
|
$album['vehicle_id'] = $info->id;
|
||||||
$album_res = $VehicleNewAlbumService->create($album);
|
$album_res = $VehicleNewAlbumService->create($album);
|
||||||
if (!$trait_res) {
|
if (!$album_res) {
|
||||||
throw new BusinessException('提交失败');
|
throw new BusinessException('提交失败');
|
||||||
}
|
}
|
||||||
(new TranslationService())->queueTranslations(
|
(new TranslationService())->queueTranslations(
|
||||||
@@ -183,14 +191,14 @@ class VehicleNewService extends BaseService
|
|||||||
foreach ($contents as $content) {
|
foreach ($contents as $content) {
|
||||||
$contentsourceFields = $VehicleNewContentService->extractSourceFields($content);
|
$contentsourceFields = $VehicleNewContentService->extractSourceFields($content);
|
||||||
$content['vehicle_id'] = $info->id;
|
$content['vehicle_id'] = $info->id;
|
||||||
$trait_res = $VehicleNewContentService->create($content);
|
$content_res = $VehicleNewContentService->create($content);
|
||||||
if (!$trait_res) {
|
if (!$content_res) {
|
||||||
throw new BusinessException('提交失败');
|
throw new BusinessException('提交失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
(new TranslationService())->queueTranslations(
|
(new TranslationService())->queueTranslations(
|
||||||
'vehicleNewContent',
|
'vehicleNewContent',
|
||||||
$trait_res->id,
|
$content_res->id,
|
||||||
$sourceLocale,
|
$sourceLocale,
|
||||||
$contentsourceFields
|
$contentsourceFields
|
||||||
);
|
);
|
||||||
@@ -213,18 +221,35 @@ class VehicleNewService extends BaseService
|
|||||||
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||||
};
|
};
|
||||||
|
|
||||||
$album = [];
|
$askeds = $params['asked'];
|
||||||
$trans = [];
|
unset($params['asked']);
|
||||||
$albums = VehicleNewAlbumModel::VEHICLE_New_ALBUM_FIELDS;
|
$traits = $params['trait'];
|
||||||
foreach ($params as $ko => $vo) {
|
unset($params['trait']);
|
||||||
if (in_array($ko, $albums)) {
|
$albums = $params['album'];
|
||||||
$album[$ko] = $vo ?? '';
|
unset($params['album']);
|
||||||
} elseif (in_array($ko, VehicleNewModel::TRANS_FIELDS)) {
|
$contents = $params['content'];
|
||||||
$trans[$ko] = $vo ?? '';
|
unset($params['content']);
|
||||||
}else{
|
$VehicleNewAskedService = new VehicleNewAskedService(new VehicleNewAskedModel());
|
||||||
$data[$ko] = $vo ?? '';
|
$VehicleNewTraitService = new VehicleNewTraitService(new VehicleNewTraitModel());
|
||||||
}
|
$VehicleNewAlbumService = new VehicleNewAlbumService(new VehicleNewAlbumModel());
|
||||||
}
|
$VehicleNewContentService = new VehicleNewContentService(new VehicleNewContentModel());
|
||||||
|
// foreach ($params as $ko => $vo) {
|
||||||
|
// if (in_array($ko, $albums)) {
|
||||||
|
// $album[$ko] = $vo ?? '';
|
||||||
|
// } elseif (in_array($ko, $albums)) {
|
||||||
|
// $album[$ko] = $vo ?? '';
|
||||||
|
// } elseif (in_array($ko, $albums)) {
|
||||||
|
// $album[$ko] = $vo ?? '';
|
||||||
|
// } elseif (in_array($ko, $albums)) {
|
||||||
|
// $album[$ko] = $vo ?? '';
|
||||||
|
// } elseif (in_array($ko, $albums)) {
|
||||||
|
// $album[$ko] = $vo ?? '';
|
||||||
|
// } elseif (in_array($ko, VehicleNewModel::TRANS_FIELDS)) {
|
||||||
|
// $trans[$ko] = $vo ?? '';
|
||||||
|
// }else{
|
||||||
|
// $data[$ko] = $vo ?? '';
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
Db::beginTransaction();
|
Db::beginTransaction();
|
||||||
try {
|
try {
|
||||||
@@ -235,22 +260,149 @@ class VehicleNewService extends BaseService
|
|||||||
|
|
||||||
// 异步翻译并写入 hs_vehicle_data_translation 表
|
// 异步翻译并写入 hs_vehicle_data_translation 表
|
||||||
(new TranslationService())->queueTranslations(
|
(new TranslationService())->queueTranslations(
|
||||||
'vehicle',
|
'vehicleNew',
|
||||||
$id,
|
$id,
|
||||||
$sourceLocale,
|
$sourceLocale,
|
||||||
$sourceFields
|
$sourceFields
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($album) {
|
foreach ($askeds as $asked) {
|
||||||
// $album['vehicle_data_id'] = $info->id;
|
$askedsourceFields = $VehicleNewAskedService->extractSourceFields($asked);
|
||||||
$albumModel = new VehicleAlbumModel();
|
$asked['vehicle_id'] = $id;
|
||||||
if (!$albumModel->updateOrCreate(
|
$askedsId = [];
|
||||||
['vehicle_data_id' => $id],
|
if(!empty($asked['id'])){
|
||||||
$album
|
$askedId = $asked['id'];
|
||||||
)) {
|
$askedsId[] = $askedId;
|
||||||
throw new BusinessException('提交失败');
|
$asked_res = $VehicleNewAskedService->update($askedId, $asked);
|
||||||
|
if (!$asked_res) {
|
||||||
|
throw new BusinessException('提交失败:常见问题');
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$asked_res = $VehicleNewAskedService->create($asked);
|
||||||
|
if (!$asked_res) {
|
||||||
|
throw new BusinessException('提交失败:常见问题');
|
||||||
}
|
}
|
||||||
|
$askedId = $asked_res->id;
|
||||||
|
$askedsId[] = $askedId;
|
||||||
|
}
|
||||||
|
(new TranslationService())->queueTranslations(
|
||||||
|
'vehicleNewAsked',
|
||||||
|
$askedId,
|
||||||
|
$sourceLocale,
|
||||||
|
$askedsourceFields
|
||||||
|
);
|
||||||
|
}
|
||||||
|
VehicleNewAskedModel::whereNotIn('id', $askedsId)->where('vehicle_id',$id)->delete();
|
||||||
|
|
||||||
|
foreach ($traits as $trait) {
|
||||||
|
$traitsourceFields = $VehicleNewTraitService->extractSourceFields($trait);
|
||||||
|
$trait['vehicle_id'] = $id;
|
||||||
|
$traitsId = [];
|
||||||
|
if(!empty($trait['id'])){
|
||||||
|
$traitId = $trait['id'];
|
||||||
|
$traitsId[] = $traitId;
|
||||||
|
$trait_res = $VehicleNewAskedService->update($traitId, $trait);
|
||||||
|
if (!$trait_res) {
|
||||||
|
throw new BusinessException('提交失败:车辆特性');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$trait_res = $VehicleNewAskedService->create($trait);
|
||||||
|
if (!$trait_res) {
|
||||||
|
throw new BusinessException('提交失败:车辆特性');
|
||||||
|
}
|
||||||
|
$traitId = $trait_res->id;
|
||||||
|
$traitsId[] = $traitId;
|
||||||
|
}
|
||||||
|
(new TranslationService())->queueTranslations(
|
||||||
|
'vehicleNewTrait',
|
||||||
|
$traitId,
|
||||||
|
$sourceLocale,
|
||||||
|
$traitsourceFields
|
||||||
|
);
|
||||||
|
}
|
||||||
|
VehicleNewTraitModel::whereNotIn('id', $traitsId)->where('vehicle_id',$id)->delete();
|
||||||
|
|
||||||
|
foreach ($albums as $album) {
|
||||||
|
$albumsourceFields = $VehicleNewAlbumService->extractSourceFields($album);
|
||||||
|
$album['vehicle_id'] = $id;
|
||||||
|
// $albumId = $album['id'];
|
||||||
|
// $album_res = $VehicleNewAskedService->update($albumId, $album);
|
||||||
|
// if (!$album_res) {
|
||||||
|
// throw new BusinessException('提交失败');
|
||||||
|
// }
|
||||||
|
|
||||||
|
$albumsId = [];
|
||||||
|
// var_dump(!empty($album['id']));
|
||||||
|
$album['vehicle_id'] = 78;
|
||||||
|
if(!empty($album['id'])){
|
||||||
|
$albumId =$album['id'];
|
||||||
|
$albumsId[] =$albumId;
|
||||||
|
$album_res = $VehicleNewAlbumService->update($albumId,$album);
|
||||||
|
if (!$album_res) {
|
||||||
|
throw new BusinessException('提交失败:车辆图册');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$album_res = $VehicleNewAlbumService->create($album);
|
||||||
|
if (!$album_res) {
|
||||||
|
throw new BusinessException('提交失败:车辆图册1');
|
||||||
|
}
|
||||||
|
$albumId = $album_res->id;
|
||||||
|
$albumsId[] = $albumId;
|
||||||
|
}
|
||||||
|
|
||||||
|
(new TranslationService())->queueTranslations(
|
||||||
|
'VehicleNewAlbum',
|
||||||
|
$albumId,
|
||||||
|
$sourceLocale,
|
||||||
|
$albumsourceFields
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($contents as $content) {
|
||||||
|
$contentsourceFields = $VehicleNewContentService->extractSourceFields($content);
|
||||||
|
$content['vehicle_id'] = $id;
|
||||||
|
// $contentId = $content['id'];
|
||||||
|
// $trait_res = $VehicleNewContentService->update($contentId, $content);
|
||||||
|
// if (!$trait_res) {
|
||||||
|
// throw new BusinessException('提交失败');
|
||||||
|
// }
|
||||||
|
|
||||||
|
$contentsId = [];
|
||||||
|
if(!empty($content['id'])){
|
||||||
|
$contentId =$content['id'];
|
||||||
|
$contentsId[] =$contentId;
|
||||||
|
$content['vehicle_id'] = 78;
|
||||||
|
$content_res = $VehicleNewContentService->update($contentId,$content);
|
||||||
|
if (!$content_res) {
|
||||||
|
throw new BusinessException('提交失败:车辆介绍1');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$content_res = $VehicleNewAskedService->create($content);
|
||||||
|
if (!$content_res) {
|
||||||
|
throw new BusinessException('提交失败:车辆介绍');
|
||||||
|
}
|
||||||
|
$contentId = $content_res->id;
|
||||||
|
$contentsId[] = $contentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
(new TranslationService())->queueTranslations(
|
||||||
|
'vehicleNewContent',
|
||||||
|
$contentId,
|
||||||
|
$sourceLocale,
|
||||||
|
$contentsourceFields
|
||||||
|
);
|
||||||
|
}
|
||||||
|
VehicleNewContentModel::whereNotIn('id', $contentsId)->where('vehicle_id',$id)->delete();
|
||||||
|
// if ($album) {
|
||||||
|
// // $album['vehicle_data_id'] = $info->id;
|
||||||
|
// $albumModel = new VehicleAlbumModel();
|
||||||
|
// if (!$albumModel->updateOrCreate(
|
||||||
|
// ['vehicle_data_id' => $id],
|
||||||
|
// $album
|
||||||
|
// )) {
|
||||||
|
// throw new BusinessException('提交失败');
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// $applyModel = new VehicleApplyModel();
|
// $applyModel = new VehicleApplyModel();
|
||||||
// if (!$applyModel->create([
|
// if (!$applyModel->create([
|
||||||
|
|||||||
Reference in New Issue
Block a user