IssueService.php
3.13 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
<?php
namespace App\Services;
use App\Helper\AesEncrypt;
use App\Helper\CosHelper;
use App\Helper\ErrorCode;
use App\Helper\Response;
use App\Models\Legal\SongsApply;
use App\Models\Legal\Stakeholder;
use App\Models\Legal\Subject;
use Illuminate\Support\Facades\Log;
/**
* Class IssueService
* @package App\Services
*/
class IssueService extends Service
{
/**
* 转发
* @return \Illuminate\Http\JsonResponse
*/
public function forward()
{
$client = new \GuzzleHttp\Client([
'base_uri' => env('resource_url'),
'timeout' => 3.0,
]);
$token = uniqid();
try {
$params['data'] = $this->request->all();
$params['ext'] = [
'user_id' => $this->request->get('identifier')->company_id, //机构id
'operator' => $this->request->get('identifier')->user_id, //操作人id
'stakeholder_ids' => $this->request->get('stakeholder_ids'),
];
Log::info(__METHOD__.':请求参数', ['params'=>$params, 'token'=>$token, 'uri'=>$client->post($this->request->getRequestUri())]);
$data = ['params' => AesEncrypt::encrypt(json_encode($params))];
$response = $client->post($this->request->getRequestUri(), [
'json' => $data,
]);
$respArr = json_decode($response->getBody()->getContents(), true);
$respArr['msg'] = $respArr['message'];
unset($respArr['message']);
Log::info(__METHOD__.':请求返回体', ['respArr'=>$respArr, 'token'=>$token, 'data'=>$data, 'uri'=>$client->post($this->request->getRequestUri())]);
return response()->json($respArr, 200);
} catch (\Throwable $throwable) {
return Response::error(ErrorCode::SERVER_ERROR, $throwable->getMessage());
}
}
/**
* 版权方
* @return \Illuminate\Http\JsonResponse
*/
public function subCompany()
{
$company_ids = Stakeholder::query()->whereIn('id', $this->request->get('stakeholder_ids'))->pluck('company_id')->toArray();
$subject = Subject::query()->whereIn('company_id', $company_ids)
->where('attr', 'like', "%3%")
->groupBy('no')
->get(['no as value', 'name']);
return Response::success($subject);
}
/**
* 发行(上架成功记录)
* @return \Illuminate\Http\JsonResponse
*/
public function latestRecord()
{
$res = SongsApply::query()->where(['from'=>1, 'user_id'=>$this->request->get('identifier')->company_id])
->whereNotNull('qy_url')->with('songs_album.cover:link_id,key')
->select(['name','album_id','singer','issue_time','qy_url'])->paginate($this->pageSize);
$cos = new CosHelper(env('MATERIAL_BUCKET'));
foreach ($res as &$item) {
if (!empty($item->songs_album)) {
$item->cover = $cos->getPreviewUrl($item->songs_album->cover->key);
}
}
return Response::success($res);
}
}