|
@@ -59,12 +59,12 @@ class InfoController extends Controller
|
|
$pics = (array) request('pic');
|
|
$pics = (array) request('pic');
|
|
if($pics){
|
|
if($pics){
|
|
foreach ($pics['url'] as $key => $pic) {
|
|
foreach ($pics['url'] as $key => $pic) {
|
|
- $data['pic'.($key+1)] = getenv('APP_URL').$pic;
|
|
|
|
|
|
+ $data['pic'.($key+1)] = $pic;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (request("file")) {
|
|
|
|
- $file = request("file");
|
|
|
|
|
|
+ if (request("video")) {
|
|
|
|
+ $file = request("video");
|
|
$fileSize = $file->getSize();
|
|
$fileSize = $file->getSize();
|
|
$size = 200 * 1024 * 1024;
|
|
$size = 200 * 1024 * 1024;
|
|
if ($fileSize > $size) {
|
|
if ($fileSize > $size) {
|
|
@@ -77,7 +77,7 @@ class InfoController extends Controller
|
|
if (!empty($mimeType) && !in_array($fileMimeType, $mimeType)) {
|
|
if (!empty($mimeType) && !in_array($fileMimeType, $mimeType)) {
|
|
return back()->with('error','File type allow MP4!');
|
|
return back()->with('error','File type allow MP4!');
|
|
}
|
|
}
|
|
- if (!$file = VideoUpload::mvFile('file')) return back()->with('error','上传失败');
|
|
|
|
|
|
+ if (!$file = VideoUpload::mvFile('video')) return back()->with('error','上传失败');
|
|
$data["video"] = $file;
|
|
$data["video"] = $file;
|
|
}
|
|
}
|
|
$id = InteractionInfo::create($data);
|
|
$id = InteractionInfo::create($data);
|
|
@@ -119,43 +119,32 @@ class InfoController extends Controller
|
|
$data = (array) request('data');
|
|
$data = (array) request('data');
|
|
$interaction_id = request('id');
|
|
$interaction_id = request('id');
|
|
$interaction = InteractionInfo::find($interaction_id)->toArray();
|
|
$interaction = InteractionInfo::find($interaction_id)->toArray();
|
|
|
|
+ $interaction['title'] = $data['title'];
|
|
$old_pics = [];
|
|
$old_pics = [];
|
|
for ($i = 1; $i <=9; $i++) {
|
|
for ($i = 1; $i <=9; $i++) {
|
|
if (!empty($interaction['pic'.($i)])) {
|
|
if (!empty($interaction['pic'.($i)])) {
|
|
- $old_pics[] = $interaction['pic'.($i)];
|
|
|
|
|
|
+ $old_pics[$i] = $interaction['pic'.($i)];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
$new_pics = (array) request('pic');
|
|
$new_pics = (array) request('pic');
|
|
- $a = array_diff($new_pics['url'],$old_pics);
|
|
|
|
- $b = array_diff($old_pics,$new_pics['url']);
|
|
|
|
- if (!empty($a) || !empty($b)) { //有图片变化执行
|
|
|
|
- // 删除以前图片 重新插入
|
|
|
|
- if (!empty($b)) {
|
|
|
|
- foreach ($b as $old_pic){
|
|
|
|
- $key = array_search($old_pic,$interaction);
|
|
|
|
- $interaction[$key] = '';
|
|
|
|
- if (is_file('.'.str_replace(getenv('APP_URL'),'',$old_pic))) {
|
|
|
|
- unlink('.'.str_replace(getenv('APP_URL'),'',$old_pic));
|
|
|
|
- }
|
|
|
|
- BaseAttachmentModel::where('url',$old_pic)->delete();
|
|
|
|
- InteractionInfo::find(request('id'))->update($interaction);
|
|
|
|
- }
|
|
|
|
|
|
+ if (!empty($new_pics)) {
|
|
|
|
+// 图片不为空
|
|
|
|
+ //操作成功,删除原来的图片
|
|
|
|
+ foreach ($new_pics['url'] as $key => $pic) {
|
|
|
|
+ $interaction['pic'.($key+1)] = $pic;
|
|
}
|
|
}
|
|
-
|
|
|
|
- $a = array_values($a);
|
|
|
|
- $c = -1;
|
|
|
|
- for ($i = 1; $i <=9; $i++) {
|
|
|
|
- if (empty($interaction['pic'.($i)])) {
|
|
|
|
- $c++;
|
|
|
|
- if (array_key_exists($c,$a)) {
|
|
|
|
- $interaction['pic'.($i)] = getenv('APP_URL').$a[$c];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ foreach ($old_pics as $k => $pic) {
|
|
|
|
+ if (!in_array($pic, $new_pics['url'])) {
|
|
|
|
+ $md5 = $this->getarea($pic);
|
|
|
|
+ $attache = new \App\Services\Base\Attachment();
|
|
|
|
+ $attache->deleteAttachment($md5);
|
|
|
|
+ $interaction['pic'.($k+1)] = '';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (!empty(request("file"))) {
|
|
|
|
- $file = request("file");
|
|
|
|
|
|
+ if (!empty(request("video"))) {
|
|
|
|
+ $file = request("video");
|
|
$fileSize = $file->getSize();
|
|
$fileSize = $file->getSize();
|
|
$size = 200 * 1024 * 1024;
|
|
$size = 200 * 1024 * 1024;
|
|
if ($fileSize > $size) {
|
|
if ($fileSize > $size) {
|
|
@@ -168,16 +157,8 @@ class InfoController extends Controller
|
|
if (!empty($mimeType) && !in_array($fileMimeType, $mimeType)) {
|
|
if (!empty($mimeType) && !in_array($fileMimeType, $mimeType)) {
|
|
return back()->with('error','File type allow MP4!');
|
|
return back()->with('error','File type allow MP4!');
|
|
}
|
|
}
|
|
- if (!$file = VideoUpload::mvFile('file')) return back()->with('error','上传失败');
|
|
|
|
|
|
+ if (!$file = VideoUpload::mvFile('video')) return back()->with('error','上传失败');
|
|
$interaction["video"] = $file;
|
|
$interaction["video"] = $file;
|
|
- }else{
|
|
|
|
-// 更新是视频不存在则删除
|
|
|
|
- $info = InteractionInfo::find(request('id'));
|
|
|
|
- if (is_file('.'.str_replace(getenv('APP_URL'),'',$info->video))) {
|
|
|
|
- unlink('.'.str_replace(getenv('APP_URL'),'',$info->video));
|
|
|
|
- }
|
|
|
|
- $info->video = null;
|
|
|
|
- $info->save();
|
|
|
|
}
|
|
}
|
|
$ok = InteractionInfo::find(request('id'))->update($interaction);
|
|
$ok = InteractionInfo::find(request('id'))->update($interaction);
|
|
if($ok) {
|
|
if($ok) {
|
|
@@ -270,4 +251,13 @@ class InfoController extends Controller
|
|
}
|
|
}
|
|
return view('admin.comment.edit',compact('interaction_id'));
|
|
return view('admin.comment.edit',compact('interaction_id'));
|
|
}
|
|
}
|
|
|
|
+ // 获取视频图片后缀码
|
|
|
|
+ public function getarea($str)
|
|
|
|
+ {
|
|
|
|
+ $start = strripos($str, '/');
|
|
|
|
+ $first = substr($str, $start + 1);
|
|
|
|
+ $end = strripos($first, '.');
|
|
|
|
+ $last = substr($first, 0, $end);
|
|
|
|
+ return $last;
|
|
|
|
+ }
|
|
}
|
|
}
|