Contract.php
7.94 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?php
namespace App\Models\Legal;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Contract
* @package App\Models\Legal
*/
class Contract extends BaseModel
{
use HasFactory,SoftDeletes;
/**
* 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 $rightgetModel
* @return string
*/
public static function getModel($cooperation_type, $right)
{
switch ($cooperation_type) {
case -1:
return '未填写';
case 0:
return '无';
case 1:
return "一次性费用" . self::formatCost($right);
case 2:
return "分成" . self::formatDivide($right);
case 3:
return '分成' . self::formatDivide($right) .'+预付'. self::formatPrepaid($right);
case 5:
return '分成' . self::formatDivide($right) .'+一次性费用'. self::formatCost($right);
case 6:
return '抵扣成本后再分成' . self::formatDivide($right);
case 7:
return '分成' . self::formatDivide($right) . '+预付' .self::formatPrepaid($right). '+一次性费用' . self::formatCost($right);
case 8:
return '抵扣成本后分成' .self::formatDivide($right). '+预付' . self::formatPrepaid($right);
case 9:
return '一次性费用' . self::formatCost($right) .'+抵扣成本后分成' . self::formatDivide($right);
}
}
/**
* 费用模式
* @param $cooperation_type
* @return string
*/
public static function getCooperation($cooperation_type)
{
switch ($cooperation_type) {
case 1:
return "一次性费用";
case 2:
return "分成";
case 3:
return '分成+预付';
case 5:
return '分成+一次性费用';
case 6:
return '抵扣成本后再分成';
case 7:
return '分成+预付+一次性费用';
case 8:
return '抵扣成本后分成+预付';
case 9:
return '一次性费用+抵扣成本后分成';
}
}
/**
* 一次性费用
* @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;
}
}
/**
* 授权区域区域
* @return string
*/
public static function getDistrict($district_id)
{
if (empty($district_id)) return '';
$district_ids = explode(',', $district_id);
$district_data = District::getDistricts();
foreach ($district_ids as $id) {
$district[] = $district_data[$id] ?? '';
}
return join('|', array_filter($district));
}
/**
* 授权形式
* @param $is_exclusive
* @return string
*/
public static function isExclusive($is_exclusive)
{
return $is_exclusive ? '独家' : '非独';
}
/**
* 分成
* @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');
}
}