2025-05-14 13:19:23 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\applet\controller;
|
|
|
|
|
|
|
|
|
|
use support\Request;
|
|
|
|
|
use support\Response;
|
2025-05-14 17:30:37 +08:00
|
|
|
use app\applet\model\DraftsDataModel;
|
|
|
|
|
use app\applet\service\DraftsDataService;
|
2025-05-14 13:19:23 +08:00
|
|
|
use app\applet\validate\DraftsValidator;
|
|
|
|
|
use app\mzl\common\controller\BaseController;
|
|
|
|
|
|
2025-05-14 17:30:37 +08:00
|
|
|
class DraftsDataController extends BaseController
|
2025-05-14 13:19:23 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 不需要验证token的接口
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $noNeedJwt = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证器
|
|
|
|
|
*/
|
|
|
|
|
protected mixed $validator = DraftsValidator::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回业务 Service 实例
|
|
|
|
|
*/
|
|
|
|
|
protected function getService()
|
|
|
|
|
{
|
2025-05-14 17:30:37 +08:00
|
|
|
return new DraftsDataService(new DraftsDataModel());
|
2025-05-14 13:19:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 额外字段处理 (根据场景处理)
|
|
|
|
|
* @param array $item
|
|
|
|
|
* @param string $scene
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function postProcessItem(array $item, string $scene): array
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if ($scene === 'default') {
|
|
|
|
|
|
|
|
|
|
}
|
2025-05-15 13:25:17 +08:00
|
|
|
|
|
|
|
|
if ($scene === 'show') {
|
|
|
|
|
if ($item['cover']) {
|
|
|
|
|
$item['cover_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['cover']);
|
|
|
|
|
}
|
|
|
|
|
$arr = [];
|
|
|
|
|
if (isset($item['album'])) {
|
|
|
|
|
$albumFields = \app\console\model\DraftsAlbumModel::VEHICLE_ALBUM_FIELDS;
|
|
|
|
|
$arr = [];
|
|
|
|
|
foreach ($albumFields as $field) {
|
|
|
|
|
$arr[] = [
|
|
|
|
|
'field' => $field,
|
|
|
|
|
'name' => trans($field),
|
|
|
|
|
'value_full' => $item['album'][$field]
|
|
|
|
|
? (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['album'][$field])
|
|
|
|
|
: '',
|
|
|
|
|
'value' => $item['album'][$field]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
|
'id' => $item['id'],
|
|
|
|
|
'vin' => $item['vin'],
|
|
|
|
|
'user_nickname' => isset($item['user']) ? $item['user']['nickname'] : '',
|
|
|
|
|
'price' => $item['price'],
|
|
|
|
|
|
|
|
|
|
'brand_name' => is_array($item['brand']) ? $item['brand']['translation']['name'] : '',
|
|
|
|
|
'energy_name' => is_array($item['energy']) ? $item['energy']['translation']['name'] : '',
|
|
|
|
|
'type_name' => isset($item['types']) ? $item['types']['translation']['name'] : '',
|
|
|
|
|
'model_name' => isset($item['models']) ? $item['models']['translation']['name'] : '',
|
|
|
|
|
|
|
|
|
|
'mileage' => $item['mileage'],
|
|
|
|
|
'vehicle_age' => $item['vehicle_age'],
|
|
|
|
|
'views' => $item['views'],
|
|
|
|
|
'is_hot' => $item['is_hot'],
|
|
|
|
|
'store_status' => $item['store_status'],
|
|
|
|
|
'store_status_name' => trans(\app\apis\model\VehicleDataModel::STORE_STATUS_VALUE[$item['store_status']]),
|
|
|
|
|
'name' => isset($item['translation']) ? $item['translation']['name'] : '',
|
|
|
|
|
'condition_desc' => isset($item['translation']) ? $item['translation']['condition_desc'] : '',
|
|
|
|
|
'cover' => isset($item['cover']) ? $item['cover'] : '',
|
|
|
|
|
'cover_full' => isset($item['cover']) ? $item['cover_full'] : '',
|
|
|
|
|
'albums' => $arr,
|
|
|
|
|
'created_at' => date('Y-m-d H:i:s', $item['created_at']),
|
|
|
|
|
'updated_at' => date('Y-m-d H:i:s', $item['updated_at']),
|
|
|
|
|
|
|
|
|
|
'brand' => is_array($item['brand']) ? $item['brand']['translation']['brand_id'] : $item['brand'],
|
|
|
|
|
'energy' => is_array($item['energy']) ? $item['energy']['translation']['energy_id'] : $item['energy'],
|
|
|
|
|
'type' => isset($item['types']) ? $item['types']['translation']['type_id'] : $item['type'],
|
|
|
|
|
'model' => isset($item['models']) ? $item['models']['translation']['model_id'] : $item['model'],
|
|
|
|
|
'location_name' => $item['location'] ? $item['location']['translation']['name'] : '',
|
|
|
|
|
'location' => is_array($item['location']) ? $item['location']['translation']['location_id'] : $item['location'],
|
|
|
|
|
];
|
|
|
|
|
foreach ($arr as $album){
|
|
|
|
|
$result[$album['field']] = $album['value'];
|
|
|
|
|
$result[$album['field'].'_full'] = $album['value_full'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2025-05-14 13:19:23 +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') {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-05-14 17:30:37 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增草稿
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return Response
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function add(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$data = $this->injectAdd($request->all());
|
|
|
|
|
return $this->getService()->add($data)
|
|
|
|
|
? $this->successResponse()
|
|
|
|
|
: $this->errorResponse();
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
return $this->errorResponse($th->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function show(Request $request, int $id, string $scene = 'show'): Response
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-05-15 13:09:47 +08:00
|
|
|
$request->setGet('id', $id);
|
2025-05-14 17:30:37 +08:00
|
|
|
return parent::show($request, $id, $scene);
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
return $this->errorResponse($th->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function edit(Request $request, int $id): Response
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-05-15 13:09:47 +08:00
|
|
|
$request->setGet('id', $id);
|
2025-05-14 17:30:37 +08:00
|
|
|
return $this->getService()->edit($request->all(), $id)
|
|
|
|
|
? $this->successResponse()
|
|
|
|
|
: $this->errorResponse();
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
return $this->errorResponse($th->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-14 13:19:23 +08:00
|
|
|
}
|