Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into develop
正在显示
13 个修改的文件
包含
549 行增加
和
123 行删除
| @@ -38,6 +38,7 @@ class ProjectImport extends Command | @@ -38,6 +38,7 @@ class ProjectImport extends Command | ||
| 38 | 38 | ||
| 39 | public function handle() | 39 | public function handle() |
| 40 | { | 40 | { |
| 41 | + ini_set('memory_limit', '512M'); | ||
| 41 | while (true) { | 42 | while (true) { |
| 42 | $this->start_import(); | 43 | $this->start_import(); |
| 43 | } | 44 | } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands\Update; | ||
| 4 | + | ||
| 5 | +use App\Models\Collect\CollectSource; | ||
| 6 | +use App\Models\Collect\CollectTask; | ||
| 7 | +use App\Models\Com\UpdateLog; | ||
| 8 | +use App\Models\RouteMap\RouteMap; | ||
| 9 | +use App\Services\CosService; | ||
| 10 | +use App\Services\ProjectServer; | ||
| 11 | +use Illuminate\Console\Command; | ||
| 12 | +use Illuminate\Support\Facades\DB; | ||
| 13 | +use Illuminate\Support\Facades\Redis; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * 4.0,5.0升级到6.0,主站自定义页面采集 | ||
| 17 | + * Class ProjectImport | ||
| 18 | + * @package App\Console\Commands | ||
| 19 | + * @author Akun | ||
| 20 | + * @date 2023/12/13 14:44 | ||
| 21 | + */ | ||
| 22 | +class HtmlCustomCollect extends Command | ||
| 23 | +{ | ||
| 24 | + /** | ||
| 25 | + * The name and signature of the console command. | ||
| 26 | + * | ||
| 27 | + * @var string | ||
| 28 | + */ | ||
| 29 | + protected $signature = 'project_html_custom_collect'; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * The console command description. | ||
| 33 | + * | ||
| 34 | + * @var string | ||
| 35 | + */ | ||
| 36 | + protected $description = '执行项目自定义html页面采集'; | ||
| 37 | + | ||
| 38 | + | ||
| 39 | + public function handle() | ||
| 40 | + { | ||
| 41 | + ini_set('memory_limit', '512M'); | ||
| 42 | + | ||
| 43 | + $project_id = 633; | ||
| 44 | + $project_site = 'v6-ke5nz.globalso.site'; | ||
| 45 | + $pages = [ | ||
| 46 | + 'https://www.mach-sales.com/case_catalog/cases/', | ||
| 47 | + 'https://www.mach-sales.com/case_catalog/cases/page/2/', | ||
| 48 | + 'https://www.mach-sales.com/case_catalog/cases/page/3/', | ||
| 49 | + 'https://www.mach-sales.com/case/growing-with-customers-from-small-motors-to-big-drivers/', | ||
| 50 | + 'https://www.mach-sales.com/case/growing-together-with-customers-the-journey-of-intelligent-manufacturing-in-a-modernized-factory/', | ||
| 51 | + 'https://www.mach-sales.com/case/%e3%80%90growing-together-with-customers%e3%80%91-the-evolutionary-journey-of-a-baking-brand/', | ||
| 52 | + 'https://www.mach-sales.com/case/sumecs-footprints-in-belt-and-road-singapore/', | ||
| 53 | + 'https://www.mach-sales.com/case/sumecs-footprints-in-belt-and-road-southeast-asia/', | ||
| 54 | + 'https://www.mach-sales.com/case/naming-and-delivery-of-a-new-ship-1/', | ||
| 55 | + 'https://www.mach-sales.com/case/a-newly-signed-contract-cable-manufacturing-equipment/', | ||
| 56 | + 'https://www.mach-sales.com/case/its-amazing-that-the-glass-can-also-save-energy/', | ||
| 57 | + 'https://www.mach-sales.com/case/%e3%80%90grow-with-customers%e3%80%91better-service-for-papermaking-equipment-procurement/', | ||
| 58 | + 'https://www.mach-sales.com/case/expansion-of-blower-equipment-contributes-to-environmental-protection/', | ||
| 59 | + 'https://www.mach-sales.com/case/new-ship-type-new-contract/', | ||
| 60 | + 'https://www.mach-sales.com/case/new-arrival-introducing-the-latest-ship-model/', | ||
| 61 | + 'https://www.mach-sales.com/case/another-contract-signed-in-the-philippines/', | ||
| 62 | + 'https://www.mach-sales.com/case/the-road-to-going-global-is-supported-by-sumec-services/', | ||
| 63 | + 'https://www.mach-sales.com/case/sumec-textile-launches-sun-protection-series-in-collaboration-with-skechers-kids/', | ||
| 64 | + 'https://www.mach-sales.com/case/footwear-manufacturing-equipment-new-contract/', | ||
| 65 | + 'https://www.mach-sales.com/case/sumec-energy-company-has-successfully-signed-a-photovoltaic-component-supply-agreement-with-wattkraft-a-german-engineering-system-integrator/', | ||
| 66 | + 'https://www.mach-sales.com/case/sumec-technology-company-successfully-signed-a-contract-for-the-equipment-related-to-the-high-strength-particleboard-project/', | ||
| 67 | + 'https://www.mach-sales.com/case/%e3%80%90growing-together-with-our-customers%e3%80%91together-on-the-road-to-transformation/', | ||
| 68 | + 'https://www.mach-sales.com/case/new-signing/', | ||
| 69 | + 'https://www.mach-sales.com/case/complete-the-last-mile-equipment-procurement-from-around-the-world/', | ||
| 70 | + 'https://www.mach-sales.com/case/science-and-technology-to-rejuvenate-agriculture-this-plant-factory-is-not-simple/', | ||
| 71 | + 'https://www.mach-sales.com/case/new-cooperation-high-end-equipment-going-global/', | ||
| 72 | + 'https://www.mach-sales.com/case/a-new-cooperation-with-an-annual-output-of-40000-tons/', | ||
| 73 | + 'https://www.mach-sales.com/case/a-new-contract-cooperation-upgrades/', | ||
| 74 | + 'https://www.mach-sales.com/case/annual-output-of-50000-tons-this-bopp-film-production-line-was-officially-put-into-operation/', | ||
| 75 | + 'https://www.mach-sales.com/case/this-is-sumec-speed/', | ||
| 76 | + 'https://www.mach-sales.com/case/the-first-order-of-a-new-semiconductor-brand-equipment-direct-sales-bear-fruit-again/', | ||
| 77 | + 'https://www.mach-sales.com/case/sumec-touch-world-celebrates-its-5th-anniversary-with-well-known-suppliers/', | ||
| 78 | + 'https://www.mach-sales.com/case/from-traditional-agency-to-digital-service/', | ||
| 79 | + 'https://www.mach-sales.com/case/cooperation-win-win-and-starting-anew-sumec-creates-a-new-sample-of-strong-enterprise-cooperation/' | ||
| 80 | + ]; | ||
| 81 | + | ||
| 82 | +// $project_id = 437; | ||
| 83 | +// $project_site = 'v6-1500k.globalso.site'; | ||
| 84 | +// $pages = [ | ||
| 85 | +// 'https://www.tourletent.com/project/b300-glamping-tent-in-china/', | ||
| 86 | +// 'https://www.tourletent.com/project/lotus-bell-tent-in-australia/', | ||
| 87 | +// 'https://www.tourletent.com/project/luxury-resort-in-china/', | ||
| 88 | +// 'https://www.tourletent.com/project/canvas-safari-tent-inthailand/', | ||
| 89 | +// 'https://www.tourletent.com/project/safari-tent-for-m8-in-mexcio/', | ||
| 90 | +// 'https://www.tourletent.com/project/9m-pvc-dome-tent-in-canada/', | ||
| 91 | +// 'https://www.tourletent.com/project/c900-hotel-tent-in-korea/', | ||
| 92 | +// 'https://www.tourletent.com/project/safari-tent-in-guizhou/', | ||
| 93 | +// 'https://www.tourletent.com/project/dome-tent-in-austin/', | ||
| 94 | +// 'https://www.tourletent.com/project/safari-tent-in-italy/', | ||
| 95 | +// 'https://www.tourletent.com/project/glass-igloo-in-china/', | ||
| 96 | +// 'https://www.tourletent.com/project/tree-house-in-sichuan/' | ||
| 97 | +// ]; | ||
| 98 | + | ||
| 99 | +// $project_id = 626; | ||
| 100 | +// $project_site = 'v6-m342g.globalso.site'; | ||
| 101 | +// $pages = [ | ||
| 102 | +// 'https://www.lecusostreetlight.com/project_catalog/project/', | ||
| 103 | +// 'https://www.lecusostreetlight.com/project_catalog/project/page/2/', | ||
| 104 | +// 'https://www.lecusostreetlight.com/project/560pcs-250w-smart-led-street-light-in-manila-city-philippines/', | ||
| 105 | +// 'https://www.lecusostreetlight.com/project/3200pcs-8m-150w-solar-street-light-in-cebu-philippines/', | ||
| 106 | +// 'https://lecusostreetlight.com/project/170pcs-100w-split-lithium-battery-solar-street-light-in-tanzania/', | ||
| 107 | +// 'https://www.lecusostreetlight.com/project/250pcs-40w-sl-series-solar-street-light-in-kuwait/', | ||
| 108 | +// 'https://www.lecusostreetlight.com/project/272pcs-8m-80w-solar-street-light-in-tanzania/', | ||
| 109 | +// 'https://www.lecusostreetlight.com/project/185pcs-10m-120w-highway-solar-street-light-in-jordan/', | ||
| 110 | +// 'https://www.lecusostreetlight.com/project/270pcs-9m-patterned-decorative-light-pole-with-150w-led-cobra-light-in-cambodia/', | ||
| 111 | +// 'https://www.lecusostreetlight.com/project/48pcs-5m-24w-decorative-aluminium-pole-in-dubai-uae/', | ||
| 112 | +// 'https://www.lecusostreetlight.com/project/105pcs-9m-100w-led-street-light-in-sri-lanka/', | ||
| 113 | +// 'https://www.lecusostreetlight.com/project/45pcs-6m-hot-dip-galvanized-double-arm-street-light-pole-in-dubai-uae/', | ||
| 114 | +// 'https://www.lecusostreetlight.com/project/356pcs-8m-100w-solar-street-light-in-ethiopia/', | ||
| 115 | +// 'https://www.lecusostreetlight.com/project/52pcs-6m-30w-solar-led-street-light-with-gel-battery-in-poland/', | ||
| 116 | +// 'https://www.lecusostreetlight.com/project/225pcs-6m-80w-solar-street-light-in-vietnam/', | ||
| 117 | +// 'https://www.lecusostreetlight.com/project/450pcs-7m-60w-double-arm-solar-light-in-nigeria/', | ||
| 118 | +// 'https://www.lecusostreetlight.com/project/100pcs-6m-50w-led-street-light-in-maldives/', | ||
| 119 | +// 'https://www.lecusostreetlight.com/project/202pcs-6m-40w-3000k-solar-street-light-in-manila-philippines/', | ||
| 120 | +// 'https://www.lecusostreetlight.com/project/245pcs-120w-smart-led-street-light-in-bangkok-thailand/', | ||
| 121 | +// 'https://www.lecusostreetlight.com/project/170pcs-7m-50w-all-in-one-solar-light-in-davao-philippines/', | ||
| 122 | +// 'https://www.lecusostreetlight.com/project/80pcs-9m-150w-led-street-light-in-iraq/', | ||
| 123 | +// 'https://www.lecusostreetlight.com/project/252pcs-6m-40w-separate-solar-street-light-with-lithium-battery-in-thailand/', | ||
| 124 | +// 'https://www.lecusostreetlight.com/project/198pcs-8m-80w-zc-series-all-in-two-solar-light-in-philippines/', | ||
| 125 | +// 'https://www.lecusostreetlight.com/project/5m-30w-morden-led-garden-light-in-russian/', | ||
| 126 | +// 'https://www.lecusostreetlight.com/project/135pcs-all-in-one-solar-street-light-in-uae-dubai-park/' | ||
| 127 | +// ]; | ||
| 128 | + | ||
| 129 | + foreach ($pages as $page) { | ||
| 130 | + $this->start_collect(urldecode($page), $project_id, $project_site); | ||
| 131 | + } | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + protected function start_collect($page, $project_id, $project_site) | ||
| 135 | + { | ||
| 136 | + $page_arr = parse_url($page); | ||
| 137 | + $domain = $page_arr['host']; | ||
| 138 | + $path = $page_arr['path']; | ||
| 139 | + | ||
| 140 | + //设置数据库 | ||
| 141 | + $project = ProjectServer::useProject($project_id); | ||
| 142 | + if ($project) { | ||
| 143 | + echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', page: ' . $page . ', collect start' . PHP_EOL; | ||
| 144 | + | ||
| 145 | + //获取站点原始域名信息 | ||
| 146 | + $old_info = getOldDomain($project_id, $domain); | ||
| 147 | + | ||
| 148 | + //采集html页面,下载资源到本地并替换 | ||
| 149 | + try { | ||
| 150 | + $html = curl_c($page, false); | ||
| 151 | + if ($html == '0') { | ||
| 152 | + echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', page: ' . $page . ', error: no html' . PHP_EOL; | ||
| 153 | + sleep(2); | ||
| 154 | + return true; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + //如果有base64图片,先替换掉,再进行资源匹配 | ||
| 158 | + $new_html = $html; | ||
| 159 | + preg_match_all("/data:([^;]*);base64,(.*)?\"/", $new_html, $result_img); | ||
| 160 | + $img_base64 = $result_img[2] ?? []; | ||
| 161 | + foreach ($img_base64 as $v64) { | ||
| 162 | + $new_html = str_replace($v64, '', $new_html); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + //匹配资源链接 | ||
| 166 | + $source_list = $this->html_preg($new_html, $project_id, $domain, $old_info['web_url_domain'], $old_info['home_url']); | ||
| 167 | + | ||
| 168 | + //下载资源 | ||
| 169 | + if ($source_list) { | ||
| 170 | + $html = $this->upload_source($html, $source_list, $project_id, $domain, $old_info['web_url_domain'], $old_info['home_url']); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + //替换域名 | ||
| 174 | + $html = str_replace($old_info['web_url_domain'], $project_site, $html); | ||
| 175 | + $html = str_replace($old_info['home_url'], $project_site, $html); | ||
| 176 | + | ||
| 177 | + //暂时隐藏小语种 | ||
| 178 | + $html = str_replace('<div class="change-language ensemble">', '<div class="change-language ensemble" style="display: none">', $html); | ||
| 179 | + $html = str_replace('<div class="language_more">', '<div class="language_more" style="display: none">', $html); | ||
| 180 | + $html = str_replace('</body>', '<script src="https://ecdn6.globalso.com/public/customerVisit.min.js\"></script></body>', $html); | ||
| 181 | + | ||
| 182 | + //html写入文件 | ||
| 183 | + $file_path = '/www/wwwroot/globalso-v6-c-glo/public/' . $project_site . $path; | ||
| 184 | + if (!file_exists($file_path)) { | ||
| 185 | + mkdir($file_path, 0777, true); | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + file_put_contents($file_path . 'index.html', $html); | ||
| 189 | + chmod($file_path . 'index.html', 0777); | ||
| 190 | + | ||
| 191 | + } catch (\Exception $e) { | ||
| 192 | + echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', page: ' . $page . ', error: ' . $e->getMessage() . PHP_EOL; | ||
| 193 | + sleep(2); | ||
| 194 | + return true; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + | ||
| 198 | + echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', page: ' . $page . ', collect end' . PHP_EOL; | ||
| 199 | + } else { | ||
| 200 | + echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', page: ' . $page . ', no project' . PHP_EOL; | ||
| 201 | + } | ||
| 202 | + //关闭数据库 | ||
| 203 | + DB::disconnect('custom_mysql'); | ||
| 204 | + | ||
| 205 | + sleep(2); | ||
| 206 | + return true; | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + //正则匹配html资源 | ||
| 210 | + protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url) | ||
| 211 | + { | ||
| 212 | + $source = []; | ||
| 213 | + | ||
| 214 | + if (!$html) { | ||
| 215 | + return $source; | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + //image | ||
| 219 | + preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_img); | ||
| 220 | + $img = $result_img[2] ?? []; | ||
| 221 | + foreach ($img as $vi) { | ||
| 222 | + $check_vi = $this->url_check($vi, $project_id, $domain, $web_url_domain, $home_url); | ||
| 223 | + $check_vi && $source[] = $check_vi; | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + //js | ||
| 227 | + preg_match_all('/<script\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_js); | ||
| 228 | + $js = $result_js[2] ?? []; | ||
| 229 | + foreach ($js as $vj) { | ||
| 230 | + $check_vj = $this->url_check($vj, $project_id, $domain, $web_url_domain, $home_url); | ||
| 231 | + $check_vj && $source[] = $check_vj; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + //video | ||
| 235 | + preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_video); | ||
| 236 | + $video = $result_video[2] ?? []; | ||
| 237 | + foreach ($video as $vv) { | ||
| 238 | + $check_vv = $this->url_check($vv, $project_id, $domain, $web_url_domain, $home_url); | ||
| 239 | + $check_vv && $source[] = $check_vv; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + //css | ||
| 243 | + preg_match_all('/<link\s+[^>]*?href\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_css); | ||
| 244 | + $css = $result_css[2] ?? []; | ||
| 245 | + foreach ($css as $vc) { | ||
| 246 | + $check_vc = $this->url_check($vc, $project_id, $domain, $web_url_domain, $home_url); | ||
| 247 | + $check_vc && $source[] = $check_vc; | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + //css background | ||
| 251 | + preg_match_all("/url\(['\"]?(\s*[^>]+?)['\"]?\)/i", $html, $result_css_b); | ||
| 252 | + $css_b = $result_css_b[1] ?? []; | ||
| 253 | + foreach ($css_b as $vc_b) { | ||
| 254 | + $check_vc_b = $this->url_check($vc_b, $project_id, $domain, $web_url_domain, $home_url); | ||
| 255 | + $check_vc_b && $source[] = $check_vc_b; | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + //a标签下载资源 | ||
| 259 | + preg_match_all('/<a\s+[^>]*?href\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_a); | ||
| 260 | + $down = $result_a[2] ?? []; | ||
| 261 | + foreach ($down as $vd) { | ||
| 262 | + $check_vd = $this->url_check($vd, $project_id, $domain, $web_url_domain, $home_url); | ||
| 263 | + $check_vd && $source[] = $check_vd; | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + return $source; | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + //判断资源是否需要下载 | ||
| 270 | + protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url) | ||
| 271 | + { | ||
| 272 | + if ($url) { | ||
| 273 | + $url = str_replace('"', '', $url); | ||
| 274 | + $arr = parse_url($url); | ||
| 275 | + $scheme = $arr['scheme'] ?? ''; | ||
| 276 | + $host = $arr['host'] ?? ''; | ||
| 277 | + $path = $arr['path'] ?? ''; | ||
| 278 | + $query = $arr['query'] ?? ''; | ||
| 279 | + | ||
| 280 | + $path_arr = explode('.', $path); | ||
| 281 | + if ( | ||
| 282 | + (empty($scheme) || $scheme == 'https' || $scheme == 'http') | ||
| 283 | + && (empty($host) || (strpos($web_url_domain, $host) !== false) || (strpos($home_url, $host) !== false)) | ||
| 284 | + && $path | ||
| 285 | + && (substr($path, 0, 1) == '/') | ||
| 286 | + && (strpos($path, '.') !== false) | ||
| 287 | + && (!in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) | ||
| 288 | + ) { | ||
| 289 | + $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first(); | ||
| 290 | + if (!$source) { | ||
| 291 | + return [ | ||
| 292 | + 'download' => true, | ||
| 293 | + 'url' => $url, | ||
| 294 | + 'url_complete' => ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path . ($query ? '?' . $query : '') | ||
| 295 | + ]; | ||
| 296 | + } else { | ||
| 297 | + return [ | ||
| 298 | + 'download' => false, | ||
| 299 | + 'url' => $url, | ||
| 300 | + 'url_complete' => $source['target'] | ||
| 301 | + ]; | ||
| 302 | + } | ||
| 303 | + } else { | ||
| 304 | + return false; | ||
| 305 | + } | ||
| 306 | + } else { | ||
| 307 | + return false; | ||
| 308 | + } | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + //下载并替换资源 | ||
| 312 | + protected function upload_source($html, $source, $project_id, $domain, $web_url_domain, $home_url) | ||
| 313 | + { | ||
| 314 | + foreach ($source as $vs) { | ||
| 315 | + | ||
| 316 | + if ($vs['download']) { | ||
| 317 | + $new_source = CosService::uploadRemote($project_id, 'source', $vs['url_complete']); | ||
| 318 | + if ($new_source) { | ||
| 319 | + CollectSource::insert([ | ||
| 320 | + 'project_id' => $project_id, | ||
| 321 | + 'origin' => $vs['url'], | ||
| 322 | + 'target' => $new_source, | ||
| 323 | + 'created_at' => date('Y-m-d H:i:s'), | ||
| 324 | + 'updated_at' => date('Y-m-d H:i:s'), | ||
| 325 | + ]); | ||
| 326 | + $html = str_replace($vs['url'], getImageUrl($new_source), $html); | ||
| 327 | + | ||
| 328 | + if (substr($new_source, -3, 3) == 'css' || substr($new_source, -2, 2) == 'js') { | ||
| 329 | + | ||
| 330 | + $source_html = curl_c(getImageUrl($new_source), false); | ||
| 331 | + | ||
| 332 | + if (substr($new_source, -3, 3) == 'css') { | ||
| 333 | + preg_match_all("/url\(['\"]?(\s*[^>]+?)['\"]?\)/i", $source_html, $result_source); | ||
| 334 | + } else { | ||
| 335 | + preg_match_all("/[large|thumb]+URL:['\"]+(\s*[^>]+?)['\"]+,/i", $source_html, $result_source); | ||
| 336 | + } | ||
| 337 | + | ||
| 338 | + $js_css_source = $result_source[1] ?? []; | ||
| 339 | + if ($js_css_source) { | ||
| 340 | + foreach ($js_css_source as $vjs) { | ||
| 341 | + $vjs_down = str_replace('"', '', $vjs); | ||
| 342 | + if (strpos($vjs_down, 'data:') !== false) { | ||
| 343 | + //过滤二进制文件 | ||
| 344 | + continue; | ||
| 345 | + } | ||
| 346 | + if (strlen($vjs_down) > 255) { | ||
| 347 | + //过滤太长文件 | ||
| 348 | + continue; | ||
| 349 | + } | ||
| 350 | + | ||
| 351 | + $vjs_down_arr = parse_url($vjs_down); | ||
| 352 | + $vjs_down_host = $vjs_down_arr['host'] ?? ''; | ||
| 353 | + | ||
| 354 | + $cos = config('filesystems.disks.cos'); | ||
| 355 | + $cosCdn = $cos['cdn']; | ||
| 356 | + | ||
| 357 | + if ($vjs_down_host && $vjs_down_host == $cosCdn) { | ||
| 358 | + //过滤已经下载的 | ||
| 359 | + continue; | ||
| 360 | + } | ||
| 361 | + | ||
| 362 | + if (empty($vjs_down_host) && substr($vjs_down, 0, 1) != '/') { | ||
| 363 | + //相对路径 | ||
| 364 | + $url_arr = explode('/', $vs['url']); | ||
| 365 | + $url_arr[count($url_arr) - 1] = $vjs_down; | ||
| 366 | + $vjs_down = implode('/', $url_arr); | ||
| 367 | + } | ||
| 368 | + | ||
| 369 | + $vjs_result = $this->url_check($vjs_down, $project_id, $domain, $web_url_domain, $home_url); | ||
| 370 | + if (!$vjs_result) { | ||
| 371 | + continue; | ||
| 372 | + } | ||
| 373 | + | ||
| 374 | + if ($vjs_result['download']) { | ||
| 375 | + $new_vjs = CosService::uploadRemote($project_id, 'source', $vjs_result['url_complete']); | ||
| 376 | + if ($new_vjs) { | ||
| 377 | + CollectSource::insert([ | ||
| 378 | + 'project_id' => $project_id, | ||
| 379 | + 'origin' => $vjs_result['url'], | ||
| 380 | + 'target' => $new_vjs, | ||
| 381 | + 'created_at' => date('Y-m-d H:i:s'), | ||
| 382 | + 'updated_at' => date('Y-m-d H:i:s'), | ||
| 383 | + ]); | ||
| 384 | + $source_html = str_replace($vjs, getImageUrl($new_vjs), $source_html); | ||
| 385 | + } | ||
| 386 | + } else { | ||
| 387 | + $source_html = str_replace($vjs, getImageUrl($vjs_result['url_complete']), $source_html); | ||
| 388 | + } | ||
| 389 | + } | ||
| 390 | + | ||
| 391 | + CosService::uploadRemote($project_id, 'source', $new_source, $new_source, $source_html); | ||
| 392 | + } | ||
| 393 | + } | ||
| 394 | + } | ||
| 395 | + } else { | ||
| 396 | + $html = str_replace($vs['url'], getImageUrl($vs['url_complete']), $html); | ||
| 397 | + } | ||
| 398 | + } | ||
| 399 | + | ||
| 400 | + return $html; | ||
| 401 | + } | ||
| 402 | +} |
app/Console/Commands/Update/ProjectReset.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands\Update; | ||
| 4 | + | ||
| 5 | +use App\Models\Com\UpdateLog; | ||
| 6 | +use App\Services\ProjectServer; | ||
| 7 | +use Illuminate\Console\Command; | ||
| 8 | +use Illuminate\Support\Facades\DB; | ||
| 9 | + | ||
| 10 | +class ProjectReset extends Command | ||
| 11 | +{ | ||
| 12 | + /** | ||
| 13 | + * The name and signature of the console command. | ||
| 14 | + * | ||
| 15 | + * @var string | ||
| 16 | + */ | ||
| 17 | + protected $signature = 'project_reset {project_id}'; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * The console command description. | ||
| 21 | + * | ||
| 22 | + * @var string | ||
| 23 | + */ | ||
| 24 | + protected $description = '项目采集重置'; | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + public function handle() | ||
| 28 | + { | ||
| 29 | + $project_id = $this->argument('project_id'); | ||
| 30 | + | ||
| 31 | + $project = ProjectServer::useProject($project_id); | ||
| 32 | + if ($project) { | ||
| 33 | + try { | ||
| 34 | + DB::connection('custom_mysql')->statement("DELETE FROM `gl_collect_source` WHERE `origin` LIKE '%.css%' OR `origin` LIKE '%.js%'"); | ||
| 35 | + DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0"); | ||
| 36 | + } catch (\Exception $e) { | ||
| 37 | + echo $project_id . ',重置失败' . PHP_EOL; | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + //关闭数据库 | ||
| 41 | + DB::disconnect('custom_mysql'); | ||
| 42 | + | ||
| 43 | + UpdateLog::where('project_id', $project_id)->whereIn('api_type', ['post', 'page', 'news', 'blog'])->update(['collect_status' => 0]); | ||
| 44 | + | ||
| 45 | + echo $project_id . ',重置成功' . PHP_EOL; | ||
| 46 | + } | ||
| 47 | +} |
| @@ -452,7 +452,7 @@ class ProjectUpdate extends Command | @@ -452,7 +452,7 @@ class ProjectUpdate extends Command | ||
| 452 | return $task_id; | 452 | return $task_id; |
| 453 | } | 453 | } |
| 454 | 454 | ||
| 455 | - $task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(8)->get(); | 455 | + $task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('sort', 'asc')->orderBy('project_id', 'asc')->limit(20)->get(); |
| 456 | if ($task_list->count() == 0) { | 456 | if ($task_list->count() == 0) { |
| 457 | return false; | 457 | return false; |
| 458 | } | 458 | } |
| @@ -527,18 +527,20 @@ class ProjectUpdate extends Command | @@ -527,18 +527,20 @@ class ProjectUpdate extends Command | ||
| 527 | { | 527 | { |
| 528 | $model = new NewsCategory(); | 528 | $model = new NewsCategory(); |
| 529 | foreach ($items as $item) { | 529 | foreach ($items as $item) { |
| 530 | - $item['name'] = $this->special2str($item['name'] ?? ''); | ||
| 531 | - if ($item['name']) { | ||
| 532 | - $parent = $model->read(['pid' => $pid, 'name' => $item['name']], 'id'); | 530 | + $route = $this->get_url_route($item['url'] ?? ''); |
| 531 | + if ($route) { | ||
| 532 | + $parent = $model->read(['pid' => $pid, 'alias' => $route], 'id'); | ||
| 533 | if (!$parent) { | 533 | if (!$parent) { |
| 534 | try { | 534 | try { |
| 535 | + $item['name'] = $this->special2str($item['name'] ?? ''); | ||
| 535 | $parent_id = $model->addReturnId([ | 536 | $parent_id = $model->addReturnId([ |
| 536 | 'project_id' => $project_id, | 537 | 'project_id' => $project_id, |
| 537 | 'name' => $item['name'], | 538 | 'name' => $item['name'], |
| 538 | 'pid' => $pid, | 539 | 'pid' => $pid, |
| 539 | - 'original_id' => $item['id'] | 540 | + 'original_id' => $item['id'], |
| 541 | + 'alias' => $route | ||
| 540 | ]); | 542 | ]); |
| 541 | - $this->set_map($this->get_url_route($item['url'] ?? ''), RouteMap::SOURCE_NEWS_CATE, $parent_id, $project_id); | 543 | + $this->set_map($route, RouteMap::SOURCE_NEWS_CATE, $parent_id, $project_id); |
| 542 | } catch (\Exception $e) { | 544 | } catch (\Exception $e) { |
| 543 | echo 'date:' . date('Y-m-d H:i:s') . ', category_news_insert error: ' . $e->getMessage() . PHP_EOL; | 545 | echo 'date:' . date('Y-m-d H:i:s') . ', category_news_insert error: ' . $e->getMessage() . PHP_EOL; |
| 544 | continue; | 546 | continue; |
| @@ -592,7 +594,7 @@ class ProjectUpdate extends Command | @@ -592,7 +594,7 @@ class ProjectUpdate extends Command | ||
| 592 | if ($source == RouteMap::SOURCE_NEWS) { | 594 | if ($source == RouteMap::SOURCE_NEWS) { |
| 593 | $route_map->path = RouteMap::SOURCE_NEWS; | 595 | $route_map->path = RouteMap::SOURCE_NEWS; |
| 594 | } elseif ($source == RouteMap::SOURCE_BLOG) { | 596 | } elseif ($source == RouteMap::SOURCE_BLOG) { |
| 595 | - $route_map->path = RouteMap::SOURCE_BLOG; | 597 | + $route_map->path = RouteMap::SOURCE_BLOG.'s'; |
| 596 | } | 598 | } |
| 597 | 599 | ||
| 598 | $route_map->save(); | 600 | $route_map->save(); |
| @@ -199,8 +199,6 @@ class ProofreadingController extends BaseController | @@ -199,8 +199,6 @@ class ProofreadingController extends BaseController | ||
| 199 | $strippedContent = preg_replace($pattern, '', $strippedContent); // 删除`<script>`标签及其内容 | 199 | $strippedContent = preg_replace($pattern, '', $strippedContent); // 删除`<script>`标签及其内容 |
| 200 | $pattern = '/<link\b[^>]*>/'; // 定义匹配 `<link>` 标签的正则表达式 | 200 | $pattern = '/<link\b[^>]*>/'; // 定义匹配 `<link>` 标签的正则表达式 |
| 201 | $strippedContent = preg_replace($pattern, '', $strippedContent); // 删除 `<link>` 标签 | 201 | $strippedContent = preg_replace($pattern, '', $strippedContent); // 删除 `<link>` 标签 |
| 202 | - $pattern = '/<footer\b[^>]*>(.*?)<\/footer>/s'; // 定义匹配`<script>`标签及其内容的正则表达式 | ||
| 203 | - $strippedContent = preg_replace($pattern, '', $strippedContent); // 删除`<script>`标签及其内容 | ||
| 204 | $pattern = '/>([^<]+)</'; // 定义匹配中间内容不是标签的正则表达式 | 202 | $pattern = '/>([^<]+)</'; // 定义匹配中间内容不是标签的正则表达式 |
| 205 | $matches = array(); | 203 | $matches = array(); |
| 206 | preg_match_all($pattern, $strippedContent, $matches); | 204 | preg_match_all($pattern, $strippedContent, $matches); |
| @@ -33,7 +33,7 @@ class BlogCategoryLogic extends BaseLogic | @@ -33,7 +33,7 @@ class BlogCategoryLogic extends BaseLogic | ||
| 33 | try { | 33 | try { |
| 34 | if(isset($this->param['id']) && !empty($this->param['id'])){ | 34 | if(isset($this->param['id']) && !empty($this->param['id'])){ |
| 35 | $this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']); | 35 | $this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']); |
| 36 | - $this->editCategoryRoute($this->param['id'], $this->param['alias']); | 36 | + $route = $this->param['alias']; |
| 37 | $this->editHandleCategory($this->param['id'],$this->param['pid']); | 37 | $this->editHandleCategory($this->param['id'],$this->param['pid']); |
| 38 | $this->param['operator_id'] = $this->user['id']; | 38 | $this->param['operator_id'] = $this->user['id']; |
| 39 | $this->edit($this->param,['id'=>$this->param['id']]); | 39 | $this->edit($this->param,['id'=>$this->param['id']]); |
| @@ -46,12 +46,12 @@ class BlogCategoryLogic extends BaseLogic | @@ -46,12 +46,12 @@ class BlogCategoryLogic extends BaseLogic | ||
| 46 | $this->param = $this->addParamProcessing($this->param); | 46 | $this->param = $this->addParamProcessing($this->param); |
| 47 | $id = $this->model->addReturnId($this->param); | 47 | $id = $this->model->addReturnId($this->param); |
| 48 | $route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']); | 48 | $route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']); |
| 49 | - $this->addUpdateNotify(RouteMap::SOURCE_BLOG_CATE,$route); | ||
| 50 | - $this->curlDelRoute(['new_route'=>$route]); | ||
| 51 | $this->edit(['alias'=>$route],['id'=>$id]); | 49 | $this->edit(['alias'=>$route],['id'=>$id]); |
| 52 | //处理子集 | 50 | //处理子集 |
| 53 | $this->addProcessingSon($id); | 51 | $this->addProcessingSon($id); |
| 54 | } | 52 | } |
| 53 | + $this->addUpdateNotify(RouteMap::SOURCE_BLOG_CATE,$route); | ||
| 54 | + $this->curlDelRoute(['new_route'=>$route]); | ||
| 55 | DB::commit(); | 55 | DB::commit(); |
| 56 | }catch (\Exception $e){ | 56 | }catch (\Exception $e){ |
| 57 | DB::rollBack(); | 57 | DB::rollBack(); |
| @@ -103,23 +103,6 @@ class BlogCategoryLogic extends BaseLogic | @@ -103,23 +103,6 @@ class BlogCategoryLogic extends BaseLogic | ||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | /** | 105 | /** |
| 106 | - * @remark :编辑路由时生成路由记录 | ||
| 107 | - * @name :editCategoryRoute | ||
| 108 | - * @author :lyh | ||
| 109 | - * @method :post | ||
| 110 | - * @time :2023/9/7 10:51 | ||
| 111 | - */ | ||
| 112 | - public function editCategoryRoute($id,$route){ | ||
| 113 | - //生成一条删除路由记录 | ||
| 114 | - $info = $this->model->read(['id'=>$id],['id','alias']); | ||
| 115 | - if($info['alias'] != $route){ | ||
| 116 | - $this->addUpdateNotify(RouteMap::SOURCE_BLOG_CATE,$route); | ||
| 117 | - $this->curlDelRoute(['route'=>$info['alias'],'new_route'=>$route]); | ||
| 118 | - } | ||
| 119 | - return true; | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | - /** | ||
| 123 | * @name :详情 | 106 | * @name :详情 |
| 124 | * @return array | 107 | * @return array |
| 125 | * @author :liyuhang | 108 | * @author :liyuhang |
| @@ -35,15 +35,15 @@ class BlogLogic extends BaseLogic | @@ -35,15 +35,15 @@ class BlogLogic extends BaseLogic | ||
| 35 | $this->param = $this->paramProcessing($this->param); | 35 | $this->param = $this->paramProcessing($this->param); |
| 36 | if(isset($this->param['id']) && !empty($this->param['id'])){ | 36 | if(isset($this->param['id']) && !empty($this->param['id'])){ |
| 37 | $this->param['url'] = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']); | 37 | $this->param['url'] = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']); |
| 38 | - $this->editNewsRoute($this->param['id'],$this->param['url']); | 38 | + $route = $this->param['url']; |
| 39 | $this->edit($this->param,['id'=>$this->param['id']]); | 39 | $this->edit($this->param,['id'=>$this->param['id']]); |
| 40 | }else{ | 40 | }else{ |
| 41 | $id = $this->model->addReturnId($this->param); | 41 | $id = $this->model->addReturnId($this->param); |
| 42 | $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']); | 42 | $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']); |
| 43 | - $this->addUpdateNotify(RouteMap::SOURCE_BLOG,$route); | ||
| 44 | - $this->curlDelRoute(['new_route'=>$route]); | ||
| 45 | $this->edit(['url'=>$route],['id'=>$id]); | 43 | $this->edit(['url'=>$route],['id'=>$id]); |
| 46 | } | 44 | } |
| 45 | + $this->addUpdateNotify(RouteMap::SOURCE_BLOG,$route); | ||
| 46 | + $this->curlDelRoute(['new_route'=>$route]); | ||
| 47 | DB::commit(); | 47 | DB::commit(); |
| 48 | }catch (\Exception $e){ | 48 | }catch (\Exception $e){ |
| 49 | DB::rollBack(); | 49 | DB::rollBack(); |
| @@ -53,23 +53,6 @@ class BlogLogic extends BaseLogic | @@ -53,23 +53,6 @@ class BlogLogic extends BaseLogic | ||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | /** | 55 | /** |
| 56 | - * @remark :查看是否编辑路由 | ||
| 57 | - * @name :editCategoryRoute | ||
| 58 | - * @author :lyh | ||
| 59 | - * @method :post | ||
| 60 | - * @time :2023/9/7 11:05 | ||
| 61 | - */ | ||
| 62 | - public function editNewsRoute($id,$route){ | ||
| 63 | - //生成一条删除路由记录 | ||
| 64 | - $info = $this->model->read(['id'=>$id],['id','url']); | ||
| 65 | - if($info['url'] != $route){ | ||
| 66 | - $this->addUpdateNotify(RouteMap::SOURCE_BLOG,$route); | ||
| 67 | - $this->curlDelRoute(['route'=>$info['url'],'new_route'=>$route]); | ||
| 68 | - } | ||
| 69 | - return true; | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - /** | ||
| 73 | * @name :编辑seo | 56 | * @name :编辑seo |
| 74 | * @return void | 57 | * @return void |
| 75 | * @author :liyuhang | 58 | * @author :liyuhang |
| @@ -249,7 +232,12 @@ class BlogLogic extends BaseLogic | @@ -249,7 +232,12 @@ class BlogLogic extends BaseLogic | ||
| 249 | */ | 232 | */ |
| 250 | public function importBlog($project_id, $user_id, $data) | 233 | public function importBlog($project_id, $user_id, $data) |
| 251 | { | 234 | { |
| 252 | - $blog = $this->model->read(['name' => $data[0]]); | 235 | + $route = $data[1]??'';//自定义路由 |
| 236 | + if($route){ | ||
| 237 | + $blog = $this->model->read(['url' => $route]); | ||
| 238 | + }else{ | ||
| 239 | + $blog = $this->model->read(['name' => $data[0]]); | ||
| 240 | + } | ||
| 253 | if (!$blog) { | 241 | if (!$blog) { |
| 254 | 242 | ||
| 255 | $category_id = ''; | 243 | $category_id = ''; |
| @@ -303,7 +291,22 @@ class BlogLogic extends BaseLogic | @@ -303,7 +291,22 @@ class BlogLogic extends BaseLogic | ||
| 303 | ] | 291 | ] |
| 304 | ); | 292 | ); |
| 305 | //更新路由 | 293 | //更新路由 |
| 306 | - $route = RouteMap::setRoute((isset($data[1]) && $data[1]) ? $data[1] : $data[0], RouteMap::SOURCE_BLOG, $id, $project_id); | 294 | + if($route){ |
| 295 | + $route_map = RouteMap::where('project_id', $project_id)->where('source', RouteMap::SOURCE_BLOG)->where('source_id', $id)->first(); | ||
| 296 | + if (!$route_map) { | ||
| 297 | + $route_map = new RouteMap(); | ||
| 298 | + $route_map->project_id = $project_id; | ||
| 299 | + $route_map->path = RouteMap::SOURCE_BLOG.'s'; | ||
| 300 | + $route_map->source = RouteMap::SOURCE_BLOG; | ||
| 301 | + $route_map->source_id = $id; | ||
| 302 | + $route_map->route = $route; | ||
| 303 | + | ||
| 304 | + $route_map->save(); | ||
| 305 | + } | ||
| 306 | + }else{ | ||
| 307 | + $route = RouteMap::setRoute($data[0], RouteMap::SOURCE_BLOG, $id, $project_id); | ||
| 308 | + } | ||
| 309 | + | ||
| 307 | $this->edit(['url' => $route], ['id' => $id]); | 310 | $this->edit(['url' => $route], ['id' => $id]); |
| 308 | 311 | ||
| 309 | return true; | 312 | return true; |
| @@ -32,6 +32,7 @@ class ImportLogic extends BaseLogic | @@ -32,6 +32,7 @@ class ImportLogic extends BaseLogic | ||
| 32 | 32 | ||
| 33 | $this->param['project_id'] = $this->user['project_id']; | 33 | $this->param['project_id'] = $this->user['project_id']; |
| 34 | $this->param['user_id'] = $this->user['id']; | 34 | $this->param['user_id'] = $this->user['id']; |
| 35 | + $this->param['status'] = 9; | ||
| 35 | $rs = $this->model->add($this->param); | 36 | $rs = $this->model->add($this->param); |
| 36 | if($rs === false){ | 37 | if($rs === false){ |
| 37 | $this->fail('error'); | 38 | $this->fail('error'); |
| @@ -45,7 +45,7 @@ class NewsCategoryLogic extends BaseLogic | @@ -45,7 +45,7 @@ class NewsCategoryLogic extends BaseLogic | ||
| 45 | try { | 45 | try { |
| 46 | if(isset($this->param['id']) && !empty($this->param['id'])){ | 46 | if(isset($this->param['id']) && !empty($this->param['id'])){ |
| 47 | $this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']); | 47 | $this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']); |
| 48 | - $this->editCategoryRoute($this->param['id'],$this->param['alias']); | 48 | + $route = $this->param['alias']; |
| 49 | $this->editHandleCategory($this->param['id'],$this->param['pid']); | 49 | $this->editHandleCategory($this->param['id'],$this->param['pid']); |
| 50 | $this->param['operator_id'] = $this->user['id']; | 50 | $this->param['operator_id'] = $this->user['id']; |
| 51 | $this->edit($this->param,['id'=>$this->param['id']]); | 51 | $this->edit($this->param,['id'=>$this->param['id']]); |
| @@ -56,12 +56,12 @@ class NewsCategoryLogic extends BaseLogic | @@ -56,12 +56,12 @@ class NewsCategoryLogic extends BaseLogic | ||
| 56 | $this->param = $this->addParamProcessing($this->param); | 56 | $this->param = $this->addParamProcessing($this->param); |
| 57 | $id = $this->model->addReturnId($this->param); | 57 | $id = $this->model->addReturnId($this->param); |
| 58 | $route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']); | 58 | $route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']); |
| 59 | - $this->addUpdateNotify(RouteMap::SOURCE_NEWS_CATE,$route); | ||
| 60 | - $this->curlDelRoute(['new_route'=>$route]); | ||
| 61 | $this->model->edit(['alias'=>$route],['id'=>$id]); | 59 | $this->model->edit(['alias'=>$route],['id'=>$id]); |
| 62 | //当父级分类拥有产品时,处理子集 | 60 | //当父级分类拥有产品时,处理子集 |
| 63 | $this->addProcessingSon($id); | 61 | $this->addProcessingSon($id); |
| 64 | } | 62 | } |
| 63 | + $this->addUpdateNotify(RouteMap::SOURCE_NEWS_CATE,$route); | ||
| 64 | + $this->curlDelRoute(['new_route'=>$route]); | ||
| 65 | DB::commit(); | 65 | DB::commit(); |
| 66 | }catch (\Exception $e){ | 66 | }catch (\Exception $e){ |
| 67 | DB::rollBack(); | 67 | DB::rollBack(); |
| @@ -112,23 +112,6 @@ class NewsCategoryLogic extends BaseLogic | @@ -112,23 +112,6 @@ class NewsCategoryLogic extends BaseLogic | ||
| 112 | } | 112 | } |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | - /** | ||
| 116 | - * @remark :编辑路由时生成路由记录 | ||
| 117 | - * @name :editCategoryRoute | ||
| 118 | - * @author :lyh | ||
| 119 | - * @method :post | ||
| 120 | - * @time :2023/9/7 10:51 | ||
| 121 | - */ | ||
| 122 | - public function editCategoryRoute($id,$route){ | ||
| 123 | - //生成一条删除路由记录 | ||
| 124 | - $info = $this->model->read(['id'=>$id],['id','alias']); | ||
| 125 | - if($info['alias'] != $route){ | ||
| 126 | - $this->addUpdateNotify(RouteMap::SOURCE_NEWS_CATE,$route); | ||
| 127 | - $this->curlDelRoute(['route'=>$info['alias'],'new_route'=>$route]); | ||
| 128 | - } | ||
| 129 | - return true; | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | 115 | ||
| 133 | /** | 116 | /** |
| 134 | * @remark :修改状态 | 117 | * @remark :修改状态 |
| @@ -65,15 +65,15 @@ class NewsLogic extends BaseLogic | @@ -65,15 +65,15 @@ class NewsLogic extends BaseLogic | ||
| 65 | if (isset($this->param['id']) && !empty($this->param['id'])) { | 65 | if (isset($this->param['id']) && !empty($this->param['id'])) { |
| 66 | $this->param['url'] = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']); | 66 | $this->param['url'] = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']); |
| 67 | //是否更新路由 | 67 | //是否更新路由 |
| 68 | - $this->editNewsRoute($this->param['id'], $this->param['url']); | 68 | + $route = $this->param['url']; |
| 69 | $this->edit($this->param, ['id' => $this->param['id']]); | 69 | $this->edit($this->param, ['id' => $this->param['id']]); |
| 70 | } else { | 70 | } else { |
| 71 | $id = $this->model->addReturnId($this->param); | 71 | $id = $this->model->addReturnId($this->param); |
| 72 | $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $id, $this->user['project_id']); | 72 | $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $id, $this->user['project_id']); |
| 73 | - $this->addUpdateNotify(RouteMap::SOURCE_NEWS,$route); | ||
| 74 | - $this->curlDelRoute(['new_route'=>$route]); | ||
| 75 | $this->edit(['url' => $route], ['id' => $id]); | 73 | $this->edit(['url' => $route], ['id' => $id]); |
| 76 | } | 74 | } |
| 75 | + $this->addUpdateNotify(RouteMap::SOURCE_NEWS,$route); | ||
| 76 | + $this->curlDelRoute(['new_route'=>$route]); | ||
| 77 | //更新路由 | 77 | //更新路由 |
| 78 | DB::commit(); | 78 | DB::commit(); |
| 79 | } catch (\Exception $e) { | 79 | } catch (\Exception $e) { |
| @@ -84,24 +84,6 @@ class NewsLogic extends BaseLogic | @@ -84,24 +84,6 @@ class NewsLogic extends BaseLogic | ||
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | /** | 86 | /** |
| 87 | - * @remark :查看是否编辑路由 | ||
| 88 | - * @name :editCategoryRoute | ||
| 89 | - * @author :lyh | ||
| 90 | - * @method :post | ||
| 91 | - * @time :2023/9/7 11:05 | ||
| 92 | - */ | ||
| 93 | - public function editNewsRoute($id, $route) | ||
| 94 | - { | ||
| 95 | - //生成一条删除路由记录 | ||
| 96 | - $info = $this->model->read(['id' => $id], ['id', 'url']); | ||
| 97 | - if ($info['url'] != $route) { | ||
| 98 | - $this->addUpdateNotify(RouteMap::SOURCE_NEWS,$route); | ||
| 99 | - $this->curlDelRoute(['route'=>$info['url'],'new_route'=>$route]); | ||
| 100 | - } | ||
| 101 | - return true; | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - /** | ||
| 105 | * @name :编辑seo | 87 | * @name :编辑seo |
| 106 | * @return void | 88 | * @return void |
| 107 | * @author :liyuhang | 89 | * @author :liyuhang |
| @@ -283,7 +265,12 @@ class NewsLogic extends BaseLogic | @@ -283,7 +265,12 @@ class NewsLogic extends BaseLogic | ||
| 283 | */ | 265 | */ |
| 284 | public function importNews($project_id, $user_id, $data) | 266 | public function importNews($project_id, $user_id, $data) |
| 285 | { | 267 | { |
| 286 | - $news = $this->model->read(['name' => $data[0]]); | 268 | + $route = $data[1]??'';//自定义路由 |
| 269 | + if($route){ | ||
| 270 | + $news = $this->model->read(['url' => $route]); | ||
| 271 | + }else{ | ||
| 272 | + $news = $this->model->read(['name' => $data[0]]); | ||
| 273 | + } | ||
| 287 | if (!$news) { | 274 | if (!$news) { |
| 288 | 275 | ||
| 289 | $category_id = ''; | 276 | $category_id = ''; |
| @@ -337,7 +324,22 @@ class NewsLogic extends BaseLogic | @@ -337,7 +324,22 @@ class NewsLogic extends BaseLogic | ||
| 337 | ] | 324 | ] |
| 338 | ); | 325 | ); |
| 339 | //更新路由 | 326 | //更新路由 |
| 340 | - $route = RouteMap::setRoute((isset($data[1]) && $data[1]) ? $data[1] : $data[0], RouteMap::SOURCE_NEWS, $id, $project_id); | 327 | + if($route){ |
| 328 | + $route_map = RouteMap::where('project_id', $project_id)->where('source', RouteMap::SOURCE_NEWS)->where('source_id', $id)->first(); | ||
| 329 | + if (!$route_map) { | ||
| 330 | + $route_map = new RouteMap(); | ||
| 331 | + $route_map->project_id = $project_id; | ||
| 332 | + $route_map->path = RouteMap::SOURCE_NEWS; | ||
| 333 | + $route_map->source = RouteMap::SOURCE_NEWS; | ||
| 334 | + $route_map->source_id = $id; | ||
| 335 | + $route_map->route = $route; | ||
| 336 | + | ||
| 337 | + $route_map->save(); | ||
| 338 | + } | ||
| 339 | + }else{ | ||
| 340 | + $route = RouteMap::setRoute($data[0], RouteMap::SOURCE_NEWS, $id, $project_id); | ||
| 341 | + } | ||
| 342 | + | ||
| 341 | $this->edit(['url' => $route], ['id' => $id]); | 343 | $this->edit(['url' => $route], ['id' => $id]); |
| 342 | 344 | ||
| 343 | return true; | 345 | return true; |
| @@ -114,7 +114,7 @@ class CategoryLogic extends BaseLogic | @@ -114,7 +114,7 @@ class CategoryLogic extends BaseLogic | ||
| 114 | try { | 114 | try { |
| 115 | if(isset($this->param['id']) && !empty($this->param['id'])){ | 115 | if(isset($this->param['id']) && !empty($this->param['id'])){ |
| 116 | $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $this->param['id'], $this->user['project_id']); | 116 | $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $this->param['id'], $this->user['project_id']); |
| 117 | - $this->editCategoryRoute($this->param['id'],$this->param['route']); | 117 | + $route = $this->param['route']; |
| 118 | //处理子集 | 118 | //处理子集 |
| 119 | $this->editHandleCategory($this->param['id'],$this->param['pid']); | 119 | $this->editHandleCategory($this->param['id'],$this->param['pid']); |
| 120 | $this->model->edit($this->param,['id'=>$this->param['id']]); | 120 | $this->model->edit($this->param,['id'=>$this->param['id']]); |
| @@ -122,12 +122,12 @@ class CategoryLogic extends BaseLogic | @@ -122,12 +122,12 @@ class CategoryLogic extends BaseLogic | ||
| 122 | $this->param['project_id'] = $this->user['project_id']; | 122 | $this->param['project_id'] = $this->user['project_id']; |
| 123 | $id = $this->model->addReturnId($this->param); | 123 | $id = $this->model->addReturnId($this->param); |
| 124 | $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']); | 124 | $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']); |
| 125 | - $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_CATE,$route); | ||
| 126 | - $this->curlDelRoute(['new_route'=>$route]); | ||
| 127 | $this->edit(['route'=>$route],['id'=>$id]); | 125 | $this->edit(['route'=>$route],['id'=>$id]); |
| 128 | //处理子集 | 126 | //处理子集 |
| 129 | $this->addProcessingSon($id); | 127 | $this->addProcessingSon($id); |
| 130 | } | 128 | } |
| 129 | + $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_CATE,$route); | ||
| 130 | + $this->curlDelRoute(['new_route'=>$route]); | ||
| 131 | //清除缓存 | 131 | //清除缓存 |
| 132 | Common::del_user_cache('product_category',$this->user['project_id']); | 132 | Common::del_user_cache('product_category',$this->user['project_id']); |
| 133 | DB::commit(); | 133 | DB::commit(); |
| @@ -223,23 +223,6 @@ class CategoryLogic extends BaseLogic | @@ -223,23 +223,6 @@ class CategoryLogic extends BaseLogic | ||
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | /** | 225 | /** |
| 226 | - * @remark :编辑路由时生成路由记录 | ||
| 227 | - * @name :editCategoryRoute | ||
| 228 | - * @author :lyh | ||
| 229 | - * @method :post | ||
| 230 | - * @time :2023/9/7 10:51 | ||
| 231 | - */ | ||
| 232 | - public function editCategoryRoute($id,$route){ | ||
| 233 | - //生成一条删除路由记录 | ||
| 234 | - $info = $this->model->read(['id'=>$id],['id','route']); | ||
| 235 | - if($info['route'] != $route){ | ||
| 236 | - $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_CATE,$route); | ||
| 237 | - $this->curlDelRoute(['route'=>$info['route'],'new_route'=>$route]); | ||
| 238 | - } | ||
| 239 | - return true; | ||
| 240 | - } | ||
| 241 | - | ||
| 242 | - /** | ||
| 243 | * @remark :删除 | 226 | * @remark :删除 |
| 244 | * @name :delete | 227 | * @name :delete |
| 245 | * @author :lyh | 228 | * @author :lyh |
| @@ -58,15 +58,16 @@ class KeywordLogic extends BaseLogic | @@ -58,15 +58,16 @@ class KeywordLogic extends BaseLogic | ||
| 58 | if(isset($this->param['id']) && !empty($this->param['id'])){ | 58 | if(isset($this->param['id']) && !empty($this->param['id'])){ |
| 59 | //TODO::不能修改路由 | 59 | //TODO::不能修改路由 |
| 60 | $this->model->edit($this->param,['id'=>$this->param['id']]); | 60 | $this->model->edit($this->param,['id'=>$this->param['id']]); |
| 61 | + $route = $this->param['route']; | ||
| 61 | }else{ | 62 | }else{ |
| 62 | $this->param = $this->addHandleParam($this->param); | 63 | $this->param = $this->addHandleParam($this->param); |
| 63 | $id = $this->model->insertGetId($this->param); | 64 | $id = $this->model->insertGetId($this->param); |
| 64 | //路由映射 | 65 | //路由映射 |
| 65 | $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); | 66 | $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); |
| 66 | - $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_KEYWORD,$route); | ||
| 67 | - $this->curlDelRoute(['new_route'=>$route]); | ||
| 68 | $this->model->edit(['route'=>$route],['id'=>$id]); | 67 | $this->model->edit(['route'=>$route],['id'=>$id]); |
| 69 | } | 68 | } |
| 69 | + $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_KEYWORD,$route); | ||
| 70 | + $this->curlDelRoute(['new_route'=>$route]); | ||
| 70 | //清除缓存 | 71 | //清除缓存 |
| 71 | Common::del_user_cache('product_keyword',$this->user['project_id']); | 72 | Common::del_user_cache('product_keyword',$this->user['project_id']); |
| 72 | DB::commit(); | 73 | DB::commit(); |
| @@ -48,18 +48,17 @@ class ProductLogic extends BaseLogic | @@ -48,18 +48,17 @@ class ProductLogic extends BaseLogic | ||
| 48 | try { | 48 | try { |
| 49 | if(isset($this->param['id']) && !empty($this->param['id'])){ | 49 | if(isset($this->param['id']) && !empty($this->param['id'])){ |
| 50 | $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']); | 50 | $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']); |
| 51 | - //查看路由是否更新 | ||
| 52 | - $this->editProductRoute($this->param['id'],$this->param['route']); | 51 | + $route = $this->param['route']; |
| 53 | $this->model->edit($this->param,['id'=>$this->param['id']]); | 52 | $this->model->edit($this->param,['id'=>$this->param['id']]); |
| 54 | $id = $this->param['id']; | 53 | $id = $this->param['id']; |
| 55 | }else{ | 54 | }else{ |
| 56 | $this->param = $this->addHandleParam($this->param); | 55 | $this->param = $this->addHandleParam($this->param); |
| 57 | $id = $this->model->addReturnId($this->param); | 56 | $id = $this->model->addReturnId($this->param); |
| 58 | $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); | 57 | $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); |
| 59 | - $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route); | ||
| 60 | - $this->curlDelRoute(['new_route'=>$route]); | ||
| 61 | $this->model->edit(['route'=>$route],['id'=>$id]); | 58 | $this->model->edit(['route'=>$route],['id'=>$id]); |
| 62 | } | 59 | } |
| 60 | + $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route); | ||
| 61 | + $this->curlDelRoute(['new_route'=>$route]); | ||
| 63 | //产品分类关联 | 62 | //产品分类关联 |
| 64 | CategoryRelated::saveRelated($id, $category_ids); | 63 | CategoryRelated::saveRelated($id, $category_ids); |
| 65 | //保存扩展字段 | 64 | //保存扩展字段 |
| @@ -332,8 +331,8 @@ class ProductLogic extends BaseLogic | @@ -332,8 +331,8 @@ class ProductLogic extends BaseLogic | ||
| 332 | $info = $this->model->read(['id'=>$id]); | 331 | $info = $this->model->read(['id'=>$id]); |
| 333 | if($info['route'] != $route){ | 332 | if($info['route'] != $route){ |
| 334 | $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route); | 333 | $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route); |
| 335 | - $this->curlDelRoute(['route'=>$info['route'],'new_route'=>$route]); | ||
| 336 | } | 334 | } |
| 335 | + $this->curlDelRoute(['route'=>$info['route'],'new_route'=>$route]); | ||
| 337 | return $route; | 336 | return $route; |
| 338 | } | 337 | } |
| 339 | 338 | ||
| @@ -596,7 +595,13 @@ class ProductLogic extends BaseLogic | @@ -596,7 +595,13 @@ class ProductLogic extends BaseLogic | ||
| 596 | */ | 595 | */ |
| 597 | public function importProduct($project_id, $user_id, $data) | 596 | public function importProduct($project_id, $user_id, $data) |
| 598 | { | 597 | { |
| 599 | - $product = $this->model->read(['title' => $data[0]]); | 598 | + $route = $data[1]??'';//自定义路由 |
| 599 | + if($route){ | ||
| 600 | + $product = $this->model->read(['route' => $route]); | ||
| 601 | + }else{ | ||
| 602 | + $product = $this->model->read(['title' => $data[0]]); | ||
| 603 | + } | ||
| 604 | + | ||
| 600 | if (!$product) { | 605 | if (!$product) { |
| 601 | 606 | ||
| 602 | $category_id = ''; | 607 | $category_id = ''; |
| @@ -729,8 +734,23 @@ class ProductLogic extends BaseLogic | @@ -729,8 +734,23 @@ class ProductLogic extends BaseLogic | ||
| 729 | 'status' => Product::STATUS_ON | 734 | 'status' => Product::STATUS_ON |
| 730 | ] | 735 | ] |
| 731 | ); | 736 | ); |
| 737 | + | ||
| 732 | //更新路由 | 738 | //更新路由 |
| 733 | - $route = RouteMap::setRoute((isset($data[1]) && $data[1]) ? $data[1] : $data[0], RouteMap::SOURCE_PRODUCT, $id, $project_id); | 739 | + if($route){ |
| 740 | + $route_map = RouteMap::where('project_id', $project_id)->where('source', RouteMap::SOURCE_PRODUCT)->where('source_id', $id)->first(); | ||
| 741 | + if (!$route_map) { | ||
| 742 | + $route_map = new RouteMap(); | ||
| 743 | + $route_map->project_id = $project_id; | ||
| 744 | + $route_map->source = RouteMap::SOURCE_PRODUCT; | ||
| 745 | + $route_map->source_id = $id; | ||
| 746 | + $route_map->route = $route; | ||
| 747 | + | ||
| 748 | + $route_map->save(); | ||
| 749 | + } | ||
| 750 | + }else{ | ||
| 751 | + $route = RouteMap::setRoute($data[0], RouteMap::SOURCE_PRODUCT, $id, $project_id); | ||
| 752 | + } | ||
| 753 | + | ||
| 734 | $this->edit(['route' => $route], ['id' => $id]); | 754 | $this->edit(['route' => $route], ['id' => $id]); |
| 735 | 755 | ||
| 736 | return true; | 756 | return true; |
-
请 注册 或 登录 后发表评论