101 lines
2.5 KiB
PHP
101 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace app\console\controller;
|
|
|
|
use support\Request;
|
|
use support\Response;
|
|
use app\console\model\VehicleApplyModel;
|
|
use app\console\service\VehicleApplyService;
|
|
use app\console\validate\VehicleApplyValidator;
|
|
use app\mzl\common\controller\BaseController;
|
|
|
|
class VehicleApplyController extends BaseController
|
|
{
|
|
|
|
/**
|
|
* 不需要验证token的接口
|
|
* @var array
|
|
*/
|
|
protected $noNeedJwt = [];
|
|
|
|
/**
|
|
* 验证器
|
|
*/
|
|
protected mixed $validator = VehicleApplyValidator::class;
|
|
|
|
/**
|
|
* 返回业务 Service 实例
|
|
*/
|
|
protected function getService()
|
|
{
|
|
return new VehicleApplyService(new VehicleApplyModel());
|
|
}
|
|
|
|
/**
|
|
* 额外字段处理 (根据场景处理)
|
|
* @param array $item
|
|
* @param string $scene
|
|
* @return array
|
|
*/
|
|
protected function postProcessItem(array $item, string $scene): array
|
|
{
|
|
|
|
if ($scene === 'default') {
|
|
return [
|
|
'id' => $item['id'],
|
|
'vehicle_data_id' => $item['vehicle_data_id'],
|
|
'apply_status' => $item['apply_status'],
|
|
'desc' => $item['desc'],
|
|
'name' => $item['vehicleDataInfo'] ? $item['vehicleDataInfo']['translation']['name'] : '',
|
|
'created_at' => date('Y-m-d H:i:s', $item['created_at']),
|
|
'updated_at' => date('Y-m-d H:i:s', $item['updated_at'])
|
|
];
|
|
}
|
|
|
|
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 doApply(Request $request, int $id): Response
|
|
{
|
|
try {
|
|
return $this->getService()->doApply($request->all(), $id)
|
|
? $this->successResponse()
|
|
: $this->errorResponse();
|
|
} catch (\Throwable $th) {
|
|
return $this->errorResponse($th->getMessage());
|
|
}
|
|
}
|
|
} |