MusicianAgreementService.php
6.48 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
<?php
namespace App\Services;
use App\Helper\CosHelper;
use App\Helper\Response;
use App\Models\Legal\Contract;
use App\Models\Legal\StakeholderContract;
use App\Models\Legal\Treaty;
use Qcloud\Cos\Client;
/**
* Class MusicianAgreementService
* @package App\Services
*/
class MusicianAgreementService extends Service
{
/**
* @return \Illuminate\Http\JsonResponse
*/
public function treatyList()
{
$res = Treaty::query()->whereIn('party_b', $this->stakeholder_ids)->where('deadline_date', '>', $this->now)->with(['file:id,treaty_id,file_id', 'file.fileInfo:id,key'])
->select(['id', 'treaty_name', 'treaty_type', 'service_type', 'deadline_date', 'music_no'])->orderByDesc('created_at')->paginate($this->pageSize);
$client = new CosHelper();
foreach ($res as &$item) {
$item_res = $item->toArray();
$files = [];
if (!empty($item_res['file'])) {
foreach ($item_res['file'] as $file_item) {
!empty($file_item['file_info']['key']) && $files[] = $file_item['file_info']['key'];
}
}
foreach ($files as &$file) {
$file = $client->getPreviewUrl($file);
}
$item->setAttribute('files', $files);
unset($item->file);
}
return Response::success($res);
}
/**
* 我的合约列表
* @return \Illuminate\Http\JsonResponse
*/
public function agreementList()
{
$client = new CosHelper();
$treaty = Treaty::query()->whereIn('party_b', $this->stakeholder_ids)->with(['file:id,treaty_id,file_id', 'file.fileInfo:id,key'])
->select(['id', 'treaty_no as no', 'treaty_type', 'treaty_name as name', 'effective_date', 'deadline_date as date_ending', 'cost_model', 'music_no', 's_rate', 'l_rate', 'c_rate', 'p_rate', 'cost', 'prepaid'])->get();
foreach ($treaty as &$item) {
$item->setAttribute('model', $item->charge_model);
$treaty_item = $item->toArray();
$files = [];
if (!empty($treaty_item['file'])) {
if ($file_info = array_column($treaty_item['file'], 'file_info')){
$files = array_column($file_info, 'key');
}
}
foreach ($files as &$file) {
$file = $client->getPreviewUrl($file);
}
if ((time() >= strtotime($item->effective_date)) && (time() <= strtotime($item->date_ending))) {
//进行中
$item->setAttribute('status', 1);
} else {
//未生效 || 已经结束
$item->setAttribute('status', 0);
}
$item->setAttribute('type', 1); //经纪合约
$item->setAttribute('files', $files);
unset($item->file);
}
//歌曲版权
$contract_table = Contract::table();
$contract = Contract::query()->with(['files', 'files.fileInfo:id,key', 'moreSongs'])->where(['flag'=>1])->whereIn('sc.stakeholder_id', $this->stakeholder_ids)
->join(StakeholderContract::table()." as sc", Contract::table().".id", '=', 'sc.contract_id')
->select(["{$contract_table}.id", 'contract_no', 'name', 'right_type', 'proportion', 'date_signing', 'date_starting', 'date_ending', 'cooperation_type', 'prepaid_money', 'reward_money'])->get()->toArray();
$rights = [];
foreach ($contract as $contract_item) {
$files = [];
if (!empty($contract_item['files'])) {
if ($file_info = array_column($contract_item['files'], 'file_info')){
$files = array_column($file_info, 'key');
}
}
foreach ($files as &$file) {
$file = $client->getPreviewUrl($file);
}
if (!isset($rights[$contract_item['id']])) {
$rights[$contract_item['id']] = [
'id'=>$contract_item['id'],
'no'=>$contract_item['contract_no'],
'name'=>$contract_item['name'],
'date_signing'=>$contract_item['date_signing'],
'date_starting'=>$contract_item['date_starting'],
'date_ending'=>$contract_item['date_ending'], //截止日期
'files'=>$files,
'songs'=>$contract_item['more_songs'],
'type'=>2, //歌曲版权合同
'cooperation_type'=>$contract_item['cooperation_type'],
];
}
$rights[$contract_item['id']]['right'][] = [
'right_type'=>$contract_item['right_type'],
'proportion'=>$contract_item['proportion'],
'prepaid_money'=>$contract_item['prepaid_money'],
'reward_money'=>$contract_item['reward_money'],
];
if ((strtotime($contract_item['date_starting']) >= time()) && (strtotime($contract_item['date_ending']) <= time())) {
//进行中
$rights[$contract_item['id']]['status'] = 1;
} else {
//未生效 || 已经结束
$rights[$contract_item['id']]['status'] = 0;
}
}
$rights = array_values($rights);
foreach ($rights as &$right_item) {
//关联歌曲
$right_item['relation_song'] = Contract::relationSong($right_item['songs']);
//权利类型
$right_item['role'] = Contract::getRole($right_item['right']);
//费用模式
$right_item['model'] = Contract::getModel($right_item['cooperation_type'], $right_item['right']);
unset($right_item['songs'], $right_item['right']);
}
$agreement = array_merge($treaty->toArray(), $rights);
//排序
usort($agreement, function ($a, $b) {
if ($a['status'] == $b['status']) {
if (!empty($a['date_signing']) && !empty($b['date_signing'])) {
return strtotime($a['date_signing']) > strtotime($b['date_signing']) ? -1 : 1;
} else if (!empty($a['date_signing'])) {
return -1;
} else if (!empty($b['date_signing'])) {
return 1;
} else {
return -1;
}
}
return $a['status'] > $b['status'] ? -1 : 1;
});
return Response::success($agreement);
}
}