diff --git a/app/apis/controller/VehicleNewAttributeValuesController.php b/app/apis/controller/VehicleNewAttributeValuesController.php new file mode 100644 index 0000000..7fd1a66 --- /dev/null +++ b/app/apis/controller/VehicleNewAttributeValuesController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewAttributeValuesTranslationController.php b/app/apis/controller/VehicleNewAttributeValuesTranslationController.php new file mode 100644 index 0000000..eb9f54e --- /dev/null +++ b/app/apis/controller/VehicleNewAttributeValuesTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewAttributesController.php b/app/apis/controller/VehicleNewAttributesController.php new file mode 100644 index 0000000..8268a37 --- /dev/null +++ b/app/apis/controller/VehicleNewAttributesController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewAttributesTranslationController.php b/app/apis/controller/VehicleNewAttributesTranslationController.php new file mode 100644 index 0000000..640ec56 --- /dev/null +++ b/app/apis/controller/VehicleNewAttributesTranslationController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewController.php b/app/apis/controller/VehicleNewController.php index b28b832..ab2034a 100644 --- a/app/apis/controller/VehicleNewController.php +++ b/app/apis/controller/VehicleNewController.php @@ -2,6 +2,8 @@ namespace app\apis\controller; +use app\apis\model\VehicleNewAttributesTranslationModel; +use app\apis\model\VehicleNewAttributeValuesTranslationModel; use support\Request; use support\Response; use app\apis\model\VehicleNewModel; @@ -104,6 +106,16 @@ class VehicleNewController extends BaseController $contentRes['content'] = isset($content['translation']) ? $content['translation']['content']:''; $result['content'][] = $contentRes; } + foreach ($item['sku'] as &$sku) { + foreach ($sku['skuAttributes'] as &$skuAttribute){ + $attribute = VehicleNewAttributesTranslationModel::where(['attributes_id' => $skuAttribute['attribute']['id'],'locale'=>locale()])->first(); + $value = VehicleNewAttributeValuesTranslationModel::where(['values_id' => $skuAttribute['value']['id'],'locale'=>locale()])->first(); + + $skuAttribute['attribute']['attribute_name'] = $attribute['attribute_name'] ; + $skuAttribute['value']['value_name'] = $value['value_name']; + } + $result['sku'][] = $sku; + } return $result; } diff --git a/app/apis/controller/VehicleNewSkuAttributesController.php b/app/apis/controller/VehicleNewSkuAttributesController.php new file mode 100644 index 0000000..13b09a2 --- /dev/null +++ b/app/apis/controller/VehicleNewSkuAttributesController.php @@ -0,0 +1,81 @@ +errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/controller/VehicleNewSkusController.php b/app/apis/controller/VehicleNewSkusController.php new file mode 100644 index 0000000..61f6d23 --- /dev/null +++ b/app/apis/controller/VehicleNewSkusController.php @@ -0,0 +1,98 @@ + $skuAttribute['attribute']['id'],'locale'=>locale()])->first(); + $value = VehicleNewAttributeValuesTranslationModel::where(['values_id' => $skuAttribute['value']['id'],'locale'=>locale()])->first(); + + $skuAttribute['attribute']['attribute_name'] = $attribute['attribute_name'] ; + $skuAttribute['value']['value_name'] = $value['value_name']; + } + } + + 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()); + } + } + + public function detail(Request $request, int $id, string $scene = 'show'): Response + { + try { + $request->setGet(['id'=>$id]); + return parent::one($request, $scene); + } catch (\Throwable $th) { + return $this->errorResponse($th->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewAttributeValuesModel.php b/app/apis/model/VehicleNewAttributeValuesModel.php new file mode 100644 index 0000000..972b646 --- /dev/null +++ b/app/apis/model/VehicleNewAttributeValuesModel.php @@ -0,0 +1,72 @@ +hasOne(VehicleNewAttributeValuesTranslationModel::class, 'values_id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewAttributeValuesTranslationModel::class, 'values_id'); + } +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewAttributeValuesTranslationModel.php b/app/apis/model/VehicleNewAttributeValuesTranslationModel.php new file mode 100644 index 0000000..47d2b02 --- /dev/null +++ b/app/apis/model/VehicleNewAttributeValuesTranslationModel.php @@ -0,0 +1,56 @@ +hasOne(VehicleNewAttributesTranslationModel::class, 'attributes_id','id')->where('locale', locale()); + } + + /** + * 多条翻译 + */ + public function translations() + { + return $this->hasMany(VehicleNewAttributesTranslationModel::class, 'attributes_id'); + } + + public function value() + { + return $this->hasMany(VehicleNewAttributeValuesModel::class, 'attribute_id', 'id'); + } +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewAttributesTranslationModel.php b/app/apis/model/VehicleNewAttributesTranslationModel.php new file mode 100644 index 0000000..2cdc0e2 --- /dev/null +++ b/app/apis/model/VehicleNewAttributesTranslationModel.php @@ -0,0 +1,56 @@ +hasMany(VehicleNewContentModel::class, 'vehicle_id', 'id'); } + + public function sku() + { + return $this->hasMany(VehicleNewSkusModel::class, 'vehicle_id', 'id'); + } } \ No newline at end of file diff --git a/app/apis/model/VehicleNewSkuAttributesModel.php b/app/apis/model/VehicleNewSkuAttributesModel.php new file mode 100644 index 0000000..29be361 --- /dev/null +++ b/app/apis/model/VehicleNewSkuAttributesModel.php @@ -0,0 +1,71 @@ +belongsTo(VehicleNewAttributesModel::class, 'attribute_id', 'id'); + } + + public function value() + { + return $this->belongsTo(VehicleNewAttributeValuesModel::class, 'value_id', 'id'); + } + + public function skuAttributes() + { + return $this->belongsTo(VehicleNewSkusModel::class, 'sku_id', 'id'); + } +} \ No newline at end of file diff --git a/app/apis/model/VehicleNewSkusModel.php b/app/apis/model/VehicleNewSkusModel.php new file mode 100644 index 0000000..f9c8fd9 --- /dev/null +++ b/app/apis/model/VehicleNewSkusModel.php @@ -0,0 +1,62 @@ +hasMany(VehicleNewSkuAttributesModel::class, 'sku_id', 'id'); + } +} \ No newline at end of file diff --git a/app/apis/service/VehicleNewAttributeValuesService.php b/app/apis/service/VehicleNewAttributeValuesService.php new file mode 100644 index 0000000..89bb2a3 --- /dev/null +++ b/app/apis/service/VehicleNewAttributeValuesService.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/service/VehicleNewAttributeValuesTranslationService.php b/app/apis/service/VehicleNewAttributeValuesTranslationService.php new file mode 100644 index 0000000..419f79b --- /dev/null +++ b/app/apis/service/VehicleNewAttributeValuesTranslationService.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/service/VehicleNewAttributesService.php b/app/apis/service/VehicleNewAttributesService.php new file mode 100644 index 0000000..2be59a4 --- /dev/null +++ b/app/apis/service/VehicleNewAttributesService.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/service/VehicleNewAttributesTranslationService.php b/app/apis/service/VehicleNewAttributesTranslationService.php new file mode 100644 index 0000000..606e203 --- /dev/null +++ b/app/apis/service/VehicleNewAttributesTranslationService.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/service/VehicleNewService.php b/app/apis/service/VehicleNewService.php index c444c01..064c37b 100644 --- a/app/apis/service/VehicleNewService.php +++ b/app/apis/service/VehicleNewService.php @@ -78,6 +78,10 @@ class VehicleNewService extends BaseService 'types.translation' => ['type_id', 'name'], 'energy.translation' => ['energy_id', 'name'], 'models.translation' => ['model_id', 'name'], + 'sku' => [], + 'sku.skuAttributes' => [], + 'sku.skuAttributes.attribute' => ['id', 'input_type', 'is_img', 'status'], + 'sku.skuAttributes.value' => ['id','color_code'], ], 'sorts' => [ ['field' => 'id', 'direction' => 'desc'] diff --git a/app/apis/service/VehicleNewSkuAttributesService.php b/app/apis/service/VehicleNewSkuAttributesService.php new file mode 100644 index 0000000..f02cfe0 --- /dev/null +++ b/app/apis/service/VehicleNewSkuAttributesService.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/service/VehicleNewSkusService.php b/app/apis/service/VehicleNewSkusService.php new file mode 100644 index 0000000..74844a2 --- /dev/null +++ b/app/apis/service/VehicleNewSkusService.php @@ -0,0 +1,93 @@ + function ($params) { + return [ + 'filters' => [ + ['field' => 'status', 'operator' => '=', 'value' => '1'], + ], + 'fields' => ['id','status'], + 'relations' => [ + 'skuAttributes' => [], + 'skuAttributes.attribute' => ['id', 'input_type', 'is_img', 'status'], + 'skuAttributes.value' => ['id','color_code'], + ], + 'sorts' => [ + ['field' => 'created_at', 'direction' => 'desc'] + ], + 'pagination' => [ + 'page' => $params['page'] ?? 1, + 'per_page' => $params['per_page'] ?? 10, + ] + ]; + }, + 'show' => function ($params) { + return [ + 'filters' => [ + ['field'=>'id', 'operator'=>'=', 'value'=> $params['id']], + ], + 'fields' => ['id', 'status'], + 'relations' => [ + 'skuAttributes' => [], + 'skuAttributes.attribute' => ['id', 'input_type', 'is_img', 'status'], + 'skuAttributes.attribute.translation' => ['attribute_name'], + 'skuAttributes.value' => ['id','color_code'], + ], + ]; + }, + // '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, + // ] + // ]; + // } + ]; + } +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewAttributeValuesTranslationValidator.php b/app/apis/validate/VehicleNewAttributeValuesTranslationValidator.php new file mode 100644 index 0000000..331fd33 --- /dev/null +++ b/app/apis/validate/VehicleNewAttributeValuesTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewAttributeValuesValidator.php b/app/apis/validate/VehicleNewAttributeValuesValidator.php new file mode 100644 index 0000000..8906427 --- /dev/null +++ b/app/apis/validate/VehicleNewAttributeValuesValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewAttributesTranslationValidator.php b/app/apis/validate/VehicleNewAttributesTranslationValidator.php new file mode 100644 index 0000000..93d20c1 --- /dev/null +++ b/app/apis/validate/VehicleNewAttributesTranslationValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewAttributesValidator.php b/app/apis/validate/VehicleNewAttributesValidator.php new file mode 100644 index 0000000..65f4fff --- /dev/null +++ b/app/apis/validate/VehicleNewAttributesValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewSkuAttributesValidator.php b/app/apis/validate/VehicleNewSkuAttributesValidator.php new file mode 100644 index 0000000..176a45a --- /dev/null +++ b/app/apis/validate/VehicleNewSkuAttributesValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/apis/validate/VehicleNewSkusValidator.php b/app/apis/validate/VehicleNewSkusValidator.php new file mode 100644 index 0000000..b139ffb --- /dev/null +++ b/app/apis/validate/VehicleNewSkusValidator.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/config/route.php b/config/route.php index 45b0d0f..59857dd 100644 --- a/config/route.php +++ b/config/route.php @@ -49,6 +49,9 @@ Route::group('/apis', function() { // 新车管理 Route::any('/vehicle/new/list', [\app\apis\controller\VehicleNewController::class, 'index']); Route::any('/vehicle/new/{id}/detail', [\app\apis\controller\VehicleNewController::class, 'detail']); + //新车属性 + Route::any('/vehicle/new/sku/{id}/detail', [\app\apis\controller\VehicleNewSkusController::class, 'detail']); + Route::any('/vehicle/new/sku/list', [\app\apis\controller\VehicleNewSkusController::class, 'index']); // 能源列表 Route::any('/energy/preset', [\app\console\controller\EnergyController::class, 'presets']); });