1
This commit is contained in:
@@ -68,15 +68,19 @@ class VehicleNewSkusService extends BaseService
|
||||
];
|
||||
}
|
||||
|
||||
// 声明需要多语言翻译
|
||||
protected array $translatable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function add(array $params)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
// $sourceFields = $this->extractSourceFields($params);
|
||||
//
|
||||
// if (empty($sourceFields)) {
|
||||
// throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||
// };
|
||||
$sourceFields = $this->extractSourceFields($params);
|
||||
|
||||
if (empty($sourceFields)) {
|
||||
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||
};
|
||||
|
||||
$skuAttributes = $params['skuAttributes'];
|
||||
unset($params['skuAttributes']);
|
||||
@@ -91,13 +95,13 @@ class VehicleNewSkusService extends BaseService
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
// 异步翻译并写入 hs_vehicle_data_translation 表
|
||||
// (new TranslationService())->queueTranslations(
|
||||
// 'vehicleNewAttributes',
|
||||
// $info->id,
|
||||
// $sourceLocale,
|
||||
// $sourceFields
|
||||
// );
|
||||
// 异步翻译并写入 hs_vehicle_new_skus_translation 表
|
||||
(new TranslationService())->queueTranslations(
|
||||
'vehicleNewSku',
|
||||
$info->id,
|
||||
$sourceLocale,
|
||||
$sourceFields
|
||||
);
|
||||
|
||||
foreach ($skuAttributes as $skuAttribute) {
|
||||
$skuAttribute['sku_id'] = $info->id;
|
||||
@@ -118,11 +122,11 @@ class VehicleNewSkusService extends BaseService
|
||||
public function edit(array $params, int $id)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
// $sourceFields = $this->extractSourceFields($params);
|
||||
//
|
||||
// if (empty($sourceFields)) {
|
||||
// throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||
// };
|
||||
$sourceFields = $this->extractSourceFields($params);
|
||||
|
||||
if (empty($sourceFields)) {
|
||||
throw new \InvalidArgumentException("请传递至少一条 {$sourceLocale} 语言的翻译字段");
|
||||
};
|
||||
|
||||
$skuAttributes = $params['skuAttributes'];
|
||||
unset($params['skuAttributes']);
|
||||
@@ -134,13 +138,13 @@ class VehicleNewSkusService extends BaseService
|
||||
throw new BusinessException('提交失败');
|
||||
}
|
||||
|
||||
// 异步翻译并写入 hs_vehicle_data_translation 表
|
||||
// (new TranslationService())->queueTranslations(
|
||||
// 'vehicleNewAttributes',
|
||||
// $id,
|
||||
// $sourceLocale,
|
||||
// $sourceFields
|
||||
// );
|
||||
//异步翻译并写入 hs_vehicle_new_skus_translation 表
|
||||
(new TranslationService())->queueTranslations(
|
||||
'vehicleNewSku',
|
||||
$id,
|
||||
$sourceLocale,
|
||||
$sourceFields
|
||||
);
|
||||
|
||||
|
||||
$skuAttributesId = [];
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\console\model\VehicleNewSkusTranslationModel;
|
||||
use app\mzl\common\services\BaseService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VehicleNewSkusTranslationService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 定义模型
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return VehicleNewSkusTranslationModel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多场景配置
|
||||
*/
|
||||
public function queryScenes(): array
|
||||
{
|
||||
return [
|
||||
// 'default' => function ($params) {
|
||||
// $keyword = $params['keyword'] ?? '';
|
||||
// return [
|
||||
// 'filters' => [
|
||||
// ['field' => '***', 'operator' => '=', 'value' => '***']
|
||||
// ],
|
||||
// 'fields' => ['id'],
|
||||
// 'relations' => [],
|
||||
// 'custom' => function(Builder $q) use ($keyword) {
|
||||
// // 示例
|
||||
// if ($keyword) {
|
||||
// $q->where(function($q2) use($keyword) {
|
||||
// $q2->whereHas('***', function($q3) use($keyword) {
|
||||
// $q3->where('***', 'like', "%{$keyword}%");
|
||||
// })->orWhereHas('***', function($q4) use($keyword) {
|
||||
// $q4->where('***', 'like', "%{$keyword}%");
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
// 'sorts' => [
|
||||
// ['field' => 'created_at', 'direction' => 'desc']
|
||||
// ],
|
||||
// 'pagination' => [
|
||||
// 'page' => $params['page'] ?? 1,
|
||||
// 'per_page' => $params['per_page'] ?? 10,
|
||||
// ]
|
||||
// ];
|
||||
// }
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user