Company   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 38
c 1
b 0
f 0
dl 0
loc 98
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A profile() 0 3 1
A accounts() 0 3 1
A apply() 0 3 1
A logs() 0 3 1
A getLogoAttribute() 0 8 2
1
<?php
2
3
namespace SimpleCMS\Company\Models;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Collection;
8
use SimpleCMS\Framework\Contracts\SimpleMedia;
9
use Illuminate\Database\Eloquent\Relations\HasMany;
10
use SimpleCMS\Framework\Traits\MediaAttributeTrait;
11
use SimpleCMS\Framework\Traits\PrimaryKeyUuidTrait;
12
use Illuminate\Database\Eloquent\Factories\HasFactory;
13
use Spatie\MediaLibrary\MediaCollections\Models\Media;
14
15
/**
16
 * Company Model
17
 * @author Dennis Lui <[email protected]>
18
 *
19
 * @property string $id 主键
20
 * @property string $company_apply_id 注册申请表ID
21
 * @property string $name 名称
22
 * @property string $uid 暴露UID
23
 * @property int $status 状态
24
 * @property string $type 资料类型
25
 * @property bool $is_valid 是否有效
26
 * @property ?string $introduction 介绍说明
27
 * @property int $level 账户等级
28
 * @property ?string $business 商务信息
29
 * @property ?string $remark 备注
30
 * @property ?Carbon $success_at 通过时间
31
 * @property ?Carbon $reject_at 拒绝时间
32
 * @property-read ?Carbon $created_at 创建时间
33
 * @property-read ?Carbon $updated_at 更新时间
34
 * @property-read ?Collection<CompanyAccount> $accounts 登录账号
35
 * @property-read ?Collection<CompanyLog> $logs 请求日志
36
 * @property-read ?CompanyProfile $profile 子项
37
 * @property-read ?CompanyApply $apply 子项
38
 * @property-read ?Collection<Media> $media 附件
39
 * @property-read ?array<string,string> $logo Logo
40
 */
41
class Company extends Model implements SimpleMedia
42
{
43
    use HasFactory, PrimaryKeyUuidTrait, MediaAttributeTrait;
44
45
    /**
46
     * Logo
47
     */
48
    const MEDIA_LOGO = 'logo';
49
50
    const HAS_ONE_MEDIA = ['logo'];
51
52
    /**
53
     * 可输入字段
54
     */
55
    protected $fillable = [
56
        'id',
57
        'company_apply_id',
58
        'name',
59
        'uid',
60
        'status',
61
        'type',
62
        'is_valid',
63
        'introduction',
64
        'level',
65
        'business',
66
        'remark',
67
        'success_at',
68
        'reject_at',
69
    ];
70
71
    /**
72
     * 显示字段类型
73
     */
74
    public $casts = [
75
        'status' => 'integer',
76
        'level' => 'integer',
77
        'is_valid' => 'boolean',
78
        'success_at' => 'datetime',
79
        'reject_at' => 'datetime',
80
        'created_at' => 'datetime',
81
        'updated_at' => 'datetime'
82
    ];
83
84
    /**
85
     * 追加字段
86
     */
87
    public $appends = ['logo'];
88
89
    /**
90
     * 隐藏关系
91
     */
92
    public $hidden = ['media'];
93
94
    public function getLogoAttribute()
95
    {
96
        if (!$media = $this->getFirstMedia(self::MEDIA_LOGO))
97
            return [];
98
        return [
99
            'name' => $media->file_name,
100
            'url' => $media->original_url,
101
            'uuid' => $media->uuid
102
        ];
103
    }
104
105
    /**
106
     * 登录账号
107
     * @return HasMany
108
     */
109
    public function accounts()
110
    {
111
        return $this->hasMany(CompanyAccount::class);
112
    }
113
114
    /**
115
     * 企业资料
116
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
117
     */
118
    public function profile()
119
    {
120
        return $this->hasOne(CompanyProfile::class);
121
    }
122
123
    /**
124
     * 申请记录
125
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
126
     */
127
    public function apply()
128
    {
129
        return $this->belongsTo(CompanyApply::class);
130
    }
131
132
    /**
133
     * 操作日志
134
     * @return HasMany
135
     */
136
    public function logs()
137
    {
138
        return $this->hasMany(CompanyLog::class);
139
    }
140
}
141