| xqd
@@ -16,7 +16,9 @@ class InfoController extends Controller
|
|
|
public function view(Request $request)
|
|
|
{
|
|
|
$dream_id = $request->id;
|
|
|
- $dream = DreamInfoModel::where('id',$request->id)->with('interactions')->first();
|
|
|
+ $dream = DreamInfoModel::where('id',$request->id)->with(['interactions'=> function ($query) {
|
|
|
+ $query->orderBy('id','desc');
|
|
|
+ }])->first();
|
|
|
$list = $dream->interactions;
|
|
|
foreach ($list as $item){
|
|
|
$comments = CommentInfoModel::where('interaction_id',$item->id)->orderBy('created_at')->get();
|
| xqd
@@ -101,6 +103,12 @@ class InfoController extends Controller
|
|
|
}
|
|
|
}
|
|
|
$data->imgs = $arr;
|
|
|
+ if (empty($data->video)) {
|
|
|
+ $data->is_video = 0;
|
|
|
+ }else{
|
|
|
+ $data->is_video = 1;
|
|
|
+
|
|
|
+ }
|
|
|
return view('admin.interaction.info.edit',compact('data'));
|
|
|
}
|
|
|
|
| xqd
@@ -135,16 +143,50 @@ class InfoController extends Controller
|
|
|
}
|
|
|
|
|
|
$a = array_values($a);
|
|
|
+ $c = -1;
|
|
|
for ($i = 1; $i <=9; $i++) {
|
|
|
if (empty($interaction['pic'.($i)])) {
|
|
|
- $c = -1;
|
|
|
$c++;
|
|
|
- $interaction['pic'.($i)] = getenv('APP_URL').$a[$c];
|
|
|
+ if (array_key_exists($c,$a)) {
|
|
|
+ $interaction['pic'.($i)] = getenv('APP_URL').$a[$c];
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- $ok = InteractionInfo::find(request('id'))->update($interaction);
|
|
|
+ if (!empty(request("file"))) {
|
|
|
+ $file = request("file");
|
|
|
+ $fileSize = $file->getSize();
|
|
|
+ $size = 200 * 1024 * 1024;
|
|
|
+ if ($fileSize > $size) {
|
|
|
+ return back()->with('error','请上传小于200 MB的文件!');
|
|
|
+ }
|
|
|
+ $mimeType = [
|
|
|
+ 'video/mp4',
|
|
|
+ ];
|
|
|
+ $fileMimeType = $file->getMimeType();
|
|
|
+ if (!empty($mimeType) && !in_array($fileMimeType, $mimeType)) {
|
|
|
+ return back()->with('error','File type allow MP4!');
|
|
|
+ }
|
|
|
+ if (!$file = VideoUpload::mvFile('file')) return back()->with('error','上传失败');
|
|
|
+ $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->update(['video'=>'']);
|
|
|
+ $info->video = null;
|
|
|
+ $info->save();
|
|
|
+// dd($info);
|
|
|
+ }
|
|
|
+ if (empty(request("file"))) {
|
|
|
+ $ok = InteractionInfo::find(request('id'))->update($interaction);
|
|
|
+ }else{
|
|
|
+ InteractionInfo::find(request('id'))->update($interaction);
|
|
|
+ $ok=1;
|
|
|
+ }
|
|
|
if($ok) {
|
|
|
$url[] = array('url'=>U( 'Interaction/Info/index'),'title'=>'返回列表');
|
|
|
return $this->showMessage('操作成功',urldecode(request('_referer')));
|
| xqd
@@ -159,7 +201,31 @@ class InfoController extends Controller
|
|
|
*/
|
|
|
public function destroy(Request $reqeust)
|
|
|
{
|
|
|
-
|
|
|
+ // 删除动态的图片 视频 评论...
|
|
|
+ $data = InteractionInfo::find($reqeust->get('id'));
|
|
|
+ $arr = [];
|
|
|
+ for ($i = 1; $i <=9; $i++) {
|
|
|
+ if (!empty($data['pic'.($i)])) {
|
|
|
+ $arr[] = $data['pic'.($i)];
|
|
|
+ }
|
|
|
+ }
|
|
|
+// 删除图片
|
|
|
+ if (!empty($arr)) {
|
|
|
+ foreach ($arr 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+// 删除视频
|
|
|
+ if (!empty($data->video)) {
|
|
|
+ if (is_file('.'.str_replace(getenv('APP_URL'),'',$data->video))) {
|
|
|
+ unlink('.'.str_replace(getenv('APP_URL'),'',$data->video));
|
|
|
+ }
|
|
|
+ }
|
|
|
+// 删除评论
|
|
|
+ CommentInfoModel::where('interaction_id',$reqeust->get('id'))->delete();
|
|
|
$ok = InteractionInfo::destroy($reqeust->get('id'));
|
|
|
if ($ok) {
|
|
|
return $this->showMessage('操作成功');
|