2025-06-17 15:54:24 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\console\controller;
|
|
|
|
|
|
2025-06-18 16:36:03 +08:00
|
|
|
use app\console\model\VehicleNewAttributeValuesTranslationModel;
|
2025-06-17 15:54:24 +08:00
|
|
|
use support\Request;
|
|
|
|
|
use support\Response;
|
|
|
|
|
use app\console\model\VehicleNewAttributeValuesModel;
|
|
|
|
|
use app\console\service\VehicleNewAttributeValuesService;
|
|
|
|
|
use app\console\validate\VehicleNewAttributeValuesValidator;
|
|
|
|
|
use app\mzl\common\controller\BaseController;
|
|
|
|
|
|
|
|
|
|
class VehicleNewAttributeValuesController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 不需要验证token的接口
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $noNeedJwt = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证器
|
|
|
|
|
*/
|
|
|
|
|
protected mixed $validator = VehicleNewAttributeValuesValidator::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回业务 Service 实例
|
|
|
|
|
*/
|
|
|
|
|
protected function getService()
|
|
|
|
|
{
|
|
|
|
|
return new VehicleNewAttributeValuesService(new VehicleNewAttributeValuesModel());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 额外字段处理 (根据场景处理)
|
|
|
|
|
* @param array $item
|
|
|
|
|
* @param string $scene
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function postProcessItem(array $item, string $scene): array
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if ($scene === 'default') {
|
|
|
|
|
|
|
|
|
|
}
|
2025-06-18 16:36:03 +08:00
|
|
|
|
|
|
|
|
if ($scene === 'preset') {
|
|
|
|
|
$result = [
|
|
|
|
|
'id' => $item['id'],
|
|
|
|
|
'color_code' => $item['color_code'],
|
|
|
|
|
// 'value_name' => isset($item['translation']) ? $item['translation']['value_name'] : '1',
|
|
|
|
|
];
|
|
|
|
|
$translation = VehicleNewAttributeValuesTranslationModel::where(['values_id' => $item['id'],'locale'=>locale()])->first();
|
|
|
|
|
$result['value_name'] = $translation->value_name;
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2025-06-17 15:54:24 +08:00
|
|
|
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') {
|
2025-06-18 16:36:03 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if ($scene === 'preset') {
|
|
|
|
|
$params['filters'][] = ['field' => 'attribute_id', 'operator' => '=', 'value' => $params['id']];
|
2025-06-17 15:54:24 +08:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-18 16:36:03 +08:00
|
|
|
|
|
|
|
|
public function presets(Request $request, string $scene = 'preset'): Response
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return parent::all($request, $scene);
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
return $this->errorResponse($th->getMessage().$th->getFile().$th->getLine());
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-17 15:54:24 +08:00
|
|
|
}
|