gq 7 年之前
父節點
當前提交
50398f8579

+ 72 - 6
server/app/Http/Controllers/Admin/Interaction/InfoController.php

xqd xqd xqd 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();
@@ -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'));
     }
 
@@ -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')));
@@ -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('操作成功');

+ 1 - 1
server/app/Http/Controllers/Api/V1/AuthController.php

xqd
@@ -303,7 +303,7 @@ class AuthController extends Controller
         $keyexist = $this->keySmsCodeExist . $phone;
         $times = Cache::store('file')->get($keyexist);
 
-        if($times>20) {
+        if($times>40) {
             return $this->error(ErrorCode::VERIFY_CODE_TOO_MUCH);
         }else{
             $times++;

+ 2 - 2
server/resources/views/admin/interaction/info/edit.blade.php

xqd xqd
@@ -64,7 +64,7 @@
                                             @endif>
                                         <label class="control-label col-sm-3" >&nbsp;</label>
                                         <div class="col-sm-9" style="width: 50%;height: 50%">
-                                            <video style="width: 300px" src="{{ $data['video'] or ''}}" poster="{{ $data['poster'] or ''}}" controls >
+                                            <video style="width: 300px" src="{{ $data['video'] or ''}}" controls >
                                             </video>
                                         </div>
                                     </div>
@@ -115,7 +115,7 @@
 @endsection
 @section('footer')
     <script>
-        if ($('input:radio[name="data[type_id]"]:checked').val() == 1) {
+        if ($('input:radio[name="data[is_video]"]:checked').val() == 1) {
             $('#is_video').show();
             $('#data_media').hide();
         }else{