UpdateLog.php
1.7 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
<?php
namespace App\Models\Com;
use Illuminate\Database\Eloquent\Model;
class UpdateLog extends Model
{
//设置关联表名
protected $table = 'gl_update_log';
const STATUS_UN = 0;//未开始
const STATUS_ING = 1;//导入中
const STATUS_COM = 2;//导入完成
const COLLECT_STATUS_UN = 0;//未开始
const COLLECT_STATUS_COM = 1;//全站小语种采集完成
const COLLECT_STATUS_MAIN = 2;//英语主站采集完成
/**
* 创建更新日志
* @param $project_id
* @param $type
* @param $url
* @param $sort
* @return mixed
*/
public static function createLog($project_id, $type, $url)
{
$log = self::where('project_id', $project_id)->where('api_type', $type)->first();
if (!$log) {
$log = new self();
$log->project_id = $project_id;
$log->api_type = $type;
$log->api_url = $url;
$log->sort = ($type == 'category' || $type == 'category_news' || $type == 'tag') ? 0 : 1;
$log->collect_status = ($type == 'category' || $type == 'category_news' || $type == 'website_info' || $type == 'tag') ? 1 : 0;
return $log->save();
}
return true;
}
/**
* 重置更新日志
* @param $project_id
* @return bool
* @author Akun
* @date 2023/11/24 11:43
*/
public static function updateLog($project_id)
{
$logs = self::where('project_id', $project_id)->get();
foreach ($logs as $log) {
$log->status = 0;
if (!in_array($log->api_type, ['website_info', 'category'])) {
$log->collect_status = 0;
}
$log->save();
}
return true;
}
}