1
This commit is contained in:
@@ -68,7 +68,8 @@ class VehicleNewSkusController extends BaseController
|
||||
$params = parent::prepareParams($request, $scene);
|
||||
|
||||
if ($scene === 'default') {
|
||||
|
||||
$params['filters'] = [];
|
||||
$params['filters'][] = ['id' => 'brand', 'operator' => '=', 'value' => $params['id']];
|
||||
}
|
||||
|
||||
return $params;
|
||||
@@ -83,8 +84,9 @@ class VehicleNewSkusController extends BaseController
|
||||
public function index(Request $request, string $scene = 'default'): Response
|
||||
{
|
||||
try {
|
||||
// $res = VehicleNewSkusModel::with('skuAttributes')->find(9);
|
||||
// return $this->successResponse($res);
|
||||
if(empty($request->get('id'))){
|
||||
return $this->errorResponse('id is not null');
|
||||
}
|
||||
return parent::index($request, $scene);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->errorResponse($th->getMessage());
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\console\model\VehicleNewSkusTranslationModel;
|
||||
use app\console\service\VehicleNewSkusTranslationService;
|
||||
use app\console\validate\VehicleNewSkusTranslationValidator;
|
||||
use app\mzl\common\controller\BaseController;
|
||||
|
||||
class VehicleNewSkusTranslationController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要验证token的接口
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedJwt = [];
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected mixed $validator = VehicleNewSkusTranslationValidator::class;
|
||||
|
||||
/**
|
||||
* 返回业务 Service 实例
|
||||
*/
|
||||
protected function getService()
|
||||
{
|
||||
return new VehicleNewSkusTranslationService(new VehicleNewSkusTranslationModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外字段处理 (根据场景处理)
|
||||
* @param array $item
|
||||
* @param string $scene
|
||||
* @return array
|
||||
*/
|
||||
protected function postProcessItem(array $item, string $scene): array
|
||||
{
|
||||
|
||||
if ($scene === 'default') {
|
||||
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数预处理 (根据场景处理)
|
||||
* @param Request $request
|
||||
* @param string $scene
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareParams(Request $request, string $scene): array
|
||||
{
|
||||
$params = parent::prepareParams($request, $scene);
|
||||
|
||||
if ($scene === 'default') {
|
||||
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return Response 响应对象
|
||||
*/
|
||||
public function index(Request $request, string $scene = 'default'): Response
|
||||
{
|
||||
try {
|
||||
return parent::index($request, $scene);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->errorResponse($th->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* VehicleNewSkusTranslationModel
|
||||
*/
|
||||
class VehicleNewSkusTranslationModel extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'hs_vehicle_new_skus_translation';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* 模型的数据字段的保存格式。
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'sku_id', 'locale', 'name', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -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,
|
||||
// ]
|
||||
// ];
|
||||
// }
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\console\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class VehicleNewSkusTranslationValidator extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -79,6 +79,10 @@ return [
|
||||
'translation_model' => \app\console\model\VehicleNewAttributeCategoriesTranslationModel::class,
|
||||
'foreign_key' => 'categories_id',
|
||||
],
|
||||
'vehicleNewSku' => [
|
||||
'translation_model' => \app\console\model\VehicleNewSkusTranslationModel::class,
|
||||
'foreign_key' => 'sku_id',
|
||||
],
|
||||
],
|
||||
|
||||
// 默认支持的目标语种列表
|
||||
|
||||
Reference in New Issue
Block a user