Merge branch 'develop' into feature/mzl_dev

This commit is contained in:
mzl
2025-10-11 16:50:14 +08:00
15 changed files with 902 additions and 13 deletions
+76
View File
@@ -0,0 +1,76 @@
<?php
namespace app\common\service;
use app\common\logic\BrandLogic;
use QL\QueryList;
class CrawlService
{
public function brandSeries($brand)
{
$url = "https://www.dongchedi.com/search?currTab=6&keyword=".$brand;
$ql = QueryList::get($url );
$series = [];
$ql->find('div.card-name')->texts()->map(function($item) use(&$series) {
$series[] = $item;
});
return $series;
}
public function seriesModel($series)
{
$href = $this->modelSearch($series);
//例如 $seriesUrl = "https://www.dongchedi.com/auto/series/4865?anchorId=carModels"
if (empty($href)) {
return [];
}
$seriesUrl = (strpos($href, 'http') === 0) ? $href : ("https://www.dongchedi.com" . $href);
$ql = QueryList::get($seriesUrl);
$nodes = $ql->find('div.tw-grid div.tw-relative div.tw-items-center>a');
$texts = $nodes->texts()->all();
$links = $nodes->attrs('href')->all();
$nodes = $ql->find('div.tw-grid div.tw-text-color-gray-800');
$price = $nodes->texts()->all();
$results = [];
foreach ($texts as $index => $text) {
$link = $links[$index] ?? '';
if (!empty($link) && strpos($link, 'http') !== 0) {
$link = 'https://www.dongchedi.com' . $link;
}
$results[] = [
'title' => trim($text),
'link' => $link,
'msrp' => (int)(str_replace("万", "", $price[$index]) * 10000) ?? 0,
];
}
return $results;
}
// public function modelDesc(array $models)
// {
//
// }
/**
* 返回车系地址
* @param $series
* @return mixed|string
*/
public function modelSearch($series)
{
$url = "https://www.dongchedi.com/search?keyword=".$series;
$ql = QueryList::get($url );
$href = '';
$ql->find('a.fold-btn')->attrs('href')
->map(function ($item) use(&$href) {
$href = $item;
});
return $href;
}
}
@@ -5,6 +5,9 @@ namespace app\common\service;
use app\common\logic\Fingerprint;
use app\common\logic\ModelNaming;
use app\common\logic\SkuCodeBuilder;
use app\common\logic\VehVehicleSkuLogic;
use app\common\model\Brand;
use app\common\model\BrandSeries;
use app\common\validate\VehVehicleSkuValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\VehVehicleSku;
@@ -25,6 +28,13 @@ class VehVehicleSkuService
*/
protected $validator = VehVehicleSkuValidate::class;
protected $logic;
public function __construct()
{
$this->logic = (new VehVehicleSkuLogic());
}
/**
* 获取验证器
*/
@@ -111,6 +121,15 @@ class VehVehicleSkuService
$config['orWhere'][] = [$col, 'like', $k];
}
}
if(isset($p['brand_id']) && $p['brand_id']){
$brand_code = Brand::where('id', $p['brand_id'])->value('brand_code');
$config['where']['brand_code'] = $brand_code;
}
if(isset($p['series_id']) && $p['series_id']){
$series_code = BrandSeries::where('id', $p['series_id'])->value('series_code');
$config['where']['series_code'] = $series_code;
}
break;
case 'show':
$config['where']['id'] = $p['id'];
@@ -138,6 +157,33 @@ class VehVehicleSkuService
if (empty($data['model_name'])) {
$data['model_name'] = ModelNaming::buildModelName($data);
}
if (empty($data['engine_disp_l'])) {
$data['engine_disp_l'] = 0;
}
if (empty($data['engine_turbo'])) {
$data['engine_turbo'] = 0;
}
if (empty($data['engine_power_kw'])) {
$data['engine_power_kw'] = 0;
}
if (empty($data['battery_kwh'])) {
$data['battery_kwh'] = 0;
}
if (empty($data['gears'])) {
$data['gears'] = 1;
}
if (empty($data['range_km'])) { //续航
$data['range_km'] = 0;
}
if (empty($data['doors'])) { //车位数
$data['doors'] = 0;
}
if (empty($data['seats'])) { //座位数
$data['seats'] = 0;
}
if (empty($data['weight_kg'])) { //整车质量
$data['weight_kg'] = 0;
}
$data['sku_code'] = SkuCodeBuilder::build($data);
$data['corp_id'] = 0;
$data['created_by'] = $request->user->uid;
@@ -177,4 +223,12 @@ class VehVehicleSkuService
return $res;
}
/**
* 获取车型list
*/
public function getList($data)
{
return $this->logic->getList($data);
}
}