浏览代码

批量删除待导列表

wesley 6 年之前
父节点
当前提交
3b619a978f

+ 29 - 8
app/Http/Controllers/Admin/Call/ListController.php

xqd xqd xqd
@@ -8,6 +8,7 @@
  */
 namespace App\Http\Controllers\Admin\Call;
 use App\Http\Controllers\Admin\Controller;
+use App\Models\CallListModel;
 use Illuminate\Http\Request;
 use App\Repositories\Base\Criteria\OrderBy;
 use App\Repositories\Call\Lists\Criteria\MultiWhere;
@@ -25,16 +26,29 @@ class ListController extends Controller
      * 列表页
      */
     function index(Request $request) {
-        $search['keyword'] = $request->input('keyword');
-        $query = $this->repository->pushCriteria(new MultiWhere($search));
+        $search = $request->all();
+
+        $order = array();
+        if (isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $order[$request['sort_field']] = $request['sort_field_by'];
+        } else {
+            $order['id'] = 'DESC';
+        }
+
+
+        $list = $this->repository->searchList($search, $order);
+
+        $allIds = $list->pluck('id');
+        $list = $list->paginate(16);
+
+        if ($request->ajax()) {
+            $view = view('admin.call.list.data', compact('list','allIds'))->render();
+
+            return response()->json(['html' => $view]);
 
-        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
-        $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
-        }else{
-            $query = $query->pushCriteria(new OrderBy('updated_at','DESC'));
         }
-        $list = $query->paginate(16);
-        return view('admin.call.list.index',compact('list'));
+
+        return view('admin.call.list.index',compact('list','allIds'));
     }
 
 
@@ -109,4 +123,11 @@ class ListController extends Controller
             return  $this->showWarning("操作失败");
         }
     }
+
+    public function alldelete(Request $request){
+        $list_ids = $request->get('list_ids');
+        CallListModel::destroy($list_ids);
+
+        return 200;
+    }
 }

+ 18 - 0
app/Repositories/Call/ListRepository.php

xqd
@@ -17,5 +17,23 @@ class ListRepository extends Repository {
         return \App\Models\CallListModel::class;
     }
 
+    public function searchList(array $search, array $orderby = ['id' => 'desc'])
+    {
+        $currentQuery = $this->model;
+        if (isset($search['keyword']) && !empty($search['keyword'])) {
+            $keywords = '%'.$search['keyword'].'%';
+            $currentQuery = $currentQuery->where(function ($query) use ($keywords) {
+                $query->where('ip','like', $keywords)->orWhere('phone','like', $keywords);
+            });
+        };
+
+        if ($orderby && is_array($orderby)) {
+            foreach ($orderby AS $field => $value) {
+                $currentQuery = $currentQuery->orderBy($field, $value);
+            }
+        };
+
+        return $currentQuery;
+    }
     
 }

+ 15 - 0
app/Repositories/Call/RecordsRepository.php

xqd
@@ -53,6 +53,21 @@ class RecordsRepository extends Repository
             });
         };
 
+        if (isset($search['start']) && !empty($search['start'])) {
+            $start = $search['start'];
+            $currentQuery = $currentQuery->where(function ($query) use ($start) {
+                $query->where('start_time', '>=', $start);
+            });
+        };
+
+        if (isset($search['end']) && !empty($search['end'])) {
+            $end = $search['end'];
+            $currentQuery = $currentQuery->where(function ($query) use ($end) {
+                $query->where('end_time', '<=', $end);
+            });
+        };
+
+
 
         if ($orderby && is_array($orderby)) {
             foreach ($orderby AS $field => $value) {

+ 56 - 0
resources/views/admin/call/list/data.blade.php

xqd
@@ -0,0 +1,56 @@
+<table class="table table-striped table-bordered table-hover dataTables-example dataTable">
+    <thead>
+    <tr>
+        <th>
+            <label><input type="checkbox" id="checkAll"> 本页</label>
+            <label><input type="checkbox" id="checkTotal"> 全部</label>
+        </th>
+        <th class="sorting" data-sort="id"> ID</th>
+        <th class="sorting" data-sort="phone"> 电话号码</th>
+        <th class="sorting" data-sort="ip"> 拨打IP</th>
+        <th class="sorting" data-sort="sync"> 是否同步到拨打列表:</th>
+        <th class="sorting" data-sort="created_at"> 添加时间</th>
+        <th class="sorting" data-sort="updated_at"> 更新时间</th>
+        <th width="22%">相关操作</th>
+    </tr>
+    </thead>
+    <tbody>
+    @if(isset($list))
+        @foreach($list as $key => $item)
+            <tr>
+                <td>
+                    <label><input class="calllist" name='calllist_id[]' type="checkbox"
+                                  value="{{ $item->id }}" data-id="{{ $item->id }}"></label>
+                </td>
+                <td>{{ $item->id }}</td>
+                <td>{{ $item->phone }}</td>
+                <td>{{ $item->ip }}</td>
+                <td>{{ dict()->get('call_list','sync',$item->sync) }}</td>
+                <td>{{ $item->created_at }}</td>
+                <td>{{ $item->updated_at }}</td>
+                <td>
+                    @if(role('Call/List/destroy'))
+                        <a class="btn btn-sm btn-danger"
+                           href="{{ U('Call/List/destroy',['id'=>$item->id])}}"
+                           onclick="return confirm('你确定执行删除操作?');">删除</a>
+                    @endif
+                </td>
+            </tr>
+        @endforeach
+    @endif
+
+    </tbody>
+</table>
+<div class="row">
+    <div class="col-sm-6">
+        <div class="dataTables_info" id="DataTables_Table_0_info"
+             role="alert" aria-live="polite" aria-relevant="all">每页{{ $list->count() }}
+            条,共{{ $list->lastPage() }}页,总{{ $list->total() }}条。
+        </div>
+    </div>
+    <div class="col-sm-6">
+        <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
+            {!! $list->setPath('')->appends(Request::all())->render() !!}
+        </div>
+    </div>
+</div>

+ 171 - 54
resources/views/admin/call/list/index.blade.php

xqd xqd
@@ -15,7 +15,7 @@
                     <div class="form-group">
                         <div class="row">
                             <div class="col-sm-4">
-                                <form method="GET" action="" accept-charset="UTF-8">
+                                <form method="GET" action="" accept-charset="UTF-8" id="filter_list">
                                     <div class="input-group">
                                         <input type="text" class="form-control" value="{{Request::get('keyword')}}"
                                                placeholder="请输入关键词"
@@ -28,66 +28,183 @@
                                 </form>
                             </div>
 
-                            @if(role('Call/List/create'))
-                                <div class="col-sm-8 pull-right">
+
+                            <div class="col-sm-8 pull-right">
+                                @if(role('Call/List/create'))
                                     <a href="{{ U('Call/List/create')}}" class="btn btn-primary pull-right">添加</a>
-                                </div>
-                            @endif
-                        </div>
-                    </div>
+                                @endif
 
-                    <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
-                        <thead>
-                        <tr>
-
-                            <th class="sorting" data-sort="id"> ID</th>
-                            <th class="sorting" data-sort="phone"> 电话号码</th>
-                            <th class="sorting" data-sort="ip"> 拨打IP</th>
-                            <th class="sorting" data-sort="sync"> 是否同步到拨打列表:</th>
-                            <th class="sorting" data-sort="created_at"> 添加时间</th>
-                            <th class="sorting" data-sort="updated_at"> 更新时间</th>
-                            <th width="22%">相关操作</th>
-                        </tr>
-                        </thead>
-                        <tbody>
-                        @if(isset($list))
-                            @foreach($list as $key => $item)
-                                <tr>
-
-                                    <td>{{ $item->id }}</td>
-                                    <td>{{ $item->phone }}</td>
-                                    <td>{{ $item->ip }}</td>
-                                    <td>{{ dict()->get('call_list','sync',$item->sync) }}</td>
-                                    <td>{{ $item->created_at }}</td>
-                                    <td>{{ $item->updated_at }}</td>
-                                    <td>
-                                        @if(role('Call/List/destroy'))
-                                            <a class="btn btn-sm btn-danger"
-                                               href="{{ U('Call/List/destroy',['id'=>$item->id])}}"
-                                               onclick="return confirm('你确定执行删除操作?');">删除</a>
-                                        @endif
-                                    </td>
-                                </tr>
-                            @endforeach
-                        @endif
-
-                        </tbody>
-                    </table>
-                    <div class="row">
-                        <div class="col-sm-6">
-                            <div class="dataTables_info" id="DataTables_Table_0_info"
-                                 role="alert" aria-live="polite" aria-relevant="all">每页{{ $list->count() }}
-                                条,共{{ $list->lastPage() }}页,总{{ $list->total() }}条。
-                            </div>
-                        </div>
-                        <div class="col-sm-6">
-                            <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
-                                {!! $list->setPath('')->appends(Request::all())->render() !!}
+                                @if(role('Call/List/alldelete'))
+                                    <button class="btn btn-danger pull-right" id="alldelete" style="display: none">批量删除</button>
+                                @endif
                             </div>
+
+
                         </div>
                     </div>
+                    <div id="call-list">
+                        @include('admin.call.list.data')
+                    </div>
+
                 </div>
             </div>
         </div>
     </div>
+@endsection
+
+@section('js')
+    <script type="text/javascript">
+        var checkedIds = []
+
+        /*电话全选功能*/
+        $('body').on('click', '#checkAll', function () {
+            items = $('.calllist');
+
+            isChecked = $(this).prop('checked')
+            items.prop('checked', isChecked)
+            items.each(function () {
+                saveChecked($(this))
+            });
+            if (checkedIds.length) {
+                $('#alldelete').show()
+            } else {
+                $('#alldelete').hide()
+            }
+
+        })
+
+        $('body').on('click', '#checkTotal', function () {
+            items = $('.calllist');
+
+            isChecked = $(this).prop('checked')
+            items.prop('checked', isChecked)
+
+            if (isChecked == true) {
+                $('#alldelete').show()
+                checkedIds = [{{ $allIds }}][0]
+                $('#checkAll').prop('checked', true)
+            } else {
+                $('#alldelete').hide()
+                $('#checkAll').prop('checked', false)
+                checkedIds = []
+            }
+        })
+
+        $('body').on('click', '.calllist', function () {
+            items = $('.calllist');
+
+            checkedLength = $('.calllist:checked').length
+            if (checkedLength) {
+                $('#alldelete').show()
+            } else {
+                $('#alldelete').hide()
+            }
+            if (items.length == checkedLength) {
+                $('#checkAll').prop('checked', true)
+                $('#alldelete').show()
+            } else {
+                $('#checkAll').prop('checked', false)
+            }
+
+            saveChecked($(this))
+        });
+
+
+        /*批量删除*/
+        $('#alldelete').click(function () {
+            layer.confirm('你确定要删除选择的待导入电话吗?', {
+                btn: ['确定', '取消']//按钮
+            }, function (index) {
+
+                layer.close(index);
+                list_ids = checkedIds;
+                csrf_token = "{{ csrf_token() }}";
+
+                $.ajax({
+                    type: 'post',
+                    url: '{{ U('Call/list/alldelete') }}',
+                    data: {list_ids: list_ids, _token: csrf_token},
+                    success: function (data) {
+                        if (data == 200) {
+                            layer.msg('删除成功', {
+                                icon: 1,
+                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
+                            }, function () {
+                                window.location.href = window.location.href
+                            });
+
+                        }
+                    }
+
+                })
+            });
+
+
+        });
+
+        /*保存选中的项*/
+        function saveChecked(e) {
+            if (e.is(":checked") && checkedIds.indexOf(e.data("id"), 0) == -1) {
+                checkedIds.push(e.data("id"));
+            } else {
+                for (var i = 0; i < checkedIds.length; i++) {
+                    if (e.data("id") == checkedIds[i]) {
+                        checkedIds.splice(i, 1);
+                        break;
+                    }
+                }
+            }
+
+        }
+
+        /*翻页后设置选中项*/
+        function setChecked() {
+            var $boxes = $('.calllist');
+            $boxes.each(function () {
+                id = $(this).data('id')
+                if (checkedIds.indexOf(id, 0) != -1) {
+                    $(this).prop('checked', true)
+                } else {
+                    $(this).prop('checked', false)
+                }
+            })
+
+            checkedLength = $('.calllist:checked').length
+            if (checkedLength == $boxes.length) {
+                $('#checkAll').prop('checked', true)
+            }
+
+        }
+
+
+        /*通话纪录筛选*/
+        function filter_records() {
+            data = $('#filter_list').serialize();
+            $.ajax({
+                type: 'get',
+                data: data,
+            }).done(function (data) {
+                $('#call-list').html(data.html)
+            })
+        }
+
+        /*Ajax分页*/
+        $('body').on('click', '.pagination a', function (e) {
+            e.preventDefault();
+            if ($(this).attr('href') != '#') {
+                data = $('#filter_list').serialize()
+                $.ajax({
+                    url: $(this).attr('href'),
+                    type: 'get',
+                    data: data,
+                }).done(function (data) {
+                    $('#call-list').html(data.html)
+                    setChecked()
+                })
+            }
+
+        });
+
+
+    </script>
 @endsection

+ 71 - 18
resources/views/admin/call/records/index.blade.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -16,7 +16,8 @@
 
                         @if(role('Call/Records/addCallList'))
                             <div class="col-sm-8 pull-right">
-                                    <span class="btn btn-primary pull-right fa fa-phone" data-toggle="modal" data-target="#myModal2" style="display: none">添加到电话列表</span>
+                                <span class="btn btn-primary pull-right fa fa-phone" data-toggle="modal"
+                                      data-target="#myModal2" style="display: none">添加到电话列表</span>
                             </div>
                         @endif
                         {{--@if(role('Call/Records/create'))--}}
@@ -28,11 +29,14 @@
                 </div>
 
                 {{-- 过滤条件 --}}
-                <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
-                    <tr>
-                        <th> 过滤条件</th>
-                        <form method="GET" action="" accept-charset="UTF-8" id="filter_records">
-                            <th>
+                <div class="col-xl-12" style="padding: 5px">
+                    <form method="GET" action="" accept-charset="UTF-8" id="filter_records">
+                        {{ csrf_field() }}
+                        <div class="row">
+                            <div class="col-sm-1" style="font-weight: 500;text-align: right;color: #999;">
+                                <h4>过滤条件:</h4>
+                            </div>
+                            <div class="col-sm-2">
                                 <select name="ip" class="form-control" onchange="filter_records()">
                                     <option value="">拨打IP</option>
                                     <option value="172.31.20.133">172.31.20.133</option>
@@ -41,17 +45,38 @@
                                     <option value="172.31.20.136">172.31.20.136</option>
                                     <option value="172.31.20.137">172.31.20.137</option>
                                 </select>
-                            </th>
+                            </div>
 
-                            <th>
+                            <div class="col-sm-2">
                                 <select name="term_status" class="form-control" onchange="filter_records()">
                                     <option value="">接听状态</option>
                                     <option value="200">已接通</option>
                                     <option value="408">未接通</option>
                                 </select>
-                            </th>
+                            </div>
+
+
+                            <div class="col-sm-2" id="data_1">
+                                <div class="input-group date">
+                                                <span class="input-group-addon">
+                                                    <i class="fa fa-calendar"></i></span>
+                                    <input type="text" id="start" class="form-control" placeholder="开始日期" name="start"
+                                           value="{{Request::get('start') ? : ''}}">
+                                </div>
+                            </div>
+
 
-                            <th>
+                            <div class="col-sm-2" id="data_2">
+                                <div class="input-group date">
+                                                <span class="input-group-addon">
+                                                    <i class="fa fa-calendar"></i></span>
+                                    <input type="text" id="end" class="form-control" placeholder="结束日期" name="end"
+                                           value="{{Request::get('end') ? : ''}}">
+                                </div>
+                            </div>
+
+
+                            <div class="col-sm-2">
                                 <div class="input-group">
                                     <input type="text" class="form-control" value="{{Request::get('phone')}}"
                                            placeholder="请输入电话号码或标签"
@@ -61,10 +86,37 @@
                                                       style="height: 100%" onclick="filter_records()">搜索</span>
                                             </span>
                                 </div>
-                            </th>
-                        </form>
-                    </tr>
-                </table>
+                            </div>
+
+
+                        </div>
+                    </form>
+
+                </div>
+
+                {{--<table class="table table-striped table-bordered table-hover dataTables-example dataTable">--}}
+                {{--<tr>--}}
+                {{--<th> 过滤条件</th>--}}
+                {{--<form method="GET" action="" accept-charset="UTF-8" id="filter_records">--}}
+                {{--<th>--}}
+
+                {{--</th>--}}
+
+                {{--<th>--}}
+
+                {{--</th>--}}
+
+                {{--<th>--}}
+
+
+                {{--</th>--}}
+
+                {{--<th>--}}
+
+                {{--</th>--}}
+                {{--</form>--}}
+                {{--</tr>--}}
+                {{--</table>--}}
 
                 <div id="records-list">
                     @include('admin.call.records.data')
@@ -131,7 +183,7 @@
             items.each(function () {
                 saveChecked($(this))
             });
-            if (isChecked == true) {
+            if (checkedIds.length) {
                 $('.fa-phone').show()
             } else {
                 $('.fa-phone').hide()
@@ -148,7 +200,7 @@
             if (isChecked == true) {
                 $('.fa-phone').show()
                 checkedIds = [{{ $allIds }}][0]
-                $('#checkAll').prop('checked',true)
+                $('#checkAll').prop('checked', true)
             } else {
                 $('.fa-phone').hide()
                 $('#checkAll').prop('checked', false)
@@ -185,7 +237,7 @@
             $.ajax({
                 type: 'post',
                 url: '{{ U('Call/Records/addCallList') }}',
-                data: {contact_phones: contact_phones, _token: csrf_token, ip:ip},
+                data: {contact_phones: contact_phones, _token: csrf_token, ip: ip},
                 success: function (data) {
                     if (data == 200) {
                         layer.msg('导入成功', {
@@ -229,7 +281,7 @@
             })
 
             checkedLength = $('.contacts:checked').length
-            if(checkedLength == $boxes.length){
+            if (checkedLength == $boxes.length) {
                 $('#checkAll').prop('checked', true)
             }
 
@@ -238,6 +290,7 @@
 
         /*通话纪录筛选*/
         function filter_records() {
+            console.log(1)
             data = $('#filter_records').serialize();
             $.ajax({
                 type: 'get',