|
@@ -77,6 +77,11 @@ class ImageController extends Controller |
|
@@ -77,6 +77,11 @@ class ImageController extends Controller |
|
77
|
if ($info === false) {
|
77
|
if ($info === false) {
|
|
78
|
$this->response('指定图片不存在!', Code::USER_ERROR);
|
78
|
$this->response('指定图片不存在!', Code::USER_ERROR);
|
|
79
|
}
|
79
|
}
|
|
|
|
80
|
+ //获取cos链接
|
|
|
|
81
|
+ if($info['cos'] == 1){
|
|
|
|
82
|
+ $cos = new CosService();
|
|
|
|
83
|
+ return $cos->getImageUrl($info['path']);
|
|
|
|
84
|
+ }
|
|
80
|
//查看缩略图是否存在
|
85
|
//查看缩略图是否存在
|
|
81
|
$filename = $this->config['root'] . '/' .$info['path'] . '_' . $w . '_' . $h;
|
86
|
$filename = $this->config['root'] . '/' .$info['path'] . '_' . $w . '_' . $h;
|
|
82
|
if(is_file($filename)){
|
87
|
if(is_file($filename)){
|
|
@@ -107,6 +112,7 @@ class ImageController extends Controller |
|
@@ -107,6 +112,7 @@ class ImageController extends Controller |
|
107
|
return response($content,200,$header);
|
112
|
return response($content,200,$header);
|
|
108
|
}
|
113
|
}
|
|
109
|
|
114
|
|
|
|
|
115
|
+
|
|
110
|
/**
|
116
|
/**
|
|
111
|
* @name :(图片上传)upload
|
117
|
* @name :(图片上传)upload
|
|
112
|
* @author :lyh
|
118
|
* @author :lyh
|
|
@@ -155,6 +161,7 @@ class ImageController extends Controller |
|
@@ -155,6 +161,7 @@ class ImageController extends Controller |
|
155
|
//同步数据到cos
|
161
|
//同步数据到cos
|
|
156
|
if($this->upload_location == 1){
|
162
|
if($this->upload_location == 1){
|
|
157
|
$cosService = new CosService();
|
163
|
$cosService = new CosService();
|
|
|
|
164
|
+ $is_cos = 1;//上传到cos
|
|
158
|
$cosService->uploadFile($files,$this->path,$fileName);
|
165
|
$cosService->uploadFile($files,$this->path,$fileName);
|
|
159
|
}else{
|
166
|
}else{
|
|
160
|
$res = $files->move($url,$fileName);
|
167
|
$res = $files->move($url,$fileName);
|
|
@@ -162,7 +169,7 @@ class ImageController extends Controller |
|
@@ -162,7 +169,7 @@ class ImageController extends Controller |
|
162
|
return $this->response($files->getError(), Code::USER_ERROR);
|
169
|
return $this->response($files->getError(), Code::USER_ERROR);
|
|
163
|
}
|
170
|
}
|
|
164
|
}
|
171
|
}
|
|
165
|
- $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash);
|
172
|
+ $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$is_cos);
|
|
166
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
173
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
|
167
|
}
|
174
|
}
|
|
168
|
|
175
|
|
|
@@ -173,7 +180,7 @@ class ImageController extends Controller |
|
@@ -173,7 +180,7 @@ class ImageController extends Controller |
|
173
|
* @method :post
|
180
|
* @method :post
|
|
174
|
* @time :2023/7/19 16:38
|
181
|
* @time :2023/7/19 16:38
|
|
175
|
*/
|
182
|
*/
|
|
176
|
- public function saveMysql(&$imageModel,$size,$image_type,$fileName,$hash){
|
183
|
+ public function saveMysql(&$imageModel,$size,$image_type,$fileName,$hash,$is_cos = 0){
|
|
177
|
$data = [
|
184
|
$data = [
|
|
178
|
'path' => $this->path.'/'.$fileName,
|
185
|
'path' => $this->path.'/'.$fileName,
|
|
179
|
'created_at' => date('Y-m-d H:i:s',time()),
|
186
|
'created_at' => date('Y-m-d H:i:s',time()),
|
|
@@ -181,6 +188,7 @@ class ImageController extends Controller |
|
@@ -181,6 +188,7 @@ class ImageController extends Controller |
|
181
|
'hash' => $hash,
|
188
|
'hash' => $hash,
|
|
182
|
'type'=>$image_type,
|
189
|
'type'=>$image_type,
|
|
183
|
'refer'=>$this->param['refer'] ?? 1,
|
190
|
'refer'=>$this->param['refer'] ?? 1,
|
|
|
|
191
|
+ 'is_cos'=>$is_cos
|
|
184
|
];
|
192
|
];
|
|
185
|
$rs = $imageModel->add($data);
|
193
|
$rs = $imageModel->add($data);
|
|
186
|
if ($rs === false) {
|
194
|
if ($rs === false) {
|
|
@@ -231,6 +239,7 @@ class ImageController extends Controller |
|
@@ -231,6 +239,7 @@ class ImageController extends Controller |
|
231
|
//同步数据到cos
|
239
|
//同步数据到cos
|
|
232
|
if($this->upload_location == 1){
|
240
|
if($this->upload_location == 1){
|
|
233
|
$cosService = new CosService();
|
241
|
$cosService = new CosService();
|
|
|
|
242
|
+ $is_cos = 1;//上传到cos
|
|
234
|
$cosService->uploadFile($file,$this->path,$fileName);
|
243
|
$cosService->uploadFile($file,$this->path,$fileName);
|
|
235
|
}else{
|
244
|
}else{
|
|
236
|
$res = $file->move($url,$fileName);
|
245
|
$res = $file->move($url,$fileName);
|
|
@@ -246,6 +255,7 @@ class ImageController extends Controller |
|
@@ -246,6 +255,7 @@ class ImageController extends Controller |
|
246
|
'hash' => $hash,
|
255
|
'hash' => $hash,
|
|
247
|
'type'=>$image_type,
|
256
|
'type'=>$image_type,
|
|
248
|
'refer'=>$this->param['refer'] ?? 0,
|
257
|
'refer'=>$this->param['refer'] ?? 0,
|
|
|
|
258
|
+ 'is_cos'=>$is_cos ?? 0
|
|
249
|
];
|
259
|
];
|
|
250
|
$data[] = ['image'=>$hash];
|
260
|
$data[] = ['image'=>$hash];
|
|
251
|
}
|
261
|
}
|
|
@@ -253,16 +263,30 @@ class ImageController extends Controller |
|
@@ -253,16 +263,30 @@ class ImageController extends Controller |
|
253
|
return $this->response('图片资源',Code::SUCCESS,$data);
|
263
|
return $this->response('图片资源',Code::SUCCESS,$data);
|
|
254
|
}
|
264
|
}
|
|
255
|
|
265
|
|
|
256
|
- //下载
|
266
|
+ /**
|
|
|
|
267
|
+ * @param $filename
|
|
|
|
268
|
+ * @remark :下载
|
|
|
|
269
|
+ * @name :download
|
|
|
|
270
|
+ * @author :lyh
|
|
|
|
271
|
+ * @method :post
|
|
|
|
272
|
+ * @time :2023/7/19 17:59
|
|
|
|
273
|
+ */
|
|
257
|
public function download($filename){
|
274
|
public function download($filename){
|
|
258
|
$path = Storage::path($filename);
|
275
|
$path = Storage::path($filename);
|
|
259
|
return response()->download($path,time().rand(1,100000));
|
276
|
return response()->download($path,time().rand(1,100000));
|
|
260
|
}
|
277
|
}
|
|
|
|
278
|
+
|
|
261
|
/**
|
279
|
/**
|
|
262
|
- * @name 统一返回参数
|
|
|
|
263
|
- * @return JsonResponse
|
|
|
|
264
|
- * @author :liyuhang
|
|
|
|
265
|
- * @method
|
280
|
+ * @param $msg
|
|
|
|
281
|
+ * @param string $code
|
|
|
|
282
|
+ * @param $data
|
|
|
|
283
|
+ * @param $result_code
|
|
|
|
284
|
+ * @param $type
|
|
|
|
285
|
+ * @remark :统一返回
|
|
|
|
286
|
+ * @name :response
|
|
|
|
287
|
+ * @author :lyh
|
|
|
|
288
|
+ * @method :post
|
|
|
|
289
|
+ * @time :2023/7/19 17:59
|
|
266
|
*/
|
290
|
*/
|
|
267
|
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
|
291
|
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
|
|
268
|
{
|
292
|
{
|