Merge branch 'develop' into feature/mzl_dev
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\BrandService;
|
||||
use support\Request;
|
||||
|
||||
class BrandController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new BrandService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @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['logo']))
|
||||
$data['logo_full'] = (new OssService)->generatePrivateUrl($data['logo']);
|
||||
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['logo']))
|
||||
$data['logo_full'] = (new OssService)->generatePrivateUrl($data['logo']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 抓取品牌系列
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function crawlSeries(Request $request){
|
||||
try {
|
||||
$result = $this->service->crawlSeries($request);
|
||||
if($result){
|
||||
return $this->success($result,'成功');
|
||||
}else{
|
||||
return $this->error('抓取任务提交失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建被抓取且选中的品牌系列
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function crawlSeriesCreate(Request $request){
|
||||
try {
|
||||
$result = $this->service->crawlSeriesCreate($request);
|
||||
if($result){
|
||||
return $this->success([],$result);
|
||||
}else{
|
||||
return $this->error('创建失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\BrandSeriesService;
|
||||
use support\Request;
|
||||
|
||||
class BrandSeriesController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new BrandSeriesService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @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']);
|
||||
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']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步抓取系列车型
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function crawlModels(Request $request){
|
||||
try {
|
||||
$result = $this->service->crawlModel($request);
|
||||
if($result){
|
||||
return $this->success($result,'抓取成功');
|
||||
}else{
|
||||
return $this->error('抓取任务提交失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步抓取系列车型
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function crawlModelCreate(Request $request){
|
||||
try {
|
||||
$result = $this->service->crawlModelCreate($request);
|
||||
if($result){
|
||||
return $this->success($result,'成功');
|
||||
}else{
|
||||
return $this->error('创建失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\Country;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\SysPortService;
|
||||
|
||||
class SysPortController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new SysPortService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @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 (isset($data['country_id']))
|
||||
if (isset($data['country_id']))
|
||||
$data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr');
|
||||
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']);
|
||||
$data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr');
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -170,6 +170,8 @@ class UploadController
|
||||
'original_name' => $file->getUploadName(),
|
||||
];
|
||||
|
||||
$partition = !empty($partition)?$partition:'other';
|
||||
$category = !empty($category)?$category:'other';
|
||||
$recordResult = $uploadedFilesService->recordFileInfo($fileInfo, $request, $partition, $category);
|
||||
$data = [];
|
||||
$data['file_id'] = $recordResult['id'];
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\BrandSeries;
|
||||
use app\common\service\VehModificationService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\VehVehicleSkuService;
|
||||
use support\exception\BusinessException;
|
||||
@@ -89,6 +91,22 @@ class VehVehicleSkuController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
public function preset(Request $request){
|
||||
|
||||
|
||||
try {
|
||||
$series_id = $request->input('series_id');
|
||||
$series_code = BrandSeries::where('id', $series_id)->value('series_code');
|
||||
$data = [
|
||||
'series_code' => $series_code,
|
||||
];
|
||||
$result = $this->service->getList($data);
|
||||
return $this->success($result, '获取车型列表');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function fields_desc(Request $request)
|
||||
{
|
||||
|
||||
@@ -52,4 +52,9 @@ class VehVehicleSkuLogic
|
||||
$plain = implode('|', $parts);
|
||||
return hash('sha256', $plain);
|
||||
}
|
||||
|
||||
public function getList($data)
|
||||
{
|
||||
return VehVehicleSku::where($data)->orderBy('id','desc')->get(['id', 'sku_code', 'brand_code', 'brand_code', 'series_code', 'series_name', 'model_code', 'model_name', 'model_year', 'msrp']);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user