上传
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace app\applet\service;
|
||||
|
||||
use app\applet\model\DraftsModel;
|
||||
use app\applet\model\DraftsDataModel;
|
||||
use app\applet\model\VehicleApplyModel;
|
||||
use app\applet\model\VehicleAlbumModel;
|
||||
use app\applet\model\VehicleDataModel;
|
||||
@@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use support\exception\BusinessException;
|
||||
use support\Db;
|
||||
use app\mzl\modules\translation\service\TranslationService;
|
||||
use support\Request;
|
||||
|
||||
class VehicleDataService extends BaseService
|
||||
{
|
||||
@@ -36,7 +37,7 @@ class VehicleDataService extends BaseService
|
||||
'filters' => $params['filters'],
|
||||
'fields' => [
|
||||
'id','vin','price','cover',
|
||||
'type','energy','model','mileage','vehicle_age',
|
||||
'type','energy','model','mileage','vehicle_age','info_status',
|
||||
'views','is_hot','created_at','updated_at', 'brand', 'model', 'user_id', 'location'
|
||||
],
|
||||
'relations' => [
|
||||
@@ -125,69 +126,69 @@ class VehicleDataService extends BaseService
|
||||
];
|
||||
|
||||
public function add(array $params)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$sourceFields = $this->extractSourceFields($params);
|
||||
if (empty($sourceFields)) {
|
||||
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||
};
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$sourceFields = $this->extractSourceFields($params);
|
||||
if (empty($sourceFields)) {
|
||||
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||
};
|
||||
|
||||
$albums = VehicleAlbumModel::VEHICLE_ALBUM_FIELDS;
|
||||
foreach ($params as $ko => $vo) {
|
||||
if (in_array($ko, $albums)) {
|
||||
$album[$ko] = $vo ?? '';
|
||||
$albums = VehicleAlbumModel::VEHICLE_ALBUM_FIELDS;
|
||||
foreach ($params as $ko => $vo) {
|
||||
if (in_array($ko, $albums)) {
|
||||
$album[$ko] = $vo ?? '';
|
||||
} else {
|
||||
if (in_array($ko, VehicleDataModel::TRANS_FIELDS)) {
|
||||
$trans[$ko] = $vo ?? '';
|
||||
} else {
|
||||
if (in_array($ko, VehicleDataModel::TRANS_FIELDS)) {
|
||||
$trans[$ko] = $vo ?? '';
|
||||
} else {
|
||||
$data[$ko] = $vo ?? '';
|
||||
}
|
||||
$data[$ko] = $vo ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$info = $this->create($data);
|
||||
if (!$info) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
// 异步翻译并写入 hs_vehicle_data_translation 表
|
||||
(new TranslationService())->queueTranslations(
|
||||
'vehicle',
|
||||
$info->id,
|
||||
$sourceLocale,
|
||||
$sourceFields
|
||||
);
|
||||
|
||||
$album['vehicle_data_id'] = $info->id;
|
||||
$albumModel = new VehicleAlbumModel();
|
||||
if (!$albumModel->create($album)) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
$applyModel = new VehicleApplyModel();
|
||||
if (!$applyModel->create([
|
||||
'vehicle_data_id' => $info->id,
|
||||
'desc' => '提交审核'
|
||||
])) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
if (isset($params['draft_id']) && $params['draft_id']) {
|
||||
if (!DraftsModel::where('id', $params['draft_id'])->delete()) {
|
||||
throw new BusinessException('草稿移除失败');
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollBack();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$info = $this->create($data);
|
||||
if (!$info) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
// 异步翻译并写入 hs_vehicle_data_translation 表
|
||||
(new TranslationService())->queueTranslations(
|
||||
'vehicle',
|
||||
$info->id,
|
||||
$sourceLocale,
|
||||
$sourceFields
|
||||
);
|
||||
|
||||
$album['vehicle_data_id'] = $info->id;
|
||||
$albumModel = new VehicleAlbumModel();
|
||||
if (!$albumModel->create($album)) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
$applyModel = new VehicleApplyModel();
|
||||
if (!$applyModel->create([
|
||||
'vehicle_data_id' => $info->id,
|
||||
'desc' => '提交审核'
|
||||
])) {
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
if (isset($params['draft_id']) && $params['draft_id']) {
|
||||
if (!DraftsDataModel::where('id', $params['draft_id'])->delete()) {
|
||||
throw new BusinessException('草稿移除失败');
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollBack();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
public function edit(array $params, int $id)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
@@ -247,7 +248,7 @@ class VehicleDataService extends BaseService
|
||||
}
|
||||
|
||||
if (isset($params['draft_id']) && $params['draft_id']) {
|
||||
if (!DraftsModel::where('id', $params['draft_id'])->delete()) {
|
||||
if (!DraftsDataModel::where('id', $params['draft_id'])->delete()) {
|
||||
throw new BusinessException('草稿移除失败');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user