ActivityWork.php
4.18 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
namespace App\Models\Views;
use App\Enums\ActivityStatusEnum;
use App\Enums\ActivityWorkModeEnum;
use App\Enums\ActivityWorkSingTypeEnum;
use App\Enums\ActivityWorkStatusEnum;
use App\Enums\ActivityWorkTypeEnum;
use App\Models\Activity;
use App\Models\ActivityUserPrice;
use App\Models\Pivots\ActivityTagPivot;
use App\Models\Project;
use App\Models\SystemTag;
use App\Models\User;
use App\Support\Model;
use Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo;
use Awobaz\Compoships\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class ActivityWork extends Model
{
use SoftDeletes;
protected $table = 'activity_works';
/**
* @var array<string,mixed>
*/
protected $casts = [
'share_id' => 'int',
'user_id' => 'int',
'business_id' => 'int',
'syn_data' => 'json',
'type' => ActivityWorkTypeEnum::class,
'mode' => ActivityWorkModeEnum::class,
'sing_type' => ActivityWorkSingTypeEnum::class,
'status' => ActivityWorkStatusEnum::class,
'activity_status' => ActivityStatusEnum::class
];
/**
* @return string
*/
public function getFormatStatus(): string
{
if ($this->getAttribute('status') === ActivityWorkStatusEnum::SUCCESS) {
return '确认合作';
}
if ($this->getAttribute('status') === ActivityWorkStatusEnum::REJECT) {
return '不合适';
}
if ($this->getAttribute('status') === ActivityWorkStatusEnum::WAIT && $this->getAttribute('activity_status') === 1) {
return '待采纳';
}
if ($this->getAttribute('status') === ActivityWorkStatusEnum::WAIT && $this->getAttribute('activity_status') >= 3) {
return '未采纳';
}
return '其他';
}
/**
* @param string $format
* @return string
*/
public function getUserFullName(string $format = '%s(%s)'): string
{
return sprintf($format, $this->getAttribute('user_nick_name'), $this->getAttribute('user_real_name'));
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
*/
public function activity(): BelongsTo
{
return $this->belongsTo(Activity::class)->withTrashed();
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
*/
public function business(): BelongsTo
{
return $this->belongsTo(User::class, 'business_id')->withTrashed();
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
*/
public function broker(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
*/
public function share(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
*/
public function children(): HasMany
{
return $this->hasMany(__CLASS__, ['activity_id', 'user_id'], ['activity_id', 'user_id'])
->where('type', ActivityWorkTypeEnum::SAVE);
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
*/
public function price(): BelongsTo
{
return $this->belongsTo(ActivityUserPrice::class);
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
*/
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function tags(): BelongsToMany
{
return $this
->belongsToMany(SystemTag::class, ActivityTagPivot::class, 'activity_id', 'tag_id', 'activity_id', 'id')
->wherePivotNull('deleted_at')->withTimestamps();
}
}