CollectTask.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace App\Models\Collect;
use App\Models\Base;
class CollectTask extends Base
{
//设置关联表名
protected $table = 'gl_collect_task';
//连接数据库
protected $connection = 'custom_mysql';
const STATUS_UN = 0;
const STATUS_ING = 1;
const STATUS_COM = 2;
const STATUS_FAIL = 3;
public static function _insert($url, $project_id, $source, $source_id, $domain, $link_type = 0, $language_list = [], $page_list = [])
{
if (!$url) {
return;
}
$url_arr = parse_url($url);
$where = [
'project_id' => $project_id,
'source' => $source,
'source_id' => $source_id,
'language' => ''
];
$task = self::where($where)->first();
$data = [];
$now = date('Y-m-d H:i:s');
if (!$task) {
$data[] = [
'project_id' => $project_id,
'source' => $source,
'source_id' => $source_id,
'domain' => $domain,
'route' => substr($url_arr['path'], 0, 1) == '/' ? $url_arr['path'] : '/' . $url_arr['path'],
'language' => '',
'created_at' => $now,
'updated_at' => $now,
];
if ($link_type > 0 && $language_list && in_array($url_arr['path'], $page_list)) {
$domain_arr = explode('.', $url_arr['host'] ?? $domain);
foreach ($language_list as $v_lan) {
if ($link_type == 1) {
//二级域名
$domain_arr[0] = $v_lan;
$new_domain = implode('.', $domain_arr);
} else {
//二级目录
$new_domain = ($url_arr['host'] ?? $domain) . '/' . $v_lan;
}
$data[] = [
'project_id' => $project_id,
'source' => $source,
'source_id' => $source_id,
'domain' => $new_domain,
'route' => $url_arr['path'],
'language' => $v_lan,
'created_at' => $now,
'updated_at' => $now,
];
}
}
self::insert($data);
}
}
}