|
@@ -8,6 +8,7 @@
|
|
*/
|
|
*/
|
|
namespace App\Http\Controllers\Admin\Dream;
|
|
namespace App\Http\Controllers\Admin\Dream;
|
|
use App\Http\Controllers\Admin\Controller;
|
|
use App\Http\Controllers\Admin\Controller;
|
|
|
|
+use App\Models\Attachment;
|
|
use App\Models\BaseAttachmentModel;
|
|
use App\Models\BaseAttachmentModel;
|
|
use App\Models\BaseSettingsModel;
|
|
use App\Models\BaseSettingsModel;
|
|
use App\Models\DreamImages;
|
|
use App\Models\DreamImages;
|
|
@@ -113,8 +114,8 @@ class InfoController extends Controller
|
|
$data['sign'] = join(',',$data['sign']);
|
|
$data['sign'] = join(',',$data['sign']);
|
|
}
|
|
}
|
|
$pics = (array) request('pic');
|
|
$pics = (array) request('pic');
|
|
- if (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) {
|
|
@@ -127,7 +128,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;
|
|
}
|
|
}
|
|
$data['created_at'] = date('Y-m-d H:i:s');
|
|
$data['created_at'] = date('Y-m-d H:i:s');
|
|
@@ -146,7 +147,7 @@ class InfoController extends Controller
|
|
if (!empty($pics)) {
|
|
if (!empty($pics)) {
|
|
foreach ($pics['url'] as $pic) {
|
|
foreach ($pics['url'] as $pic) {
|
|
$arr[] = [
|
|
$arr[] = [
|
|
- 'pic'=>getenv('APP_URL').$pic,
|
|
|
|
|
|
+ 'pic'=>$pic,
|
|
'dream_id'=>$id,
|
|
'dream_id'=>$id,
|
|
'created_at'=>date("Y-m-d H:i:s"),
|
|
'created_at'=>date("Y-m-d H:i:s"),
|
|
'updated_at'=>date("Y-m-d H:i:s"),
|
|
'updated_at'=>date("Y-m-d H:i:s"),
|
|
@@ -187,6 +188,7 @@ class InfoController extends Controller
|
|
$data->imgs = $arr;
|
|
$data->imgs = $arr;
|
|
$data['sign'] = explode(',',$data['sign']);
|
|
$data['sign'] = explode(',',$data['sign']);
|
|
$signs = BaseSettingsModel::where('category','sign')->orderBy('id')->get();
|
|
$signs = BaseSettingsModel::where('category','sign')->orderBy('id')->get();
|
|
|
|
+// dd($data);
|
|
return view('admin.dream.info.edit',compact('data','signs'));
|
|
return view('admin.dream.info.edit',compact('data','signs'));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -229,8 +231,13 @@ class InfoController extends Controller
|
|
$data['score'] = (log($care_num,$x) + ($a/$t) + $b)*100000000000000 ;
|
|
$data['score'] = (log($care_num,$x) + ($a/$t) + $b)*100000000000000 ;
|
|
}
|
|
}
|
|
$pics = (array) request('pic');
|
|
$pics = (array) request('pic');
|
|
- if (request("file")) {
|
|
|
|
- $file = request("file");
|
|
|
|
|
|
+ if (!empty(request("video"))) {
|
|
|
|
+ $md5 = $this->getarea($dream->video);
|
|
|
|
+ if (!empty($md5)) {
|
|
|
|
+ $attache = new \App\Services\Base\Attachment();
|
|
|
|
+ $attache->deleteAttachment($md5);
|
|
|
|
+ }
|
|
|
|
+ $file = request("video");
|
|
$fileSize = $file->getSize();
|
|
$fileSize = $file->getSize();
|
|
$size = 200 * 1024 * 1024;
|
|
$size = 200 * 1024 * 1024;
|
|
if ($fileSize > $size) {
|
|
if ($fileSize > $size) {
|
|
@@ -243,45 +250,32 @@ 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;
|
|
- }else{
|
|
|
|
-// 更新是视频不存在则删除
|
|
|
|
- $dream = $this->repository->find(request('id'));
|
|
|
|
- if (is_file('.'.str_replace(getenv('APP_URL'),'',$dream->video))) {
|
|
|
|
- unlink('.'.str_replace(getenv('APP_URL'),'',$dream->video));
|
|
|
|
- }
|
|
|
|
- $dream->video = '';
|
|
|
|
- $dream->save();
|
|
|
|
}
|
|
}
|
|
if (!empty($pics)) {
|
|
if (!empty($pics)) {
|
|
// 图片不为空
|
|
// 图片不为空
|
|
$old_data_pics = $this->repository->find(request('id'))->imgs->toArray();
|
|
$old_data_pics = $this->repository->find(request('id'))->imgs->toArray();
|
|
$old_pics = array_column($old_data_pics,'pic');
|
|
$old_pics = array_column($old_data_pics,'pic');
|
|
- $a = array_diff($pics['url'],$old_pics);
|
|
|
|
- $b = array_diff($old_pics,$pics['url']);
|
|
|
|
- if (!empty($a) || !empty($b)) { //有图片变化执行
|
|
|
|
- // 删除以前图片 重新插入
|
|
|
|
- if (!empty($b)) {
|
|
|
|
- foreach ($b as $old_pic){
|
|
|
|
- if (is_file('.'.str_replace(getenv('APP_URL'),'',$old_pic))) {
|
|
|
|
- unlink('.'.str_replace(getenv('APP_URL'),'',$old_pic));
|
|
|
|
- }
|
|
|
|
- BaseAttachmentModel::where('url',$old_pic)->delete();
|
|
|
|
- DreamImages::where('pic',$old_pic)->delete();
|
|
|
|
|
|
+ //操作成功,删除原来的图片
|
|
|
|
+ foreach ($old_pics as $pic) {
|
|
|
|
+ if (!in_array($pic, $pics['url'])) {
|
|
|
|
+ $md5 = $this->getarea($pic);
|
|
|
|
+ $attache = new \App\Services\Base\Attachment();
|
|
|
|
+ $attache->deleteAttachment($md5);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ DreamImages::where('dream_id',request('id'))->delete();
|
|
$arr = []; //插入新的图片
|
|
$arr = []; //插入新的图片
|
|
- foreach ($a as $pic) {
|
|
|
|
|
|
+ foreach ($pics['url'] as $pic) {
|
|
$arr[] = [
|
|
$arr[] = [
|
|
- 'pic'=>getenv('APP_URL').$pic,
|
|
|
|
|
|
+ 'pic'=>$pic,
|
|
'dream_id'=>request('id'),
|
|
'dream_id'=>request('id'),
|
|
'created_at'=>date('Y-m-d H:i:s'),
|
|
'created_at'=>date('Y-m-d H:i:s'),
|
|
'updated_at'=>date('Y-m-d H:i:s'),
|
|
'updated_at'=>date('Y-m-d H:i:s'),
|
|
];
|
|
];
|
|
}
|
|
}
|
|
DreamImages::insert($arr);
|
|
DreamImages::insert($arr);
|
|
- }
|
|
|
|
}
|
|
}
|
|
$ok = $this->repository->update(request('id'),$data);
|
|
$ok = $this->repository->update(request('id'),$data);
|
|
if ($data['status'] == 1) { //审核通过
|
|
if ($data['status'] == 1) { //审核通过
|
|
@@ -371,4 +365,14 @@ class InfoController extends Controller
|
|
$list = $query->with('user')->where('dream_id',$dream_id)->paginate();
|
|
$list = $query->with('user')->where('dream_id',$dream_id)->paginate();
|
|
return view('admin.dream.support_dream.index',compact('list'));
|
|
return view('admin.dream.support_dream.index',compact('list'));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 获取视频图片后缀码
|
|
|
|
+ public function getarea($str)
|
|
|
|
+ {
|
|
|
|
+ $start = strripos($str, '/');
|
|
|
|
+ $first = substr($str, $start + 1);
|
|
|
|
+ $end = strripos($first, '.');
|
|
|
|
+ $last = substr($first, 0, $end);
|
|
|
|
+ return $last;
|
|
|
|
+ }
|
|
}
|
|
}
|