2025-05-22 09:26:19 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\console\service;
|
|
|
|
|
|
|
|
|
|
use app\console\model\VehicleNewAlbumModel;
|
|
|
|
|
use app\console\model\VehicleNewAskedModel;
|
|
|
|
|
use app\console\model\VehicleNewContentModel;
|
|
|
|
|
use app\console\model\VehicleNewModel;
|
2025-06-20 09:17:14 +08:00
|
|
|
use app\console\model\VehicleNewSkuAttributesModel;
|
|
|
|
|
use app\console\model\VehicleNewSkusModel;
|
2025-05-22 09:26:19 +08:00
|
|
|
use app\console\model\VehicleNewTraitModel;
|
|
|
|
|
use app\mzl\common\services\BaseService;
|
|
|
|
|
use app\mzl\modules\translation\service\TranslationService;
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use support\Db;
|
|
|
|
|
use support\exception\BusinessException;
|
|
|
|
|
|
|
|
|
|
class VehicleNewService extends BaseService
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 定义模型
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getModel(): string
|
|
|
|
|
{
|
|
|
|
|
return VehicleNewModel::class;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 多场景配置
|
|
|
|
|
*/
|
|
|
|
|
public function queryScenes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'default' => function ($params) {
|
|
|
|
|
$keyword = $params['keyword'] ?? '';
|
|
|
|
|
return [
|
2025-05-30 15:35:28 +08:00
|
|
|
'filters' => $params['filters'],
|
2025-05-22 09:26:19 +08:00
|
|
|
'fields' => ['id', 'vin', 'brand', 'cover', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at'],
|
|
|
|
|
'relations' => [
|
2025-05-22 10:59:47 +08:00
|
|
|
'translation' => ['vehicle_id', 'locale', 'name', 'condition_desc', 'location'],
|
2025-05-22 09:26:19 +08:00
|
|
|
'asked' => ['id', 'vehicle_id', 'status', 'sort'],
|
|
|
|
|
'asked.translation' => ['id', 'asked_id', 'locale', 'title', 'content'],
|
|
|
|
|
'trait' => ['id', 'vehicle_id', 'status', 'sort'],
|
|
|
|
|
'trait.translation' => ['id', 'trait_id', 'locale', 'title', 'content'],
|
2025-05-22 10:59:47 +08:00
|
|
|
'album' => ['id', 'vehicle_id', 'pic', 'status', 'sort'],
|
|
|
|
|
'album.translation' => ['id', 'album_id', 'locale', 'alt'],
|
|
|
|
|
'content' => ['id', 'vehicle_id', 'status', 'sort'],
|
|
|
|
|
'content.translation' => ['id', 'content_id', 'locale', 'content'],
|
2025-05-23 08:52:37 +08:00
|
|
|
'brand.translation' => ['brand_id', 'name'],
|
|
|
|
|
'types.translation' => ['type_id', 'name'],
|
|
|
|
|
'energy.translation' => ['energy_id', 'name'],
|
|
|
|
|
'models.translation' => ['model_id', 'name'],
|
2025-05-22 10:59:47 +08:00
|
|
|
],
|
|
|
|
|
'sorts' => [
|
|
|
|
|
['field' => 'id', 'direction' => 'desc']
|
|
|
|
|
],
|
|
|
|
|
'pagination' => [
|
|
|
|
|
'page' => $params['page'] ?? 1,
|
|
|
|
|
'per_page' => $params['per_page'] ?? 10,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
'show' => function ($params) {
|
|
|
|
|
$keyword = $params['keyword'] ?? '';
|
|
|
|
|
return [
|
|
|
|
|
'filters' => [
|
2025-05-22 14:52:24 +08:00
|
|
|
['field'=>'id', 'operator'=>'=', 'value'=> $params['id']],
|
2025-05-22 10:59:47 +08:00
|
|
|
],
|
|
|
|
|
'fields' => ['id', 'vin', 'brand', 'cover', 'price', 'type', 'energy', 'model', 'video', 'views', 'created_at', 'updated_at'],
|
|
|
|
|
'relations' => [
|
|
|
|
|
'translation' => ['vehicle_id', 'locale', 'name', 'condition_desc', 'location'],
|
|
|
|
|
'asked' => ['id', 'vehicle_id', 'status', 'sort'],
|
|
|
|
|
'asked.translation' => ['id', 'asked_id', 'locale', 'title', 'content'],
|
|
|
|
|
'trait' => ['id', 'vehicle_id', 'status', 'sort'],
|
|
|
|
|
'trait.translation' => ['id', 'trait_id', 'locale', 'title', 'content'],
|
|
|
|
|
'album' => ['id', 'vehicle_id', 'pic', 'status', 'sort'],
|
2025-05-22 09:26:19 +08:00
|
|
|
'album.translation' => ['id', 'album_id', 'locale', 'alt'],
|
|
|
|
|
'content' => ['id', 'vehicle_id', 'status', 'sort'],
|
|
|
|
|
'content.translation' => ['id', 'content_id', 'locale', 'content'],
|
2025-05-23 09:42:30 +08:00
|
|
|
'brand.translation' => ['brand_id', 'name'],
|
|
|
|
|
'types.translation' => ['type_id', 'name'],
|
|
|
|
|
'energy.translation' => ['energy_id', 'name'],
|
|
|
|
|
'models.translation' => ['model_id', 'name'],
|
2025-05-22 09:26:19 +08:00
|
|
|
],
|
|
|
|
|
'sorts' => [
|
|
|
|
|
['field' => 'id', 'direction' => 'desc']
|
|
|
|
|
],
|
|
|
|
|
'pagination' => [
|
|
|
|
|
'page' => $params['page'] ?? 1,
|
|
|
|
|
'per_page' => $params['per_page'] ?? 10,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 声明需要多语言翻译
|
|
|
|
|
protected array $translatable = [
|
2025-05-22 10:59:47 +08:00
|
|
|
'condition_desc','name',
|
2025-05-22 09:26:19 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function add(array $params)
|
|
|
|
|
{
|
|
|
|
|
$sourceLocale = locale();
|
|
|
|
|
$sourceFields = $this->extractSourceFields($params);
|
|
|
|
|
|
|
|
|
|
if (empty($sourceFields)) {
|
|
|
|
|
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$askeds = $params['asked'];
|
|
|
|
|
unset($params['asked']);
|
|
|
|
|
$traits = $params['trait'];
|
|
|
|
|
unset($params['trait']);
|
|
|
|
|
$albums = $params['album'];
|
|
|
|
|
unset($params['album']);
|
|
|
|
|
$contents = $params['content'];
|
|
|
|
|
unset($params['content']);
|
2025-06-20 09:17:14 +08:00
|
|
|
$skus = $params['sku'];
|
|
|
|
|
unset($params['sku']);
|
2025-05-22 09:26:19 +08:00
|
|
|
|
|
|
|
|
$VehicleNewAskedService = new VehicleNewAskedService(new VehicleNewAskedModel());
|
|
|
|
|
$VehicleNewTraitService = new VehicleNewTraitService(new VehicleNewTraitModel());
|
|
|
|
|
$VehicleNewAlbumService = new VehicleNewAlbumService(new VehicleNewAlbumModel());
|
|
|
|
|
$VehicleNewContentService = new VehicleNewContentService(new VehicleNewContentModel());
|
2025-06-20 09:17:14 +08:00
|
|
|
$VehicleNewSkusService = new VehicleNewSkusService(new VehicleNewSkusModel());
|
|
|
|
|
$VehicleNewSkuAttributesService = new VehicleNewSkuAttributesService(new VehicleNewSkuAttributesModel());
|
2025-05-22 09:26:19 +08:00
|
|
|
|
|
|
|
|
Db::beginTransaction();
|
|
|
|
|
try {
|
2025-05-30 14:19:28 +08:00
|
|
|
if(empty($params['model'])){
|
|
|
|
|
$params['model'] = 0;
|
|
|
|
|
}
|
2025-05-22 09:26:19 +08:00
|
|
|
$info = $this->create($params);
|
|
|
|
|
if (!$info) {
|
|
|
|
|
throw new BusinessException('提交失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 异步翻译并写入 hs_vehicle_data_translation 表
|
|
|
|
|
(new TranslationService())->queueTranslations(
|
|
|
|
|
'vehicleNew',
|
|
|
|
|
$info->id,
|
|
|
|
|
$sourceLocale,
|
|
|
|
|
$sourceFields
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ($askeds as $asked) {
|
|
|
|
|
$askedsourceFields = $VehicleNewAskedService->extractSourceFields($asked);
|
|
|
|
|
$asked['vehicle_id'] = $info->id;
|
|
|
|
|
$asked_res = $VehicleNewAskedService->create($asked);
|
|
|
|
|
if (!$asked_res) {
|
|
|
|
|
throw new BusinessException('提交失败');
|
|
|
|
|
}
|
|
|
|
|
// $askedsourceFields['asked_id'] = $asked_res->id;
|
|
|
|
|
(new TranslationService())->queueTranslations(
|
|
|
|
|
'vehicleNewAsked',
|
|
|
|
|
$asked_res->id,
|
|
|
|
|
$sourceLocale,
|
|
|
|
|
$askedsourceFields
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($traits as $trait) {
|
|
|
|
|
$traitsourceFields = $VehicleNewTraitService->extractSourceFields($trait);
|
|
|
|
|
$trait['vehicle_id'] = $info->id;
|
|
|
|
|
$trait_res = $VehicleNewTraitService->create($trait);
|
|
|
|
|
if (!$trait_res) {
|
|
|
|
|
throw new BusinessException('提交失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(new TranslationService())->queueTranslations(
|
|
|
|
|
'vehicleNewTrait',
|
|
|
|
|
$trait_res->id,
|
|
|
|
|
$sourceLocale,
|
|
|
|
|
$traitsourceFields
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($albums as $album) {
|
|
|
|
|
$albumsourceFields = $VehicleNewAlbumService->extractSourceFields($album);
|
|
|
|
|
$album['vehicle_id'] = $info->id;
|
2025-05-22 10:59:47 +08:00
|
|
|
$album_res = $VehicleNewAlbumService->create($album);
|
2025-05-22 14:38:48 +08:00
|
|
|
if (!$album_res) {
|
2025-05-22 09:26:19 +08:00
|
|
|
throw new BusinessException('提交失败');
|
|
|
|
|
}
|
|
|
|
|
(new TranslationService())->queueTranslations(
|
2025-05-22 10:59:47 +08:00
|
|
|
'vehicleNewAlbum',
|
|
|
|
|
$album_res->id,
|
2025-05-22 09:26:19 +08:00
|
|
|
$sourceLocale,
|
|
|
|
|
$albumsourceFields
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($contents as $content) {
|
|
|
|
|
$contentsourceFields = $VehicleNewContentService->extractSourceFields($content);
|
|
|
|
|
$content['vehicle_id'] = $info->id;
|
2025-05-22 14:38:48 +08:00
|
|
|
$content_res = $VehicleNewContentService->create($content);
|
|
|
|
|
if (!$content_res) {
|
2025-05-22 09:26:19 +08:00
|
|
|
throw new BusinessException('提交失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(new TranslationService())->queueTranslations(
|
|
|
|
|
'vehicleNewContent',
|
2025-05-22 14:38:48 +08:00
|
|
|
$content_res->id,
|
2025-05-22 09:26:19 +08:00
|
|
|
$sourceLocale,
|
|
|
|
|
$contentsourceFields
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 09:17:14 +08:00
|
|
|
foreach ($skus as $sku) {
|
|
|
|
|
$sku['vehicle_id'] = $info->id;
|
|
|
|
|
$sku_code = sprintf("%05d", $info->id);
|
|
|
|
|
$sku['sku_code'] = rand(100,999).$sku_code[0].' '.substr($sku_code,1).' '.sprintf("%04d", $sku['skuAttributes'][0]['attribute_id']).' '.sprintf("%04d", $sku['skuAttributes'][0]['value_id']);
|
|
|
|
|
|
|
|
|
|
$sku_res = $VehicleNewSkusService->create($sku);
|
|
|
|
|
if (!$sku_res) {
|
|
|
|
|
throw new BusinessException('提交失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$skuAttributes = $sku['skuAttributes'];
|
|
|
|
|
foreach ($skuAttributes as $skuAttribute) {
|
|
|
|
|
$skuAttribute['sku_id'] = $sku_res->id;
|
|
|
|
|
$skuAttribute_res = $VehicleNewSkuAttributesService->create($skuAttribute);
|
|
|
|
|
if (!$skuAttribute_res) {
|
|
|
|
|
throw new BusinessException('提交失败');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 09:26:19 +08:00
|
|
|
Db::commit();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
Db::rollBack();
|
|
|
|
|
throw $th;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-22 10:59:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public function edit(array $params, int $id)
|
|
|
|
|
{
|
|
|
|
|
$sourceLocale = locale();
|
|
|
|
|
$sourceFields = $this->extractSourceFields($params);
|
|
|
|
|
if (empty($sourceFields)) {
|
|
|
|
|
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-22 14:38:48 +08:00
|
|
|
$askeds = $params['asked'];
|
|
|
|
|
unset($params['asked']);
|
|
|
|
|
$traits = $params['trait'];
|
|
|
|
|
unset($params['trait']);
|
|
|
|
|
$albums = $params['album'];
|
|
|
|
|
unset($params['album']);
|
|
|
|
|
$contents = $params['content'];
|
|
|
|
|
unset($params['content']);
|
2025-06-20 09:17:14 +08:00
|
|
|
$skus = $params['sku'];
|
|
|
|
|
unset($params['sku']);
|
|
|
|
|
|
2025-05-22 14:38:48 +08:00
|
|
|
$VehicleNewAskedService = new VehicleNewAskedService(new VehicleNewAskedModel());
|
|
|
|
|
$VehicleNewTraitService = new VehicleNewTraitService(new VehicleNewTraitModel());
|
|
|
|
|
$VehicleNewAlbumService = new VehicleNewAlbumService(new VehicleNewAlbumModel());
|
|
|
|
|
$VehicleNewContentService = new VehicleNewContentService(new VehicleNewContentModel());
|
2025-06-20 09:17:14 +08:00
|
|
|
$VehicleNewSkusService = new VehicleNewSkusService(new VehicleNewSkusModel());
|
|
|
|
|
$VehicleNewSkuAttributesService = new VehicleNewSkuAttributesService(new VehicleNewSkuAttributesModel());
|
2025-05-22 10:59:47 +08:00
|
|
|
|
|
|
|
|
Db::beginTransaction();
|
|
|
|
|
try {
|
2025-05-30 14:19:28 +08:00
|
|
|
if(empty($params['model'])){
|
|
|
|
|
$params['model'] = 0;
|
|
|
|
|
}
|
2025-05-22 10:59:47 +08:00
|
|
|
$info = $this->update($id, $params);
|
|
|
|
|
if (!$info) {
|
|
|
|
|
throw new BusinessException('提交失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 异步翻译并写入 hs_vehicle_data_translation 表
|
|
|
|
|
(new TranslationService())->queueTranslations(
|
2025-05-22 14:38:48 +08:00
|
|
|
'vehicleNew',
|
2025-05-22 10:59:47 +08:00
|
|
|
$id,
|
|
|
|
|
$sourceLocale,
|
|
|
|
|
$sourceFields
|
|
|
|
|
);
|
|
|
|
|
|
2025-05-23 08:52:37 +08:00
|
|
|
$askedsId = [];
|
2025-05-22 14:38:48 +08:00
|
|
|
foreach ($askeds as $asked) {
|
|
|
|
|
$askedsourceFields = $VehicleNewAskedService->extractSourceFields($asked);
|
|
|
|
|
$asked['vehicle_id'] = $id;
|
|
|
|
|
if(!empty($asked['id'])){
|
|
|
|
|
$askedId = $asked['id'];
|
|
|
|
|
$askedsId[] = $askedId;
|
|
|
|
|
$asked_res = $VehicleNewAskedService->update($askedId, $asked);
|
|
|
|
|
if (!$asked_res) {
|
2025-05-23 08:52:37 +08:00
|
|
|
throw new BusinessException('提交失败:常见问题2');
|
2025-05-22 14:38:48 +08:00
|
|
|
}
|
|
|
|
|
} else {
|
2025-05-22 17:08:42 +08:00
|
|
|
unset($asked['id']);
|
2025-05-22 14:38:48 +08:00
|
|
|
$asked_res = $VehicleNewAskedService->create($asked);
|
|
|
|
|
if (!$asked_res) {
|
2025-05-23 08:52:37 +08:00
|
|
|
throw new BusinessException('提交失败:常见问题1');
|
2025-05-22 14:38:48 +08:00
|
|
|
}
|
|
|
|
|
$askedId = $asked_res->id;
|
|
|
|
|
$askedsId[] = $askedId;
|
2025-05-22 10:59:47 +08:00
|
|
|
}
|
2025-05-22 14:38:48 +08:00
|
|
|
(new TranslationService())->queueTranslations(
|
|
|
|
|
'vehicleNewAsked',
|
|
|
|
|
$askedId,
|
|
|
|
|
$sourceLocale,
|
|
|
|
|
$askedsourceFields
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
VehicleNewAskedModel::whereNotIn('id', $askedsId)->where('vehicle_id',$id)->delete();
|
|
|
|
|
|
2025-05-23 08:52:37 +08:00
|
|
|
$traitsId = [];
|
2025-05-22 14:38:48 +08:00
|
|
|
foreach ($traits as $trait) {
|
|
|
|
|
$traitsourceFields = $VehicleNewTraitService->extractSourceFields($trait);
|
|
|
|
|
$trait['vehicle_id'] = $id;
|
|
|
|
|
if(!empty($trait['id'])){
|
|
|
|
|
$traitId = $trait['id'];
|
|
|
|
|
$traitsId[] = $traitId;
|
2025-05-22 17:45:02 +08:00
|
|
|
$trait_res = $VehicleNewTraitService->update($traitId, $trait);
|
2025-05-22 14:38:48 +08:00
|
|
|
if (!$trait_res) {
|
|
|
|
|
throw new BusinessException('提交失败:车辆特性');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-05-22 17:08:42 +08:00
|
|
|
unset($trait['id']);
|
2025-05-22 17:45:02 +08:00
|
|
|
$trait_res = $VehicleNewTraitService->create($trait);
|
2025-05-22 14:38:48 +08:00
|
|
|
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();
|
|
|
|
|
|
2025-05-23 08:52:37 +08:00
|
|
|
$albumsId = [];
|
2025-05-22 14:38:48 +08:00
|
|
|
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('提交失败');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if(!empty($album['id'])){
|
|
|
|
|
$albumId =$album['id'];
|
|
|
|
|
$albumsId[] =$albumId;
|
|
|
|
|
$album_res = $VehicleNewAlbumService->update($albumId,$album);
|
|
|
|
|
if (!$album_res) {
|
|
|
|
|
throw new BusinessException('提交失败:车辆图册');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-05-22 17:08:42 +08:00
|
|
|
unset($album['id']);
|
2025-05-22 14:38:48 +08:00
|
|
|
$album_res = $VehicleNewAlbumService->create($album);
|
|
|
|
|
if (!$album_res) {
|
|
|
|
|
throw new BusinessException('提交失败:车辆图册1');
|
|
|
|
|
}
|
|
|
|
|
$albumId = $album_res->id;
|
|
|
|
|
$albumsId[] = $albumId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(new TranslationService())->queueTranslations(
|
2025-05-26 09:43:32 +08:00
|
|
|
'vehicleNewAlbum',
|
2025-05-22 14:38:48 +08:00
|
|
|
$albumId,
|
|
|
|
|
$sourceLocale,
|
|
|
|
|
$albumsourceFields
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-05-23 09:34:06 +08:00
|
|
|
VehicleNewAlbumModel::whereNotIn('id', $albumsId)->where('vehicle_id',$id)->delete();
|
2025-05-22 14:38:48 +08:00
|
|
|
|
2025-05-23 08:52:37 +08:00
|
|
|
$contentsId = [];
|
2025-05-22 14:38:48 +08:00
|
|
|
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('提交失败');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if(!empty($content['id'])){
|
|
|
|
|
$contentId =$content['id'];
|
|
|
|
|
$contentsId[] =$contentId;
|
|
|
|
|
$content_res = $VehicleNewContentService->update($contentId,$content);
|
|
|
|
|
if (!$content_res) {
|
|
|
|
|
throw new BusinessException('提交失败:车辆介绍1');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-05-22 17:08:42 +08:00
|
|
|
unset($content['id']);
|
2025-05-23 09:34:06 +08:00
|
|
|
$content_res = $VehicleNewContentService->create($content);
|
2025-05-22 14:38:48 +08:00
|
|
|
if (!$content_res) {
|
|
|
|
|
throw new BusinessException('提交失败:车辆介绍');
|
|
|
|
|
}
|
|
|
|
|
$contentId = $content_res->id;
|
|
|
|
|
$contentsId[] = $contentId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(new TranslationService())->queueTranslations(
|
|
|
|
|
'vehicleNewContent',
|
|
|
|
|
$contentId,
|
|
|
|
|
$sourceLocale,
|
|
|
|
|
$contentsourceFields
|
|
|
|
|
);
|
2025-05-22 10:59:47 +08:00
|
|
|
}
|
2025-05-22 14:38:48 +08:00
|
|
|
VehicleNewContentModel::whereNotIn('id', $contentsId)->where('vehicle_id',$id)->delete();
|
2025-06-20 09:17:14 +08:00
|
|
|
|
|
|
|
|
$skusId = [];
|
|
|
|
|
foreach ($skus as $sku) {
|
|
|
|
|
if(!empty($sku['id'])){
|
|
|
|
|
$skuId =$sku['id'];
|
|
|
|
|
$skusId[] =$skuId;
|
|
|
|
|
$skuAttributes = $sku['skuAttributes'];
|
|
|
|
|
unset($sku['skuAttributes']);
|
|
|
|
|
$sku_res = $VehicleNewSkusService->update($skuId,$sku);
|
|
|
|
|
if (!$sku_res) {
|
|
|
|
|
throw new BusinessException('提交失败5');
|
|
|
|
|
}
|
|
|
|
|
$skuAttributeIds = [];
|
|
|
|
|
foreach ($skuAttributes as $skuAttribute) {
|
|
|
|
|
if(!empty($skuAttribute['id'])){
|
|
|
|
|
$skuAttributeId = $skuAttribute['id'];
|
|
|
|
|
$skuAttributeIds[] =$skuAttributeId;
|
|
|
|
|
$skuAttribute['sku_id'] = $skuId;
|
|
|
|
|
$skuAttribute_res = $VehicleNewSkuAttributesService->update($skuAttributeId, $skuAttribute);
|
|
|
|
|
var_dump($skuAttribute_res);
|
|
|
|
|
if (!$skuAttribute_res) {
|
|
|
|
|
throw new BusinessException('提交失败4');
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
$skuAttribute['sku_id'] = $sku_res->id;
|
|
|
|
|
$skuAttribute_res = $VehicleNewSkuAttributesService->create($skuAttribute);
|
|
|
|
|
$skuAttributeIds[] =$skuAttribute_res->id;
|
|
|
|
|
if (!$skuAttribute_res) {
|
|
|
|
|
throw new BusinessException('提交失败3');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
VehicleNewSkuAttributesModel::whereNotIn('id', $skuAttributeIds)->where('sku_id',$skuId)->delete();
|
|
|
|
|
}else{
|
|
|
|
|
$sku['vehicle_id'] = $id;
|
|
|
|
|
$sku_code = sprintf("%05d", $id);
|
|
|
|
|
$sku['sku_code'] = rand(100,999).$sku_code[0].' '.substr($sku_code,1).' '.sprintf("%04d", $sku['skuAttributes'][0]['attribute_id']).' '.sprintf("%04d", $sku['skuAttributes'][0]['value_id']);
|
|
|
|
|
|
|
|
|
|
$skuAttributes = $sku['skuAttributes'];
|
|
|
|
|
unset($sku['skuAttributes']);
|
|
|
|
|
|
|
|
|
|
$sku_res = $VehicleNewSkusService->create($sku);
|
|
|
|
|
$skusId[] =$sku_res->id;
|
|
|
|
|
if (!$sku_res) {
|
|
|
|
|
throw new BusinessException('提交失败2');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// $skuAttributes = $sku['skuAttributes'];
|
|
|
|
|
foreach ($skuAttributes as $skuAttribute) {
|
|
|
|
|
$skuAttribute['sku_id'] = $sku_res->id;
|
|
|
|
|
$skuAttribute_res = $VehicleNewSkuAttributesService->create($skuAttribute);
|
|
|
|
|
if (!$skuAttribute_res) {
|
|
|
|
|
throw new BusinessException('提交失败1');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
VehicleNewSkusModel::whereNotIn('id', $skusId)->where('vehicle_id',$id)->delete();
|
|
|
|
|
}
|
2025-05-22 10:59:47 +08:00
|
|
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
Db::rollBack();
|
|
|
|
|
throw $th;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-22 09:26:19 +08:00
|
|
|
}
|