80 lines
2.3 KiB
PHP
80 lines
2.3 KiB
PHP
<?php
|
|
namespace app\common\controller;
|
|
|
|
use app\common\controller\BaseController;
|
|
use app\common\service\OssService;
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
use app\common\service\UsedCarService;
|
|
use support\Request;
|
|
|
|
class UsedCarController extends BaseController
|
|
{
|
|
use CrudControllerTrait;
|
|
|
|
protected $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = new UsedCarService();
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function indexFormat($data)
|
|
{
|
|
if (isset($data['created_at']))
|
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
|
if (isset($data['updated_at']))
|
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
|
if (!empty($data['images'])){
|
|
$images = explode(',', $data['images']);
|
|
$ossService = new OssService();
|
|
$images_pull = [];
|
|
foreach ($images as $image){
|
|
$images_pull[] = $ossService->generatePrivateUrl($image);
|
|
}
|
|
$data['images_pull'] = $images_pull;
|
|
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function showFormat($data)
|
|
{
|
|
if (isset($data['created_at']))
|
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
|
if (isset($data['updated_at']))
|
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
|
if (!empty($data['images'])){
|
|
$images = explode(',', $data['images']);
|
|
$ossService = new OssService();
|
|
$images_pull = [];
|
|
foreach ($images as $image){
|
|
$images_pull[] = $ossService->generatePrivateUrl($image);
|
|
}
|
|
$data['images_pull'] = $images_pull;
|
|
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function crawlKeyword(Request $request){
|
|
try {
|
|
// $keyword = $request->get('keyword');
|
|
$data = $this->service->crawlKeyword($request);
|
|
return $this->success($data);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
} |