2026-03-09 17:46:17 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
namespace app\common\controller;
|
|
|
|
|
|
|
|
|
|
|
|
use app\common\controller\BaseController;
|
|
|
|
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
|
|
|
|
use app\common\service\UsedCarDetailService;
|
|
|
|
|
|
use app\common\service\OssService;
|
|
|
|
|
|
use support\Request;
|
|
|
|
|
|
use support\exception\BusinessException;
|
2026-03-11 15:01:54 +08:00
|
|
|
|
use support\Log;
|
2026-03-09 17:46:17 +08:00
|
|
|
|
|
|
|
|
|
|
class UsedCarDetailController extends BaseController
|
|
|
|
|
|
{
|
|
|
|
|
|
use CrudControllerTrait;
|
|
|
|
|
|
|
|
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->service = new UsedCarDetailService();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 列表页数据格式化
|
|
|
|
|
|
*
|
|
|
|
|
|
* @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'])) {
|
2026-03-10 11:05:30 +08:00
|
|
|
|
$images = is_array($data['images']) ? $data['images'] : explode(',', $data['images']);
|
2026-03-09 17:46:17 +08:00
|
|
|
|
if ($images) {
|
|
|
|
|
|
$ossService = new OssService();
|
|
|
|
|
|
$images_pull = [];
|
|
|
|
|
|
foreach ($images as $image) {
|
|
|
|
|
|
$images_pull[] = $ossService->generatePrivateUrl($image);
|
|
|
|
|
|
}
|
|
|
|
|
|
$data['images_pull'] = $images_pull;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$data['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'])) {
|
2026-03-10 11:25:09 +08:00
|
|
|
|
$images = is_array($data['images']) ? $data['images'] : explode(',', $data['images']);
|
2026-03-09 17:46:17 +08:00
|
|
|
|
if ($images) {
|
|
|
|
|
|
$ossService = new OssService();
|
|
|
|
|
|
$images_pull = [];
|
|
|
|
|
|
$process = 'image/resize,w_800/quality,Q_40/format,webp';
|
|
|
|
|
|
foreach ($images as $image) {
|
|
|
|
|
|
$images_pull[] = $ossService->generatePrivateUrlResize($image, 3600, $process);
|
|
|
|
|
|
}
|
|
|
|
|
|
$data['images_pull'] = $images_pull;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$data['images_pull'] = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$data['images_pull'] = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 10:19:55 +08:00
|
|
|
|
if (!empty($data['intro_video'])){
|
|
|
|
|
|
$videos = explode(',', $data['intro_video']);
|
|
|
|
|
|
$ossService = new OssService();
|
|
|
|
|
|
$videos_pull = [];
|
|
|
|
|
|
foreach ($videos as $video){
|
|
|
|
|
|
$videos_pull[] = $ossService->generatePrivateUrl($video);
|
|
|
|
|
|
}
|
|
|
|
|
|
$data['video_pull'] = $videos_pull;
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$data['video_pull'] = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-09 17:46:17 +08:00
|
|
|
|
// 处理介绍图片
|
|
|
|
|
|
if (!empty($data['intro_images'])) {
|
2026-03-10 11:25:09 +08:00
|
|
|
|
$introImages = is_array($data['intro_images']) ? $data['intro_images'] : explode(',', $data['intro_images']);
|
2026-03-09 17:46:17 +08:00
|
|
|
|
if ($introImages) {
|
|
|
|
|
|
$ossService = new OssService();
|
|
|
|
|
|
$intro_images_pull = [];
|
|
|
|
|
|
foreach ($introImages as $image) {
|
|
|
|
|
|
$intro_images_pull[] = $ossService->generatePrivateUrl($image);
|
|
|
|
|
|
}
|
|
|
|
|
|
$data['intro_images_pull'] = $intro_images_pull;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$data['intro_images_pull'] = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$data['intro_images_pull'] = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理附件
|
|
|
|
|
|
if (!empty($data['attachment'])) {
|
|
|
|
|
|
$attachments = is_array($data['attachment']) ? $data['attachment'] : json_decode($data['attachment'], true);
|
|
|
|
|
|
if ($attachments) {
|
|
|
|
|
|
$ossService = new OssService();
|
|
|
|
|
|
$attachment_pull = [];
|
|
|
|
|
|
foreach ($attachments as $attachment) {
|
|
|
|
|
|
$attachment_pull[] = [
|
|
|
|
|
|
'name' => $attachment['name'] ?? '',
|
|
|
|
|
|
'src' => $attachment['src'] ?? '',
|
|
|
|
|
|
'src_pull' => $ossService->generatePrivateUrl($attachment['src'] ?? ''),
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
$data['attachment_pull'] = $attachment_pull;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$data['attachment_pull'] = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$data['attachment_pull'] = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 更新状态
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Request $request
|
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function status(Request $request)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$data = $request->post();
|
|
|
|
|
|
$res = $this->service->serviceUpdateStatus($request, $data);
|
|
|
|
|
|
return $this->success([], '更新成功');
|
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 保存FAQ
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Request $request
|
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function saveFaqs(Request $request)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$carId = $request->post('id');
|
|
|
|
|
|
$faqs = $request->post('faqs', []);
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($carId)) {
|
|
|
|
|
|
throw new BusinessException('车辆ID不能为空');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->service->saveFaqs($carId, $faqs);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success([], '保存成功');
|
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 创建车辆(含FAQ)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Request $request
|
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function storeWithFaqs(Request $request)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$data = $request->post();
|
|
|
|
|
|
$faqs = $data['faqs'] ?? [];
|
|
|
|
|
|
|
|
|
|
|
|
// 先创建车辆
|
2026-03-10 10:35:16 +08:00
|
|
|
|
$result = $this->service->serviceStore($request,$data);
|
2026-03-09 17:46:17 +08:00
|
|
|
|
|
|
|
|
|
|
// 再保存FAQ
|
|
|
|
|
|
if (!empty($faqs) && isset($result['id'])) {
|
|
|
|
|
|
$this->service->saveFaqs($result['id'], $faqs);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success($result, '创建成功');
|
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 更新车辆(含FAQ)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Request $request
|
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function updateWithFaqs(Request $request)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$data = $request->post();
|
|
|
|
|
|
$faqs = $data['faqs'] ?? [];
|
|
|
|
|
|
$carId = $data['id'] ?? null;
|
|
|
|
|
|
|
|
|
|
|
|
// 先更新车辆
|
2026-03-10 10:35:16 +08:00
|
|
|
|
$result = $this->service->serviceUpdate($request,$data);
|
2026-03-09 17:46:17 +08:00
|
|
|
|
|
|
|
|
|
|
// 再更新FAQ
|
|
|
|
|
|
if (!empty($faqs) && $carId) {
|
|
|
|
|
|
$this->service->saveFaqs($carId, $faqs);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success($result, '更新成功');
|
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 提交审核
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Request $request
|
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function submitAudit(Request $request)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$carId = $request->post('id');
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($carId)) {
|
|
|
|
|
|
throw new BusinessException('车辆ID不能为空');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->service->submitAudit($request, $carId);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success([], '提交审核成功');
|
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 审核车辆
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Request $request
|
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function audit(Request $request)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$data = $request->post();
|
|
|
|
|
|
|
2026-03-11 16:01:18 +08:00
|
|
|
|
$result = $this->service->audit($request, $data);
|
2026-03-09 17:46:17 +08:00
|
|
|
|
|
|
|
|
|
|
$statusText = $data['audit_status'] == 1 ? '通过' : '拒绝';
|
2026-03-11 16:01:18 +08:00
|
|
|
|
$message = "审核{$statusText}成功";
|
|
|
|
|
|
|
|
|
|
|
|
// 审核通过时,提示推送任务已加入队列
|
|
|
|
|
|
if ($data['audit_status'] == 1 && $result['push_queued']) {
|
|
|
|
|
|
$message .= ',WordPress推送任务已加入队列,将在后台处理';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success($result, $message);
|
2026-03-09 17:46:17 +08:00
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取审核记录
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Request $request
|
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function auditRecords(Request $request)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$carId = $request->get('id');
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($carId)) {
|
|
|
|
|
|
throw new BusinessException('车辆ID不能为空');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$records = $this->service->getAuditRecords($carId);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success($records);
|
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取审核统计
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Request $request
|
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function auditStats(Request $request)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$stats = $this->service->getAuditStats($request);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success($stats);
|
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-03-11 15:01:54 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 抓取懂车帝二手车数据并保存
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param Request $request
|
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function crawlAndStore(Request $request)
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$url = $request->post('url');
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($url)) {
|
|
|
|
|
|
throw new BusinessException('链接不能为空');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 验证是否是懂车帝链接
|
|
|
|
|
|
if (!str_contains($url, 'dongchedi.com')) {
|
|
|
|
|
|
throw new BusinessException('只支持懂车帝二手车链接');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$userId = $request->user['id'] ?? 0;
|
|
|
|
|
|
if (empty($userId)) {
|
|
|
|
|
|
throw new BusinessException('用户未登录');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->service->crawlAndStore($url, $userId);
|
|
|
|
|
|
|
2026-03-11 16:01:18 +08:00
|
|
|
|
return $this->success($result, '抓取成功,WordPress推送任务已加入队列,将在后台处理');
|
2026-03-11 15:01:54 +08:00
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
|
Log::error('抓取懂车帝二手车失败', [
|
|
|
|
|
|
'url' => $request->post('url'),
|
|
|
|
|
|
'error' => $e->getMessage(),
|
|
|
|
|
|
]);
|
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-03-09 17:46:17 +08:00
|
|
|
|
}
|