ActivityUser.php
1.53 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
<?php
namespace App\Models;
use App\Enums\ActivityWorkModeEnum;
use App\Enums\ActivityWorkTypeEnum;
use App\Support\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;
class ActivityUser extends Model
{
use SoftDeletes;
protected $table = 'activity_has_users';
public $guarded = [];
protected $casts = [
'type' => ActivityWorkTypeEnum::class,
'mode' => ActivityWorkModeEnum::class
];
protected $hidden = ['deleted_at'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
}
public function project(): BelongsTo
{
return $this->belongsTo(Project::class)->withTrashed();
}
public function unread()
{
$userId = Auth::id();
return $this->hasOne(UserMessage::class, ['sender_id', 'activity_id'], ['user_id', 'activity_id'])->where(['type' => 3, 'receiver_id' => $userId, 'is_read' => 0, 'is_bind' => 0])->latest();
}
public function ShareUser()
{
return $this->hasOne(ActivityShareUser::class, ['activity_id', 'user_id'], ['activity_id', 'user_id']);
}
public function SelfPrice()
{
return $this->hasOne(ActivityUserPrice::class, ['activity_id', 'user_id'], ['activity_id', 'user_id']);
}
public function activity()
{
return $this->hasOne(Activity::class, 'id', 'activity_id');
}
}