gq 7 years ago
parent
commit
fffe7646f3

+ 124 - 0
server/app/Http/Controllers/Admin/Interaction/InfoController.php

xqd xqd
@@ -2,9 +2,11 @@
 
 namespace App\Http\Controllers\Admin\Interaction;
 
+use App\Models\BaseAttachmentModel;
 use App\Models\CommentInfoModel;
 use App\Models\DreamInfoModel;
 use App\Models\InteractionInfo;
+use App\Models\UserInfoModel;
 use App\Widget\Tools\VideoUpload;
 use Illuminate\Http\Request;
 use App\Http\Controllers\Admin\Controller;
@@ -85,4 +87,126 @@ class InfoController extends Controller
             return $this->showWarning('添加失败',$url);
         }
     }
+
+//    修改动态
+    public function updateInteraction(Request $reqeust) {
+        if($reqeust->method() == 'POST') {
+            return $this->_updateSave();
+        }
+        $data = InteractionInfo::find($reqeust->get('id'));
+        $arr = [];
+        for ($i = 1; $i <=9; $i++) {
+            if (!empty($data['pic'.($i)])) {
+                $arr[] = $data['pic'.($i)];
+            }
+        }
+        $data->imgs = $arr;
+        return view('admin.interaction.info.edit',compact('data'));
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _updateSave() {
+        $data = (array) request('data');
+        $interaction_id = request('id');
+        $interaction = InteractionInfo::find($interaction_id)->toArray();
+        $old_pics = [];
+        for ($i = 1; $i <=9; $i++) {
+            if (!empty($interaction['pic'.($i)])) {
+                $old_pics[] = $interaction['pic'.($i)];
+            }
+        }
+        $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);
+                }
+            }
+
+            $a = array_values($a);
+            for ($i = 1; $i <=9; $i++) {
+                if (empty($interaction['pic'.($i)])) {
+                    $c = -1;
+                    $c++;
+                    $interaction['pic'.($i)] = getenv('APP_URL').$a[$c];
+                }
+            }
+
+        }
+        $ok = InteractionInfo::find(request('id'))->update($interaction);
+        if($ok) {
+            $url[] = array('url'=>U( 'Interaction/Info/index'),'title'=>'返回列表');
+            return $this->showMessage('操作成功',urldecode(request('_referer')));
+        }else{
+            $url[] = array('url'=>U( 'Interaction/Info/index'),'title'=>'返回列表');
+            return $this->showWarning('操作失败',$url);
+        }
+    }
+
+    /**
+     * 删除
+     */
+    public function destroy(Request $reqeust)
+    {
+
+        $ok = InteractionInfo::destroy($reqeust->get('id'));
+        if ($ok) {
+            return $this->showMessage('操作成功');
+        } else {
+            return $this->showWarning("操作失败");
+        }
+    }
+
+    public function comment(Request $request)
+    {
+        $interaction_id = $request->input('id');
+        $comment_id = $request->input('comment_id');
+        if ($request->isMethod('POST')) {
+            $comment = $request->input('comment');
+            $interaction = InteractionInfo::find($interaction_id);
+            $user_id = empty($interaction->dream) ? 0 : $interaction->dream->user_id;
+            $user = UserInfoModel::find($user_id);
+            if(!empty($comment_id)){
+                $comment = CommentInfoModel::find($comment_id);
+                $arr = [
+                    'interaction_id'=>$comment->interaction_id,
+                    'user_id'=>$comment->user_id,
+                    'user_avatar'=>$comment->user_avatar,
+                    'user_nickname'=>$comment->user_nickname,
+                    'to_user_id'=>$user_id,
+                    'content'=>$comment,
+                    'to_user_avatar'=>empty($user) ? '' : $user->avatar ,
+                    'to_user_nickname'=>empty($user) ? '' : $user->nickname ,
+                ];
+//                dug
+                $ok = CommentInfoModel::create($arr);
+            }else{
+                $arr = [
+                    'interaction_id'=>$interaction_id,
+                    'user_id'=>$user_id,
+                    'content'=>$comment,
+                    'user_avatar'=>empty($user) ? '' : $user->avatar ,
+                    'user_nickname'=>empty($user) ? '' : $user->nickname ,
+                ];
+                $ok = CommentInfoModel::create($arr);
+            }
+            if ($ok) {
+                return $this->showMessage('操作成功');
+            } else {
+                return $this->showWarning("操作失败");
+            }
+        }
+     return view('admin.comment.edit',compact('interaction_id'));
+    }
 }

+ 70 - 0
server/resources/views/admin/comment/edit.blade.php

xqd
@@ -0,0 +1,70 @@
+@extends('admin.layout')
+
+@section('content')
+
+<?php
+    if(!isset($data)) $data = array();
+    if(!$data && session("data")){
+        $data = session("data");
+    }
+    if(!$data && session('_old_input')){
+        $data = session("_old_input");
+    }
+?>
+<div class="wrapper wrapper-content animated fadeInRight">
+	<div class="row">
+		<div class="col-sm-12">
+			<div class="ibox float-e-margins">
+				<div class="ibox-title">
+					<h5>评论动态</h5>
+					<div class="ibox-tools">
+						<a class="collapse-link"> <i class="fa fa-chevron-up"></i>
+						</a>
+					</div>
+				</div>
+				<div class="ibox-content">
+                    <div class="row">
+                        <div class="col-sm-3 pull-right">
+                            <a href="{{ U('Dream/Info/index')}}" class="btn btn-sm btn-primary pull-right">返回列表</a>
+                        </div>
+                    </div>
+
+		            <div class="row">
+                        <div class="col-lg-10">
+                            <form name="form_product" id="form-validation" action="" class="form-horizontal form-validation" accept-charset="UTF-8" method="post">
+
+                                    
+
+                <div class="form-group">
+                                    
+                 <label class="control-label col-sm-3">评论内容</label>
+                                    
+                   <div class="col-sm-9">
+                     <input id="" name="comment" class="form-control"  required="" aria-required="true"  placeholder="">
+                    </div>
+                                
+                </div>    
+
+                                <div class="form-group">
+                                    <label class="control-label col-sm-3">&nbsp;</label>
+                                    <div class="col-sm-9">
+                                        <input type="hidden" name="_referer" value="<?php echo urlencode(request()->server('HTTP_REFERER'));?>"/>
+                                        <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>"/>
+                                        <input type="submit" class="btn btn-success" style="margin-right:20px;">
+                                        <input type="hidden" name="interaction_id" value="{{$interaction_id}}">
+                                        <input type="reset" class="btn btn-default" >
+                                    </div>
+                                </div>
+        
+                            </form>
+                        </div>
+                        <!-- /.col-lg-10 -->
+                    </div>
+                    <!-- /.row -->
+				</div>
+			</div>
+		</div>
+	</div>
+</div>
+
+@endsection

+ 1 - 1
server/resources/views/admin/dream/info/index.blade.php

xqd
@@ -36,7 +36,7 @@
 						<thead>
     						<tr>
 								
-            <th class="sorting" data-sort="id"> id </th>
+            <th class="sorting" data-sort="id"> id</th>
             <th class="sorting" data-sort="user_id"> 用户ID </th>
             <th class="sorting" data-sort="name"> 梦想名称 </th>
             <th class="sorting" data-sort="coin"> 所需梦想币 </th>

+ 4 - 2
server/resources/views/admin/dream/interaction/view.blade.php

xqd xqd
@@ -38,8 +38,9 @@
                                     <input  class="form-control" style="text-align: right" value="{{ $item ->title}}" disabled required="" aria-required="true"  placeholder="">
                                 </div>
                                 <div class="col-sm-2 ">
-                                    <a  href="{{ U('Interaction/Info/create',['dream_id'=>$dream_id])}}" class="btn btn-sm btn-success pull-right">修改</a>
-                                    <a  href="{{ U('Dream/Info/index')}}" class="btn btn-sm btn-primary pull-right">删除</a>
+                                    <a  href="{{ U('Interaction/Info/updateInteraction',['id'=>$item->id])}}" class="btn btn-sm btn-success ">修改</a>
+                                    <a  href="{{ U('Interaction/Info/comment',['id'=>$item->id])}}" class="btn btn-sm btn-info  ">评论</a>
+                                    <a class="btn btn-sm btn-default pull-right" href="{{ U('Interaction/Info/destroy',['id'=>$item->id])}}" onclick="return confirm('你确定执行删除操作?');">删除</a>
                                 </div>
                             </div>
                             <div class="col-lg-10">
@@ -57,6 +58,7 @@
                                                 <input type="hidden" name="_referer" value="<?php echo urlencode(request()->server('HTTP_REFERER'));?>"/>
                                                 <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>"/>
                                                 <input type="submit" class="btn btn-success" style="margin-right:20px;">
+                                                <a class="btn btn-info" href="{{ U('Interaction/Info/comment',['comment_id'=>$comm->id])}}" >回复</a>
                                                 <a class="btn btn-default" href="{{ U('Comment/Info/destroy',['id'=>$comm->id])}}" onclick="return confirm('你确定执行删除操作?');">删除</a>
                                             </div>
                                         </div>