BaseRepository.php
3.32 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
<?php
namespace App\Modules\Repositories;
/**
* Class BaseRepository.
*/
use App\Exceptions\GeneralException;
use YueCode\Cos\QCloudCos;
class BaseRepository
{
/**
* @return mixed
*/
public function getAll()
{
return $this->query()->where('auto_send', 0)->get();
}
/**
* @return mixed
*/
public function getCount()
{
return $this->query()->count();
}
/**
* @param $id
*
* @return mixed
*/
public function find($id)
{
return $this->query()->find($id);
}
/**
* @return mixed
*/
public function query()
{
return call_user_func(static::MODEL . '::query');
}
//上传音频文件按
public function audio()
{
$allow_file_type =['mp3','mp4'];
if(!$_FILES||!$_FILES['audio_url']){
throw new GeneralException(trans('exceptions.backend.explain_info.create_error')); //请选上传文件
}
$file_name = $_FILES['audio_url']['name'];
$tmp_file_extend = explode('.',$file_name); //mp3
if(!in_array(strtolower(end($tmp_file_extend)),$allow_file_type)) {
throw new GeneralException(trans('exceptions.backend.explain_info.type_error')); // '请选择指定上传的音频类型'
}
//限制音频大小
if($_FILES['audio_url']['size']>25004900){
throw new GeneralException(trans('exceptions.backend.explain_info.size_error'));// '请选择指定上传的大小'
}
//上传cdn
$num =md5(uniqid());
$path ="/audio/".$num.".mp3";
$dd=QCloudCos::upload('dev',$_FILES['audio_url']['tmp_name'],$path);
if($dd){
$info =json_decode($dd,true);
$info['path'] =$path;
$info['size'] =$_FILES['audio_url']['size'];
return $info ;
} else{
throw new GeneralException(trans('exceptions.backend.explain_info.cos_error'));
return false;
}
}
public function imgup($backet)
{
$allow_file_type =['jpg','png','gif','jpeg'];
if(!$_FILES||!$_FILES[$backet]){
throw new GeneralException(trans('exceptions.backend.explain_info.upload_error')); //请选上传文件
}
$file_name = $_FILES[$backet]['name'];
$tmp_file_extend = explode('.',$file_name);
if(!in_array(strtolower(end($tmp_file_extend)),$allow_file_type)) {
throw new GeneralException(trans('exceptions.backend.explain_info.type_error')); // '请选择指定上传的图片类型'
}
if($_FILES[$backet]['size']>1502480)
{
throw new GeneralException(trans('exceptions.backend.explain_info.size_error'));// '请选择指定上传的大小'
}
//上传cdn
$num =md5(uniqid());
$path ="/img/".$num.".png";
$dd=QCloudCos::upload('dev',$_FILES[$backet]['tmp_name'],$path);
if($dd){
$info =json_decode($dd,true);
$info['path'] =$path;
$info['size'] =$_FILES[$backet]['size'];
return $info ;
} else{
throw new GeneralException(trans('exceptions.backend.explain_info.cos_error'));
return false;
}
}
}