文件上传
Showing
2 changed files
with
70 additions
and
1 deletions
... | @@ -7,11 +7,13 @@ use App\Helper\ErrorCode; | ... | @@ -7,11 +7,13 @@ use App\Helper\ErrorCode; |
7 | use App\Helper\RedisClient; | 7 | use App\Helper\RedisClient; |
8 | use App\Helper\Response; | 8 | use App\Helper\Response; |
9 | use App\Models\Legal\Contract; | 9 | use App\Models\Legal\Contract; |
10 | use App\Models\Legal\FileMap; | ||
10 | use App\Models\Legal\PropertyFileType; | 11 | use App\Models\Legal\PropertyFileType; |
11 | use App\Models\Legal\PropertyShare; | 12 | use App\Models\Legal\PropertyShare; |
12 | use App\Models\Legal\PropertyShareVerification; | 13 | use App\Models\Legal\PropertyShareVerification; |
13 | use App\Models\Legal\PropertyTrack; | 14 | use App\Models\Legal\PropertyTrack; |
14 | use App\Models\Legal\PropertyTrackFile; | 15 | use App\Models\Legal\PropertyTrackFile; |
16 | use App\Models\Legal\PropertyTrackFileType; | ||
15 | use App\Models\Legal\StakeholderContract; | 17 | use App\Models\Legal\StakeholderContract; |
16 | use App\Models\Legal\Treaty; | 18 | use App\Models\Legal\Treaty; |
17 | use App\Models\Legal\User; | 19 | use App\Models\Legal\User; |
... | @@ -20,6 +22,8 @@ use App\Models\Musician\AppCompanyUser; | ... | @@ -20,6 +22,8 @@ use App\Models\Musician\AppCompanyUser; |
20 | use Carbon\Carbon; | 22 | use Carbon\Carbon; |
21 | use Illuminate\Database\Eloquent\Builder; | 23 | use Illuminate\Database\Eloquent\Builder; |
22 | use Illuminate\Http\Request; | 24 | use Illuminate\Http\Request; |
25 | use Illuminate\Support\Facades\DB; | ||
26 | use Illuminate\Support\Facades\Log; | ||
23 | use Qcloud\Cos\Client; | 27 | use Qcloud\Cos\Client; |
24 | 28 | ||
25 | /** | 29 | /** |
... | @@ -238,4 +242,68 @@ class PropertyTrackService extends Service | ... | @@ -238,4 +242,68 @@ class PropertyTrackService extends Service |
238 | $res = PropertyFileType::query()->where(['type'=>'track', 'visible'=>1])->orderBy('id')->get(); | 242 | $res = PropertyFileType::query()->where(['type'=>'track', 'visible'=>1])->orderBy('id')->get(); |
239 | return Response::success($res); | 243 | return Response::success($res); |
240 | } | 244 | } |
245 | |||
246 | /** | ||
247 | * 歌曲文件存储 | ||
248 | * @return \Illuminate\Http\JsonResponse|mixed | ||
249 | */ | ||
250 | public function fileSave() | ||
251 | { | ||
252 | try { | ||
253 | |||
254 | $fileTypes = $this->request->input('file_types'); | ||
255 | |||
256 | DB::transaction(function () use ($fileTypes){ | ||
257 | |||
258 | $upload_user = ''; | ||
259 | if ($this->request->input('from') == 1) { | ||
260 | $upload_user = $this->request->get('identifier')->user_id; | ||
261 | } | ||
262 | |||
263 | //property_track_files | ||
264 | $res = PropertyTrackFile::query()->create([ | ||
265 | 'pt_id' => $this->request->get('track_id'), | ||
266 | 'name' => $this->request->input('name'), | ||
267 | 'size_byte' => $this->request->input('size'), | ||
268 | 'upload_user' => $upload_user, | ||
269 | 'upload_ip' => $this->request->input('upload_ip'), //上传客户端ip | ||
270 | 'from' => $this->request->input('from'), // 0:版权 1:分贝登录用户 2:通过分享 | ||
271 | ]); | ||
272 | |||
273 | $data = []; | ||
274 | foreach ($fileTypes as $tpye_id) { | ||
275 | $data[] = [ | ||
276 | 'pt_id' => $this->request->input('track_id'), | ||
277 | 'p_file_id' => $res->id, | ||
278 | 'p_type_id' => $tpye_id, | ||
279 | 'created_at'=> $this->now, | ||
280 | ]; | ||
281 | } | ||
282 | |||
283 | //property_track_file_types | ||
284 | PropertyTrackFileType::query()->insert($data); | ||
285 | |||
286 | //file_maps | ||
287 | FileMap::query()->create([ | ||
288 | 'user_id' => $this->request->get('identifier') ? $this->request->get('identifier')->user_id : 0, | ||
289 | 'company_id' => $this->request->get('identifier') ? $this->request->get('identifier')->company_id : 0, | ||
290 | 'name' => $this->request->input('name'), | ||
291 | 'path' => $this->request->input('dir'), | ||
292 | 'location' => $this->request->input('location'), | ||
293 | 'key' => $this->request->input('url'), | ||
294 | 'mime' => $this->request->input('mime'), | ||
295 | 'size' => $this->request->input('size'), | ||
296 | 'link' => 'property', | ||
297 | 'link_id' => $res->id, | ||
298 | ]); | ||
299 | }); | ||
300 | |||
301 | return Response::success(); | ||
302 | } catch (\Throwable $throwable) { | ||
303 | Log::info(__METHOD__, ['msg'=>$throwable->getMessage()]); | ||
304 | return Response::error(); | ||
305 | } | ||
306 | |||
307 | } | ||
308 | |||
241 | } | 309 | } | ... | ... |
... | @@ -32,7 +32,8 @@ Route::group(["prefix"=>"property"], function (){ | ... | @@ -32,7 +32,8 @@ Route::group(["prefix"=>"property"], function (){ |
32 | Route::group(["prefix"=>"property", "middleware"=>['auth.share']], function (){ | 32 | Route::group(["prefix"=>"property", "middleware"=>['auth.share']], function (){ |
33 | Route::get('/track/shareShow', 'PropertyTrackController@shareShow'); | 33 | Route::get('/track/shareShow', 'PropertyTrackController@shareShow'); |
34 | Route::get('/track/shareFile', 'PropertyTrackController@shareFile'); | 34 | Route::get('/track/shareFile', 'PropertyTrackController@shareFile'); |
35 | 35 | Route::get('/track/getCosToken', 'PropertyTrackController@getCosToken'); | |
36 | Route::post('/track/fileSave', 'PropertyTrackController@fileSave'); | ||
36 | }); | 37 | }); |
37 | 38 | ||
38 | 39 | ... | ... |
-
Please register or sign in to post a comment