Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6
正在显示
5 个修改的文件
包含
421 行增加
和
54 行删除
| @@ -11,7 +11,6 @@ use App\Services\ProjectServer; | @@ -11,7 +11,6 @@ use App\Services\ProjectServer; | ||
| 11 | use Illuminate\Console\Command; | 11 | use Illuminate\Console\Command; |
| 12 | use Illuminate\Support\Facades\Cache; | 12 | use Illuminate\Support\Facades\Cache; |
| 13 | use Illuminate\Support\Facades\DB; | 13 | use Illuminate\Support\Facades\DB; |
| 14 | -use Illuminate\Support\Facades\Log; | ||
| 15 | use Illuminate\Support\Facades\Redis; | 14 | use Illuminate\Support\Facades\Redis; |
| 16 | 15 | ||
| 17 | /** | 16 | /** |
| @@ -283,6 +282,7 @@ class HtmlCollect extends Command | @@ -283,6 +282,7 @@ class HtmlCollect extends Command | ||
| 283 | protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url) | 282 | protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url) |
| 284 | { | 283 | { |
| 285 | if ($url) { | 284 | if ($url) { |
| 285 | + $url = str_replace('"', '', $url); | ||
| 286 | $arr = parse_url($url); | 286 | $arr = parse_url($url); |
| 287 | $scheme = $arr['scheme'] ?? ''; | 287 | $scheme = $arr['scheme'] ?? ''; |
| 288 | $host = $arr['host'] ?? ''; | 288 | $host = $arr['host'] ?? ''; |
| @@ -344,6 +344,7 @@ class HtmlCollect extends Command | @@ -344,6 +344,7 @@ class HtmlCollect extends Command | ||
| 344 | $url_arr = explode('/', $vs['url_complete']); | 344 | $url_arr = explode('/', $vs['url_complete']); |
| 345 | $target_arr = explode('/', $new_source); | 345 | $target_arr = explode('/', $new_source); |
| 346 | foreach ($css_source as $vcs) { | 346 | foreach ($css_source as $vcs) { |
| 347 | + $vcs = str_replace('"', '', $vcs); | ||
| 347 | $vcs_arr = parse_url($vcs); | 348 | $vcs_arr = parse_url($vcs); |
| 348 | if (isset($vcs_arr['domain'])) { | 349 | if (isset($vcs_arr['domain'])) { |
| 349 | //不是相对路径,不下载 | 350 | //不是相对路径,不下载 |
| @@ -358,7 +359,7 @@ class HtmlCollect extends Command | @@ -358,7 +359,7 @@ class HtmlCollect extends Command | ||
| 358 | continue; | 359 | continue; |
| 359 | } | 360 | } |
| 360 | $path_arr = explode('.', $vcs); | 361 | $path_arr = explode('.', $vcs); |
| 361 | - if (end($path_arr) == 'html') { | 362 | + if (in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) { |
| 362 | continue; | 363 | continue; |
| 363 | } | 364 | } |
| 364 | 365 |
| @@ -9,6 +9,7 @@ use App\Models\RouteMap\RouteMap; | @@ -9,6 +9,7 @@ use App\Models\RouteMap\RouteMap; | ||
| 9 | use App\Services\CosService; | 9 | use App\Services\CosService; |
| 10 | use App\Services\ProjectServer; | 10 | use App\Services\ProjectServer; |
| 11 | use Illuminate\Console\Command; | 11 | use Illuminate\Console\Command; |
| 12 | +use Illuminate\Support\Facades\Cache; | ||
| 12 | use Illuminate\Support\Facades\DB; | 13 | use Illuminate\Support\Facades\DB; |
| 13 | use Illuminate\Support\Facades\Redis; | 14 | use Illuminate\Support\Facades\Redis; |
| 14 | 15 | ||
| @@ -75,34 +76,13 @@ class HtmlLanguageCollect extends Command | @@ -75,34 +76,13 @@ class HtmlLanguageCollect extends Command | ||
| 75 | $collect_info->status = CollectTask::STATUS_ING; | 76 | $collect_info->status = CollectTask::STATUS_ING; |
| 76 | $collect_info->save(); | 77 | $collect_info->save(); |
| 77 | 78 | ||
| 78 | - //获取英文站域名 | ||
| 79 | - $domain = $collect_info->domain; | ||
| 80 | - if (strpos($domain, '/') !== false) { | ||
| 81 | - $domain = substr($domain, 0, strpos($domain, '/')); | ||
| 82 | - } else { | ||
| 83 | - $domain = str_replace($collect_info->language, 'www', $domain); | ||
| 84 | - } | ||
| 85 | - | ||
| 86 | - $web_url_domain = $domain; | ||
| 87 | - $home_url = $domain; | ||
| 88 | - $url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text'; | ||
| 89 | - $data_config = curl_c($url_web_config); | ||
| 90 | - if ($data_config) { | ||
| 91 | - $web_url_arr = parse_url($data_config['web_url_domain'] ?? ''); | ||
| 92 | - if (isset($web_url_arr['host'])) { | ||
| 93 | - $web_url_domain = $web_url_arr['host']; | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - $home_url_arr = parse_url($data_config['home_url'] ?? ''); | ||
| 97 | - if (isset($home_url_arr['host'])) { | ||
| 98 | - $home_url = $home_url_arr['host']; | ||
| 99 | - } | ||
| 100 | - } | 79 | + //获取站点正式和测试域名 |
| 80 | + $old_info = $this->getOldDomain($project_id, $collect_info->domain); | ||
| 101 | 81 | ||
| 102 | //采集html页面,下载资源到本地并替换 | 82 | //采集html页面,下载资源到本地并替换 |
| 103 | try { | 83 | try { |
| 104 | $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false); | 84 | $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false); |
| 105 | - if($html == '0'){ | 85 | + if ($html == '0') { |
| 106 | $collect_info->status = CollectTask::STATUS_FAIL; | 86 | $collect_info->status = CollectTask::STATUS_FAIL; |
| 107 | $collect_info->save(); | 87 | $collect_info->save(); |
| 108 | echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL; | 88 | echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL; |
| @@ -110,7 +90,15 @@ class HtmlLanguageCollect extends Command | @@ -110,7 +90,15 @@ class HtmlLanguageCollect extends Command | ||
| 110 | return true; | 90 | return true; |
| 111 | } | 91 | } |
| 112 | 92 | ||
| 113 | - $source_list = $this->html_preg($html, $project_id, $collect_info->domain, $web_url_domain, $home_url); | 93 | + //如果有base64图片,先替换掉,再进行资源匹配 |
| 94 | + $new_html = $html; | ||
| 95 | + preg_match_all("/data:([^;]*);base64,(.*)?\"/", $new_html, $result_img); | ||
| 96 | + $img_base64 = $result_img[2] ?? []; | ||
| 97 | + foreach ($img_base64 as $v64) { | ||
| 98 | + $new_html = str_replace($v64, '', $new_html); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + $source_list = $this->html_preg($new_html, $project_id, $collect_info->domain, $old_info['web_url_domain'], $old_info['home_url']); | ||
| 114 | 102 | ||
| 115 | if ($source_list) { | 103 | if ($source_list) { |
| 116 | $html = $this->upload_source($html, $source_list, $project_id); | 104 | $html = $this->upload_source($html, $source_list, $project_id); |
| @@ -162,9 +150,6 @@ class HtmlLanguageCollect extends Command | @@ -162,9 +150,6 @@ class HtmlLanguageCollect extends Command | ||
| 162 | case 'blog': | 150 | case 'blog': |
| 163 | $source = RouteMap::SOURCE_BLOG; | 151 | $source = RouteMap::SOURCE_BLOG; |
| 164 | break; | 152 | break; |
| 165 | - case 'tag': | ||
| 166 | - $source = RouteMap::SOURCE_PRODUCT_KEYWORD; | ||
| 167 | - break; | ||
| 168 | default: | 153 | default: |
| 169 | $source = RouteMap::SOURCE_PRODUCT; | 154 | $source = RouteMap::SOURCE_PRODUCT; |
| 170 | break; | 155 | break; |
| @@ -197,6 +182,42 @@ class HtmlLanguageCollect extends Command | @@ -197,6 +182,42 @@ class HtmlLanguageCollect extends Command | ||
| 197 | return $task_id; | 182 | return $task_id; |
| 198 | } | 183 | } |
| 199 | 184 | ||
| 185 | + //获取站点老域名 | ||
| 186 | + protected function getOldDomain($project_id, $domain) | ||
| 187 | + { | ||
| 188 | + $key = 'project_collect_lan_domain_' . $project_id; | ||
| 189 | + | ||
| 190 | + $data = Cache::get($key); | ||
| 191 | + | ||
| 192 | + if (!$data) { | ||
| 193 | + $web_url_domain = $domain; | ||
| 194 | + $home_url = $domain; | ||
| 195 | + | ||
| 196 | + $url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text'; | ||
| 197 | + $data_config = curl_c($url_web_config); | ||
| 198 | + if ($data_config) { | ||
| 199 | + $web_url_arr = parse_url($data_config['web_url_domain'] ?? ''); | ||
| 200 | + if (isset($web_url_arr['host'])) { | ||
| 201 | + $web_url_domain = $web_url_arr['host']; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + $home_url_arr = parse_url($data_config['home_url'] ?? ''); | ||
| 205 | + if (isset($home_url_arr['host'])) { | ||
| 206 | + $home_url = $home_url_arr['host']; | ||
| 207 | + } | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + $data = [ | ||
| 211 | + 'web_url_domain' => $web_url_domain, | ||
| 212 | + 'home_url' => $home_url, | ||
| 213 | + ]; | ||
| 214 | + | ||
| 215 | + Cache::add($key, $data, 3600);//缓存1小时 | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + return $data; | ||
| 219 | + } | ||
| 220 | + | ||
| 200 | //正则匹配html资源 | 221 | //正则匹配html资源 |
| 201 | protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url) | 222 | protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url) |
| 202 | { | 223 | { |
| @@ -246,6 +267,13 @@ class HtmlLanguageCollect extends Command | @@ -246,6 +267,13 @@ class HtmlLanguageCollect extends Command | ||
| 246 | $check_vc_b && $source[] = $check_vc_b; | 267 | $check_vc_b && $source[] = $check_vc_b; |
| 247 | } | 268 | } |
| 248 | 269 | ||
| 270 | + //a标签下载资源 | ||
| 271 | + preg_match_all('/<a\s+[^>]*?href\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_a); | ||
| 272 | + $down = $result_a[2] ?? []; | ||
| 273 | + foreach ($down as $vd) { | ||
| 274 | + $check_vd = $this->url_check($vd, $project_id, $domain, $web_url_domain, $home_url); | ||
| 275 | + $check_vd && $source[] = $check_vd; | ||
| 276 | + } | ||
| 249 | 277 | ||
| 250 | return $source; | 278 | return $source; |
| 251 | } | 279 | } |
| @@ -254,6 +282,7 @@ class HtmlLanguageCollect extends Command | @@ -254,6 +282,7 @@ class HtmlLanguageCollect extends Command | ||
| 254 | protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url) | 282 | protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url) |
| 255 | { | 283 | { |
| 256 | if ($url) { | 284 | if ($url) { |
| 285 | + $url = str_replace('"', '', $url); | ||
| 257 | $arr = parse_url($url); | 286 | $arr = parse_url($url); |
| 258 | $scheme = $arr['scheme'] ?? ''; | 287 | $scheme = $arr['scheme'] ?? ''; |
| 259 | $host = $arr['host'] ?? ''; | 288 | $host = $arr['host'] ?? ''; |
| @@ -265,7 +294,7 @@ class HtmlLanguageCollect extends Command | @@ -265,7 +294,7 @@ class HtmlLanguageCollect extends Command | ||
| 265 | (empty($host) || $host == $web_url_domain || $host == $home_url) | 294 | (empty($host) || $host == $web_url_domain || $host == $home_url) |
| 266 | && $path | 295 | && $path |
| 267 | && (strpos($path, '.') !== false) | 296 | && (strpos($path, '.') !== false) |
| 268 | - && (end($path_arr) != 'html') | 297 | + && (!in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) |
| 269 | ) { | 298 | ) { |
| 270 | $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first(); | 299 | $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first(); |
| 271 | if (!$source) { | 300 | if (!$source) { |
| @@ -315,6 +344,7 @@ class HtmlLanguageCollect extends Command | @@ -315,6 +344,7 @@ class HtmlLanguageCollect extends Command | ||
| 315 | $url_arr = explode('/', $vs['url_complete']); | 344 | $url_arr = explode('/', $vs['url_complete']); |
| 316 | $target_arr = explode('/', $new_source); | 345 | $target_arr = explode('/', $new_source); |
| 317 | foreach ($css_source as $vcs) { | 346 | foreach ($css_source as $vcs) { |
| 347 | + $vcs = str_replace('"', '', $vcs); | ||
| 318 | $vcs_arr = parse_url($vcs); | 348 | $vcs_arr = parse_url($vcs); |
| 319 | if (isset($vcs_arr['domain'])) { | 349 | if (isset($vcs_arr['domain'])) { |
| 320 | //不是相对路径,不下载 | 350 | //不是相对路径,不下载 |
| @@ -329,7 +359,7 @@ class HtmlLanguageCollect extends Command | @@ -329,7 +359,7 @@ class HtmlLanguageCollect extends Command | ||
| 329 | continue; | 359 | continue; |
| 330 | } | 360 | } |
| 331 | $path_arr = explode('.', $vcs); | 361 | $path_arr = explode('.', $vcs); |
| 332 | - if(end($path_arr) == 'html'){ | 362 | + if (in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) { |
| 333 | continue; | 363 | continue; |
| 334 | } | 364 | } |
| 335 | 365 |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands\Update; | ||
| 4 | + | ||
| 5 | +use App\Helper\Arr; | ||
| 6 | +use App\Http\Logic\Bside\Product\CategoryLogic; | ||
| 7 | +use App\Models\Collect\CollectSource; | ||
| 8 | +use App\Models\Collect\CollectTask; | ||
| 9 | +use App\Models\Com\UpdateLog; | ||
| 10 | +use App\Models\Product\Category; | ||
| 11 | +use App\Models\Product\Product; | ||
| 12 | +use App\Models\RouteMap\RouteMap; | ||
| 13 | +use App\Services\CosService; | ||
| 14 | +use App\Services\ProjectServer; | ||
| 15 | +use Illuminate\Console\Command; | ||
| 16 | +use Illuminate\Support\Facades\DB; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 4.0,5.0升级到6.0,内容同步 | ||
| 20 | + * Class ProjectImport | ||
| 21 | + * @package App\Console\Commands | ||
| 22 | + * @author Akun | ||
| 23 | + * @date 2023/10/9 15:04 | ||
| 24 | + */ | ||
| 25 | +class ProjectUpdateTemp extends Command | ||
| 26 | +{ | ||
| 27 | + /** | ||
| 28 | + * The name and signature of the console command. | ||
| 29 | + * | ||
| 30 | + * @var string | ||
| 31 | + */ | ||
| 32 | + protected $signature = 'project_update_temp'; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * The console command description. | ||
| 36 | + * | ||
| 37 | + * @var string | ||
| 38 | + */ | ||
| 39 | + protected $description = '执行项目升级任务'; | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + public function handle() | ||
| 43 | + { | ||
| 44 | + while (true) { | ||
| 45 | + $this->start_update(); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + protected function start_update() | ||
| 50 | + { | ||
| 51 | + $list = UpdateLog::where('api_type', 'category')->get(); | ||
| 52 | + | ||
| 53 | + foreach ($list as $task) { | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + $project_id = $task->project_id; | ||
| 57 | + $api_type = $task->api_type; | ||
| 58 | + $api_url_arr = explode('?', $task->api_url); | ||
| 59 | + $api_url = $api_url_arr[0]; | ||
| 60 | + | ||
| 61 | + $page_size = 20; | ||
| 62 | + | ||
| 63 | + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL; | ||
| 64 | + | ||
| 65 | + $task->status = UpdateLog::STATUS_ING;//同步中 | ||
| 66 | + $task->save(); | ||
| 67 | + | ||
| 68 | + $domain_arr = parse_url($api_url); | ||
| 69 | + //获取网站配置 | ||
| 70 | + $link_type = 0; | ||
| 71 | + $web_url_domain = $domain_arr['host']; | ||
| 72 | + $home_url = $domain_arr['host']; | ||
| 73 | + $url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text'; | ||
| 74 | + $data_config = curl_c($url_web_config); | ||
| 75 | + if ($data_config) { | ||
| 76 | + $link_type = $data_config['link_type'] ?? 0; | ||
| 77 | + | ||
| 78 | + $web_url_arr = parse_url($data_config['web_url_domain'] ?? ''); | ||
| 79 | + if (isset($web_url_arr['host'])) { | ||
| 80 | + $web_url_domain = $web_url_arr['host']; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + $home_url_arr = parse_url($data_config['home_url'] ?? ''); | ||
| 84 | + if (isset($home_url_arr['host'])) { | ||
| 85 | + $home_url = $home_url_arr['host']; | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + //获取所有语种 | ||
| 89 | + $language_list = []; | ||
| 90 | + $url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json'; | ||
| 91 | + $data_language = curl_c($url_language); | ||
| 92 | + if ($data_language) { | ||
| 93 | + $language_list = array_column($data_language, 'short'); | ||
| 94 | + } | ||
| 95 | + //获取所有页面 | ||
| 96 | + $page_list = []; | ||
| 97 | + $url_page = 'https://' . $domain_arr['host'] . '/wp-content/cache/pages_list.json'; | ||
| 98 | + $data_page = curl_c($url_page); | ||
| 99 | + if ($data_page) { | ||
| 100 | + $page_list = array_column($data_page, 'path'); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + //设置数据库 | ||
| 104 | + $project = ProjectServer::useProject($project_id); | ||
| 105 | + if ($project) { | ||
| 106 | + if ($api_type == 'category') { | ||
| 107 | + //产品分类 | ||
| 108 | + $url = $api_url . '?' . http_build_query(['w' => 'category']); | ||
| 109 | + $data = curl_c($url); | ||
| 110 | + if (isset($data['code']) && $data['code'] == 200) { | ||
| 111 | + $items = $data['data'] ?? []; | ||
| 112 | + $this->category_insert($project_id, $items, 0); | ||
| 113 | + } else { | ||
| 114 | + return true; | ||
| 115 | + } | ||
| 116 | + } elseif ($api_type == 'post') { | ||
| 117 | + //产品 | ||
| 118 | + $url = $api_url . '?' . http_build_query(['w' => 'post', 'page' => 1, 'pagesize' => 0]); | ||
| 119 | + $data = curl_c($url); | ||
| 120 | + if (isset($data['code']) && $data['code'] == 200) { | ||
| 121 | + $count = $data['data']['count'] ?? 0; | ||
| 122 | + | ||
| 123 | + $total_page = ceil($count / $page_size); | ||
| 124 | + for ($page = 1; $page <= $total_page; $page++) { | ||
| 125 | + $url_page = $api_url . '?' . http_build_query(['w' => 'post', 'page' => $page, 'pagesize' => $page_size]); | ||
| 126 | + $data_page = curl_c($url_page); | ||
| 127 | + if (isset($data_page['code']) && $data_page['code'] == 200) { | ||
| 128 | + $items = $data_page['data']['data'] ?? []; | ||
| 129 | + | ||
| 130 | + $model = new Product(); | ||
| 131 | + $category_model = new Category(); | ||
| 132 | + $logic = new CategoryLogic(); | ||
| 133 | + | ||
| 134 | + foreach ($items as $item) { | ||
| 135 | + $route = $this->get_url_route($item['url'] ?? ''); | ||
| 136 | + if ($route) { | ||
| 137 | + $product = $model->read(['route' => $route], 'id'); | ||
| 138 | + if (!$product) { | ||
| 139 | + //图片 | ||
| 140 | + $gallery = []; | ||
| 141 | + if ($item['images'] ?? []) { | ||
| 142 | + foreach ($item['images'] as $k_img => $img) { | ||
| 143 | + $gallery[] = ['alt' => '这是一张产品图', 'url' => $this->source_download($img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)]; | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + //分类 | ||
| 147 | + $category_id = ''; | ||
| 148 | + if ($item['category'] ?? []) { | ||
| 149 | + $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); | ||
| 150 | + $category_id = $logic->getLastCategory(array_column($category_arr, 'id')); | ||
| 151 | + } | ||
| 152 | + try { | ||
| 153 | + $item['ttile'] = $this->special2str($item['ttile'] ?? ''); | ||
| 154 | + $id = $model->insertGetId([ | ||
| 155 | + 'project_id' => $project_id, | ||
| 156 | + 'title' => $item['ttile'], | ||
| 157 | + 'intro' => $item['short_description'] ?? '', | ||
| 158 | + 'content' => $item['content'] ?? '', | ||
| 159 | + 'category_id' => $category_id, | ||
| 160 | + 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '', | ||
| 161 | + 'gallery' => Arr::a2s($gallery), | ||
| 162 | + 'seo_mate' => Arr::a2s([ | ||
| 163 | + 'title' => $item['ttile'], | ||
| 164 | + 'keyword' => $item['keywords'] ?? '', | ||
| 165 | + 'description' => $item['description'] ?? '' | ||
| 166 | + ]), | ||
| 167 | + 'status' => Product::STATUS_ON, | ||
| 168 | + 'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), | ||
| 169 | + 'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), | ||
| 170 | + 'sort' => $item['sort'] ?? 0, | ||
| 171 | + 'is_upgrade' => 1, | ||
| 172 | + 'six_read' => 1, | ||
| 173 | + 'route' => $route | ||
| 174 | + ]); | ||
| 175 | + $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id); | ||
| 176 | + | ||
| 177 | + CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); | ||
| 178 | + } catch (\Exception $e) { | ||
| 179 | + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | ||
| 180 | + continue; | ||
| 181 | + } | ||
| 182 | + } else { | ||
| 183 | + $category_id = ''; | ||
| 184 | + if ($item['category'] ?? []) { | ||
| 185 | + $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); | ||
| 186 | + $category_id = $logic->getLastCategory(array_column($category_arr, 'id')); | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + $model->edit(['category_id' => $category_id, 'product_type' => ''], ['id' => $product['id']]); | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + } | ||
| 193 | + } | ||
| 194 | + } | ||
| 195 | + } else { | ||
| 196 | + return true; | ||
| 197 | + } | ||
| 198 | + } | ||
| 199 | + } | ||
| 200 | + //关闭数据库 | ||
| 201 | + DB::disconnect('custom_mysql'); | ||
| 202 | + | ||
| 203 | + $task->status = UpdateLog::STATUS_COM;//同步完成 | ||
| 204 | + if ($api_type == 'post' || $api_type == 'page' || $api_type == 'news' || $api_type == 'blog') { | ||
| 205 | + $task->collect_status = UpdateLog::COLLECT_STATUS_UN; | ||
| 206 | + } | ||
| 207 | + $task->save(); | ||
| 208 | + | ||
| 209 | + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL; | ||
| 210 | + | ||
| 211 | + sleep(2); | ||
| 212 | + } | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + | ||
| 216 | + //获取地址路由 | ||
| 217 | + protected function get_url_route($url) | ||
| 218 | + { | ||
| 219 | + $arr = parse_url(urldecode($url)); | ||
| 220 | + if (empty($arr['path'])) { | ||
| 221 | + return ''; | ||
| 222 | + } | ||
| 223 | + $path = $arr['path']; | ||
| 224 | + | ||
| 225 | + if (strpos($path, '.') !== false) { | ||
| 226 | + $path = substr($path, 0, strpos($path, '.')); | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + $path_arr = explode('/', $path); | ||
| 230 | + | ||
| 231 | + return end($path_arr) ? end($path_arr) : $path_arr[count($path_arr) - 2]; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + //产品多级分类入库 | ||
| 235 | + protected function category_insert($project_id, $items, $pid = 0) | ||
| 236 | + { | ||
| 237 | + $model = new Category(); | ||
| 238 | + foreach ($items as $item) { | ||
| 239 | + $route = $this->get_url_route($item['url'] ?? ''); | ||
| 240 | + if ($route) { | ||
| 241 | + $parent = $model->read(['pid' => $pid, 'route' => $route], 'id'); | ||
| 242 | + if (!$parent) { | ||
| 243 | + try { | ||
| 244 | + $item['name'] = $this->special2str($item['name'] ?? ''); | ||
| 245 | + $parent_id = $model->addReturnId([ | ||
| 246 | + 'project_id' => $project_id, | ||
| 247 | + 'title' => $item['name'], | ||
| 248 | + 'pid' => $pid, | ||
| 249 | + 'keywords' => $item['keywords'] ?? '', | ||
| 250 | + 'describe' => $item['description'] ?? '', | ||
| 251 | + 'original_id' => $item['id'], | ||
| 252 | + 'route' => $route | ||
| 253 | + ]); | ||
| 254 | + $this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id); | ||
| 255 | + } catch (\Exception $e) { | ||
| 256 | + echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL; | ||
| 257 | + continue; | ||
| 258 | + } | ||
| 259 | + } else { | ||
| 260 | + $parent_id = $parent['id']; | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + if (!empty($item['children'])) { | ||
| 264 | + $this->category_insert($project_id, $item['children'], $parent_id); | ||
| 265 | + } | ||
| 266 | + } | ||
| 267 | + } | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + //特殊字符转换 | ||
| 271 | + protected function special2str($str) | ||
| 272 | + { | ||
| 273 | + if (strpos($str, ';') === false) { | ||
| 274 | + return $str; | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + $list = [ | ||
| 278 | + '<' => '<', | ||
| 279 | + '>' => '>', | ||
| 280 | + '&' => '&', | ||
| 281 | + '´' => '´', | ||
| 282 | + '"' => '“', | ||
| 283 | + ' ' => ' ' | ||
| 284 | + ]; | ||
| 285 | + | ||
| 286 | + foreach ($list as $k => $v) { | ||
| 287 | + $str = str_replace($k, $v, $str); | ||
| 288 | + } | ||
| 289 | + | ||
| 290 | + return $str; | ||
| 291 | + } | ||
| 292 | + | ||
| 293 | + //路由入库 | ||
| 294 | + protected function set_map($route, $source, $source_id, $project_id) | ||
| 295 | + { | ||
| 296 | + if ($route) { | ||
| 297 | + $route_map = RouteMap::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->first(); | ||
| 298 | + if (!$route_map) { | ||
| 299 | + $route_map = new RouteMap(); | ||
| 300 | + $route_map->project_id = $project_id; | ||
| 301 | + $route_map->source = $source; | ||
| 302 | + $route_map->source_id = $source_id; | ||
| 303 | + $route_map->route = $route; | ||
| 304 | + | ||
| 305 | + if ($source == RouteMap::SOURCE_NEWS) { | ||
| 306 | + $route_map->path = RouteMap::SOURCE_NEWS; | ||
| 307 | + } elseif ($source == RouteMap::SOURCE_BLOG) { | ||
| 308 | + $route_map->path = RouteMap::SOURCE_BLOG; | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + $route_map->save(); | ||
| 312 | + } | ||
| 313 | + } | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + //资源下载 | ||
| 317 | + protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url) | ||
| 318 | + { | ||
| 319 | + if (!$url) { | ||
| 320 | + return ''; | ||
| 321 | + } | ||
| 322 | + | ||
| 323 | + $arr = parse_url($url); | ||
| 324 | + $scheme = $arr['scheme'] ?? ''; | ||
| 325 | + $host = $arr['host'] ?? ''; | ||
| 326 | + $path = $arr['path'] ?? ''; | ||
| 327 | + | ||
| 328 | + $url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path; | ||
| 329 | + | ||
| 330 | + if ((empty($host) || $host == $web_url_domain || $host == $home_url) && $path) { | ||
| 331 | + | ||
| 332 | + $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first(); | ||
| 333 | + if (!$source) { | ||
| 334 | + $new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete); | ||
| 335 | + | ||
| 336 | + if ($new_url) { | ||
| 337 | + CollectSource::insert([ | ||
| 338 | + 'project_id' => $project_id, | ||
| 339 | + 'origin' => $url, | ||
| 340 | + 'target' => $new_url, | ||
| 341 | + 'created_at' => date('Y-m-d H:i:s'), | ||
| 342 | + 'updated_at' => date('Y-m-d H:i:s'), | ||
| 343 | + ]); | ||
| 344 | + | ||
| 345 | + return getImageUrl($new_url); | ||
| 346 | + } else { | ||
| 347 | + return $url_complete; | ||
| 348 | + } | ||
| 349 | + } else { | ||
| 350 | + return getImageUrl($source['target']); | ||
| 351 | + } | ||
| 352 | + } else { | ||
| 353 | + return $url_complete; | ||
| 354 | + } | ||
| 355 | + } | ||
| 356 | +} |
| @@ -181,6 +181,7 @@ class LoginController extends BaseController | @@ -181,6 +181,7 @@ class LoginController extends BaseController | ||
| 181 | */ | 181 | */ |
| 182 | public function eventMessage(){ | 182 | public function eventMessage(){ |
| 183 | $message = file_get_contents("php://input"); | 183 | $message = file_get_contents("php://input"); |
| 184 | + @file_put_contents(storage_path('logs/lyh_error.log'), var_export($message, true) . PHP_EOL, FILE_APPEND); | ||
| 184 | $message = simplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR); | 185 | $message = simplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR); |
| 185 | $jsonData = json_encode($message); | 186 | $jsonData = json_encode($message); |
| 186 | $arrayData = json_decode($jsonData, true); | 187 | $arrayData = json_decode($jsonData, true); |
| @@ -299,25 +300,4 @@ class LoginController extends BaseController | @@ -299,25 +300,4 @@ class LoginController extends BaseController | ||
| 299 | } | 300 | } |
| 300 | return $data; | 301 | return $data; |
| 301 | } | 302 | } |
| 302 | - | ||
| 303 | - public function ceshi(){ | ||
| 304 | - $url = 'https://demo.globalso.site/'; | ||
| 305 | - $contextOptions = [ | ||
| 306 | - 'ssl' => [ | ||
| 307 | - 'verify_peer' => false, | ||
| 308 | - 'verify_peer_name' => false, | ||
| 309 | - ], | ||
| 310 | - ]; | ||
| 311 | - $context = stream_context_create($contextOptions); | ||
| 312 | - $sourceCode = file_get_contents($url, false, $context); | ||
| 313 | - $pattern = '/<style\b[^>]*>(.*?)<\/style>/s'; // 定义匹配`<style>`标签及其内容的正则表达式 | ||
| 314 | - $strippedContent = preg_replace($pattern, '', $sourceCode); // 删除`<style>`标签及其内容 | ||
| 315 | - $pattern = '/<link\b[^>]*>/'; // 定义匹配 `<link>` 标签的正则表达式 | ||
| 316 | - $strippedContent = preg_replace($pattern, '', $strippedContent); // 删除 `<link>` 标签 | ||
| 317 | - $pattern = '/>([^<]+)</'; // 定义匹配中间内容不是标签的正则表达式 | ||
| 318 | - $matches = array(); | ||
| 319 | - preg_match_all($pattern, $strippedContent, $matches); | ||
| 320 | - $textContentArray = $matches[1]; | ||
| 321 | - var_dump($textContentArray); | ||
| 322 | - } | ||
| 323 | } | 303 | } |
| @@ -425,7 +425,7 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -425,7 +425,7 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 425 | }); | 425 | }); |
| 426 | 426 | ||
| 427 | //自定义模板 | 427 | //自定义模板 |
| 428 | - Route::prefix('custom')->group(function () { | 428 | + Route::prefix('custom_module')->group(function () { |
| 429 | Route::any('/', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'lists'])->name('custom_lists'); | 429 | Route::any('/', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'lists'])->name('custom_lists'); |
| 430 | Route::any('/save', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'save'])->name('custom_save'); | 430 | Route::any('/save', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'save'])->name('custom_save'); |
| 431 | Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'del'])->name('custom_del'); | 431 | Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'del'])->name('custom_del'); |
-
请 注册 或 登录 后发表评论