Task.php
1.5 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
<?php
namespace App\Models\Task;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Models\Base;
use App\Services\Facades\Upload;
class Task extends Base
{
//设置关联表名
protected $table = 'gl_task';
protected $appends = ['project_id_text', 'status_text', 'timeout'];
const STATUS_WAIT = 0;
const STATUS_DONGING = 1;
const STATUS_DOWN = 2;
public static function statusMap(){
return [
self::STATUS_WAIT => '未开始',
self::STATUS_DONGING => '进程中',
self::STATUS_DOWN => '已完成',
];
}
public function getProjectIdTextAttribute(){
$project = ProjectLogic::instance()->getCacheInfo($this->project_id);
return $project['title'] ?? '';
}
public function getStatusTextAttribute(){
return self::statusMap()[$this->status] ?? '';
}
public function setAttachmentAttribute($value){
$this->attributes['attachment'] = Upload::url2path($value);
}
public function getAttachmentAttribute($value){
return Upload::path2url($value);
}
public function getTimeoutAttribute(){
if($this->status != self::STATUS_DOWN && strtotime($this->end_at) < time()){
return floor((time() - strtotime($this->end_at)) / 60);
}
return 0;
}
public function owner(){
return $this->hasMany(TaskOwner::class,'task_id','id');
}
public function follow(){
return $this->hasMany(TaskFollow::class,'task_id','id');
}
}