作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

... ... @@ -38,6 +38,7 @@ class ProjectImport extends Command
public function handle()
{
ini_set('memory_limit', '512M');
while (true) {
$this->start_import();
}
... ...
<?php
namespace App\Console\Commands\Update;
use App\Models\Collect\CollectSource;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* 4.0,5.0升级到6.0,主站自定义页面采集
* Class ProjectImport
* @package App\Console\Commands
* @author Akun
* @date 2023/12/13 14:44
*/
class HtmlCustomCollect extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project_html_custom_collect';
/**
* The console command description.
*
* @var string
*/
protected $description = '执行项目自定义html页面采集';
public function handle()
{
ini_set('memory_limit', '512M');
$project_id = 633;
$project_site = 'v6-ke5nz.globalso.site';
$pages = [
'https://www.mach-sales.com/case_catalog/cases/',
'https://www.mach-sales.com/case_catalog/cases/page/2/',
'https://www.mach-sales.com/case_catalog/cases/page/3/',
'https://www.mach-sales.com/case/growing-with-customers-from-small-motors-to-big-drivers/',
'https://www.mach-sales.com/case/growing-together-with-customers-the-journey-of-intelligent-manufacturing-in-a-modernized-factory/',
'https://www.mach-sales.com/case/%e3%80%90growing-together-with-customers%e3%80%91-the-evolutionary-journey-of-a-baking-brand/',
'https://www.mach-sales.com/case/sumecs-footprints-in-belt-and-road-singapore/',
'https://www.mach-sales.com/case/sumecs-footprints-in-belt-and-road-southeast-asia/',
'https://www.mach-sales.com/case/naming-and-delivery-of-a-new-ship-1/',
'https://www.mach-sales.com/case/a-newly-signed-contract-cable-manufacturing-equipment/',
'https://www.mach-sales.com/case/its-amazing-that-the-glass-can-also-save-energy/',
'https://www.mach-sales.com/case/%e3%80%90grow-with-customers%e3%80%91better-service-for-papermaking-equipment-procurement/',
'https://www.mach-sales.com/case/expansion-of-blower-equipment-contributes-to-environmental-protection/',
'https://www.mach-sales.com/case/new-ship-type-new-contract/',
'https://www.mach-sales.com/case/new-arrival-introducing-the-latest-ship-model/',
'https://www.mach-sales.com/case/another-contract-signed-in-the-philippines/',
'https://www.mach-sales.com/case/the-road-to-going-global-is-supported-by-sumec-services/',
'https://www.mach-sales.com/case/sumec-textile-launches-sun-protection-series-in-collaboration-with-skechers-kids/',
'https://www.mach-sales.com/case/footwear-manufacturing-equipment-new-contract/',
'https://www.mach-sales.com/case/sumec-energy-company-has-successfully-signed-a-photovoltaic-component-supply-agreement-with-wattkraft-a-german-engineering-system-integrator/',
'https://www.mach-sales.com/case/sumec-technology-company-successfully-signed-a-contract-for-the-equipment-related-to-the-high-strength-particleboard-project/',
'https://www.mach-sales.com/case/%e3%80%90growing-together-with-our-customers%e3%80%91together-on-the-road-to-transformation/',
'https://www.mach-sales.com/case/new-signing/',
'https://www.mach-sales.com/case/complete-the-last-mile-equipment-procurement-from-around-the-world/',
'https://www.mach-sales.com/case/science-and-technology-to-rejuvenate-agriculture-this-plant-factory-is-not-simple/',
'https://www.mach-sales.com/case/new-cooperation-high-end-equipment-going-global/',
'https://www.mach-sales.com/case/a-new-cooperation-with-an-annual-output-of-40000-tons/',
'https://www.mach-sales.com/case/a-new-contract-cooperation-upgrades/',
'https://www.mach-sales.com/case/annual-output-of-50000-tons-this-bopp-film-production-line-was-officially-put-into-operation/',
'https://www.mach-sales.com/case/this-is-sumec-speed/',
'https://www.mach-sales.com/case/the-first-order-of-a-new-semiconductor-brand-equipment-direct-sales-bear-fruit-again/',
'https://www.mach-sales.com/case/sumec-touch-world-celebrates-its-5th-anniversary-with-well-known-suppliers/',
'https://www.mach-sales.com/case/from-traditional-agency-to-digital-service/',
'https://www.mach-sales.com/case/cooperation-win-win-and-starting-anew-sumec-creates-a-new-sample-of-strong-enterprise-cooperation/'
];
// $project_id = 437;
// $project_site = 'v6-1500k.globalso.site';
// $pages = [
// 'https://www.tourletent.com/project/b300-glamping-tent-in-china/',
// 'https://www.tourletent.com/project/lotus-bell-tent-in-australia/',
// 'https://www.tourletent.com/project/luxury-resort-in-china/',
// 'https://www.tourletent.com/project/canvas-safari-tent-inthailand/',
// 'https://www.tourletent.com/project/safari-tent-for-m8-in-mexcio/',
// 'https://www.tourletent.com/project/9m-pvc-dome-tent-in-canada/',
// 'https://www.tourletent.com/project/c900-hotel-tent-in-korea/',
// 'https://www.tourletent.com/project/safari-tent-in-guizhou/',
// 'https://www.tourletent.com/project/dome-tent-in-austin/',
// 'https://www.tourletent.com/project/safari-tent-in-italy/',
// 'https://www.tourletent.com/project/glass-igloo-in-china/',
// 'https://www.tourletent.com/project/tree-house-in-sichuan/'
// ];
// $project_id = 626;
// $project_site = 'v6-m342g.globalso.site';
// $pages = [
// 'https://www.lecusostreetlight.com/project_catalog/project/',
// 'https://www.lecusostreetlight.com/project_catalog/project/page/2/',
// 'https://www.lecusostreetlight.com/project/560pcs-250w-smart-led-street-light-in-manila-city-philippines/',
// 'https://www.lecusostreetlight.com/project/3200pcs-8m-150w-solar-street-light-in-cebu-philippines/',
// 'https://lecusostreetlight.com/project/170pcs-100w-split-lithium-battery-solar-street-light-in-tanzania/',
// 'https://www.lecusostreetlight.com/project/250pcs-40w-sl-series-solar-street-light-in-kuwait/',
// 'https://www.lecusostreetlight.com/project/272pcs-8m-80w-solar-street-light-in-tanzania/',
// 'https://www.lecusostreetlight.com/project/185pcs-10m-120w-highway-solar-street-light-in-jordan/',
// 'https://www.lecusostreetlight.com/project/270pcs-9m-patterned-decorative-light-pole-with-150w-led-cobra-light-in-cambodia/',
// 'https://www.lecusostreetlight.com/project/48pcs-5m-24w-decorative-aluminium-pole-in-dubai-uae/',
// 'https://www.lecusostreetlight.com/project/105pcs-9m-100w-led-street-light-in-sri-lanka/',
// 'https://www.lecusostreetlight.com/project/45pcs-6m-hot-dip-galvanized-double-arm-street-light-pole-in-dubai-uae/',
// 'https://www.lecusostreetlight.com/project/356pcs-8m-100w-solar-street-light-in-ethiopia/',
// 'https://www.lecusostreetlight.com/project/52pcs-6m-30w-solar-led-street-light-with-gel-battery-in-poland/',
// 'https://www.lecusostreetlight.com/project/225pcs-6m-80w-solar-street-light-in-vietnam/',
// 'https://www.lecusostreetlight.com/project/450pcs-7m-60w-double-arm-solar-light-in-nigeria/',
// 'https://www.lecusostreetlight.com/project/100pcs-6m-50w-led-street-light-in-maldives/',
// 'https://www.lecusostreetlight.com/project/202pcs-6m-40w-3000k-solar-street-light-in-manila-philippines/',
// 'https://www.lecusostreetlight.com/project/245pcs-120w-smart-led-street-light-in-bangkok-thailand/',
// 'https://www.lecusostreetlight.com/project/170pcs-7m-50w-all-in-one-solar-light-in-davao-philippines/',
// 'https://www.lecusostreetlight.com/project/80pcs-9m-150w-led-street-light-in-iraq/',
// 'https://www.lecusostreetlight.com/project/252pcs-6m-40w-separate-solar-street-light-with-lithium-battery-in-thailand/',
// 'https://www.lecusostreetlight.com/project/198pcs-8m-80w-zc-series-all-in-two-solar-light-in-philippines/',
// 'https://www.lecusostreetlight.com/project/5m-30w-morden-led-garden-light-in-russian/',
// 'https://www.lecusostreetlight.com/project/135pcs-all-in-one-solar-street-light-in-uae-dubai-park/'
// ];
foreach ($pages as $page) {
$this->start_collect(urldecode($page), $project_id, $project_site);
}
}
protected function start_collect($page, $project_id, $project_site)
{
$page_arr = parse_url($page);
$domain = $page_arr['host'];
$path = $page_arr['path'];
//设置数据库
$project = ProjectServer::useProject($project_id);
if ($project) {
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', page: ' . $page . ', collect start' . PHP_EOL;
//获取站点原始域名信息
$old_info = getOldDomain($project_id, $domain);
//采集html页面,下载资源到本地并替换
try {
$html = curl_c($page, false);
if ($html == '0') {
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', page: ' . $page . ', error: no html' . PHP_EOL;
sleep(2);
return true;
}
//如果有base64图片,先替换掉,再进行资源匹配
$new_html = $html;
preg_match_all("/data:([^;]*);base64,(.*)?\"/", $new_html, $result_img);
$img_base64 = $result_img[2] ?? [];
foreach ($img_base64 as $v64) {
$new_html = str_replace($v64, '', $new_html);
}
//匹配资源链接
$source_list = $this->html_preg($new_html, $project_id, $domain, $old_info['web_url_domain'], $old_info['home_url']);
//下载资源
if ($source_list) {
$html = $this->upload_source($html, $source_list, $project_id, $domain, $old_info['web_url_domain'], $old_info['home_url']);
}
//替换域名
$html = str_replace($old_info['web_url_domain'], $project_site, $html);
$html = str_replace($old_info['home_url'], $project_site, $html);
//暂时隐藏小语种
$html = str_replace('<div class="change-language ensemble">', '<div class="change-language ensemble" style="display: none">', $html);
$html = str_replace('<div class="language_more">', '<div class="language_more" style="display: none">', $html);
$html = str_replace('</body>', '<script src="https://ecdn6.globalso.com/public/customerVisit.min.js\"></script></body>', $html);
//html写入文件
$file_path = '/www/wwwroot/globalso-v6-c-glo/public/' . $project_site . $path;
if (!file_exists($file_path)) {
mkdir($file_path, 0777, true);
}
file_put_contents($file_path . 'index.html', $html);
chmod($file_path . 'index.html', 0777);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', page: ' . $page . ', error: ' . $e->getMessage() . PHP_EOL;
sleep(2);
return true;
}
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', page: ' . $page . ', collect end' . PHP_EOL;
} else {
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', page: ' . $page . ', no project' . PHP_EOL;
}
//关闭数据库
DB::disconnect('custom_mysql');
sleep(2);
return true;
}
//正则匹配html资源
protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url)
{
$source = [];
if (!$html) {
return $source;
}
//image
preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_img);
$img = $result_img[2] ?? [];
foreach ($img as $vi) {
$check_vi = $this->url_check($vi, $project_id, $domain, $web_url_domain, $home_url);
$check_vi && $source[] = $check_vi;
}
//js
preg_match_all('/<script\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_js);
$js = $result_js[2] ?? [];
foreach ($js as $vj) {
$check_vj = $this->url_check($vj, $project_id, $domain, $web_url_domain, $home_url);
$check_vj && $source[] = $check_vj;
}
//video
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_video);
$video = $result_video[2] ?? [];
foreach ($video as $vv) {
$check_vv = $this->url_check($vv, $project_id, $domain, $web_url_domain, $home_url);
$check_vv && $source[] = $check_vv;
}
//css
preg_match_all('/<link\s+[^>]*?href\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_css);
$css = $result_css[2] ?? [];
foreach ($css as $vc) {
$check_vc = $this->url_check($vc, $project_id, $domain, $web_url_domain, $home_url);
$check_vc && $source[] = $check_vc;
}
//css background
preg_match_all("/url\(['\"]?(\s*[^>]+?)['\"]?\)/i", $html, $result_css_b);
$css_b = $result_css_b[1] ?? [];
foreach ($css_b as $vc_b) {
$check_vc_b = $this->url_check($vc_b, $project_id, $domain, $web_url_domain, $home_url);
$check_vc_b && $source[] = $check_vc_b;
}
//a标签下载资源
preg_match_all('/<a\s+[^>]*?href\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_a);
$down = $result_a[2] ?? [];
foreach ($down as $vd) {
$check_vd = $this->url_check($vd, $project_id, $domain, $web_url_domain, $home_url);
$check_vd && $source[] = $check_vd;
}
return $source;
}
//判断资源是否需要下载
protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url)
{
if ($url) {
$url = str_replace('&quot;', '', $url);
$arr = parse_url($url);
$scheme = $arr['scheme'] ?? '';
$host = $arr['host'] ?? '';
$path = $arr['path'] ?? '';
$query = $arr['query'] ?? '';
$path_arr = explode('.', $path);
if (
(empty($scheme) || $scheme == 'https' || $scheme == 'http')
&& (empty($host) || (strpos($web_url_domain, $host) !== false) || (strpos($home_url, $host) !== false))
&& $path
&& (substr($path, 0, 1) == '/')
&& (strpos($path, '.') !== false)
&& (!in_array(end($path_arr), ['html', 'php', 'com', 'xml']))
) {
$source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
if (!$source) {
return [
'download' => true,
'url' => $url,
'url_complete' => ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path . ($query ? '?' . $query : '')
];
} else {
return [
'download' => false,
'url' => $url,
'url_complete' => $source['target']
];
}
} else {
return false;
}
} else {
return false;
}
}
//下载并替换资源
protected function upload_source($html, $source, $project_id, $domain, $web_url_domain, $home_url)
{
foreach ($source as $vs) {
if ($vs['download']) {
$new_source = CosService::uploadRemote($project_id, 'source', $vs['url_complete']);
if ($new_source) {
CollectSource::insert([
'project_id' => $project_id,
'origin' => $vs['url'],
'target' => $new_source,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
$html = str_replace($vs['url'], getImageUrl($new_source), $html);
if (substr($new_source, -3, 3) == 'css' || substr($new_source, -2, 2) == 'js') {
$source_html = curl_c(getImageUrl($new_source), false);
if (substr($new_source, -3, 3) == 'css') {
preg_match_all("/url\(['\"]?(\s*[^>]+?)['\"]?\)/i", $source_html, $result_source);
} else {
preg_match_all("/[large|thumb]+URL:['\"]+(\s*[^>]+?)['\"]+,/i", $source_html, $result_source);
}
$js_css_source = $result_source[1] ?? [];
if ($js_css_source) {
foreach ($js_css_source as $vjs) {
$vjs_down = str_replace('&quot;', '', $vjs);
if (strpos($vjs_down, 'data:') !== false) {
//过滤二进制文件
continue;
}
if (strlen($vjs_down) > 255) {
//过滤太长文件
continue;
}
$vjs_down_arr = parse_url($vjs_down);
$vjs_down_host = $vjs_down_arr['host'] ?? '';
$cos = config('filesystems.disks.cos');
$cosCdn = $cos['cdn'];
if ($vjs_down_host && $vjs_down_host == $cosCdn) {
//过滤已经下载的
continue;
}
if (empty($vjs_down_host) && substr($vjs_down, 0, 1) != '/') {
//相对路径
$url_arr = explode('/', $vs['url']);
$url_arr[count($url_arr) - 1] = $vjs_down;
$vjs_down = implode('/', $url_arr);
}
$vjs_result = $this->url_check($vjs_down, $project_id, $domain, $web_url_domain, $home_url);
if (!$vjs_result) {
continue;
}
if ($vjs_result['download']) {
$new_vjs = CosService::uploadRemote($project_id, 'source', $vjs_result['url_complete']);
if ($new_vjs) {
CollectSource::insert([
'project_id' => $project_id,
'origin' => $vjs_result['url'],
'target' => $new_vjs,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
$source_html = str_replace($vjs, getImageUrl($new_vjs), $source_html);
}
} else {
$source_html = str_replace($vjs, getImageUrl($vjs_result['url_complete']), $source_html);
}
}
CosService::uploadRemote($project_id, 'source', $new_source, $new_source, $source_html);
}
}
}
} else {
$html = str_replace($vs['url'], getImageUrl($vs['url_complete']), $html);
}
}
return $html;
}
}
... ...
<?php
namespace App\Console\Commands\Update;
use App\Models\Com\UpdateLog;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ProjectReset extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project_reset {project_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = '项目采集重置';
public function handle()
{
$project_id = $this->argument('project_id');
$project = ProjectServer::useProject($project_id);
if ($project) {
try {
DB::connection('custom_mysql')->statement("DELETE FROM `gl_collect_source` WHERE `origin` LIKE '%.css%' OR `origin` LIKE '%.js%'");
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0");
} catch (\Exception $e) {
echo $project_id . ',重置失败' . PHP_EOL;
}
}
//关闭数据库
DB::disconnect('custom_mysql');
UpdateLog::where('project_id', $project_id)->whereIn('api_type', ['post', 'page', 'news', 'blog'])->update(['collect_status' => 0]);
echo $project_id . ',重置成功' . PHP_EOL;
}
}
... ...
... ... @@ -452,7 +452,7 @@ class ProjectUpdate extends Command
return $task_id;
}
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(8)->get();
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('sort', 'asc')->orderBy('project_id', 'asc')->limit(20)->get();
if ($task_list->count() == 0) {
return false;
}
... ... @@ -527,18 +527,20 @@ class ProjectUpdate extends Command
{
$model = new NewsCategory();
foreach ($items as $item) {
$item['name'] = $this->special2str($item['name'] ?? '');
if ($item['name']) {
$parent = $model->read(['pid' => $pid, 'name' => $item['name']], 'id');
$route = $this->get_url_route($item['url'] ?? '');
if ($route) {
$parent = $model->read(['pid' => $pid, 'alias' => $route], 'id');
if (!$parent) {
try {
$item['name'] = $this->special2str($item['name'] ?? '');
$parent_id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['name'],
'pid' => $pid,
'original_id' => $item['id']
'original_id' => $item['id'],
'alias' => $route
]);
$this->set_map($this->get_url_route($item['url'] ?? ''), RouteMap::SOURCE_NEWS_CATE, $parent_id, $project_id);
$this->set_map($route, RouteMap::SOURCE_NEWS_CATE, $parent_id, $project_id);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', category_news_insert error: ' . $e->getMessage() . PHP_EOL;
continue;
... ... @@ -592,7 +594,7 @@ class ProjectUpdate extends Command
if ($source == RouteMap::SOURCE_NEWS) {
$route_map->path = RouteMap::SOURCE_NEWS;
} elseif ($source == RouteMap::SOURCE_BLOG) {
$route_map->path = RouteMap::SOURCE_BLOG;
$route_map->path = RouteMap::SOURCE_BLOG.'s';
}
$route_map->save();
... ...
... ... @@ -199,8 +199,6 @@ class ProofreadingController extends BaseController
$strippedContent = preg_replace($pattern, '', $strippedContent); // 删除`<script>`标签及其内容
$pattern = '/<link\b[^>]*>/'; // 定义匹配 `<link>` 标签的正则表达式
$strippedContent = preg_replace($pattern, '', $strippedContent); // 删除 `<link>` 标签
$pattern = '/<footer\b[^>]*>(.*?)<\/footer>/s'; // 定义匹配`<script>`标签及其内容的正则表达式
$strippedContent = preg_replace($pattern, '', $strippedContent); // 删除`<script>`标签及其内容
$pattern = '/>([^<]+)</'; // 定义匹配中间内容不是标签的正则表达式
$matches = array();
preg_match_all($pattern, $strippedContent, $matches);
... ...
... ... @@ -33,7 +33,7 @@ class BlogCategoryLogic extends BaseLogic
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']);
$this->editCategoryRoute($this->param['id'], $this->param['alias']);
$route = $this->param['alias'];
$this->editHandleCategory($this->param['id'],$this->param['pid']);
$this->param['operator_id'] = $this->user['id'];
$this->edit($this->param,['id'=>$this->param['id']]);
... ... @@ -46,12 +46,12 @@ class BlogCategoryLogic extends BaseLogic
$this->param = $this->addParamProcessing($this->param);
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);
$this->addUpdateNotify(RouteMap::SOURCE_BLOG_CATE,$route);
$this->curlDelRoute(['new_route'=>$route]);
$this->edit(['alias'=>$route],['id'=>$id]);
//处理子集
$this->addProcessingSon($id);
}
$this->addUpdateNotify(RouteMap::SOURCE_BLOG_CATE,$route);
$this->curlDelRoute(['new_route'=>$route]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
... ... @@ -103,23 +103,6 @@ class BlogCategoryLogic extends BaseLogic
}
/**
* @remark :编辑路由时生成路由记录
* @name :editCategoryRoute
* @author :lyh
* @method :post
* @time :2023/9/7 10:51
*/
public function editCategoryRoute($id,$route){
//生成一条删除路由记录
$info = $this->model->read(['id'=>$id],['id','alias']);
if($info['alias'] != $route){
$this->addUpdateNotify(RouteMap::SOURCE_BLOG_CATE,$route);
$this->curlDelRoute(['route'=>$info['alias'],'new_route'=>$route]);
}
return true;
}
/**
* @name :详情
* @return array
* @author :liyuhang
... ...
... ... @@ -35,15 +35,15 @@ class BlogLogic extends BaseLogic
$this->param = $this->paramProcessing($this->param);
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['url'] = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']);
$this->editNewsRoute($this->param['id'],$this->param['url']);
$route = $this->param['url'];
$this->edit($this->param,['id'=>$this->param['id']]);
}else{
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']);
$this->addUpdateNotify(RouteMap::SOURCE_BLOG,$route);
$this->curlDelRoute(['new_route'=>$route]);
$this->edit(['url'=>$route],['id'=>$id]);
}
$this->addUpdateNotify(RouteMap::SOURCE_BLOG,$route);
$this->curlDelRoute(['new_route'=>$route]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
... ... @@ -53,23 +53,6 @@ class BlogLogic extends BaseLogic
}
/**
* @remark :查看是否编辑路由
* @name :editCategoryRoute
* @author :lyh
* @method :post
* @time :2023/9/7 11:05
*/
public function editNewsRoute($id,$route){
//生成一条删除路由记录
$info = $this->model->read(['id'=>$id],['id','url']);
if($info['url'] != $route){
$this->addUpdateNotify(RouteMap::SOURCE_BLOG,$route);
$this->curlDelRoute(['route'=>$info['url'],'new_route'=>$route]);
}
return true;
}
/**
* @name :编辑seo
* @return void
* @author :liyuhang
... ... @@ -249,7 +232,12 @@ class BlogLogic extends BaseLogic
*/
public function importBlog($project_id, $user_id, $data)
{
$blog = $this->model->read(['name' => $data[0]]);
$route = $data[1]??'';//自定义路由
if($route){
$blog = $this->model->read(['url' => $route]);
}else{
$blog = $this->model->read(['name' => $data[0]]);
}
if (!$blog) {
$category_id = '';
... ... @@ -303,7 +291,22 @@ class BlogLogic extends BaseLogic
]
);
//更新路由
$route = RouteMap::setRoute((isset($data[1]) && $data[1]) ? $data[1] : $data[0], RouteMap::SOURCE_BLOG, $id, $project_id);
if($route){
$route_map = RouteMap::where('project_id', $project_id)->where('source', RouteMap::SOURCE_BLOG)->where('source_id', $id)->first();
if (!$route_map) {
$route_map = new RouteMap();
$route_map->project_id = $project_id;
$route_map->path = RouteMap::SOURCE_BLOG.'s';
$route_map->source = RouteMap::SOURCE_BLOG;
$route_map->source_id = $id;
$route_map->route = $route;
$route_map->save();
}
}else{
$route = RouteMap::setRoute($data[0], RouteMap::SOURCE_BLOG, $id, $project_id);
}
$this->edit(['url' => $route], ['id' => $id]);
return true;
... ...
... ... @@ -32,6 +32,7 @@ class ImportLogic extends BaseLogic
$this->param['project_id'] = $this->user['project_id'];
$this->param['user_id'] = $this->user['id'];
$this->param['status'] = 9;
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error');
... ...
... ... @@ -45,7 +45,7 @@ class NewsCategoryLogic extends BaseLogic
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']);
$this->editCategoryRoute($this->param['id'],$this->param['alias']);
$route = $this->param['alias'];
$this->editHandleCategory($this->param['id'],$this->param['pid']);
$this->param['operator_id'] = $this->user['id'];
$this->edit($this->param,['id'=>$this->param['id']]);
... ... @@ -56,12 +56,12 @@ class NewsCategoryLogic extends BaseLogic
$this->param = $this->addParamProcessing($this->param);
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);
$this->addUpdateNotify(RouteMap::SOURCE_NEWS_CATE,$route);
$this->curlDelRoute(['new_route'=>$route]);
$this->model->edit(['alias'=>$route],['id'=>$id]);
//当父级分类拥有产品时,处理子集
$this->addProcessingSon($id);
}
$this->addUpdateNotify(RouteMap::SOURCE_NEWS_CATE,$route);
$this->curlDelRoute(['new_route'=>$route]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
... ... @@ -112,23 +112,6 @@ class NewsCategoryLogic extends BaseLogic
}
}
/**
* @remark :编辑路由时生成路由记录
* @name :editCategoryRoute
* @author :lyh
* @method :post
* @time :2023/9/7 10:51
*/
public function editCategoryRoute($id,$route){
//生成一条删除路由记录
$info = $this->model->read(['id'=>$id],['id','alias']);
if($info['alias'] != $route){
$this->addUpdateNotify(RouteMap::SOURCE_NEWS_CATE,$route);
$this->curlDelRoute(['route'=>$info['alias'],'new_route'=>$route]);
}
return true;
}
/**
* @remark :修改状态
... ...
... ... @@ -65,15 +65,15 @@ class NewsLogic extends BaseLogic
if (isset($this->param['id']) && !empty($this->param['id'])) {
$this->param['url'] = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']);
//是否更新路由
$this->editNewsRoute($this->param['id'], $this->param['url']);
$route = $this->param['url'];
$this->edit($this->param, ['id' => $this->param['id']]);
} else {
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $id, $this->user['project_id']);
$this->addUpdateNotify(RouteMap::SOURCE_NEWS,$route);
$this->curlDelRoute(['new_route'=>$route]);
$this->edit(['url' => $route], ['id' => $id]);
}
$this->addUpdateNotify(RouteMap::SOURCE_NEWS,$route);
$this->curlDelRoute(['new_route'=>$route]);
//更新路由
DB::commit();
} catch (\Exception $e) {
... ... @@ -84,24 +84,6 @@ class NewsLogic extends BaseLogic
}
/**
* @remark :查看是否编辑路由
* @name :editCategoryRoute
* @author :lyh
* @method :post
* @time :2023/9/7 11:05
*/
public function editNewsRoute($id, $route)
{
//生成一条删除路由记录
$info = $this->model->read(['id' => $id], ['id', 'url']);
if ($info['url'] != $route) {
$this->addUpdateNotify(RouteMap::SOURCE_NEWS,$route);
$this->curlDelRoute(['route'=>$info['url'],'new_route'=>$route]);
}
return true;
}
/**
* @name :编辑seo
* @return void
* @author :liyuhang
... ... @@ -283,7 +265,12 @@ class NewsLogic extends BaseLogic
*/
public function importNews($project_id, $user_id, $data)
{
$news = $this->model->read(['name' => $data[0]]);
$route = $data[1]??'';//自定义路由
if($route){
$news = $this->model->read(['url' => $route]);
}else{
$news = $this->model->read(['name' => $data[0]]);
}
if (!$news) {
$category_id = '';
... ... @@ -337,7 +324,22 @@ class NewsLogic extends BaseLogic
]
);
//更新路由
$route = RouteMap::setRoute((isset($data[1]) && $data[1]) ? $data[1] : $data[0], RouteMap::SOURCE_NEWS, $id, $project_id);
if($route){
$route_map = RouteMap::where('project_id', $project_id)->where('source', RouteMap::SOURCE_NEWS)->where('source_id', $id)->first();
if (!$route_map) {
$route_map = new RouteMap();
$route_map->project_id = $project_id;
$route_map->path = RouteMap::SOURCE_NEWS;
$route_map->source = RouteMap::SOURCE_NEWS;
$route_map->source_id = $id;
$route_map->route = $route;
$route_map->save();
}
}else{
$route = RouteMap::setRoute($data[0], RouteMap::SOURCE_NEWS, $id, $project_id);
}
$this->edit(['url' => $route], ['id' => $id]);
return true;
... ...
... ... @@ -114,7 +114,7 @@ class CategoryLogic extends BaseLogic
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $this->param['id'], $this->user['project_id']);
$this->editCategoryRoute($this->param['id'],$this->param['route']);
$route = $this->param['route'];
//处理子集
$this->editHandleCategory($this->param['id'],$this->param['pid']);
$this->model->edit($this->param,['id'=>$this->param['id']]);
... ... @@ -122,12 +122,12 @@ class CategoryLogic extends BaseLogic
$this->param['project_id'] = $this->user['project_id'];
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_CATE,$route);
$this->curlDelRoute(['new_route'=>$route]);
$this->edit(['route'=>$route],['id'=>$id]);
//处理子集
$this->addProcessingSon($id);
}
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_CATE,$route);
$this->curlDelRoute(['new_route'=>$route]);
//清除缓存
Common::del_user_cache('product_category',$this->user['project_id']);
DB::commit();
... ... @@ -223,23 +223,6 @@ class CategoryLogic extends BaseLogic
}
/**
* @remark :编辑路由时生成路由记录
* @name :editCategoryRoute
* @author :lyh
* @method :post
* @time :2023/9/7 10:51
*/
public function editCategoryRoute($id,$route){
//生成一条删除路由记录
$info = $this->model->read(['id'=>$id],['id','route']);
if($info['route'] != $route){
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_CATE,$route);
$this->curlDelRoute(['route'=>$info['route'],'new_route'=>$route]);
}
return true;
}
/**
* @remark :删除
* @name :delete
* @author :lyh
... ...
... ... @@ -58,15 +58,16 @@ class KeywordLogic extends BaseLogic
if(isset($this->param['id']) && !empty($this->param['id'])){
//TODO::不能修改路由
$this->model->edit($this->param,['id'=>$this->param['id']]);
$route = $this->param['route'];
}else{
$this->param = $this->addHandleParam($this->param);
$id = $this->model->insertGetId($this->param);
//路由映射
$route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_KEYWORD,$route);
$this->curlDelRoute(['new_route'=>$route]);
$this->model->edit(['route'=>$route],['id'=>$id]);
}
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_KEYWORD,$route);
$this->curlDelRoute(['new_route'=>$route]);
//清除缓存
Common::del_user_cache('product_keyword',$this->user['project_id']);
DB::commit();
... ...
... ... @@ -48,18 +48,17 @@ class ProductLogic extends BaseLogic
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']);
//查看路由是否更新
$this->editProductRoute($this->param['id'],$this->param['route']);
$route = $this->param['route'];
$this->model->edit($this->param,['id'=>$this->param['id']]);
$id = $this->param['id'];
}else{
$this->param = $this->addHandleParam($this->param);
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route);
$this->curlDelRoute(['new_route'=>$route]);
$this->model->edit(['route'=>$route],['id'=>$id]);
}
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route);
$this->curlDelRoute(['new_route'=>$route]);
//产品分类关联
CategoryRelated::saveRelated($id, $category_ids);
//保存扩展字段
... ... @@ -332,8 +331,8 @@ class ProductLogic extends BaseLogic
$info = $this->model->read(['id'=>$id]);
if($info['route'] != $route){
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route);
$this->curlDelRoute(['route'=>$info['route'],'new_route'=>$route]);
}
$this->curlDelRoute(['route'=>$info['route'],'new_route'=>$route]);
return $route;
}
... ... @@ -596,7 +595,13 @@ class ProductLogic extends BaseLogic
*/
public function importProduct($project_id, $user_id, $data)
{
$product = $this->model->read(['title' => $data[0]]);
$route = $data[1]??'';//自定义路由
if($route){
$product = $this->model->read(['route' => $route]);
}else{
$product = $this->model->read(['title' => $data[0]]);
}
if (!$product) {
$category_id = '';
... ... @@ -729,8 +734,23 @@ class ProductLogic extends BaseLogic
'status' => Product::STATUS_ON
]
);
//更新路由
$route = RouteMap::setRoute((isset($data[1]) && $data[1]) ? $data[1] : $data[0], RouteMap::SOURCE_PRODUCT, $id, $project_id);
if($route){
$route_map = RouteMap::where('project_id', $project_id)->where('source', RouteMap::SOURCE_PRODUCT)->where('source_id', $id)->first();
if (!$route_map) {
$route_map = new RouteMap();
$route_map->project_id = $project_id;
$route_map->source = RouteMap::SOURCE_PRODUCT;
$route_map->source_id = $id;
$route_map->route = $route;
$route_map->save();
}
}else{
$route = RouteMap::setRoute($data[0], RouteMap::SOURCE_PRODUCT, $id, $project_id);
}
$this->edit(['route' => $route], ['id' => $id]);
return true;
... ...