抓取车辆
This commit is contained in:
@@ -7,6 +7,7 @@ use app\common\service\UsedCarDetailService;
|
||||
use app\common\service\OssService;
|
||||
use support\Request;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
|
||||
class UsedCarDetailController extends BaseController
|
||||
{
|
||||
@@ -315,4 +316,41 @@ class UsedCarDetailController extends BaseController
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 抓取懂车帝二手车数据并保存
|
||||
*
|
||||
* @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);
|
||||
|
||||
return $this->success($result, '抓取成功,已保存为待审核状态');
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('抓取懂车帝二手车失败', [
|
||||
'url' => $request->post('url'),
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user