合并分支 'akun' 到 'master'
Akun 查看合并请求 !48
正在显示
5 个修改的文件
包含
91 行增加
和
17 行删除
| @@ -5,6 +5,7 @@ namespace App\Console\Commands\Update; | @@ -5,6 +5,7 @@ namespace App\Console\Commands\Update; | ||
| 5 | use App\Models\Collect\CollectSource; | 5 | use App\Models\Collect\CollectSource; |
| 6 | use App\Models\Collect\CollectTask; | 6 | use App\Models\Collect\CollectTask; |
| 7 | use App\Models\Com\UpdateLog; | 7 | use App\Models\Com\UpdateLog; |
| 8 | +use App\Models\RouteMap\RouteMap; | ||
| 8 | use App\Services\CosService; | 9 | use App\Services\CosService; |
| 9 | use App\Services\ProjectServer; | 10 | use App\Services\ProjectServer; |
| 10 | use Illuminate\Console\Command; | 11 | use Illuminate\Console\Command; |
| @@ -37,9 +38,9 @@ class HtmlCollect extends Command | @@ -37,9 +38,9 @@ class HtmlCollect extends Command | ||
| 37 | 38 | ||
| 38 | public function handle() | 39 | public function handle() |
| 39 | { | 40 | { |
| 40 | -// while (true) { | 41 | + while (true) { |
| 41 | $this->start_collect(); | 42 | $this->start_collect(); |
| 42 | -// } | 43 | + } |
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | protected function start_collect() | 46 | protected function start_collect() |
| @@ -114,11 +115,29 @@ class HtmlCollect extends Command | @@ -114,11 +115,29 @@ class HtmlCollect extends Command | ||
| 114 | return false; | 115 | return false; |
| 115 | } | 116 | } |
| 116 | 117 | ||
| 118 | + switch ($update_log->api_type) { | ||
| 119 | + case 'page': | ||
| 120 | + $source = RouteMap::SOURCE_PAGE; | ||
| 121 | + break; | ||
| 122 | + case 'news': | ||
| 123 | + $source = RouteMap::SOURCE_NEWS; | ||
| 124 | + break; | ||
| 125 | + case 'blog': | ||
| 126 | + $source = RouteMap::SOURCE_BLOG; | ||
| 127 | + break; | ||
| 128 | + case 'tag': | ||
| 129 | + $source = RouteMap::SOURCE_PRODUCT_KEYWORD; | ||
| 130 | + break; | ||
| 131 | + default: | ||
| 132 | + $source = RouteMap::SOURCE_PRODUCT; | ||
| 133 | + break; | ||
| 134 | + } | ||
| 135 | + | ||
| 117 | $complete = false; | 136 | $complete = false; |
| 118 | //设置数据库 | 137 | //设置数据库 |
| 119 | $project = ProjectServer::useProject($update_log->project_id); | 138 | $project = ProjectServer::useProject($update_log->project_id); |
| 120 | if ($project) { | 139 | if ($project) { |
| 121 | - $collect_list = CollectTask::select(['id', 'project_id'])->where('project_id', $update_log['project_id'])->where('status', CollectTask::STATUS_UN)->limit(50)->get(); | 140 | + $collect_list = CollectTask::select(['id', 'project_id'])->where('project_id', $update_log['project_id'])->where('source', $source)->where('status', CollectTask::STATUS_UN)->orderBy('language', 'asc')->limit(50)->get(); |
| 122 | 141 | ||
| 123 | if ($collect_list->count() == 0) { | 142 | if ($collect_list->count() == 0) { |
| 124 | $complete = true; | 143 | $complete = true; |
| @@ -76,6 +76,22 @@ class ProjectUpdate extends Command | @@ -76,6 +76,22 @@ class ProjectUpdate extends Command | ||
| 76 | $task->status = UpdateLog::STATUS_ING;//同步中 | 76 | $task->status = UpdateLog::STATUS_ING;//同步中 |
| 77 | $task->save(); | 77 | $task->save(); |
| 78 | 78 | ||
| 79 | + $domain_arr = parse_url($api_url); | ||
| 80 | + //获取网站配置 | ||
| 81 | + $link_type = 0; | ||
| 82 | + $url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text'; | ||
| 83 | + $data_config = http_get($url_web_config, ['charset' => 'UTF-8']); | ||
| 84 | + if ($data_config) { | ||
| 85 | + $link_type = $data_config['link_type']; | ||
| 86 | + } | ||
| 87 | + //获取所有语种 | ||
| 88 | + $language_list = []; | ||
| 89 | + $url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json'; | ||
| 90 | + $data_language = http_get($url_language, ['charset' => 'UTF-8']); | ||
| 91 | + if ($data_language) { | ||
| 92 | + $language_list = array_column($data_language, 'short'); | ||
| 93 | + } | ||
| 94 | + | ||
| 79 | //设置数据库 | 95 | //设置数据库 |
| 80 | $project = ProjectServer::useProject($project_id); | 96 | $project = ProjectServer::useProject($project_id); |
| 81 | if ($project) { | 97 | if ($project) { |
| @@ -126,7 +142,7 @@ class ProjectUpdate extends Command | @@ -126,7 +142,7 @@ class ProjectUpdate extends Command | ||
| 126 | $id = $keyword['id']; | 142 | $id = $keyword['id']; |
| 127 | } | 143 | } |
| 128 | 144 | ||
| 129 | - CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT_KEYWORD, $id); | 145 | + CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $link_type, $language_list); |
| 130 | } | 146 | } |
| 131 | } | 147 | } |
| 132 | } | 148 | } |
| @@ -258,7 +274,7 @@ class ProjectUpdate extends Command | @@ -258,7 +274,7 @@ class ProjectUpdate extends Command | ||
| 258 | $id = $product['id']; | 274 | $id = $product['id']; |
| 259 | } | 275 | } |
| 260 | 276 | ||
| 261 | - CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id); | 277 | + CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list); |
| 262 | } | 278 | } |
| 263 | } | 279 | } |
| 264 | } | 280 | } |
| @@ -312,7 +328,7 @@ class ProjectUpdate extends Command | @@ -312,7 +328,7 @@ class ProjectUpdate extends Command | ||
| 312 | $id = $news['id']; | 328 | $id = $news['id']; |
| 313 | } | 329 | } |
| 314 | 330 | ||
| 315 | - CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id); | 331 | + CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list); |
| 316 | } | 332 | } |
| 317 | } | 333 | } |
| 318 | } | 334 | } |
| @@ -360,7 +376,7 @@ class ProjectUpdate extends Command | @@ -360,7 +376,7 @@ class ProjectUpdate extends Command | ||
| 360 | $id = $custom['id']; | 376 | $id = $custom['id']; |
| 361 | } | 377 | } |
| 362 | 378 | ||
| 363 | - CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id); | 379 | + CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list); |
| 364 | } | 380 | } |
| 365 | } | 381 | } |
| 366 | } | 382 | } |
| @@ -84,7 +84,7 @@ if (!function_exists('http_get')) { | @@ -84,7 +84,7 @@ if (!function_exists('http_get')) { | ||
| 84 | /** | 84 | /** |
| 85 | * 发送http get请求 | 85 | * 发送http get请求 |
| 86 | * @param type $url | 86 | * @param type $url |
| 87 | - * @return type | 87 | + * @return [] |
| 88 | */ | 88 | */ |
| 89 | function http_get($url, $header = []) | 89 | function http_get($url, $header = []) |
| 90 | { | 90 | { |
| @@ -14,27 +14,66 @@ class CollectTask extends Base | @@ -14,27 +14,66 @@ class CollectTask extends Base | ||
| 14 | 14 | ||
| 15 | const STATUS_UN = 0; | 15 | const STATUS_UN = 0; |
| 16 | const STATUS_ING = 1; | 16 | const STATUS_ING = 1; |
| 17 | - const STATUS_COM= 2; | 17 | + const STATUS_COM = 2; |
| 18 | 18 | ||
| 19 | - public static function _insert($url, $project_id, $source, $source_id) | 19 | + public static function _insert($url, $project_id, $source, $source_id, $link_type = 0, $language_list = []) |
| 20 | { | 20 | { |
| 21 | - if(!$url){ | 21 | + if (!$url) { |
| 22 | return; | 22 | return; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | $url_arr = parse_url($url); | 25 | $url_arr = parse_url($url); |
| 26 | 26 | ||
| 27 | - $data = [ | 27 | + $where = [ |
| 28 | 'project_id' => $project_id, | 28 | 'project_id' => $project_id, |
| 29 | 'source' => $source, | 29 | 'source' => $source, |
| 30 | 'source_id' => $source_id, | 30 | 'source_id' => $source_id, |
| 31 | 'domain' => $url_arr['host'], | 31 | 'domain' => $url_arr['host'], |
| 32 | - 'route' => $url_arr['path'] | 32 | + 'route' => $url_arr['path'], |
| 33 | + 'language' => '' | ||
| 33 | ]; | 34 | ]; |
| 34 | 35 | ||
| 35 | - $task = self::where($data)->first(); | ||
| 36 | - if(!$task){ | ||
| 37 | - $data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s'); | 36 | + $task = self::where($where)->first(); |
| 37 | + if (!$task) { | ||
| 38 | + $now = date('Y-m-d H:i:s'); | ||
| 39 | + $data = [ | ||
| 40 | + [ | ||
| 41 | + 'project_id' => $project_id, | ||
| 42 | + 'source' => $source, | ||
| 43 | + 'source_id' => $source_id, | ||
| 44 | + 'domain' => $url_arr['host'], | ||
| 45 | + 'route' => $url_arr['path'], | ||
| 46 | + 'language' => '', | ||
| 47 | + 'created_at' => $now, | ||
| 48 | + 'updated_at' => $now, | ||
| 49 | + ] | ||
| 50 | + ]; | ||
| 51 | + | ||
| 52 | + if ($link_type > 0 && $language_list) { | ||
| 53 | + $domain_arr = explode(',', $url_arr['host']); | ||
| 54 | + foreach ($language_list as $v_lan) { | ||
| 55 | + if ($link_type == 1) { | ||
| 56 | + //二级域名 | ||
| 57 | + $domain_arr[0] = $v_lan; | ||
| 58 | + $new_domain = implode('.', $domain_arr); | ||
| 59 | + } else { | ||
| 60 | + //二级目录 | ||
| 61 | + $new_domain = $url_arr['host'] . '/' . $v_lan; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + $data[] = [ | ||
| 65 | + 'project_id' => $project_id, | ||
| 66 | + 'source' => $source, | ||
| 67 | + 'source_id' => $source_id, | ||
| 68 | + 'domain' => $new_domain, | ||
| 69 | + 'route' => $url_arr['path'], | ||
| 70 | + 'language' => $v_lan, | ||
| 71 | + 'created_at' => $now, | ||
| 72 | + 'updated_at' => $now, | ||
| 73 | + ]; | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + | ||
| 38 | self::insert($data); | 77 | self::insert($data); |
| 39 | } | 78 | } |
| 40 | } | 79 | } |
| @@ -33,7 +33,7 @@ class UpdateLog extends Model | @@ -33,7 +33,7 @@ class UpdateLog extends Model | ||
| 33 | $log->api_type = $type; | 33 | $log->api_type = $type; |
| 34 | $log->api_url = $url; | 34 | $log->api_url = $url; |
| 35 | $log->sort = $type == 'category' ? 0 :1; | 35 | $log->sort = $type == 'category' ? 0 :1; |
| 36 | - $log->collect_status = in_array($type, ['website_info', 'category']) ? 1 : 0; | 36 | + $log->collect_status = ($type == 'category' || $type == 'website_info') ? 1 : 0; |
| 37 | return $log->save(); | 37 | return $log->save(); |
| 38 | } | 38 | } |
| 39 | return true; | 39 | return true; |
-
请 注册 或 登录 后发表评论