Contract.php
6.59 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
namespace App\Models\Legal;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* Class Contract
* @package App\Models\Legal
*/
class Contract extends BaseModel
{
use HasFactory;
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = ['id' => 'integer', 'company_id' => 'integer', 'flag' => 'integer', 'cooperation_type' => 'integer', 'authorize_type' => 'integer', 'period' => 'integer', 'division' => 'integer', 'advance_days' => 'integer', 'is_exclusive' => 'integer', 'treaty_id' => 'integer', 'proxy_id' => 'integer', 'start_type' => 'integer', 'status' => 'integer', 'updated_at' => 'datetime', 'created_at' => 'datetime', 'user_id' => 'integer', 'copies_num' => 'integer'];
/**
* @var string[]
*/
public static $right_type = ['l'=>'作词','c'=>'作曲','p'=>'制作','s'=>'表演','a'=>'版权持有人'];
//合作类型 1:一次性费用 2:分成 3:分成+预付 5: 分成+一次性费用 6:抵扣成本后再分成 7:分成+预付+一次性费用 8:抵扣成本+分成+预付 9:一次性费用+抵扣成本后分成
/**
* 抵扣成本模式
* @var array
*/
public static $cost_mode = [6, 8, 9];
/**
* 预付模式
* @var array
*/
public static $prepaid_mode = [3, 7, 8];
/**
* @param $str
* @return array|string
*/
public static function transformRole($str)
{
if (empty($str)) return [];
$roles = array_unique(str_split(str_replace(',','', $str)));
sort($roles);
$rs = [];
foreach ($roles as $value) {
if (isset(self::$right_type[$value])) {
$rs[] = self::$right_type[$value];
}
}
return $rs;
}
/**
* @param $str
* @return string
*/
public static function transformRight($str)
{
$rs = '';
$roles = array_unique(str_split(str_replace(',','', $str)));
sort($roles);
foreach ($roles as $value) {
$rs .= (self::$right_type[$value] ?? '') . '+';
}
return rtrim($rs, '+');
}
/**
* @param $songs
* @return string
*/
public static function relationSong($songs)
{
$c = count($songs);
if ($c > 1) {
return "《{$songs[0]['name']}》等{$c}首歌";
} else if ($c == 1) {
return "《{$songs[0]['name']}》";
} else {
return '';
}
}
/**
* @param $roles
* @return array
*/
public static function getRole($right)
{
$roles = [];
foreach ($right as $item) {
$roles += self::transformRole($item['right_type']);
}
return array_unique($roles);
}
/**
* @param $cooperation_type
* @param $right
* @return string
*/
public static function getModel($cooperation_type, $right)
{
switch ($cooperation_type) {
case 1:
return "一次性费用" . self::formatCost($right);
break;
case 2:
return "分成" . self::formatDivide($right);
break;
case 3:
return '分成' . self::formatDivide($right) .'+预付'. self::formatPrepaid($right);
break;
case 5:
return '分成' . self::formatDivide($right) .'+一次性费用'. self::formatCost($right);
break;
case 6:
return '抵扣成本后再分成' . self::formatDivide($right);
break;
case 7:
return '分成' . self::formatDivide($right) . '+预付' .self::formatPrepaid($right). '+一次性费用' . self::formatCost($right);
break;
case 8:
return '抵扣成本后分成' .self::formatDivide($right). '+预付' . self::formatPrepaid($right);
break;
case 9:
return '一次性费用' . self::formatCost($right) .'+抵扣成本后分成' . self::formatDivide($right);
break;
}
}
/**
* 一次性费用
* @param $right
* @return string
*/
public static function formatCost($right)
{
$reward_money = 0;
foreach ($right as $item) {
$reward_money += (int)$item['reward_money'];
}
return "({$reward_money})";
}
/**
* 计算模式
* @param $cooperation_types
* @return int
*/
public static function cooperation($cooperation_types)
{
if (array_intersect($cooperation_types, self::$cost_mode) && array_intersect($cooperation_types, self::$prepaid_mode)) {
//抵扣和预付都有
return 1;
} else if (array_intersect($cooperation_types, self::$cost_mode)) {
//只有抵扣
return 2;
} else if (array_intersect($cooperation_types, self::$prepaid_mode)) {
//只有预付
return 3;
} else {
//只有分成
return 0;
}
}
/**
* 分成
* @param $right
* @return string
*/
public static function formatDivide($right)
{
$str = '';
foreach ($right as $item) {
$str .= self::transformRight($item['right_type']) . ($item['proportion'] * 100) . '%,';
}
$str = rtrim($str, ',');
return "($str)";
}
/**
* 预付
* @param $right
* @return string
*/
public static function formatPrepaid($right)
{
$prepaid = 0;
foreach ($right as $item) {
$prepaid += (int)$item['prepaid_money'];
}
return "({$prepaid})";
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function files()
{
return $this->hasMany(ContractFile::class, 'contract_id', 'id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function moreSongs()
{
return $this->belongsToMany(Song::class, 'contract_song', 'contract_id', 'song_id')
->select('songs.id', 'songs.custom_id', 'songs.name', 'songs.singer');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function detail()
{
return $this->hasOne(ContractDetail::class, 'contract_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function stakeholderContract()
{
return $this->hasMany(StakeholderContract::class, 'contract_id');
}
}