Files
usedcar/app/console/controller/VehicleNewSkuAttributesController.php
T

87 lines
2.4 KiB
PHP
Raw Normal View History

2025-06-17 15:54:24 +08:00
<?php
namespace app\console\controller;
use app\console\model\VehicleNewAttributesTranslationModel;
use app\console\model\VehicleNewAttributeValuesTranslationModel;
use support\Request;
use support\Response;
use app\console\model\VehicleNewSkuAttributesModel;
use app\console\service\VehicleNewSkuAttributesService;
use app\console\validate\VehicleNewSkuAttributesValidator;
use app\mzl\common\controller\BaseController;
class VehicleNewSkuAttributesController extends BaseController
{
/**
* 不需要验证token的接口
* @var array
*/
protected $noNeedJwt = [];
/**
* 验证器
*/
protected mixed $validator = VehicleNewSkuAttributesValidator::class;
/**
* 返回业务 Service 实例
*/
protected function getService()
{
return new VehicleNewSkuAttributesService(new VehicleNewSkuAttributesModel());
}
/**
* 额外字段处理 (根据场景处理)
* @param array $item
* @param string $scene
* @return array
*/
protected function postProcessItem(array $item, string $scene): array
{
if ($scene === 'default' || $scene === 'show') {
$attribute = VehicleNewAttributesTranslationModel::where(['attributes_id' => $item['attribute']['id'],'locale'=>locale()])->first();
$value = VehicleNewAttributeValuesTranslationModel::where(['values_id' => $item['value']['id'],'locale'=>locale()])->first();
$item['attribute']['attribute_name'] = $attribute['attribute_name'] ;
$item['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().$th->getLine().$th->getFile());
}
}
}