diff --git a/app/console/controller/VehicleNewSkusController.php b/app/console/controller/VehicleNewSkusController.php index 962aa43..5067b6a 100644 --- a/app/console/controller/VehicleNewSkusController.php +++ b/app/console/controller/VehicleNewSkusController.php @@ -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()); diff --git a/app/console/controller/VehicleNewSkusTranslationController.php b/app/console/controller/VehicleNewSkusTranslationController.php new file mode 100644 index 0000000..768de08 --- /dev/null +++ b/app/console/controller/VehicleNewSkusTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/console/model/VehicleNewSkusTranslationModel.php b/app/console/model/VehicleNewSkusTranslationModel.php new file mode 100644 index 0000000..443dd37 --- /dev/null +++ b/app/console/model/VehicleNewSkusTranslationModel.php @@ -0,0 +1,56 @@ +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 = []; diff --git a/app/console/service/VehicleNewSkusTranslationService.php b/app/console/service/VehicleNewSkusTranslationService.php new file mode 100644 index 0000000..433b883 --- /dev/null +++ b/app/console/service/VehicleNewSkusTranslationService.php @@ -0,0 +1,59 @@ + 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, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/console/validate/VehicleNewSkusTranslationValidator.php b/app/console/validate/VehicleNewSkusTranslationValidator.php new file mode 100644 index 0000000..55689a6 --- /dev/null +++ b/app/console/validate/VehicleNewSkusTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/mzl/modules/translation/config/trans.php b/app/mzl/modules/translation/config/trans.php index 202fc91..b191d15 100644 --- a/app/mzl/modules/translation/config/trans.php +++ b/app/mzl/modules/translation/config/trans.php @@ -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', + ], ], // 默认支持的目标语种列表