重新推送
This commit is contained in:
@@ -360,4 +360,35 @@ class UsedCarDetailController extends BaseController
|
|||||||
return $this->error($e->getMessage());
|
return $this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重新推送失败的车辆到WordPress
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return \support\Response
|
||||||
|
*/
|
||||||
|
public function retryPush(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$carId = $request->post('id');
|
||||||
|
|
||||||
|
if (empty($carId)) {
|
||||||
|
throw new BusinessException('车辆ID不能为空');
|
||||||
|
}
|
||||||
|
|
||||||
|
$count = $this->service->retryPush($carId);
|
||||||
|
|
||||||
|
if ($count === 0) {
|
||||||
|
return $this->error('车辆不存在或状态不是推送失败');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->success(['count' => $count], 'WordPress推送任务已重新加入队列');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('重新推送失败', [
|
||||||
|
'car_id' => $request->post('id'),
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -875,6 +875,15 @@ class UsedCarDetailService
|
|||||||
*/
|
*/
|
||||||
public function crawlAndStore(string $url, int $userId): array
|
public function crawlAndStore(string $url, int $userId): array
|
||||||
{
|
{
|
||||||
|
// 检查该用户是否已抓取过此URL的车辆
|
||||||
|
$existingCar = UsedCarDetail::where('user_id', $userId)
|
||||||
|
->where('source_url', $url)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($existingCar) {
|
||||||
|
throw new \Exception('该车辆信息已存在,无需重复抓取');
|
||||||
|
}
|
||||||
|
|
||||||
// 1. 抓取二手车基本信息
|
// 1. 抓取二手车基本信息
|
||||||
$usedCarCrawl = new \app\common\utils\crawl\service\UsedCarCrawlSingle();
|
$usedCarCrawl = new \app\common\utils\crawl\service\UsedCarCrawlSingle();
|
||||||
$info = $usedCarCrawl->crawlCar($url);
|
$info = $usedCarCrawl->crawlCar($url);
|
||||||
@@ -991,4 +1000,31 @@ class UsedCarDetailService
|
|||||||
$mileage = str_replace(['万公里', '万'], '', $mileage);
|
$mileage = str_replace(['万公里', '万'], '', $mileage);
|
||||||
return floatval($mileage) * 10000;
|
return floatval($mileage) * 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重新推送单辆失败的车到WordPress
|
||||||
|
*
|
||||||
|
* @param int $carId 车辆ID
|
||||||
|
* @return int 成功加入队列返回1,否则返回0
|
||||||
|
*/
|
||||||
|
public function retryPush(int $carId): int
|
||||||
|
{
|
||||||
|
$car = UsedCarDetail::where('id', $carId)
|
||||||
|
->where('status', 5) // 只处理推送失败的
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$car) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新状态为待推送
|
||||||
|
$car->update(['status' => 3]);
|
||||||
|
|
||||||
|
// 加入队列
|
||||||
|
\Webman\RedisQueue\Redis::send('wordpress-push', ['car_id' => $carId]);
|
||||||
|
|
||||||
|
Log::info('车辆重新加入推送队列', ['car_id' => $carId]);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -93,6 +93,9 @@ Route::group('/common', function () {
|
|||||||
|
|
||||||
// 抓取相关
|
// 抓取相关
|
||||||
Route::any('/crawl/store', [app\common\controller\UsedCarDetailController::class, 'crawlAndStore']);
|
Route::any('/crawl/store', [app\common\controller\UsedCarDetailController::class, 'crawlAndStore']);
|
||||||
|
|
||||||
|
// 重新推送
|
||||||
|
Route::any('/retry/push', [app\common\controller\UsedCarDetailController::class, 'retryPush']);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::group('/user', function () {
|
Route::group('/user', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user