From 7dff3c5e3ba2897ebbcd1e1249bacdd414ce1b86 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Fri, 20 Jun 2025 11:48:37 +0800 Subject: [PATCH] 1 --- .../controller/VehicleNewSkusController.php | 3 ++- app/console/model/VehicleNewSkusModel.php | 16 ++++++++++++++++ app/console/service/VehicleNewSkusService.php | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/console/controller/VehicleNewSkusController.php b/app/console/controller/VehicleNewSkusController.php index 4ce3b1d..330cfc0 100644 --- a/app/console/controller/VehicleNewSkusController.php +++ b/app/console/controller/VehicleNewSkusController.php @@ -51,7 +51,8 @@ class VehicleNewSkusController extends BaseController $skuAttribute['attribute']['attribute_name'] = $attribute['attribute_name'] ; $skuAttribute['value']['value_name'] = $value['value_name']; } - + $item['name'] = isset($item['translation']) ? $item['translation']['name'] : ''; + unset($item['translation']); } return $item; diff --git a/app/console/model/VehicleNewSkusModel.php b/app/console/model/VehicleNewSkusModel.php index a9c71f8..4980cc0 100644 --- a/app/console/model/VehicleNewSkusModel.php +++ b/app/console/model/VehicleNewSkusModel.php @@ -58,4 +58,20 @@ class VehicleNewSkusModel extends Model { return $this->hasMany(VehicleNewSkuAttributesModel::class, 'sku_id', 'id'); } + + /** + * 单条翻译 + */ + public function translation() + { + return $this->hasOne(VehicleNewSkusTranslationModel::class, 'sku_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewSkusTranslationModel::class, 'sku_id'); + } } \ No newline at end of file diff --git a/app/console/service/VehicleNewSkusService.php b/app/console/service/VehicleNewSkusService.php index 81429f9..f1992d3 100644 --- a/app/console/service/VehicleNewSkusService.php +++ b/app/console/service/VehicleNewSkusService.php @@ -35,9 +35,9 @@ class VehicleNewSkusService extends BaseService 'filters' => $params['filters'], 'fields' => ['id','vehicle_id','status'], 'relations' => [ + 'translation' => ['sku_id', 'name', 'locale'], 'skuAttributes' => [], 'skuAttributes.attribute' => ['id', 'input_type', 'is_img', 'status'], -// 'skuAttributes.attribute.translation' => ['attribute_name'], 'skuAttributes.value' => ['id','color_code'], ], 'sorts' => [ @@ -58,8 +58,8 @@ class VehicleNewSkusService extends BaseService 'relations' => [ 'skuAttributes' => [], 'skuAttributes.attribute' => ['id', 'input_type', 'is_img', 'status'], -// 'skuAttributes.attribute.translation' => ['attribute_name'], 'skuAttributes.value' => ['id','color_code'], + 'translation' => ['sku_id', 'name', 'locale'], ], ]; },