diff --git a/app/console/controller/VehicleNewAttributesController.php b/app/console/controller/VehicleNewAttributesController.php index d99ec14..639e4d6 100644 --- a/app/console/controller/VehicleNewAttributesController.php +++ b/app/console/controller/VehicleNewAttributesController.php @@ -55,6 +55,12 @@ class VehicleNewAttributesController extends BaseController } return $result; } + if ($scene === 'preset') { + return [ + 'id' => $item['id'], + 'attribute_name' => isset($item['translation']) ? $item['translation']['attribute_name'] : '', + ]; + } return $item; } @@ -102,6 +108,15 @@ class VehicleNewAttributesController extends BaseController } } + public function presets(Request $request, string $scene = 'preset'): Response + { + try { + return parent::all($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage().$th->getLine().$th->getFile()); + } + } + public function edit(Request $request, int $id): Response { try { diff --git a/app/console/service/VehicleNewAttributesService.php b/app/console/service/VehicleNewAttributesService.php index 9f1a14d..d1c2875 100644 --- a/app/console/service/VehicleNewAttributesService.php +++ b/app/console/service/VehicleNewAttributesService.php @@ -48,6 +48,21 @@ class VehicleNewAttributesService extends BaseService ] ]; }, + 'preset' => function ($params) { + return [ + 'filters' => [ + ], + 'fields' => ['id','status'], + 'relations' => [ + 'translation' => ['attributes_id', 'locale', 'attribute_name'], + 'value' => ['id', 'attribute_id', 'sort_order'], + 'value.translation' => ['id', 'values_id', 'locale', 'value_name'], + ], + 'sorts' => [ + ['field' => 'created_at', 'direction' => 'desc'] + ], + ]; + }, 'show' => function ($params) { return [ 'filters' => [ diff --git a/config/route.php b/config/route.php index 174b500..dc6bd31 100644 --- a/config/route.php +++ b/config/route.php @@ -194,6 +194,7 @@ Route::group('/console', function() { //新车属性 Route::any('/vehicle/new/attributes/list', [\app\console\controller\VehicleNewAttributesController::class, 'index']); + Route::any('/vehicle/new/attributes/preset', [\app\console\controller\VehicleNewAttributesController::class, 'presets']); Route::any('/vehicle/new/attributes/add', [\app\console\controller\VehicleNewAttributesController::class, 'add']); Route::any('/vehicle/new/attributes/{id}/update', [\app\console\controller\VehicleNewAttributesController::class, 'edit']); Route::any('/vehicle/new/attributes/{id}/delete', [\app\console\controller\VehicleNewAttributesController::class, 'destroy']);