diff --git a/app/apis/controller/VehicleNewController.php b/app/apis/controller/VehicleNewController.php index ebe8db1..503fa32 100644 --- a/app/apis/controller/VehicleNewController.php +++ b/app/apis/controller/VehicleNewController.php @@ -126,6 +126,8 @@ class VehicleNewController extends BaseController $sku['skuAttributes'][$key]['img_full'] = (!empty($skuAttribute['img']))?(new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($skuAttribute['img']):''; } + $sku['name'] = isset($sku['translation']) ? $sku['translation']['name']:''; + unset($sku['translation']); $result['sku'][] = $sku; } return $result; diff --git a/app/apis/controller/VehicleNewSkusTranslationController.php b/app/apis/controller/VehicleNewSkusTranslationController.php new file mode 100644 index 0000000..8bbf49f --- /dev/null +++ b/app/apis/controller/VehicleNewSkusTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewSkusModel.php b/app/apis/model/VehicleNewSkusModel.php index f9c8fd9..aad5c13 100644 --- a/app/apis/model/VehicleNewSkusModel.php +++ b/app/apis/model/VehicleNewSkusModel.php @@ -59,4 +59,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/apis/model/VehicleNewSkusTranslationModel.php b/app/apis/model/VehicleNewSkusTranslationModel.php new file mode 100644 index 0000000..3d04c5d --- /dev/null +++ b/app/apis/model/VehicleNewSkusTranslationModel.php @@ -0,0 +1,56 @@ + ['id','sku_id','attribute_id','value_id','img',], 'sku.skuAttributes.attribute' => ['id', 'input_type', 'is_img', 'status'], 'sku.skuAttributes.value' => ['id','color_code'], + 'sku.translation' => ['sku_id', 'name', 'locale'], ], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] diff --git a/app/apis/service/VehicleNewSkusTranslationService.php b/app/apis/service/VehicleNewSkusTranslationService.php new file mode 100644 index 0000000..01f2327 --- /dev/null +++ b/app/apis/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/apis/validate/VehicleNewSkusTranslationValidator.php b/app/apis/validate/VehicleNewSkusTranslationValidator.php new file mode 100644 index 0000000..b8a8613 --- /dev/null +++ b/app/apis/validate/VehicleNewSkusTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/console/service/VehicleNewSkusService.php b/app/console/service/VehicleNewSkusService.php index 5ba40e2..2ee9fcb 100644 --- a/app/console/service/VehicleNewSkusService.php +++ b/app/console/service/VehicleNewSkusService.php @@ -166,7 +166,7 @@ class VehicleNewSkusService extends BaseService $skuAttributesId[] = $skuAttributeId; } } - VehicleNewSkuAttributesModel::whereNotIn('id', $skuAttributesId)->where('attribute_id',$id)->delete(); + VehicleNewSkuAttributesModel::whereNotIn('id', $skuAttributesId)->where('sku_id',$id)->delete(); Db::commit();